My Project
Loading...
Searching...
No Matches
Macros | Functions | Variables
mod_raw.cc File Reference
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include "misc/auxiliary.h"
#include "reporter/reporter.h"
#include "resources/feResource.h"
#include "omalloc/omalloc.h"
#include "mod_raw.h"
#include <dlfcn.h>

Go to the source code of this file.

Macros

#define DL_TAIL   ".so"
 
#define DL_IMPLEMENTED
 

Functions

void * dynl_open_binary_warn (const char *binary_name, const char *msg)
 
void * dynl_sym_warn (void *handle, const char *proc, const char *msg)
 
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 ()
 

Variables

STATIC_VAR BOOLEAN warn_handle = FALSE
 
STATIC_VAR BOOLEAN warn_proc = FALSE
 
STATIC_VAR void * kernel_handle = NULL
 

Macro Definition Documentation

◆ DL_IMPLEMENTED

#define DL_IMPLEMENTED

Definition at line 132 of file mod_raw.cc.

◆ DL_TAIL

#define DL_TAIL   ".so"

Definition at line 41 of file mod_raw.cc.

Function Documentation

◆ dynl_check_opened()

int dynl_check_opened ( char *  filename)

Definition at line 135 of file mod_raw.cc.

138{
139 return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
140}
#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 142 of file mod_raw.cc.

145{
146 return dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
147#if 0
148// glibc 2.2:
149 if ((filename==NULL) || (dlopen(filename,RTLD_NOW|RTLD_NOLOAD)==NULL))
150 return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
151 else
152 Werror("module %s already loaded",filename);
153 return NULL;
154// alternative
155// return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
156#endif
157}
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 
)

Definition at line 45 of file mod_raw.cc.

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

◆ 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_VAR void * kernel_handle
Definition: mod_raw.cc:134
#define DYNL_KERNEL_HANDLE
Definition: mod_raw.h:32

◆ dynl_sym_warn()

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

Definition at line 89 of file mod_raw.cc.

90{
91 void *proc_ptr = NULL;
92 if (handle != NULL)
93 {
94 proc_ptr = dynl_sym(handle, proc);
95 if (proc_ptr == NULL && ! warn_proc)
96 {
97 WarnS("Could load a procedure from a dynamic library");
98 Warn("Error message from system: %s", dynl_error());
99 if (msg != NULL) Warn("%s", msg);
100 WarnS("See the INSTALL section in the Singular manual for details.");
101 warn_proc = TRUE;
102 }
103 }
104 return proc_ptr;
105}
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:16
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:159
STATIC_VAR BOOLEAN warn_proc
Definition: mod_raw.cc:39

Variable Documentation

◆ kernel_handle

STATIC_VAR void* kernel_handle = NULL

Definition at line 134 of file mod_raw.cc.

◆ warn_handle

STATIC_VAR BOOLEAN warn_handle = FALSE

Definition at line 38 of file mod_raw.cc.

◆ warn_proc

STATIC_VAR BOOLEAN warn_proc = FALSE

Definition at line 39 of file mod_raw.cc.