Macros | Enumerations | Functions
mod_raw.h File Reference

Go to the source code of this file.

Macros

#define DYNL_KERNEL_HANDLE   ((void*) 0x1)
 

Enumerations

enum  lib_types {
  LT_NONE, LT_NOTFOUND, LT_SINGULAR, LT_ELF,
  LT_HPUX, LT_MACH_O, LT_BUILTIN, LT_DLL
}
 

Functions

void * dynl_open_binary_warn (const char *binary_name, const char *msg=NULL)
 
void * dynl_sym_warn (void *handle, const char *proc, const char *msg=NULL)
 
int dynl_check_opened (char *filename)
 
void * dynl_open (char *filename)
 
void * dynl_sym (void *handle, const char *symbol)
 
int dynl_close (void *handle)
 
const char * dynl_error ()
 

Macro Definition Documentation

◆ DYNL_KERNEL_HANDLE

#define DYNL_KERNEL_HANDLE   ((void*) 0x1)

Definition at line 32 of file mod_raw.h.

Enumeration Type Documentation

◆ lib_types

enum lib_types
Enumerator
LT_NONE 
LT_NOTFOUND 
LT_SINGULAR 
LT_ELF 
LT_HPUX 
LT_MACH_O 
LT_BUILTIN 
LT_DLL 

Definition at line 16 of file mod_raw.h.

Function Documentation

◆ dynl_check_opened()

int dynl_check_opened ( char *  filename)

Definition at line 138 of file mod_raw.cc.

141 {
142  return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
143 }
#define NULL
Definition: omList.c:12

◆ dynl_close()

int dynl_close ( void *  handle)

Definition at line 170 of file mod_raw.cc.

171 {
172  return(dlclose (handle));
173 }

◆ dynl_error()

const char* dynl_error ( )

Definition at line 175 of file mod_raw.cc.

176 {
177  return(dlerror());
178 }

◆ dynl_open()

void* dynl_open ( char *  filename)

Definition at line 145 of file mod_raw.cc.

148 {
149 // glibc 2.2:
150  if ((filename==NULL) || (dlopen(filename,RTLD_NOW|RTLD_NOLOAD)==NULL))
151  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
152  else
153  Werror("module %s already loaded",filename);
154  return NULL;
155 // alternative
156 // return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
157 }
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ dynl_open_binary_warn()

void* dynl_open_binary_warn ( const char *  binary_name,
const char *  msg = NULL 
)

Definition at line 48 of file mod_raw.cc.

49 {
50  void* handle = NULL;
51  char* binary_name_so=NULL;
53 
54  // try P_PROCS_DIR (%P)
55  char* proc_path = feGetResource('P');
56  if (proc_path != NULL)
57  {
58  char *p;
59  char *q;
60  p=proc_path;
61  int binary_name_so_length = 3 + strlen(DL_TAIL) + strlen(binary_name) + strlen(DIR_SEPP) + strlen(proc_path);
62  binary_name_so = (char *)omAlloc0( binary_name_so_length * sizeof(char) );
63  while((p!=NULL)&&(*p!='\0'))
64  {
65  q=strchr(p,fePathSep);
66  if (q!=NULL) *q='\0';
67  strcpy(binary_name_so,p);
68  if (q!=NULL) *q=fePathSep;
69  strcat(binary_name_so,DIR_SEPP);
70  strcat(binary_name_so,binary_name);
71  strcat(binary_name_so,DL_TAIL);
72  if(!access(binary_name_so, R_OK)) { found=TRUE; break; }
73  if (q!=NULL) p=q+1; else p=NULL;
74  }
75  if (found) handle = dynl_open(binary_name_so);
76  }
77 
78  if (handle == NULL && ! warn_handle)
79  {
80  Warn("Could not find dynamic library: %s%s (path %s)",
81  binary_name, DL_TAIL,proc_path);
82  if (found) Warn("Error message from system: %s", dynl_error());
83  if (msg != NULL) Warn("%s", msg);
84  WarnS("See the INSTALL section in the Singular manual for details.");
85  warn_handle = TRUE;
86  }
87  omfree((ADDRESS)binary_name_so );
88 
89  return handle;
90 }
#define DL_TAIL
Definition: mod_raw.cc:44
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
void * ADDRESS
Definition: auxiliary.h:133
const char fePathSep
Definition: feResource.h:57
#define WarnS
Definition: emacs.cc:78
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
bool found
Definition: facFactorize.cc:56
static BOOLEAN warn_handle
Definition: mod_raw.cc:41
char * feGetResource(const char id, int warn)
Definition: feResource.cc:155
#define omfree(addr)
Definition: omAllocDecl.h:237
#define DIR_SEPP
Definition: feResource.h:7
#define NULL
Definition: omList.c:12
int p
Definition: cfModGcd.cc:4019
int BOOLEAN
Definition: auxiliary.h:85
#define omAlloc0(size)
Definition: omAllocDecl.h:211
const char * dynl_error()
Definition: mod_raw.cc:175
#define Warn
Definition: emacs.cc:77

◆ dynl_sym()

void* dynl_sym ( void *  handle,
const char *  symbol 
)

Definition at line 159 of file mod_raw.cc.

160 {
161  if (handle == DYNL_KERNEL_HANDLE)
162  {
163  if (kernel_handle == NULL)
165  handle = kernel_handle;
166  }
167  return(dlsym(handle, symbol));
168 }
static void * kernel_handle
Definition: mod_raw.cc:137
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
#define NULL
Definition: omList.c:12
#define DYNL_KERNEL_HANDLE
Definition: mod_raw.h:32

◆ dynl_sym_warn()

void* dynl_sym_warn ( void *  handle,
const char *  proc,
const char *  msg = NULL 
)

Definition at line 92 of file mod_raw.cc.

93 {
94  void *proc_ptr = NULL;
95  if (handle != NULL)
96  {
97  proc_ptr = dynl_sym(handle, proc);
98  if (proc_ptr == NULL && ! warn_proc)
99  {
100  WarnS("Could load a procedure from a dynamic library");
101  Warn("Error message from system: %s", dynl_error());
102  if (msg != NULL) Warn("%s", msg);
103  WarnS("See the INSTALL section in the Singular manual for details.");
104  warn_proc = TRUE;
105  }
106  }
107  return proc_ptr;
108 }
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:16
#define TRUE
Definition: auxiliary.h:98
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:159
#define WarnS
Definition: emacs.cc:78
static BOOLEAN warn_proc
Definition: mod_raw.cc:42
#define NULL
Definition: omList.c:12
const char * dynl_error()
Definition: mod_raw.cc:175
#define Warn
Definition: emacs.cc:77