This is Unofficial EPICS BASE Doxygen Site
osdFindSymbol.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /* osi/os/vxWorks/osdFindSymbol */
10 
11 /* This is needed for vxWorks 6.8 to prevent an obnoxious compiler warning */
12 #define _VSB_CONFIG_FILE <../lib/h/config/vsbConfig.h>
13 
14 #include <vxWorks.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <symLib.h>
19 #include <sysSymTbl.h>
20 #include <fcntl.h>
21 #include <unistd.h>
22 #include <loadLib.h>
23 
24 #include "dbmf.h"
25 #include "epicsString.h"
26 #include "epicsFindSymbol.h"
27 
28 static char *errmsg = NULL;
29 static char *oldmsg = NULL;
30 
31 LIBCOM_API void * epicsLoadLibrary(const char *name)
32 {
33  MODULE_ID m = 0;
34  int fd;
35 
36  if (oldmsg) {
37  free(oldmsg);
38  oldmsg = NULL;
39  }
40  if (errmsg) {
41  free(errmsg);
42  errmsg = NULL;
43  }
44 
45  fd = open(name, O_RDONLY, 0);
46  if (fd != ERROR) {
47  m = loadModule(fd, GLOBAL_SYMBOLS);
48  close(fd);
49  }
50 
51  if (!m) {
52  errmsg = epicsStrDup(strerror(errno));
53  }
54  return m;
55 }
56 
57 LIBCOM_API const char *epicsLoadError(void)
58 {
59  if (oldmsg)
60  free(oldmsg);
61 
62  oldmsg = errmsg;
63  errmsg = NULL;
64  return oldmsg;
65 }
66 
67 void *epicsFindSymbol(const char *name)
68 {
69  STATUS status;
70 
71 #if _WRS_VXWORKS_MAJOR < 6 || _WRS_VXWORKS_MINOR < 9
72  char *pvalue;
73  SYM_TYPE type;
74 
75  status = symFindByName(sysSymTbl, (char *)name, &pvalue, &type);
76  if (!status)
77  return pvalue;
78 
79  if (name[0] == '_' ) {
80  status = symFindByName(sysSymTbl, (char *)(name+1), &pvalue, &type);
81  }
82 #if CPU_FAMILY == MC680X0
83  else {
84  char *pname = dbmfMalloc(strlen(name) + 2);
85 
86  pname[0] = '_';
87  strcpy(pname + 1, name);
88  status = symFindByName(sysSymTbl, pname, &pvalue, &type);
89  dbmfFree(pname);
90  }
91 #endif
92  if (!status)
93  return pvalue;
94 
95 #else
96 
97  SYMBOL_DESC symDesc;
98 
99  memset(&symDesc, 0, sizeof(SYMBOL_DESC));
100  symDesc.mask = SYM_FIND_BY_NAME;
101  symDesc.name = (char *) name;
102  status = symFind(sysSymTbl, &symDesc);
103  if (!status)
104  return symDesc.value;
105 
106  if (name[0] == '_') {
107  symDesc.name++;
108  status = symFind(sysSymTbl, &symDesc);
109  if (!status)
110  return symDesc.value;
111  }
112  /* No need to prepend an '_'; 68K-only, no longer supported */
113 #endif
114  return 0;
115 }
LIBCOM_API void * epicsLoadLibrary(const char *name)
Definition: osdFindSymbol.c:13
LIBCOM_API void *epicsStdCall epicsFindSymbol(const char *name)
Definition: osdFindSymbol.c:23
pvd::Status status
pvd::StructureConstPtr type
#define NULL
Definition: catime.c:38
A library to manage storage that is allocated and quickly freed.
void dbmfFree(void *mem)
Free the memory allocated by dbmfMalloc.
Definition: dbmf.c:175
char * epicsStrDup(const char *s)
Definition: epicsString.c:233
LIBCOM_API const char * epicsLoadError(void)
Definition: osdFindSymbol.c:18
const std::string pname
void * dbmfMalloc(size_t size)
Allocate memory.
Definition: dbmf.c:97