Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | * Allow freebl and softoken to be loaded without util or NSPR. |
michael@0 | 7 | * |
michael@0 | 8 | * These symbols are overridden once real NSPR, and libutil are attached. |
michael@0 | 9 | */ |
michael@0 | 10 | #define _GNU_SOURCE 1 |
michael@0 | 11 | #include <stdlib.h> |
michael@0 | 12 | #include <stdio.h> |
michael@0 | 13 | #include <stdarg.h> |
michael@0 | 14 | #include <fcntl.h> |
michael@0 | 15 | #include <time.h> |
michael@0 | 16 | #include <unistd.h> |
michael@0 | 17 | #include <sys/time.h> |
michael@0 | 18 | #include <dlfcn.h> |
michael@0 | 19 | #include <prio.h> |
michael@0 | 20 | #include <prlink.h> |
michael@0 | 21 | #include <prlog.h> |
michael@0 | 22 | #include <prthread.h> |
michael@0 | 23 | #include <plstr.h> |
michael@0 | 24 | #include <prinit.h> |
michael@0 | 25 | #include <prlock.h> |
michael@0 | 26 | #include <prmem.h> |
michael@0 | 27 | #include <prerror.h> |
michael@0 | 28 | #include <prmon.h> |
michael@0 | 29 | #include <pratom.h> |
michael@0 | 30 | #include <prsystem.h> |
michael@0 | 31 | #include <prinrval.h> |
michael@0 | 32 | #include <prtime.h> |
michael@0 | 33 | #include <prcvar.h> |
michael@0 | 34 | #include <secasn1.h> |
michael@0 | 35 | #include <secdig.h> |
michael@0 | 36 | #include <secport.h> |
michael@0 | 37 | #include <secitem.h> |
michael@0 | 38 | #include <blapi.h> |
michael@0 | 39 | #include <private/pprio.h> |
michael@0 | 40 | |
michael@0 | 41 | #define FREEBL_NO_WEAK 1 |
michael@0 | 42 | |
michael@0 | 43 | #define WEAK __attribute__((weak)) |
michael@0 | 44 | |
michael@0 | 45 | #ifdef FREEBL_NO_WEAK |
michael@0 | 46 | |
michael@0 | 47 | /* |
michael@0 | 48 | * This uses function pointers. |
michael@0 | 49 | * |
michael@0 | 50 | * CONS: A separate function is needed to |
michael@0 | 51 | * fill in the function pointers. |
michael@0 | 52 | * |
michael@0 | 53 | * PROS: it works on all platforms. |
michael@0 | 54 | * it allows for dynamically finding nspr and libutil, even once |
michael@0 | 55 | * softoken is loaded and running. (NOTE: this may be a problem if |
michael@0 | 56 | * we switch between the stubs and real NSPR on the fly. NSPR will |
michael@0 | 57 | * do bad things if passed an _FakeArena to free or allocate from). |
michael@0 | 58 | */ |
michael@0 | 59 | #define STUB_DECLARE(ret, fn, args) \ |
michael@0 | 60 | typedef ret (*type_##fn) args; \ |
michael@0 | 61 | static type_##fn ptr_##fn = NULL |
michael@0 | 62 | |
michael@0 | 63 | #define STUB_SAFE_CALL0(fn) \ |
michael@0 | 64 | if (ptr_##fn) { return ptr_##fn(); } |
michael@0 | 65 | #define STUB_SAFE_CALL1(fn,a1) \ |
michael@0 | 66 | if (ptr_##fn) { return ptr_##fn(a1); } |
michael@0 | 67 | #define STUB_SAFE_CALL2(fn,a1,a2) \ |
michael@0 | 68 | if (ptr_##fn) { return ptr_##fn(a1,a2); } |
michael@0 | 69 | #define STUB_SAFE_CALL3(fn,a1,a2,a3) \ |
michael@0 | 70 | if (ptr_##fn) { return ptr_##fn(a1,a2,a3); } |
michael@0 | 71 | #define STUB_SAFE_CALL4(fn,a1,a2,a3,a4) \ |
michael@0 | 72 | if (ptr_##fn) { return ptr_##fn(a1,a2,a3,a4); } |
michael@0 | 73 | #define STUB_SAFE_CALL6(fn,a1,a2,a3,a4,a5,a6) \ |
michael@0 | 74 | if (ptr_##fn) { return ptr_##fn(a1,a2,a3,a4,a5,a6); } |
michael@0 | 75 | |
michael@0 | 76 | #define STUB_FETCH_FUNCTION(fn) \ |
michael@0 | 77 | ptr_##fn = (type_##fn) dlsym(lib,#fn); \ |
michael@0 | 78 | if (ptr_##fn == NULL) { \ |
michael@0 | 79 | return SECFailure; \ |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | #else |
michael@0 | 83 | /* |
michael@0 | 84 | * this uses the loader weak attribute. it works automatically, but once |
michael@0 | 85 | * freebl is loaded, the symbols are 'fixed' (later loading of NSPR or |
michael@0 | 86 | * libutil will not resolve these symbols. |
michael@0 | 87 | */ |
michael@0 | 88 | |
michael@0 | 89 | #define STUB_DECLARE(ret, fn, args) \ |
michael@0 | 90 | WEAK extern ret fn args |
michael@0 | 91 | |
michael@0 | 92 | #define STUB_SAFE_CALL0(fn) \ |
michael@0 | 93 | if (fn) { return fn(); } |
michael@0 | 94 | #define STUB_SAFE_CALL1(fn,a1) \ |
michael@0 | 95 | if (fn) { return fn(a1); } |
michael@0 | 96 | #define STUB_SAFE_CALL2(fn,a1,a2) \ |
michael@0 | 97 | if (fn) { return fn(a1,a2); } |
michael@0 | 98 | #define STUB_SAFE_CALL3(fn,a1,a2,a3) \ |
michael@0 | 99 | if (fn) { return fn(a1,a2,a3); } |
michael@0 | 100 | #define STUB_SAFE_CALL4(fn,a1,a2,a3,a4) \ |
michael@0 | 101 | if (fn) { return fn(a1,a2,a3,a4); } |
michael@0 | 102 | #define STUB_SAFE_CALL6(fn,a1,a2,a3,a4,a5,a6) \ |
michael@0 | 103 | if (fn) { return fn(a1,a2,a3,a4,a5,a6); } |
michael@0 | 104 | #endif |
michael@0 | 105 | |
michael@0 | 106 | |
michael@0 | 107 | STUB_DECLARE(void *,PORT_Alloc_Util,(size_t len)); |
michael@0 | 108 | STUB_DECLARE(void *,PORT_ArenaAlloc_Util,(PLArenaPool *arena, size_t size)); |
michael@0 | 109 | STUB_DECLARE(void *,PORT_ArenaZAlloc_Util,(PLArenaPool *arena, size_t size)); |
michael@0 | 110 | STUB_DECLARE(void ,PORT_Free_Util,(void *ptr)); |
michael@0 | 111 | STUB_DECLARE(void ,PORT_FreeArena_Util,(PLArenaPool *arena, PRBool zero)); |
michael@0 | 112 | STUB_DECLARE(int,PORT_GetError_Util,(void)); |
michael@0 | 113 | STUB_DECLARE(PLArenaPool *,PORT_NewArena_Util,(unsigned long chunksize)); |
michael@0 | 114 | STUB_DECLARE(void,PORT_SetError_Util,(int value)); |
michael@0 | 115 | STUB_DECLARE(void *,PORT_ZAlloc_Util,(size_t len)); |
michael@0 | 116 | STUB_DECLARE(void,PORT_ZFree_Util,(void *ptr, size_t len)); |
michael@0 | 117 | |
michael@0 | 118 | STUB_DECLARE(void,PR_Assert,(const char *s, const char *file, PRIntn ln)); |
michael@0 | 119 | STUB_DECLARE(PRStatus,PR_CallOnce,(PRCallOnceType *once, PRCallOnceFN func)); |
michael@0 | 120 | STUB_DECLARE(PRStatus,PR_Close,(PRFileDesc *fd)); |
michael@0 | 121 | STUB_DECLARE(void,PR_DestroyLock,(PRLock *lock)); |
michael@0 | 122 | STUB_DECLARE(void,PR_DestroyCondVar,(PRCondVar *cvar)); |
michael@0 | 123 | STUB_DECLARE(void,PR_Free,(void *ptr)); |
michael@0 | 124 | STUB_DECLARE(char * ,PR_GetLibraryFilePathname,(const char *name, |
michael@0 | 125 | PRFuncPtr addr)); |
michael@0 | 126 | STUB_DECLARE(PRFileDesc *,PR_ImportPipe,(PROsfd osfd)); |
michael@0 | 127 | STUB_DECLARE(void,PR_Lock,(PRLock *lock)); |
michael@0 | 128 | STUB_DECLARE(PRCondVar *,PR_NewCondVar,(PRLock *lock)); |
michael@0 | 129 | STUB_DECLARE(PRLock *,PR_NewLock,(void)); |
michael@0 | 130 | STUB_DECLARE(PRStatus,PR_NotifyCondVar,(PRCondVar *cvar)); |
michael@0 | 131 | STUB_DECLARE(PRStatus,PR_NotifyAllCondVar,(PRCondVar *cvar)); |
michael@0 | 132 | STUB_DECLARE(PRFileDesc *,PR_Open,(const char *name, PRIntn flags, |
michael@0 | 133 | PRIntn mode)); |
michael@0 | 134 | STUB_DECLARE(PRInt32,PR_Read,(PRFileDesc *fd, void *buf, PRInt32 amount)); |
michael@0 | 135 | STUB_DECLARE(PROffset32,PR_Seek,(PRFileDesc *fd, PROffset32 offset, |
michael@0 | 136 | PRSeekWhence whence)); |
michael@0 | 137 | STUB_DECLARE(PRStatus,PR_Sleep,(PRIntervalTime ticks)); |
michael@0 | 138 | STUB_DECLARE(PRStatus,PR_Unlock,(PRLock *lock)); |
michael@0 | 139 | STUB_DECLARE(PRStatus,PR_WaitCondVar,(PRCondVar *cvar, |
michael@0 | 140 | PRIntervalTime timeout)); |
michael@0 | 141 | |
michael@0 | 142 | |
michael@0 | 143 | STUB_DECLARE(SECItem *,SECITEM_AllocItem_Util,(PLArenaPool *arena, |
michael@0 | 144 | SECItem *item,unsigned int len)); |
michael@0 | 145 | STUB_DECLARE(SECComparison,SECITEM_CompareItem_Util,(const SECItem *a, |
michael@0 | 146 | const SECItem *b)); |
michael@0 | 147 | STUB_DECLARE(SECStatus,SECITEM_CopyItem_Util,(PLArenaPool *arena, |
michael@0 | 148 | SECItem *to,const SECItem *from)); |
michael@0 | 149 | STUB_DECLARE(void,SECITEM_FreeItem_Util,(SECItem *zap, PRBool freeit)); |
michael@0 | 150 | STUB_DECLARE(void,SECITEM_ZfreeItem_Util,(SECItem *zap, PRBool freeit)); |
michael@0 | 151 | STUB_DECLARE(SECOidTag,SECOID_FindOIDTag_Util,(const SECItem *oid)); |
michael@0 | 152 | STUB_DECLARE(int, NSS_SecureMemcmp,(const void *a, const void *b, size_t n)); |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | #define PORT_ZNew_stub(type) (type*)PORT_ZAlloc_stub(sizeof(type)) |
michael@0 | 156 | #define PORT_New_stub(type) (type*)PORT_Alloc_stub(sizeof(type)) |
michael@0 | 157 | #define PORT_ZNewArray_stub(type, num) \ |
michael@0 | 158 | (type*) PORT_ZAlloc_stub (sizeof(type)*(num)) |
michael@0 | 159 | |
michael@0 | 160 | |
michael@0 | 161 | /* |
michael@0 | 162 | * NOTE: in order to support hashing only the memory allocation stubs, |
michael@0 | 163 | * the get library name stubs, and the file io stubs are needed (the latter |
michael@0 | 164 | * two are for the library verification). The remaining stubs are simply to |
michael@0 | 165 | * compile. Attempts to use the library for other operations without NSPR |
michael@0 | 166 | * will most likely fail. |
michael@0 | 167 | */ |
michael@0 | 168 | |
michael@0 | 169 | |
michael@0 | 170 | /* memory */ |
michael@0 | 171 | extern void * |
michael@0 | 172 | PORT_Alloc_stub(size_t len) |
michael@0 | 173 | { |
michael@0 | 174 | STUB_SAFE_CALL1(PORT_Alloc_Util, len); |
michael@0 | 175 | return malloc(len); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | extern void |
michael@0 | 179 | PORT_Free_stub(void *ptr) |
michael@0 | 180 | { |
michael@0 | 181 | STUB_SAFE_CALL1(PORT_Free_Util, ptr); |
michael@0 | 182 | return free(ptr); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | extern void * |
michael@0 | 186 | PORT_ZAlloc_stub(size_t len) |
michael@0 | 187 | { |
michael@0 | 188 | STUB_SAFE_CALL1(PORT_ZAlloc_Util, len); |
michael@0 | 189 | void *ptr = malloc(len); |
michael@0 | 190 | if (ptr) { |
michael@0 | 191 | memset(ptr, 0, len); |
michael@0 | 192 | } |
michael@0 | 193 | return ptr; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | |
michael@0 | 197 | extern void |
michael@0 | 198 | PORT_ZFree_stub(void *ptr, size_t len) |
michael@0 | 199 | { |
michael@0 | 200 | STUB_SAFE_CALL2(PORT_ZFree_Util, ptr, len); |
michael@0 | 201 | memset(ptr, 0, len); |
michael@0 | 202 | return free(ptr); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | extern void |
michael@0 | 206 | PR_Free_stub(void *ptr) |
michael@0 | 207 | { |
michael@0 | 208 | STUB_SAFE_CALL1(PR_Free, ptr); |
michael@0 | 209 | return free(ptr); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | /* |
michael@0 | 213 | * arenas |
michael@0 | 214 | * |
michael@0 | 215 | */ |
michael@0 | 216 | extern PLArenaPool * |
michael@0 | 217 | PORT_NewArena_stub(unsigned long chunksize) |
michael@0 | 218 | { |
michael@0 | 219 | STUB_SAFE_CALL1(PORT_NewArena_Util, chunksize); |
michael@0 | 220 | abort(); |
michael@0 | 221 | return NULL; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | extern void * |
michael@0 | 225 | PORT_ArenaAlloc_stub(PLArenaPool *arena, size_t size) |
michael@0 | 226 | { |
michael@0 | 227 | |
michael@0 | 228 | STUB_SAFE_CALL2(PORT_ArenaZAlloc_Util, arena, size); |
michael@0 | 229 | abort(); |
michael@0 | 230 | return NULL; |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | extern void * |
michael@0 | 234 | PORT_ArenaZAlloc_stub(PLArenaPool *arena, size_t size) |
michael@0 | 235 | { |
michael@0 | 236 | |
michael@0 | 237 | STUB_SAFE_CALL2(PORT_ArenaZAlloc_Util, arena, size); |
michael@0 | 238 | abort(); |
michael@0 | 239 | return NULL; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | extern void |
michael@0 | 243 | PORT_FreeArena_stub(PLArenaPool *arena, PRBool zero) |
michael@0 | 244 | { |
michael@0 | 245 | |
michael@0 | 246 | STUB_SAFE_CALL2(PORT_FreeArena_Util, arena, zero); |
michael@0 | 247 | abort(); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | |
michael@0 | 251 | /* io */ |
michael@0 | 252 | extern PRFileDesc * |
michael@0 | 253 | PR_Open_stub(const char *name, PRIntn flags, PRIntn mode) |
michael@0 | 254 | { |
michael@0 | 255 | int *lfd = NULL; |
michael@0 | 256 | int fd; |
michael@0 | 257 | int lflags = 0; |
michael@0 | 258 | |
michael@0 | 259 | STUB_SAFE_CALL3(PR_Open, name, flags, mode); |
michael@0 | 260 | |
michael@0 | 261 | if (flags & PR_RDWR) { |
michael@0 | 262 | lflags = O_RDWR; |
michael@0 | 263 | } else if (flags & PR_WRONLY) { |
michael@0 | 264 | lflags = O_WRONLY; |
michael@0 | 265 | } else { |
michael@0 | 266 | lflags = O_RDONLY; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | if (flags & PR_EXCL) |
michael@0 | 270 | lflags |= O_EXCL; |
michael@0 | 271 | if (flags & PR_APPEND) |
michael@0 | 272 | lflags |= O_APPEND; |
michael@0 | 273 | if (flags & PR_TRUNCATE) |
michael@0 | 274 | lflags |= O_TRUNC; |
michael@0 | 275 | |
michael@0 | 276 | fd = open(name, lflags, mode); |
michael@0 | 277 | if (fd >= 0) { |
michael@0 | 278 | lfd = PORT_New_stub(int); |
michael@0 | 279 | if (lfd != NULL) { |
michael@0 | 280 | *lfd = fd; |
michael@0 | 281 | } |
michael@0 | 282 | } |
michael@0 | 283 | return (PRFileDesc *)lfd; |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | extern PRFileDesc * |
michael@0 | 287 | PR_ImportPipe_stub(PROsfd fd) |
michael@0 | 288 | { |
michael@0 | 289 | int *lfd = NULL; |
michael@0 | 290 | |
michael@0 | 291 | STUB_SAFE_CALL1(PR_ImportPipe, fd); |
michael@0 | 292 | |
michael@0 | 293 | lfd = PORT_New_stub(int); |
michael@0 | 294 | if (lfd != NULL) { |
michael@0 | 295 | *lfd = fd; |
michael@0 | 296 | } |
michael@0 | 297 | return (PRFileDesc *)lfd; |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | extern PRStatus |
michael@0 | 301 | PR_Close_stub(PRFileDesc *fd) |
michael@0 | 302 | { |
michael@0 | 303 | int *lfd; |
michael@0 | 304 | STUB_SAFE_CALL1(PR_Close, fd); |
michael@0 | 305 | |
michael@0 | 306 | lfd = (int *)fd; |
michael@0 | 307 | close(*lfd); |
michael@0 | 308 | PORT_Free_stub(lfd); |
michael@0 | 309 | |
michael@0 | 310 | return PR_SUCCESS; |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | extern PRInt32 |
michael@0 | 314 | PR_Read_stub(PRFileDesc *fd, void *buf, PRInt32 amount) |
michael@0 | 315 | { |
michael@0 | 316 | int *lfd; |
michael@0 | 317 | STUB_SAFE_CALL3(PR_Read, fd, buf, amount); |
michael@0 | 318 | |
michael@0 | 319 | lfd = (int *)fd; |
michael@0 | 320 | return read(*lfd, buf, amount); |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | extern PROffset32 |
michael@0 | 324 | PR_Seek_stub(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence) |
michael@0 | 325 | { |
michael@0 | 326 | int *lfd; |
michael@0 | 327 | int lwhence = SEEK_SET;; |
michael@0 | 328 | STUB_SAFE_CALL3(PR_Seek, fd, offset, whence); |
michael@0 | 329 | lfd = (int *)fd; |
michael@0 | 330 | switch (whence) { |
michael@0 | 331 | case PR_SEEK_CUR: |
michael@0 | 332 | lwhence = SEEK_CUR; |
michael@0 | 333 | break; |
michael@0 | 334 | case PR_SEEK_END: |
michael@0 | 335 | lwhence = SEEK_END; |
michael@0 | 336 | break; |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | return lseek(*lfd, offset, lwhence); |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | |
michael@0 | 343 | /* |
michael@0 | 344 | * library |
michael@0 | 345 | */ |
michael@0 | 346 | extern char * |
michael@0 | 347 | PR_GetLibraryFilePathname_stub(const char *name, PRFuncPtr addr) |
michael@0 | 348 | { |
michael@0 | 349 | Dl_info dli; |
michael@0 | 350 | char *result; |
michael@0 | 351 | |
michael@0 | 352 | STUB_SAFE_CALL2(PR_GetLibraryFilePathname, name, addr); |
michael@0 | 353 | |
michael@0 | 354 | if (dladdr((void *)addr, &dli) == 0) { |
michael@0 | 355 | return NULL; |
michael@0 | 356 | } |
michael@0 | 357 | result = PORT_Alloc_stub(strlen(dli.dli_fname)+1); |
michael@0 | 358 | if (result != NULL) { |
michael@0 | 359 | strcpy(result, dli.dli_fname); |
michael@0 | 360 | } |
michael@0 | 361 | return result; |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | |
michael@0 | 365 | #include <errno.h> |
michael@0 | 366 | |
michael@0 | 367 | /* errors */ |
michael@0 | 368 | extern int |
michael@0 | 369 | PORT_GetError_stub(void) |
michael@0 | 370 | { |
michael@0 | 371 | STUB_SAFE_CALL0(PORT_GetError_Util); |
michael@0 | 372 | return errno; |
michael@0 | 373 | } |
michael@0 | 374 | |
michael@0 | 375 | extern void |
michael@0 | 376 | PORT_SetError_stub(int value) |
michael@0 | 377 | { |
michael@0 | 378 | STUB_SAFE_CALL1(PORT_SetError_Util, value); |
michael@0 | 379 | errno = value; |
michael@0 | 380 | } |
michael@0 | 381 | |
michael@0 | 382 | /* misc */ |
michael@0 | 383 | extern void |
michael@0 | 384 | PR_Assert_stub(const char *s, const char *file, PRIntn ln) |
michael@0 | 385 | { |
michael@0 | 386 | STUB_SAFE_CALL3(PR_Assert, s, file, ln); |
michael@0 | 387 | fprintf(stderr, "%s line %d: %s\n", file, ln, s); |
michael@0 | 388 | abort(); |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | /* time */ |
michael@0 | 392 | extern PRStatus |
michael@0 | 393 | PR_Sleep_stub(PRIntervalTime ticks) |
michael@0 | 394 | { |
michael@0 | 395 | STUB_SAFE_CALL1(PR_Sleep, ticks); |
michael@0 | 396 | usleep(ticks*1000); |
michael@0 | 397 | return PR_SUCCESS; |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | |
michael@0 | 401 | /* locking */ |
michael@0 | 402 | extern PRLock * |
michael@0 | 403 | PR_NewLock_stub(void) |
michael@0 | 404 | { |
michael@0 | 405 | STUB_SAFE_CALL0(PR_NewLock); |
michael@0 | 406 | abort(); |
michael@0 | 407 | return NULL; |
michael@0 | 408 | } |
michael@0 | 409 | |
michael@0 | 410 | extern PRStatus |
michael@0 | 411 | PR_Unlock_stub(PRLock *lock) |
michael@0 | 412 | { |
michael@0 | 413 | STUB_SAFE_CALL1(PR_Unlock, lock); |
michael@0 | 414 | abort(); |
michael@0 | 415 | return PR_FAILURE; |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | extern void |
michael@0 | 419 | PR_Lock_stub(PRLock *lock) |
michael@0 | 420 | { |
michael@0 | 421 | STUB_SAFE_CALL1(PR_Lock, lock); |
michael@0 | 422 | abort(); |
michael@0 | 423 | return; |
michael@0 | 424 | } |
michael@0 | 425 | |
michael@0 | 426 | extern void |
michael@0 | 427 | PR_DestroyLock_stub(PRLock *lock) |
michael@0 | 428 | { |
michael@0 | 429 | STUB_SAFE_CALL1(PR_DestroyLock, lock); |
michael@0 | 430 | abort(); |
michael@0 | 431 | return; |
michael@0 | 432 | } |
michael@0 | 433 | |
michael@0 | 434 | extern PRCondVar * |
michael@0 | 435 | PR_NewCondVar_stub(PRLock *lock) |
michael@0 | 436 | { |
michael@0 | 437 | STUB_SAFE_CALL1(PR_NewCondVar, lock); |
michael@0 | 438 | abort(); |
michael@0 | 439 | return NULL; |
michael@0 | 440 | } |
michael@0 | 441 | |
michael@0 | 442 | extern PRStatus |
michael@0 | 443 | PR_NotifyCondVar_stub(PRCondVar *cvar) |
michael@0 | 444 | { |
michael@0 | 445 | STUB_SAFE_CALL1(PR_NotifyCondVar, cvar); |
michael@0 | 446 | abort(); |
michael@0 | 447 | return PR_FAILURE; |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | extern PRStatus |
michael@0 | 451 | PR_NotifyAllCondVar_stub(PRCondVar *cvar) |
michael@0 | 452 | { |
michael@0 | 453 | STUB_SAFE_CALL1(PR_NotifyAllCondVar, cvar); |
michael@0 | 454 | abort(); |
michael@0 | 455 | return PR_FAILURE; |
michael@0 | 456 | } |
michael@0 | 457 | |
michael@0 | 458 | extern PRStatus |
michael@0 | 459 | PR_WaitCondVar_stub(PRCondVar *cvar, PRIntervalTime timeout) |
michael@0 | 460 | { |
michael@0 | 461 | STUB_SAFE_CALL2(PR_WaitCondVar, cvar, timeout); |
michael@0 | 462 | abort(); |
michael@0 | 463 | return PR_FAILURE; |
michael@0 | 464 | } |
michael@0 | 465 | |
michael@0 | 466 | |
michael@0 | 467 | |
michael@0 | 468 | extern void |
michael@0 | 469 | PR_DestroyCondVar_stub(PRCondVar *cvar) |
michael@0 | 470 | { |
michael@0 | 471 | STUB_SAFE_CALL1(PR_DestroyCondVar, cvar); |
michael@0 | 472 | abort(); |
michael@0 | 473 | return; |
michael@0 | 474 | } |
michael@0 | 475 | |
michael@0 | 476 | /* |
michael@0 | 477 | * NOTE: this presupposes GCC 4.1 |
michael@0 | 478 | */ |
michael@0 | 479 | extern PRStatus |
michael@0 | 480 | PR_CallOnce_stub(PRCallOnceType *once, PRCallOnceFN func) |
michael@0 | 481 | { |
michael@0 | 482 | STUB_SAFE_CALL2(PR_CallOnce, once, func); |
michael@0 | 483 | abort(); |
michael@0 | 484 | return PR_FAILURE; |
michael@0 | 485 | } |
michael@0 | 486 | |
michael@0 | 487 | |
michael@0 | 488 | /* |
michael@0 | 489 | * SECITEMS implement Item Utilities |
michael@0 | 490 | */ |
michael@0 | 491 | extern void |
michael@0 | 492 | SECITEM_FreeItem_stub(SECItem *zap, PRBool freeit) |
michael@0 | 493 | { |
michael@0 | 494 | STUB_SAFE_CALL2(SECITEM_FreeItem_Util, zap, freeit); |
michael@0 | 495 | abort(); |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | extern SECItem * |
michael@0 | 499 | SECITEM_AllocItem_stub(PLArenaPool *arena, SECItem *item, unsigned int len) |
michael@0 | 500 | { |
michael@0 | 501 | STUB_SAFE_CALL3(SECITEM_AllocItem_Util, arena, item, len); |
michael@0 | 502 | abort(); |
michael@0 | 503 | return NULL; |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | extern SECComparison |
michael@0 | 507 | SECITEM_CompareItem_stub(const SECItem *a, const SECItem *b) |
michael@0 | 508 | { |
michael@0 | 509 | STUB_SAFE_CALL2(SECITEM_CompareItem_Util, a, b); |
michael@0 | 510 | abort(); |
michael@0 | 511 | return SECEqual; |
michael@0 | 512 | } |
michael@0 | 513 | |
michael@0 | 514 | extern SECStatus |
michael@0 | 515 | SECITEM_CopyItem_stub(PLArenaPool *arena, SECItem *to, const SECItem *from) |
michael@0 | 516 | { |
michael@0 | 517 | STUB_SAFE_CALL3(SECITEM_CopyItem_Util, arena, to, from); |
michael@0 | 518 | abort(); |
michael@0 | 519 | return SECFailure; |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | extern SECOidTag |
michael@0 | 523 | SECOID_FindOIDTag_stub(const SECItem *oid) |
michael@0 | 524 | { |
michael@0 | 525 | STUB_SAFE_CALL1(SECOID_FindOIDTag_Util, oid); |
michael@0 | 526 | abort(); |
michael@0 | 527 | return SEC_OID_UNKNOWN; |
michael@0 | 528 | } |
michael@0 | 529 | |
michael@0 | 530 | extern void |
michael@0 | 531 | SECITEM_ZfreeItem_stub(SECItem *zap, PRBool freeit) |
michael@0 | 532 | { |
michael@0 | 533 | STUB_SAFE_CALL2(SECITEM_ZfreeItem_Util, zap, freeit); |
michael@0 | 534 | abort(); |
michael@0 | 535 | } |
michael@0 | 536 | |
michael@0 | 537 | extern int |
michael@0 | 538 | NSS_SecureMemcmp_stub(const void *a, const void *b, size_t n) |
michael@0 | 539 | { |
michael@0 | 540 | STUB_SAFE_CALL3(NSS_SecureMemcmp, a, b, n); |
michael@0 | 541 | abort(); |
michael@0 | 542 | } |
michael@0 | 543 | |
michael@0 | 544 | #ifdef FREEBL_NO_WEAK |
michael@0 | 545 | |
michael@0 | 546 | static const char *nsprLibName = SHLIB_PREFIX"nspr4."SHLIB_SUFFIX; |
michael@0 | 547 | static const char *nssutilLibName = SHLIB_PREFIX"nssutil3."SHLIB_SUFFIX; |
michael@0 | 548 | |
michael@0 | 549 | static SECStatus |
michael@0 | 550 | freebl_InitNSPR(void *lib) |
michael@0 | 551 | { |
michael@0 | 552 | STUB_FETCH_FUNCTION(PR_Free); |
michael@0 | 553 | STUB_FETCH_FUNCTION(PR_Open); |
michael@0 | 554 | STUB_FETCH_FUNCTION(PR_ImportPipe); |
michael@0 | 555 | STUB_FETCH_FUNCTION(PR_Close); |
michael@0 | 556 | STUB_FETCH_FUNCTION(PR_Read); |
michael@0 | 557 | STUB_FETCH_FUNCTION(PR_Seek); |
michael@0 | 558 | STUB_FETCH_FUNCTION(PR_GetLibraryFilePathname); |
michael@0 | 559 | STUB_FETCH_FUNCTION(PR_Assert); |
michael@0 | 560 | STUB_FETCH_FUNCTION(PR_Sleep); |
michael@0 | 561 | STUB_FETCH_FUNCTION(PR_CallOnce); |
michael@0 | 562 | STUB_FETCH_FUNCTION(PR_NewCondVar); |
michael@0 | 563 | STUB_FETCH_FUNCTION(PR_NotifyCondVar); |
michael@0 | 564 | STUB_FETCH_FUNCTION(PR_NotifyAllCondVar); |
michael@0 | 565 | STUB_FETCH_FUNCTION(PR_WaitCondVar); |
michael@0 | 566 | STUB_FETCH_FUNCTION(PR_DestroyCondVar); |
michael@0 | 567 | STUB_FETCH_FUNCTION(PR_NewLock); |
michael@0 | 568 | STUB_FETCH_FUNCTION(PR_Unlock); |
michael@0 | 569 | STUB_FETCH_FUNCTION(PR_Lock); |
michael@0 | 570 | STUB_FETCH_FUNCTION(PR_DestroyLock); |
michael@0 | 571 | return SECSuccess; |
michael@0 | 572 | } |
michael@0 | 573 | |
michael@0 | 574 | static SECStatus |
michael@0 | 575 | freebl_InitNSSUtil(void *lib) |
michael@0 | 576 | { |
michael@0 | 577 | STUB_FETCH_FUNCTION(PORT_Alloc_Util); |
michael@0 | 578 | STUB_FETCH_FUNCTION(PORT_Free_Util); |
michael@0 | 579 | STUB_FETCH_FUNCTION(PORT_ZAlloc_Util); |
michael@0 | 580 | STUB_FETCH_FUNCTION(PORT_ZFree_Util); |
michael@0 | 581 | STUB_FETCH_FUNCTION(PORT_NewArena_Util); |
michael@0 | 582 | STUB_FETCH_FUNCTION(PORT_ArenaAlloc_Util); |
michael@0 | 583 | STUB_FETCH_FUNCTION(PORT_ArenaZAlloc_Util); |
michael@0 | 584 | STUB_FETCH_FUNCTION(PORT_FreeArena_Util); |
michael@0 | 585 | STUB_FETCH_FUNCTION(PORT_GetError_Util); |
michael@0 | 586 | STUB_FETCH_FUNCTION(PORT_SetError_Util); |
michael@0 | 587 | STUB_FETCH_FUNCTION(SECITEM_FreeItem_Util); |
michael@0 | 588 | STUB_FETCH_FUNCTION(SECITEM_AllocItem_Util); |
michael@0 | 589 | STUB_FETCH_FUNCTION(SECITEM_CompareItem_Util); |
michael@0 | 590 | STUB_FETCH_FUNCTION(SECITEM_CopyItem_Util); |
michael@0 | 591 | STUB_FETCH_FUNCTION(SECITEM_ZfreeItem_Util); |
michael@0 | 592 | STUB_FETCH_FUNCTION(SECOID_FindOIDTag_Util); |
michael@0 | 593 | STUB_FETCH_FUNCTION(NSS_SecureMemcmp); |
michael@0 | 594 | return SECSuccess; |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | /* |
michael@0 | 598 | * fetch the library if it's loaded. For NSS it should already be loaded |
michael@0 | 599 | */ |
michael@0 | 600 | #define freebl_getLibrary(libName) \ |
michael@0 | 601 | dlopen (libName, RTLD_LAZY|RTLD_NOLOAD) |
michael@0 | 602 | |
michael@0 | 603 | #define freebl_releaseLibrary(lib) \ |
michael@0 | 604 | if (lib) dlclose(lib) |
michael@0 | 605 | |
michael@0 | 606 | static void * FREEBLnsprGlobalLib = NULL; |
michael@0 | 607 | static void * FREEBLnssutilGlobalLib = NULL; |
michael@0 | 608 | |
michael@0 | 609 | void __attribute ((destructor)) FREEBL_unload() |
michael@0 | 610 | { |
michael@0 | 611 | freebl_releaseLibrary(FREEBLnsprGlobalLib); |
michael@0 | 612 | freebl_releaseLibrary(FREEBLnssutilGlobalLib); |
michael@0 | 613 | } |
michael@0 | 614 | #endif |
michael@0 | 615 | |
michael@0 | 616 | /* |
michael@0 | 617 | * load the symbols from the real libraries if available. |
michael@0 | 618 | * |
michael@0 | 619 | * if force is set, explicitly load the libraries if they are not already |
michael@0 | 620 | * loaded. If we could not use the real libraries, return failure. |
michael@0 | 621 | */ |
michael@0 | 622 | extern SECStatus |
michael@0 | 623 | FREEBL_InitStubs() |
michael@0 | 624 | { |
michael@0 | 625 | SECStatus rv = SECSuccess; |
michael@0 | 626 | #ifdef FREEBL_NO_WEAK |
michael@0 | 627 | void *nspr = NULL; |
michael@0 | 628 | void *nssutil = NULL; |
michael@0 | 629 | |
michael@0 | 630 | /* NSPR should be first */ |
michael@0 | 631 | if (!FREEBLnsprGlobalLib) { |
michael@0 | 632 | nspr = freebl_getLibrary(nsprLibName); |
michael@0 | 633 | if (!nspr) { |
michael@0 | 634 | return SECFailure; |
michael@0 | 635 | } |
michael@0 | 636 | rv = freebl_InitNSPR(nspr); |
michael@0 | 637 | if (rv != SECSuccess) { |
michael@0 | 638 | freebl_releaseLibrary(nspr); |
michael@0 | 639 | return rv; |
michael@0 | 640 | } |
michael@0 | 641 | FREEBLnsprGlobalLib = nspr; /* adopt */ |
michael@0 | 642 | } |
michael@0 | 643 | /* now load NSSUTIL */ |
michael@0 | 644 | if (!FREEBLnssutilGlobalLib) { |
michael@0 | 645 | nssutil= freebl_getLibrary(nssutilLibName); |
michael@0 | 646 | if (!nssutil) { |
michael@0 | 647 | return SECFailure; |
michael@0 | 648 | } |
michael@0 | 649 | rv = freebl_InitNSSUtil(nssutil); |
michael@0 | 650 | if (rv != SECSuccess) { |
michael@0 | 651 | freebl_releaseLibrary(nssutil); |
michael@0 | 652 | return rv; |
michael@0 | 653 | } |
michael@0 | 654 | FREEBLnssutilGlobalLib = nssutil; /* adopt */ |
michael@0 | 655 | } |
michael@0 | 656 | #endif |
michael@0 | 657 | |
michael@0 | 658 | return rv; |
michael@0 | 659 | } |