/usr/include/ace/OS_NS_dlfcn.inl is in libace-dev 6.0.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | // -*- C++ -*-
//
// $Id: OS_NS_dlfcn.inl 92474 2010-11-02 13:29:39Z johnnyw $
#include "ace/OS_NS_macros.h"
#include "ace/OS_NS_errno.h"
#include "ace/OS_NS_fcntl.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Default_Constants.h"
#include "ace/os_include/os_fcntl.h"
#include "ace/os_include/os_string.h"
#if defined (ACE_WIN32) && defined (ACE_HAS_PHARLAP)
# include "ace/OS_NS_stdio.h"
#endif
#if defined (ACE_USES_ASM_SYMBOL_IN_DLSYM)
# include "ace/OS_Memory.h"
# include "ace/OS_NS_string.h"
#endif /* ACE_USES_ASM_SYMBOL_IN_DLSYM */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
ACE_INLINE int
ACE_OS::dlclose (ACE_SHLIB_HANDLE handle)
{
ACE_OS_TRACE ("ACE_OS::dlclose");
#if defined (ACE_LACKS_DLCLOSE)
ACE_UNUSED_ARG (handle);
return 0;
#elif defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
# if !defined (ACE_HAS_AUTOMATIC_INIT_FINI)
// SunOS4 does not automatically call _fini()!
void *ptr;
ACE_OSCALL (::dlsym (handle, ACE_TEXT ("_fini")), void *, 0, ptr);
if (ptr != 0)
(*((int (*)(void)) ptr)) (); // Call _fini hook explicitly.
# endif /* ACE_HAS_AUTOMATIC_INIT_FINI */
ACE_OSCALL_RETURN (::dlclose (handle), int, -1);
#elif defined (ACE_WIN32)
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::FreeLibrary (handle), ace_result_), int, -1);
#elif defined (__hpux)
// HP-UX 10.x and 32-bit 11.00 do not pay attention to the ref count
// when unloading a dynamic lib. So, if the ref count is more than
// 1, do not unload the lib. This will cause a library loaded more
// than once to not be unloaded until the process runs down, but
// that's life. It's better than unloading a library that's in use.
// So far as I know, there's no way to decrement the refcnt that the
// kernel is looking at - the shl_descriptor is a copy of what the
// kernel has, not the actual struct. On 64-bit HP-UX using dlopen,
// this problem has been fixed.
struct shl_descriptor desc;
if (shl_gethandle_r (handle, &desc) == -1)
return -1;
if (desc.ref_count > 1)
return 0;
# if defined(__GNUC__) || __cplusplus >= 199707L
ACE_OSCALL_RETURN (::shl_unload (handle), int, -1);
# else
ACE_OSCALL_RETURN (::cxxshl_unload (handle), int, -1);
# endif /* aC++ vs. Hp C++ */
#else
ACE_UNUSED_ARG (handle);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
}
ACE_INLINE ACE_TCHAR *
ACE_OS::dlerror (void)
{
ACE_OS_TRACE ("ACE_OS::dlerror");
# if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
const char *err = 0;
ACE_OSCALL (::dlerror (), const char *, 0, err);
if (err == 0)
return 0;
# if defined (ACE_USES_WCHAR)
const size_t BufLen = 256;
static wchar_t buf[BufLen];
ACE_OS::strncpy (buf, ACE_TEXT_CHAR_TO_TCHAR (err), BufLen);
return buf;
# else
return const_cast <char *> (err);
# endif /* ACE_USES_WCHAR */
# elif defined (__hpux) || defined (ACE_VXWORKS)
//FUZZ: disable check_for_lack_ACE_OS
ACE_OSCALL_RETURN (::strerror(errno), char *, 0);
//FUZZ: enable check_for_lack_ACE_OS
# elif defined (ACE_WIN32)
static ACE_TCHAR buf[128];
# if defined (ACE_HAS_PHARLAP)
ACE_OS::sprintf (buf, "error code %d", GetLastError());
# else
ACE_TEXT_FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM,
0,
::GetLastError (),
0,
buf,
sizeof buf / sizeof buf[0],
0);
# endif /* ACE_HAS_PHARLAP */
return buf;
# else
ACE_NOTSUP_RETURN (0);
# endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
}
ACE_INLINE ACE_SHLIB_HANDLE
ACE_OS::dlopen (const ACE_TCHAR *fname,
int mode)
{
ACE_OS_TRACE ("ACE_OS::dlopen");
# if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
void *handle;
# if defined (ACE_HAS_SGIDLADD)
ACE_OSCALL
(::sgidladd (ACE_TEXT_ALWAYS_CHAR (fname), mode), void *, 0, handle);
# else
ACE_OSCALL
(::dlopen (ACE_TEXT_ALWAYS_CHAR (fname), mode), void *, 0, handle);
# endif /* ACE_HAS_SGIDLADD */
# if !defined (ACE_HAS_AUTOMATIC_INIT_FINI)
if (handle != 0)
{
void *ptr;
// Some systems (e.g., SunOS4) do not automatically call _init(), so
// we'll have to call it manually.
ACE_OSCALL (::dlsym (handle, ACE_TEXT ("_init")), void *, 0, ptr);
if (ptr != 0 && (*((int (*)(void)) ptr)) () == -1) // Call _init hook explicitly.
{
// Close down the handle to prevent leaks.
::dlclose (handle);
return 0;
}
}
# endif /* ACE_HAS_AUTOMATIC_INIT_FINI */
return handle;
# elif defined (ACE_WIN32)
ACE_UNUSED_ARG (mode);
ACE_WIN32CALL_RETURN (ACE_TEXT_LoadLibrary (fname), ACE_SHLIB_HANDLE, 0);
# elif defined (__hpux)
# if defined(__GNUC__) || __cplusplus >= 199707L
ACE_OSCALL_RETURN (::shl_load(fname, mode, 0L), ACE_SHLIB_HANDLE, 0);
# else
ACE_OSCALL_RETURN (::cxxshl_load(fname, mode, 0L), ACE_SHLIB_HANDLE, 0);
# endif /* aC++ vs. Hp C++ */
# elif defined (ACE_VXWORKS) && !defined (__RTP__)
MODULE* handle = 0;
// Open readonly
ACE_HANDLE filehandle = ACE_OS::open (fname,
O_RDONLY,
ACE_DEFAULT_FILE_PERMS);
if (filehandle != ACE_INVALID_HANDLE)
{
ACE_OS::last_error(0);
ACE_OSCALL ( ::loadModule (filehandle, LOAD_GLOBAL_SYMBOLS|LOAD_COMMON_MATCH_ALL ), MODULE *, 0, handle);
int loaderror = ACE_OS::last_error();
ACE_OS::close (filehandle);
if ( (loaderror != 0) && (handle != 0) )
{
// ouch something went wrong most likely unresolved externals
if (handle)
::unldByModuleId ( handle, 0 );
handle = 0;
}
}
else
{
// couldn't open file
handle = 0;
}
return handle;
# else
ACE_UNUSED_ARG (fname);
ACE_UNUSED_ARG (mode);
ACE_NOTSUP_RETURN (0);
# endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
}
ACE_INLINE void *
ACE_OS::dlsym (ACE_SHLIB_HANDLE handle,
const ACE_TCHAR *sname)
{
ACE_OS_TRACE ("ACE_OS::dlsym");
#if defined (ACE_HAS_DLSYM_SEGFAULT_ON_INVALID_HANDLE)
// Check if the handle is valid before making any calls using it.
if (handle == ACE_SHLIB_INVALID_HANDLE)
return 0;
#endif /* ACE_HAS_DLSYM_SEGFAULT_ON_INVALID_HANDLE */
// Get the correct OS type.
#if defined (ACE_HAS_WINCE)
// CE (at least thru Pocket PC 2003) offers GetProcAddressW, not ...A, so
// we always need a wide-char string.
const wchar_t *symbolname = 0;
# if defined (ACE_USES_WCHAR)
symbolname = sname;
# else
ACE_Ascii_To_Wide sname_xlate (sname);
symbolname = sname_xlate.wchar_rep ();
# endif /* ACE_USES_WCHAR */
#elif defined (ACE_USES_WCHAR)
// WinCE is WCHAR always; other platforms need a char * symbol name
ACE_Wide_To_Ascii w_sname (sname);
char *symbolname = w_sname.char_rep ();
#elif defined (ACE_VXWORKS)
char *symbolname = const_cast<char *> (sname);
#else
const char *symbolname = sname;
#endif /* ACE_HAS_WINCE */
# if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
# if defined (ACE_USES_ASM_SYMBOL_IN_DLSYM)
int l = ACE_OS::strlen (symbolname) + 2;
char *asm_symbolname = 0;
ACE_NEW_RETURN (asm_symbolname, char[l], 0);
ACE_OS::strcpy (asm_symbolname, "_") ;
ACE_OS::strcpy (asm_symbolname + 1, symbolname) ;
void *ace_result;
ACE_OSCALL (::dlsym (handle, asm_symbolname), void *, 0, ace_result);
delete [] asm_symbolname;
return ace_result;
# else
ACE_OSCALL_RETURN (::dlsym (handle, symbolname), void *, 0);
# endif /* ACE_USES_ASM_SYMBOL_IN_DLSYM */
# elif defined (ACE_WIN32)
ACE_WIN32CALL_RETURN (::GetProcAddress (handle, symbolname), void *, 0);
# elif defined (__hpux)
void *value = 0;
int status;
shl_t _handle = handle;
ACE_OSCALL (::shl_findsym(&_handle, symbolname, TYPE_UNDEFINED, &value), int, -1, status);
return status == 0 ? value : 0;
# elif defined (ACE_VXWORKS) && !defined (__RTP__)
// For now we use the VxWorks global symbol table
// which resolves the most recently loaded symbols .. which resolve mostly what we want..
ACE_UNUSED_ARG (handle);
SYM_TYPE symtype;
char *value = 0;
STATUS status;
ACE_OSCALL (::symFindByName(sysSymTbl, symbolname, &value, &symtype), int, -1, status);
return status == OK ? reinterpret_cast <void*>(value) : 0;
# else
ACE_UNUSED_ARG (handle);
ACE_UNUSED_ARG (symbolname);
ACE_NOTSUP_RETURN (0);
# endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
}
ACE_END_VERSIONED_NAMESPACE_DECL
|