- Timestamp:
- Jul 7, 2011 11:58:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/restartable-syscall-wrappers.c
r2445 r2446 58 58 #endif 59 59 60 /** Optional '64' suffix string for dlsym. */61 #if !defined(_LP64) && _FILE_OFFSET_BITS == 6462 # define SYM_64_SUFFIX "64"63 #else64 # define SYM_64_SUFFIX ""65 #endif66 67 60 /** Mangle a syscall name with optional '64' suffix. */ 68 61 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 … … 79 72 #endif 80 73 74 /** Used by XSTR. */ 75 #define XSTR_INNER(x) #x 76 /** Returns the expanded argument as a string. */ 77 #define XSTR(x) XSTR_INNER(x) 78 79 81 80 82 81 extern int WRAP64(open)(const char *pszName, int fFlags, ...); … … 155 154 void *pvLibc; 156 155 void *pvSym; 156 157 /* 158 * Use the RTLD_NEXT dl feature if present, it's designed for doing 159 * exactly what we want here. 160 */ 161 #ifdef RTLD_NEXT 162 pvSym = dlsym(RTLD_NEXT, pszSymbol); 163 if (pvSym) 164 { 165 *ppvSym = pvSym; 166 return 0; 167 } 168 #endif 157 169 158 170 /* … … 163 175 { 164 176 #ifdef RTLD_NOLOAD 165 pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD); 166 #else 167 pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL); 177 unsigned fFlags = RTLD_NOLOAD | RTLD_NOW; 178 #else 179 unsigned fFlags = RTLD_GLOBAL | RTLD_NOW; 180 #endif 181 #ifdef KBUILD_OS_LINUX 182 pvLibc = dlopen("/lib/libc.so.6", fFlags); 183 #else 184 pvLibc = dlopen("/lib/libc.so", fFlags); 168 185 #endif 169 186 if (!pvLibc) … … 197 214 static union 198 215 { 199 FILE *(* pfnF open)(const char *, const char *);216 FILE *(* pfnFOpen)(const char *, const char *); 200 217 void *pvSym; 201 218 } s_u; 202 219 FILE *pFile; 203 220 204 if ( !s_u.pfnF open205 && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0)221 if ( !s_u.pfnFOpen 222 && dlsym_libc("fopen", &s_u.pvSym) != 0) 206 223 return NULL; 207 224 208 225 do 209 pFile = s_u.pfnF open(pszName, pszMode);226 pFile = s_u.pfnFOpen(pszName, pszMode); 210 227 while (!pFile && SHOULD_RESTART()); 211 228 return pFile; 212 229 } 213 230 231 FILE *fopen64(const char *pszName, const char *pszMode) 232 { 233 static union 234 { 235 FILE *(* pfnFOpen64)(const char *, const char *); 236 void *pvSym; 237 } s_u; 238 FILE *pFile; 239 240 if ( !s_u.pfnFOpen64 241 && dlsym_libc("fopen64", &s_u.pvSym) != 0) 242 return NULL; 243 244 do 245 pFile = s_u.pfnFOpen64(pszName, pszMode); 246 while (!pFile && SHOULD_RESTART()); 247 return pFile; 248 } 249 214 250 /** @todo chmod, chown, chgrp, times, and possible some more. */ 215 251 216
Note:
See TracChangeset
for help on using the changeset viewer.