Loading...
Searching...
No Matches
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.

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

## dynl_close()

int dynl_close | ( | void * | handle | ) |

Definition at line 170 of file mod_raw.cc.

{
return(dlclose (handle));
}

## dynl_error()

const char * dynl_error | ( |  | ) |

Definition at line 175 of file mod_raw.cc.

{
return(dlerror());
}

## dynl_open()

void * dynl_open | ( | char * | filename | ) |

Definition at line 142 of file mod_raw.cc.

{
return dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
#if 0
// glibc 2.2:
if ((filename==NULL) || (dlopen(filename,RTLD_NOW|RTLD_NOLOAD)==NULL))
return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
else
Werror("module %s already loaded",filename);
return NULL;
// alternative
// return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
#endif
}
Werror
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.

{
void* handle = NULL;
char* binary_name_so=NULL;
BOOLEAN found=FALSE;
// try P_PROCS_DIR (%P)
char* proc_path = feGetResource('P');
if (proc_path != NULL)
{
char *p;
char *q;
p=proc_path;
int binary_name_so_length = 3 + strlen(DL_TAIL) + strlen(binary_name) + strlen(DIR_SEPP) + strlen(proc_path);
binary_name_so = (char *)omAlloc0( binary_name_so_length * sizeof(char) );
while((p!=NULL)&&(*p!='\0'))
{
q=strchr(p,fePathSep);
if (q!=NULL) *q='\0';
strcpy(binary_name_so,p);
if (q!=NULL) *q=fePathSep;
strcat(binary_name_so,DIR_SEPP);
strcat(binary_name_so,binary_name);
strcat(binary_name_so,DL_TAIL);
if(!access(binary_name_so, R_OK)) { found=TRUE; break; }
if (q!=NULL) p=q+1; else p=NULL;
}
if (found) handle = dynl_open(binary_name_so);
}
if (handle == NULL && ! warn_handle)
{
Warn("Could not find dynamic library: %s%s (path %s)",
binary_name, DL_TAIL,proc_path);
if (found) Warn("Error message from system: %s", dynl_error());
if (msg != NULL) Warn("%s", msg);
WarnS("See the INSTALL section in the Singular manual for details.");
warn_handle = TRUE;
}
omfree((ADDRESS)binary_name_so );
return handle;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
p
int p
Definition cfModGcd.cc:4086
Warn
#define Warn
Definition emacs.cc:77
WarnS
#define WarnS
Definition emacs.cc:78
found
bool found
Definition facFactorize.cc:55
feGetResource
char * feGetResource(const char id, int warn)
Definition feResource.cc:145
fePathSep
const char fePathSep
Definition feResource.h:58
DIR_SEPP
#define DIR_SEPP
Definition feResource.h:7
warn_handle
STATIC_VAR BOOLEAN warn_handle
Definition mod_raw.cc:38
DL_TAIL
#define DL_TAIL
Definition mod_raw.cc:41
dynl_error
const char * dynl_error()
Definition mod_raw.cc:175
dynl_open
void * dynl_open(char *filename)
Definition mod_raw.cc:142
omfree
#define omfree(addr)
Definition omAllocDecl.h:237
omAlloc0
#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.

{
if (handle == DYNL_KERNEL_HANDLE)
{
if (kernel_handle == NULL)
kernel_handle = dynl_open(NULL);
handle = kernel_handle;
}
return(dlsym(handle, symbol));
}
kernel_handle
STATIC_VAR void * kernel_handle
Definition mod_raw.cc:134
DYNL_KERNEL_HANDLE
#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.

{
void *proc_ptr = NULL;
if (handle != NULL)
{
proc_ptr = dynl_sym(handle, proc);
if (proc_ptr == NULL && ! warn_proc)
{
WarnS("Could load a procedure from a dynamic library");
Warn("Error message from system: %s", dynl_error());
if (msg != NULL) Warn("%s", msg);
WarnS("See the INSTALL section in the Singular manual for details.");
warn_proc = TRUE;
}
}
return proc_ptr;
}
proc
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
dynl_sym
void * dynl_sym(void *handle, const char *symbol)
Definition mod_raw.cc:159
warn_proc
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.