diff --git a/src/libCom/osi/os/vxWorks/atReboot.cpp b/src/libCom/osi/os/vxWorks/atReboot.cpp index 9a35286ef..2f755c581 100644 --- a/src/libCom/osi/os/vxWorks/atReboot.cpp +++ b/src/libCom/osi/os/vxWorks/atReboot.cpp @@ -12,7 +12,7 @@ #include -#include "epicsDynLink.h" +#include "epicsFindSymbol.h" #include "epicsExit.h" extern "C" { @@ -21,15 +21,12 @@ typedef int (*sysAtReboot_t)(void(func)(void)); void atRebootRegister(void) { - STATUS status; - sysAtReboot_t sysAtReboot; - SYM_TYPE type; + sysAtReboot_t sysAtReboot = (sysAtReboot_t) epicsFindSymbol("_sysAtReboot"); - status = symFindByNameEPICS(sysSymTbl, "_sysAtReboot", - (char **)&sysAtReboot, &type); - if (status == OK) { - status = sysAtReboot(epicsExitCallAtExits); - if (status != OK) { + if (sysAtReboot) { + STATUS status = sysAtReboot(epicsExitCallAtExits); + + if (status) { printf("atReboot: sysAtReboot returned error %d\n", status); } } else { diff --git a/src/libCom/osi/os/vxWorks/epicsDynLink.c b/src/libCom/osi/os/vxWorks/epicsDynLink.c index 57d5e9dd4..ba0fde277 100644 --- a/src/libCom/osi/os/vxWorks/epicsDynLink.c +++ b/src/libCom/osi/os/vxWorks/epicsDynLink.c @@ -1,92 +1,95 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2014 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 -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /* $Id $ * - * Comments from original version: - * On the MIPS processor, all symbols do not have the prepended underscore. - * Here we redefine symFindByName to look at the second character of the - * name string. - * - * On various RISC processors (at least MIPS and PPC), symbols do not have - * the prepended underscore. Here we redefine symFindByName so that, if the - * name lookup fails and if the first character of the name is "_", the - * lookup is repeated starting at the second character of the name string. - * - * 01a,08apr97,bdg created. - * 02a,03apr97,npr changed from mips.h into symFindByNameMips.c - * 03a,03jun98,wfl changed Mips -> EPICS and avoid architecture knowledge + * On 68K targets, all symbols have an underscore prepended to their name. + * This code permits both standards to work, as long as you're not looking + * for a symbol name that actually begins with an underscore. */ +#include + #include "epicsDynLink.h" - -STATUS symFindByNameEPICS( - SYMTAB_ID symTblId, - char *name, - char **ppvalue, - SYM_TYPE *pType ) + +#if _WRS_VXWORKS_MAJOR < 6 || _WRS_VXWORKS_MINOR < 9 + +static int symNoUnderscore(SYMTAB_ID symTblId) { - static int leadingUnderscore = 1; - static int init = 0; - STATUS status = ERROR; + static int init = 0; + static int noUnderscore = 0; - if (!init) { - char *pSymValue; - SYM_TYPE type; - status = symFindByName ( symTblId, "symFindByNameEPICS", &pSymValue, &type ); - if (status==OK) { - leadingUnderscore = 0; - } - init = 1; - } + if (!init) { + char name[] = "symFindByNameEPICS"; + char *pSymValue; + SYM_TYPE type; - if (name[0] != '_' || leadingUnderscore) { - status = symFindByName ( symTblId, name, ppvalue, pType ); - } - else { - status = symFindByName ( symTblId, (name+1), ppvalue, pType ); - } - - return status; + if (symFindByName(symTblId, name, &pSymValue, &type) == OK) + noUnderscore = 1; + init = 1; + } + return noUnderscore; } -STATUS symFindByNameAndTypeEPICS( - SYMTAB_ID symTblId, - char *name, - char **ppvalue, - SYM_TYPE *pType, - SYM_TYPE sType, - SYM_TYPE mask ) +STATUS symFindByNameEPICS(SYMTAB_ID symTblId, char *name, char **ppvalue, + SYM_TYPE *pType) { - static int leadingUnderscore = 1; - static int init = 0; - STATUS status = ERROR; + if (name[0] == '_' && symNoUnderscore(symTblId)) + name++; - if (!init) { - char *pSymValue; - SYM_TYPE type; - status = symFindByName (symTblId, "symFindByNameAndTypeEPICS", &pSymValue, &type ); - if (status==OK) { - leadingUnderscore = 0; - } - init = 1; - } - - if (name[0] != '_' || leadingUnderscore) { - status = symFindByNameAndType ( symTblId, name, ppvalue, pType, sType, mask ); - } - else if (leadingUnderscore) { - status = symFindByNameAndType ( symTblId, (name+1), ppvalue, pType, sType, mask ); - } - - return status; + return symFindByName(symTblId, name, ppvalue, pType); } +STATUS symFindByNameAndTypeEPICS(SYMTAB_ID symTblId, char *name, + char **ppvalue, SYM_TYPE *pType, SYM_TYPE sType, SYM_TYPE mask) +{ + if (name[0] == '_' && symNoUnderscore(symTblId)) + name++; + return symFindByNameAndType(symTblId, name, ppvalue, pType, sType, mask); +} +#else /* VxWorks 6.9 deprecated the symFindBy routines */ + +STATUS symFindByNameEPICS(SYMTAB_ID symTblId, char *name, char **ppvalue, + SYM_TYPE *pType) +{ + SYMBOL_DESC symDesc; + STATUS status; + + memset(&symDesc, 0, sizeof(SYMBOL_DESC)); + symDesc.mask = SYM_FIND_BY_NAME; + symDesc.name = name + (name[0] == '_'); + status = symFind(sysSymTbl, &symDesc); + if (!status) { + *ppvalue = symDesc.value; + *pType = symDesc.type; + } + return status; +} + +STATUS symFindByNameAndTypeEPICS(SYMTAB_ID symTblId, char *name, + char **ppvalue, SYM_TYPE *pType, SYM_TYPE sType, SYM_TYPE mask) +{ + SYMBOL_DESC symDesc; + STATUS status; + + memset(&symDesc, 0, sizeof(SYMBOL_DESC)); + symDesc.mask = SYM_FIND_BY_NAME | SYM_FIND_BY_TYPE; + symDesc.name = name + (name[0] == '_'); + symDesc.type = sType; + symDesc.typeMask = mask; + status = symFind(sysSymTbl, &symDesc); + if (!status) { + *ppvalue = symDesc.value; + *pType = symDesc.type; + } + return status; +} + +#endif diff --git a/src/libCom/osi/os/vxWorks/epicsDynLink.h b/src/libCom/osi/os/vxWorks/epicsDynLink.h index 85c6c8dd0..581260a49 100644 --- a/src/libCom/osi/os/vxWorks/epicsDynLink.h +++ b/src/libCom/osi/os/vxWorks/epicsDynLink.h @@ -1,11 +1,10 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2014 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 -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /* @@ -16,32 +15,22 @@ #ifndef epicsDynLinkh #define epicsDynLinkh -#ifdef symFindByName -#undef symFindByName -#endif - #include "vxWorks.h" #include "symLib.h" #include "sysSymTbl.h" +#include "compilerDependencies.h" #ifdef __cplusplus extern "C" { #endif - -STATUS symFindByNameEPICS( - SYMTAB_ID symTblId, - char *name, - char **pvalue, - SYM_TYPE *pType); +/* Use epicsFindSymbol() instead of these */ -STATUS symFindByNameAndTypeEPICS( - SYMTAB_ID symTblId, - char *name, - char **pvalue, - SYM_TYPE *pType, - SYM_TYPE sType, - SYM_TYPE mask); +STATUS symFindByNameEPICS(SYMTAB_ID symTblId, char *name, char **pvalue, + SYM_TYPE *pType) EPICS_DEPRECATED; + +STATUS symFindByNameAndTypeEPICS(SYMTAB_ID symTblId, char *name, char **pvalue, + SYM_TYPE *pType, SYM_TYPE sType, SYM_TYPE mask) EPICS_DEPRECATED; #ifdef __cplusplus } diff --git a/src/libCom/osi/os/vxWorks/osdFindSymbol.c b/src/libCom/osi/os/vxWorks/osdFindSymbol.c index 785327e8b..da17c5bf3 100644 --- a/src/libCom/osi/os/vxWorks/osdFindSymbol.c +++ b/src/libCom/osi/os/vxWorks/osdFindSymbol.c @@ -56,7 +56,9 @@ epicsShareFunc void * epicsLoadLibrary(const char *name) epicsShareFunc const char *epicsLoadError(void) { - if (oldmsg) free(oldmsg); + if (oldmsg) + free(oldmsg); + oldmsg = errmsg; errmsg = NULL; return oldmsg; @@ -65,22 +67,49 @@ epicsShareFunc const char *epicsLoadError(void) void *epicsFindSymbol(const char *name) { STATUS status; - SYM_TYPE type; + +#if _WRS_VXWORKS_MAJOR < 6 || _WRS_VXWORKS_MINOR < 9 char *pvalue; - - status = symFindByName( sysSymTbl, (char *)name, &pvalue, &type ); - if(status) { - if(name[0] == '_' ) { - status = symFindByName(sysSymTbl, (char *)(name+1), &pvalue, &type); - } else { - char *pname; - pname = dbmfMalloc(strlen(name) + 2); - strcpy(pname,"_"); - strcat(pname,name); - status = symFindByName(sysSymTbl,pname, &pvalue, &type); - dbmfFree(pname); - } + SYM_TYPE type; + + status = symFindByName(sysSymTbl, (char *)name, &pvalue, &type); + if (!status) + return pvalue; + + if (name[0] == '_' ) { + status = symFindByName(sysSymTbl, (char *)(name+1), &pvalue, &type); } - if(status) return(0); - return((void *)pvalue); +#if CPU_FAMILY == MC680X0 + else { + char *pname = dbmfMalloc(strlen(name) + 2); + + pname[0] = '_'; + strcpy(pname + 1, name); + status = symFindByName(sysSymTbl, pname, &pvalue, &type); + dbmfFree(pname); + } +#endif + if (!status) + return pvalue; + +#else + + SYMBOL_DESC symDesc; + + memset(&symDesc, 0, sizeof(SYMBOL_DESC)); + symDesc.mask = SYM_FIND_BY_NAME; + symDesc.name = (char *) name; + status = symFind(sysSymTbl, &symDesc); + if (!status) + return symDesc.value; + + if (name[0] == '_') { + symDesc.name++; + status = symFind(sysSymTbl, &symDesc); + if (!status) + return symDesc.value; + } + /* No need to prepend an '_'; 68K-only, no longer supported */ +#endif + return 0; }