Changeset 2445 in kBuild
- Timestamp:
- Jul 7, 2011 10:20:24 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Config.kmk
r2434 r2445 321 321 TEMPLATE_BIN_LDFLAGS.sparc64 += -m64 322 322 ifeq ($(KBUILD_TARGET),solaris) 323 TEMPLATE_BIN_LIBS += rt 323 TEMPLATE_BIN_LIBS += rt dl 324 324 TEMPLATE_BIN_LDFLAGS += -Wl,-i 325 325 endif -
trunk/src/lib/restartable-syscall-wrappers.c
r2444 r2445 38 38 #include <sys/types.h> 39 39 #include <sys/stat.h> 40 #include <dlfcn.h> 41 #include <errno.h> 40 42 #include <fcntl.h> 41 #include <errno.h>42 43 #include <stdarg.h> 44 #include <stddef.h> 45 #include <stdio.h> 43 46 44 47 … … 55 58 #endif 56 59 60 /** Optional '64' suffix string for dlsym. */ 61 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 62 # define SYM_64_SUFFIX "64" 63 #else 64 # define SYM_64_SUFFIX "" 65 #endif 66 57 67 /** Mangle a syscall name with optional '64' suffix. */ 58 68 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 … … 140 150 } 141 151 152 static int dlsym_libc(const char *pszSymbol, void **ppvSym) 153 { 154 static void *s_pvLibc = NULL; 155 void *pvLibc; 156 void *pvSym; 157 158 /* 159 * Open libc. 160 */ 161 pvLibc = s_pvLibc; 162 if (!pvLibc) 163 { 164 #ifdef RTLD_NOLOAD 165 pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD); 166 #else 167 pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL); 168 #endif 169 if (!pvLibc) 170 { 171 fprintf(stderr, "restartable-syscall-wrappers: failed to dlopen libc for resolving %s: %s\n", 172 pszSymbol, dlerror()); 173 errno = ENOSYS; 174 return -1; 175 } 176 /** @todo check standard symbol? */ 177 } 178 179 /* 180 * Resolve the symbol. 181 */ 182 pvSym = dlsym(pvLibc, pszSymbol); 183 if (!pvSym) 184 { 185 fprintf(stderr, "restartable-syscall-wrappers: failed to resolve %s: %s\n", 186 pszSymbol, dlerror()); 187 errno = ENOSYS; 188 return -1; 189 } 190 191 *ppvSym = pvSym; 192 return 0; 193 } 194 195 FILE *fopen(const char *pszName, const char *pszMode) 196 { 197 static union 198 { 199 FILE *(* pfnFopen)(const char *, const char *); 200 void *pvSym; 201 } s_u; 202 FILE *pFile; 203 204 if ( !s_u.pfnFopen 205 && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0) 206 return NULL; 207 208 do 209 pFile = s_u.pfnFopen(pszName, pszMode); 210 while (!pFile && SHOULD_RESTART()); 211 return pFile; 212 } 213 142 214 /** @todo chmod, chown, chgrp, times, and possible some more. */ 215 216
Note:
See TracChangeset
for help on using the changeset viewer.