dlsym.3c (2010 09)
d
dlsym(3C) dlsym(3C)
this "real"
malloc() could be another user-defined interface that added its own value and then used
RTLD_NEXT to find the system malloc()
.
EXAMPLES
The following example shows how you can use
dlopen() and dlsym() to access either function or data
objects. For simplicity, error checking has been omitted.
void *handle;
int i, *iptr;
int (*fptr)(int);
/* open the needed object */
handle = dlopen("/usr/mydir/mylib.sl", RTLD_LAZY);
/* find address of function and data objects */
fptr = (int (*)(int))dlsym(handle, "some_function");
iptr = (int *)dlsym(handle, "int_object");
/* invoke function, passing value of integer as a parameter */
i = (*fptr)(*iptr);
The next example shows how one can use
dlsym() with RTLD_NEXT to add functionality to an existing
interface. Again, error checking has been omitted.
extern void record_malloc(void *, size_t);
void *
malloc(size_t sz)
{
void *ptr;
void *(*real_malloc)(size_t);
real_malloc = (void * (*) (size_t))
dlsym(RTLD_NEXT, "malloc");
ptr = (*real_malloc)(sz);
record_malloc(ptr, sz);
return ptr;
}
SEE ALSO
dlclose(3C), dlerrno(3C), dlerror(3C), dlopen(3C).
Texts and Tutorial s
HP-UX Linker and Libraries Online User Guide
(See the
+help option)
HP-UX Linker and Libraries User’s Guide
(See manuals (5) for ordering information)
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010