From 9c3fa668f3699f575decca21f5fd0299c9ecb8ba Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 27 Feb 2009 23:26:20 +0000 Subject: [PATCH] Added epicsLoadLibrary() and some implementations. --- src/libCom/osi/epicsFindSymbol.h | 7 ++-- src/libCom/osi/os/Darwin/osdFindSymbol.c | 27 +++++++++++++ src/libCom/osi/os/Linux/osdFindSymbol.c | 27 +++++++++++++ src/libCom/osi/os/default/osdFindSymbol.c | 11 ++++-- src/libCom/osi/os/solaris/osdFindSymbol.c | 27 +++++++++++++ src/libCom/osi/os/vxWorks/osdFindSymbol.c | 47 +++++++++++++++++++++-- 6 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 src/libCom/osi/os/Darwin/osdFindSymbol.c create mode 100644 src/libCom/osi/os/Linux/osdFindSymbol.c create mode 100644 src/libCom/osi/os/solaris/osdFindSymbol.c diff --git a/src/libCom/osi/epicsFindSymbol.h b/src/libCom/osi/epicsFindSymbol.h index b64f64de8..9935834da 100644 --- a/src/libCom/osi/epicsFindSymbol.h +++ b/src/libCom/osi/epicsFindSymbol.h @@ -1,10 +1,9 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ #ifndef epicsFindSymbolh @@ -16,6 +15,8 @@ extern "C" { #include "shareLib.h" +epicsShareFunc void * epicsLoadLibrary(const char *name); +epicsShareFunc const char *epicsLoadError(void); epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name); #ifdef __cplusplus diff --git a/src/libCom/osi/os/Darwin/osdFindSymbol.c b/src/libCom/osi/os/Darwin/osdFindSymbol.c new file mode 100644 index 000000000..967c220cd --- /dev/null +++ b/src/libCom/osi/os/Darwin/osdFindSymbol.c @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* osi/os/default/epicsFindSymbol.c */ + +#include + +#define epicsExportSharedSymbols +#include "epicsFindSymbol.h" + +epicsShareFunc void * epicsLoadLibrary(const char *name) +{ + return dlopen(name, RTLD_LAZY | RTLD_GLOBAL); +} + +epicsShareFunc const char *epicsLoadError(void) +{ + return dlerror(); +} + +epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name) +{ + return dlsym(0, name); +} diff --git a/src/libCom/osi/os/Linux/osdFindSymbol.c b/src/libCom/osi/os/Linux/osdFindSymbol.c new file mode 100644 index 000000000..967c220cd --- /dev/null +++ b/src/libCom/osi/os/Linux/osdFindSymbol.c @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* osi/os/default/epicsFindSymbol.c */ + +#include + +#define epicsExportSharedSymbols +#include "epicsFindSymbol.h" + +epicsShareFunc void * epicsLoadLibrary(const char *name) +{ + return dlopen(name, RTLD_LAZY | RTLD_GLOBAL); +} + +epicsShareFunc const char *epicsLoadError(void) +{ + return dlerror(); +} + +epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name) +{ + return dlsym(0, name); +} diff --git a/src/libCom/osi/os/default/osdFindSymbol.c b/src/libCom/osi/os/default/osdFindSymbol.c index 03ac1868a..99ca2832d 100644 --- a/src/libCom/osi/os/default/osdFindSymbol.c +++ b/src/libCom/osi/os/default/osdFindSymbol.c @@ -1,10 +1,9 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ /* osi/os/default/epicsFindSymbol.c */ @@ -12,5 +11,11 @@ #define epicsExportSharedSymbols #include "epicsFindSymbol.h" +epicsShareFunc void * epicsLoadLibrary(const char *name) +{ return 0; } + +epicsShareFunc const char *epicsLoadError(void) +{ return "epicsLoadLibrary not implemented"; } + epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name) { return 0;} diff --git a/src/libCom/osi/os/solaris/osdFindSymbol.c b/src/libCom/osi/os/solaris/osdFindSymbol.c new file mode 100644 index 000000000..967c220cd --- /dev/null +++ b/src/libCom/osi/os/solaris/osdFindSymbol.c @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* osi/os/default/epicsFindSymbol.c */ + +#include + +#define epicsExportSharedSymbols +#include "epicsFindSymbol.h" + +epicsShareFunc void * epicsLoadLibrary(const char *name) +{ + return dlopen(name, RTLD_LAZY | RTLD_GLOBAL); +} + +epicsShareFunc const char *epicsLoadError(void) +{ + return dlerror(); +} + +epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name) +{ + return dlsym(0, name); +} diff --git a/src/libCom/osi/os/vxWorks/osdFindSymbol.c b/src/libCom/osi/os/vxWorks/osdFindSymbol.c index 2acb598bb..fbed10f9c 100644 --- a/src/libCom/osi/os/vxWorks/osdFindSymbol.c +++ b/src/libCom/osi/os/vxWorks/osdFindSymbol.c @@ -1,10 +1,9 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ /* osi/os/vxWorks/osiFindSymbol */ @@ -15,9 +14,51 @@ #include #include #include +#include +#include +#include #include "dbmf.h" +#include "epicsString.h" #include "epicsFindSymbol.h" + +static char *errmsg = NULL; +static char *oldmsg = NULL; + +epicsShareFunc void * epicsLoadLibrary(const char *name) +{ + MODULE_ID m = 0; + int fd; + + if (oldmsg) { + free(oldmsg); + oldmsg = NULL; + } + if (errmsg) { + free(errmsg); + errmsg = NULL; + } + + fd = open(name, O_RDONLY, 0); + if (fd != ERROR) { + m = loadModule(fd, GLOBAL_SYMBOLS); + close(fd); + } + + if (!m) { + errmsg = epicsStrDup(strerror(errno)); + } + return m; +} + +epicsShareFunc const char *epicsLoadError(void) +{ + if (oldmsg) free(oldmsg); + oldmsg = errmsg; + errmsg = NULL; + return oldmsg; +} + void *epicsFindSymbol(const char *name) { STATUS status;