Changeset 5317:6b1045321fd6 in roaraudio for libroar/roardl.c
- Timestamp:
- 12/01/11 19:38:56 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/roardl.c
r5313 r5317 41 41 42 42 struct roar_dl_lhandle { 43 size_t refc; // currently unused. 44 int flags; 45 char * libname; // only used for ROAR_DL_FLAG_STATIC. 43 46 struct roar_dl_librarypara * para; 44 47 struct roar_dl_libraryinst * lib; … … 47 50 void * global_data; 48 51 void * global_data_state; 52 struct roar_notify_core * notifycore; 49 53 } context; 50 54 #if defined(ROAR_HAVE_LIBDL) … … 118 122 para->refc--; 119 123 120 if ( para->refc == 0 ) { 121 if ( para->args_store != NULL ) { 122 roar_mm_free(para->args_store); 123 roar_mm_free(para->argv); 124 } 125 roar_mm_free(para); 126 } 124 if ( para->refc ) 125 return 0; 126 127 if ( para->notifycore != NULL ) 128 roar_notify_core_unref(para->notifycore); 129 130 if ( para->args_store != NULL ) { 131 roar_mm_free(para->args_store); 132 roar_mm_free(para->argv); 133 } 134 135 roar_mm_free(para); 127 136 128 137 return 0; … … 165 174 #if defined(ROAR_HAVE_LIBDL) 166 175 static void * _roardl2ldl (struct roar_dl_lhandle * lhandle) { 167 if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) 176 ROAR_DBG("_roardl2ldl(lhandle=%p) = ?", lhandle); 177 178 if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) { 179 ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)RTLD_DEFAULT); 168 180 return RTLD_DEFAULT; 169 170 if ( lhandle == ROAR_DL_HANDLE_NEXT ) 181 } 182 183 if ( lhandle == ROAR_DL_HANDLE_NEXT ) { 184 ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)RTLD_NEXT); 171 185 return RTLD_NEXT; 172 186 } 187 188 ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)(lhandle->handle)); 173 189 return lhandle->handle; 174 190 } … … 178 194 int ra_init, struct roar_dl_librarypara * para) { 179 195 struct roar_dl_lhandle * ret = NULL; 196 #if defined(ROAR_HAVE_LIBDL) 197 #ifdef RTLD_DEEPBIND 198 int libdl_flags = RTLD_NOW|RTLD_DEEPBIND; 199 #else 200 int libdl_flags = RTLD_NOW; 201 #endif 202 #endif 180 203 int err; 181 204 182 // early errors just return. 183 184 if ( flags != ROAR_DL_FLAG_DEFAUTS ) { 185 roar_err_set(ROAR_ERROR_NOTSUP); 186 return NULL; 187 } 205 if ( flags == ROAR_DL_FLAG_DEFAULTS ) 206 flags = ROAR_DL_FLAG_NONE; 188 207 189 208 if ( (ret = roar_mm_malloc(sizeof(struct roar_dl_lhandle))) == NULL ) … … 194 213 roar_err_initstore(&(ret->context.error_state)); 195 214 196 #if defined(ROAR_HAVE_LIBDL) 197 flags = RTLD_NOW; 198 199 #ifdef RTLD_DEEPBIND 200 flags |= RTLD_DEEPBIND; 201 #endif 202 203 ret->handle = dlopen(filename, flags); 204 205 if ( ret->handle == NULL ) { 215 ret->flags = flags; 216 217 if ( flags & ROAR_DL_FLAG_STATIC ) { 218 if ( filename == NULL ) { 219 ret->libname = NULL; 220 } else { 221 ret->libname = roar_mm_strdup(filename); 222 } 223 } else { 224 #if defined(ROAR_HAVE_LIBDL) 225 ret->handle = dlopen(filename, libdl_flags); 226 227 if ( ret->handle == NULL ) { 228 ROAR_DBG("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not load library: %s", filename, flags, ra_init, para, roar_dl_errstr(ret)); 229 roar_mm_free(ret); 230 return NULL; 231 } 232 #else 206 233 roar_mm_free(ret); 207 return NULL; 208 } 209 #else 210 roar_mm_free(ret); 211 roar_err_set(ROAR_ERROR_NOSYS); 212 return NULL; 213 #endif 234 roar_err_set(ROAR_ERROR_NOSYS); 235 return NULL; 236 #endif 237 } 214 238 215 239 ret->para = para; … … 220 244 ROAR_WARN("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not init RA lib: %s", filename, flags, ra_init, para, roar_error2str(err)); 221 245 #if defined(ROAR_HAVE_LIBDL) 222 dlclose(ret->handle); 246 if ( ret->handle != NULL ) 247 dlclose(ret->handle); 223 248 #endif 224 249 roar_mm_free(ret); … … 242 267 } 243 268 244 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) 269 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) { 270 roar_dl_context_restore(lhandle); 245 271 lhandle->lib->unload(lhandle->para, lhandle->lib); 246 247 #if defined(ROAR_HAVE_LIBDL) 248 ret = dlclose(_roardl2ldl(lhandle)); 272 roar_dl_context_store(lhandle); 273 } 274 275 #if defined(ROAR_HAVE_LIBDL) 276 if ( lhandle->handle == NULL ) { 277 ret = 0; 278 } else { 279 ret = dlclose(_roardl2ldl(lhandle)); 280 } 249 281 #else 250 282 ret = -1; … … 257 289 roar_dl_para_unref(lhandle->para); 258 290 291 if ( lhandle->libname != NULL ) 292 roar_mm_free(lhandle->libname); 293 259 294 roar_mm_free(lhandle); 260 295 … … 268 303 (void)type; 269 304 305 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i): errno=%s, dlerror()='%s'", lhandle, sym, type, ret, strerror(errno), dlerror()); 270 306 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i) = %p", lhandle, sym, type, ret); 271 307 272 308 return ret; 273 309 #else 310 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i) = NULL // errno=NOSYS", lhandle, sym, type, ret); 311 roar_err_set(ROAR_ERROR_NOSYS); 274 312 return NULL; 275 313 #endif … … 283 321 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 284 322 struct roar_dl_libraryinst * lib; 323 struct roar_dl_lhandle * getsymhandle = lhandle; 285 324 void * global_data_state = NULL; 286 325 int i; … … 290 329 return -1; 291 330 } else { 331 if ( prefix == NULL ) 332 prefix = lhandle->libname; 333 292 334 if ( para == NULL ) 293 335 para = lhandle->para; 336 337 if ( lhandle->flags & ROAR_DL_FLAG_STATIC ) 338 getsymhandle = ROAR_DL_HANDLE_DEFAULT; 294 339 } 295 340 … … 303 348 ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s'): name='%s'", lhandle, prefix, name); 304 349 305 if ( (func = roar_dl_getsym(lhandle, name, -1)) == NULL ) 306 return -1; 350 if ( (func = roar_dl_getsym(getsymhandle, name, -1)) == NULL ) { 351 ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s') = -1", lhandle, prefix); 352 return -1; 353 } 307 354 308 355 ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s'): func=%p", lhandle, prefix, func); … … 416 463 struct roar_error_state error_state; 417 464 465 ROAR_DBG("roar_dl_context_restore(lhandle=%p) = ?", lhandle); 466 418 467 if ( (void*)lhandle < (void*)128 ) { 468 ROAR_DBG("roar_dl_context_restore(lhandle=%p) = -1 // errno=NOTSUP", lhandle); 419 469 roar_err_set(ROAR_ERROR_NOTSUP); 420 470 return -1; … … 426 476 427 477 if ( lhandle->lib->global_data_pointer != NULL ) { 478 ROAR_DBG("roar_dl_context_restore(lhandle=%p): gptr(%p): %p -> %p", lhandle, 479 lhandle->lib->global_data_pointer, *(lhandle->lib->global_data_pointer), lhandle->context.global_data); 428 480 lhandle->context.global_data_state = *(lhandle->lib->global_data_pointer); 429 481 *(lhandle->lib->global_data_pointer) = lhandle->context.global_data; 430 482 } 431 483 484 if ( lhandle->para->notifycore != NULL ) 485 lhandle->context.notifycore = roar_notify_core_swap_global(lhandle->para->notifycore); 486 487 ROAR_DBG("roar_dl_context_restore(lhandle=%p) = 0", lhandle); 432 488 return 0; 433 489 } … … 436 492 struct roar_error_state error_state; 437 493 494 ROAR_DBG("roar_dl_context_store(lhandle=%p) = ?", lhandle); 495 438 496 if ( (void*)lhandle < (void*)128 ) { 497 ROAR_DBG("roar_dl_context_store(lhandle=%p) = -1 // errno=NOTSUP", lhandle); 439 498 roar_err_set(ROAR_ERROR_NOTSUP); 440 499 return -1; 441 500 } 442 501 502 if ( lhandle->para->notifycore != NULL ) { 503 roar_notify_core_unref(roar_notify_core_swap_global(lhandle->context.notifycore)); 504 roar_notify_core_unref(lhandle->context.notifycore); 505 lhandle->context.notifycore = NULL; 506 } 507 443 508 if ( lhandle->lib->global_data_pointer != NULL ) { 509 ROAR_DBG("roar_dl_context_store(lhandle=%p): gptr(%p): %p -> %p", lhandle, 510 lhandle->lib->global_data_pointer, *(lhandle->lib->global_data_pointer), lhandle->context.global_data_state); 444 511 *(lhandle->lib->global_data_pointer) = lhandle->context.global_data_state; 445 512 } … … 449 516 lhandle->context.error_state = error_state; 450 517 518 ROAR_DBG("roar_dl_context_store(lhandle=%p) = 0", lhandle); 451 519 return 0; 452 520 } 453 521 522 int roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger) { 523 int ret; 524 525 if ( (void*)lhandle < (void*)128 ) { 526 roar_err_set(ROAR_ERROR_NOTSUP); 527 return -1; 528 } 529 530 if ( lhandle->lib->appsched == NULL ) { 531 roar_err_set(ROAR_ERROR_NOENT); 532 return -1; 533 } 534 535 switch (trigger) { 536 #define _trig(lname,uname) \ 537 case ROAR_DL_APPSCHED_ ## uname : \ 538 if ( lhandle->lib->appsched->lname == NULL ) { \ 539 roar_err_set(ROAR_ERROR_NOENT); \ 540 return -1; \ 541 } \ 542 roar_dl_context_restore(lhandle); \ 543 ret = lhandle->lib->appsched->lname(lhandle->para); \ 544 roar_dl_context_store(lhandle); \ 545 return ret; \ 546 break; 547 _trig(init, INIT); 548 _trig(free, FREE); 549 _trig(update, UPDATE); 550 } 551 552 roar_err_set(ROAR_ERROR_BADRQC); 553 return -1; 554 } 555 454 556 //ll
Note: See TracChangeset
for help on using the changeset viewer.