home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / os / unix / os.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-16  |  4.2 KB  |  172 lines

  1. /*
  2.  * This file will include OS specific functions which are not inlineable.
  3.  * Any inlineable functions should be defined in os-inline.c instead.
  4.  */
  5.  
  6. #include "ap_config.h"
  7. #include "os.h"
  8.  
  9.  
  10. /* some linkers complain unless there's at least one function in each
  11.  * .o file... and extra prototype is for gcc -Wmissing-prototypes
  12.  */
  13. extern void ap_is_not_here(void);
  14. void ap_is_not_here(void) {}
  15.  
  16. /*
  17.  * Insert the DSO emulation code for AIX
  18.  */
  19. #ifdef AIX
  20. #include "os-aix-dso.c"
  21. #endif
  22.  
  23. /*
  24.  *  Abstraction layer for loading
  25.  *  Apache modules under run-time via 
  26.  *  dynamic shared object (DSO) mechanism
  27.  */
  28.  
  29. #ifdef RHAPSODY
  30. #include <mach-o/dyld.h>
  31. #include "httpd.h"
  32. #include "http_log.h"
  33.  
  34. ap_private_extern
  35. void undefined_symbol_handler(const char *symbolName)
  36. {
  37.     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, NULL,
  38.                  "dyld found undefined symbol: %s\n"
  39.                  "Aborting.\n",
  40.                  symbolName);
  41.     abort();
  42. }
  43.  
  44. ap_private_extern
  45. NSModule multiple_symbol_handler (NSSymbol s, NSModule old, NSModule new)
  46. {
  47.     /*
  48.      * Since we can't unload symbols, we're going to run into this
  49.      * every time we reload a module. Workaround here is to just
  50.      * rebind to the new symbol, and forget about the old one.
  51.      * This is crummy, because it's basically a memory leak.
  52.      * (See Radar 2262020 against dyld).
  53.      */
  54.  
  55. #ifdef DEBUG
  56.     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, NULL,
  57.                  "dyld found a multiply defined symbol %s in modules:\n"
  58.                  "%s\n%s\n",
  59.                  NSNameOfSymbol(s),
  60.                  NSNameOfModule(old), NSNameOfModule(new));
  61. #endif
  62.  
  63.     return(new);
  64. }
  65.  
  66. ap_private_extern
  67. void linkEdit_symbol_handler (NSLinkEditErrors c, int errorNumber,
  68.                               const char *fileName, const char *errorString)
  69. {
  70.     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, NULL,
  71.                  "dyld errors during link edit for file %s\n%s\n",
  72.                  fileName, errorString);
  73.     abort();
  74. }
  75.  
  76. #endif /*RHAPSODY*/
  77.  
  78. void ap_os_dso_init(void)
  79. {
  80. #if defined(RHAPSODY)
  81.     NSLinkEditErrorHandlers handlers;
  82.  
  83.     handlers.undefined = undefined_symbol_handler;
  84.     handlers.multiple  = multiple_symbol_handler;
  85.     handlers.linkEdit  = linkEdit_symbol_handler;
  86.  
  87.     NSInstallLinkEditErrorHandlers(&handlers);
  88. #endif
  89. }
  90.  
  91. void *ap_os_dso_load(const char *path)
  92. {
  93. #if defined(HPUX) || defined(HPUX10)
  94.     shl_t handle;
  95.     handle = shl_load(path, BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L);
  96.     return (void *)handle;
  97.  
  98. #elif defined(RHAPSODY)
  99.     NSObjectFileImage image;
  100.     if (NSCreateObjectFileImageFromFile(path, &image) !=
  101.         NSObjectFileImageSuccess)
  102.         return NULL;
  103.     return NSLinkModule(image, path, TRUE);
  104.  
  105. #elif defined(OSF1) ||\
  106.     (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000))
  107.     return dlopen((char *)path, RTLD_NOW | RTLD_GLOBAL);
  108.  
  109. #else
  110.     return dlopen(path, RTLD_NOW | RTLD_GLOBAL);
  111. #endif
  112. }
  113.  
  114. void ap_os_dso_unload(void *handle)
  115. {
  116. #if defined(HPUX) || defined(HPUX10)
  117.     shl_unload((shl_t)handle);
  118.  
  119. #elif defined(RHAPSODY)
  120.     NSUnLinkModule(handle,FALSE);
  121.  
  122. #else
  123.     dlclose(handle);
  124. #endif
  125.  
  126.     return;
  127. }
  128.  
  129. void *ap_os_dso_sym(void *handle, const char *symname)
  130. {
  131. #if defined(HPUX) || defined(HPUX10)
  132.     void *symaddr = NULL;
  133.     int status;
  134.  
  135.     errno = 0;
  136.     status = shl_findsym((shl_t *)&handle, symname, TYPE_PROCEDURE, &symaddr);
  137.     if (status == -1 && errno == 0) /* try TYPE_DATA instead */
  138.         status = shl_findsym((shl_t *)&handle, symname, TYPE_DATA, &symaddr);
  139.     return (status == -1 ? NULL : symaddr);
  140.  
  141. #elif defined(RHAPSODY)
  142.     NSSymbol symbol;
  143.     char *symname2 = (char*)malloc(sizeof(char)*(strlen(symname)+2));
  144.     sprintf(symname2, "_%s", symname);
  145.     symbol = NSLookupAndBindSymbol(symname2);
  146.     free(symname2);
  147.     return NSAddressOfSymbol(symbol);
  148.  
  149. #elif defined(DLSYM_NEEDS_UNDERSCORE)
  150.     char *symbol = (char*)malloc(sizeof(char)*(strlen(symname)+2));
  151.     void *retval;
  152.     sprintf(symbol, "_%s", symname);
  153.     retval = dlsym(handle, symbol);
  154.     free(symbol);
  155.     return retval;
  156.  
  157. #else
  158.     return dlsym(handle, symname);
  159. #endif
  160. }
  161.  
  162. const char *ap_os_dso_error(void)
  163. {
  164. #if defined(HPUX) || defined(HPUX10)
  165.     return strerror(errno);
  166. #elif defined(RHAPSODY)
  167.     return NULL;
  168. #else
  169.     return dlerror();
  170. #endif
  171. }
  172.