diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2007-05-05 15:21:22 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2007-05-05 15:21:22 +0000 |
commit | b769e807d32df4b2769d521a9f2e07fa5636ad46 (patch) | |
tree | a84bec994dddd31b2cb2cb0ba6947ebfc34e71e2 /libexec | |
parent | 65314bd4b49f9cce5a6d3f3c9cf77bc7272e60fa (diff) |
Provide hook so that rthreads can provide a spinlock to protect from races
in lazy binding. ok art@, kurt@
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/alpha/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/amd64/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/arm/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/dlfcn.c | 15 | ||||
-rw-r--r-- | libexec/ld.so/hppa/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/i386/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/powerpc/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/resolve.h | 4 | ||||
-rw-r--r-- | libexec/ld.so/sh/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/sparc/rtld_machine.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/sparc64/rtld_machine.c | 4 |
11 files changed, 44 insertions, 11 deletions
diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c index 328d9515b19..9ace19edba7 100644 --- a/libexec/ld.so/alpha/rtld_machine.c +++ b/libexec/ld.so/alpha/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.38 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.39 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -204,6 +204,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->plt_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect(addr, sizeof(Elf_Addr), PROT_READ|PROT_WRITE); } @@ -214,6 +215,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->plt_size != 0) { _dl_mprotect(addr, sizeof(Elf_Addr), PROT_READ); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/amd64/rtld_machine.c b/libexec/ld.so/amd64/rtld_machine.c index fdeaf40a848..5d5956a0e99 100644 --- a/libexec/ld.so/amd64/rtld_machine.c +++ b/libexec/ld.so/amd64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.11 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.12 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -364,6 +364,7 @@ _dl_bind(elf_object_t *object, int index) if (object->got_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ|PROT_WRITE); } @@ -374,6 +375,7 @@ _dl_bind(elf_object_t *object, int index) if (object->got_size != 0) { _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/arm/rtld_machine.c b/libexec/ld.so/arm/rtld_machine.c index 63225443da6..84205cb5ae3 100644 --- a/libexec/ld.so/arm/rtld_machine.c +++ b/libexec/ld.so/arm/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.10 2006/08/23 21:22:09 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.11 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -411,6 +411,7 @@ _dl_bind(elf_object_t *object, int relidx) if (object->got_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ|PROT_WRITE); } @@ -422,6 +423,7 @@ _dl_bind(elf_object_t *object, int relidx) if (object->got_size != 0) { _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } return newval; diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c index 682745d4f09..506d4110375 100644 --- a/libexec/ld.so/dlfcn.c +++ b/libexec/ld.so/dlfcn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dlfcn.c,v 1.74 2007/04/03 14:33:07 jason Exp $ */ +/* $OpenBSD: dlfcn.c,v 1.75 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -43,6 +43,7 @@ int _dl_errno; int _dl_real_close(void *handle); void (*_dl_thread_fnc)(int) = NULL; +void (*_dl_bind_lock_f)(int) = NULL; static elf_object_t *obj_from_addr(const void *addr); void * @@ -195,6 +196,11 @@ dlctl(void *handle, int command, void *data) _dl_thread_fnc = data; retval = 0; break; + case DL_SETBINDLCK: + DL_DEB(("dlctl: _dl_bind_lock_f set to %p\n", data)); + _dl_bind_lock_f = data; + retval = 0; + break; case 0x20: _dl_show_objects(); retval = 0; @@ -491,6 +497,13 @@ _dl_show_objects(void) } void +_dl_thread_bind_lock(int what) +{ + if (_dl_bind_lock_f != NULL) + (*_dl_bind_lock_f)(what); +} + +void _dl_thread_kern_stop(void) { if (_dl_thread_fnc != NULL) diff --git a/libexec/ld.so/hppa/rtld_machine.c b/libexec/ld.so/hppa/rtld_machine.c index 3bead5d3e9e..bc3a2d56cd8 100644 --- a/libexec/ld.so/hppa/rtld_machine.c +++ b/libexec/ld.so/hppa/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.12 2006/05/03 16:10:52 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.13 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -380,6 +380,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->got_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); /* mprotect the actual modified region, not the whole plt */ _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 2, PROT_READ|PROT_WRITE); @@ -393,6 +394,7 @@ _dl_bind(elf_object_t *object, int reloff) /* mprotect the actual modified region, not the whole plt */ _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 3, PROT_READ); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/i386/rtld_machine.c b/libexec/ld.so/i386/rtld_machine.c index 6662056ae20..2bd698d10ba 100644 --- a/libexec/ld.so/i386/rtld_machine.c +++ b/libexec/ld.so/i386/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.20 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.21 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -365,6 +365,7 @@ _dl_bind(elf_object_t *object, int index) if (object->got_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ|PROT_WRITE); } @@ -375,6 +376,7 @@ _dl_bind(elf_object_t *object, int index) if (object->got_size != 0) { _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index dbff78876ce..52fb8cbbf4d 100644 --- a/libexec/ld.so/powerpc/rtld_machine.c +++ b/libexec/ld.so/powerpc/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.42 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.43 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -567,6 +567,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->plt_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_WRITE|PROT_EXEC); } @@ -618,6 +619,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->plt_size != 0) { _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_EXEC); /* only PPC is PROT_EXE */ + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } return (value); diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index d03e69de490..960735bc366 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.53 2007/04/03 14:33:07 jason Exp $ */ +/* $OpenBSD: resolve.h,v 1.54 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -222,6 +222,8 @@ void _dl_load_list_free(struct load_list *load_list); void _dl_thread_kern_go(void); void _dl_thread_kern_stop(void); +void _dl_thread_bind_lock(int); + extern elf_object_t *_dl_objects; extern elf_object_t *_dl_last_object; diff --git a/libexec/ld.so/sh/rtld_machine.c b/libexec/ld.so/sh/rtld_machine.c index 9865e2af09e..9af19cfd91c 100644 --- a/libexec/ld.so/sh/rtld_machine.c +++ b/libexec/ld.so/sh/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.7 2007/03/07 18:50:02 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.8 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -858,6 +858,7 @@ _dl_bind(elf_object_t *object, int relidx) if (object->got_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ|PROT_WRITE); } @@ -870,6 +871,7 @@ _dl_bind(elf_object_t *object, int relidx) _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); + _dl_thread_bind_lock(1); } return newval; } diff --git a/libexec/ld.so/sparc/rtld_machine.c b/libexec/ld.so/sparc/rtld_machine.c index f14d49a69b1..cc3489b37bc 100644 --- a/libexec/ld.so/sparc/rtld_machine.c +++ b/libexec/ld.so/sparc/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.27 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.28 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -340,6 +340,7 @@ _dl_bind(elf_object_t *object, int reloff) if (object->plt_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); /* mprotect the actual modified region, not the whole plt */ _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 3, PROT_READ|PROT_WRITE|PROT_EXEC); @@ -352,6 +353,7 @@ _dl_bind(elf_object_t *object, int reloff) /* mprotect the actual modified region, not the whole plt */ _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 3, PROT_READ|PROT_EXEC); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index 8d8b12a24b1..74016d5e693 100644 --- a/libexec/ld.so/sparc64/rtld_machine.c +++ b/libexec/ld.so/sparc64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.38 2006/10/28 16:06:05 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.39 2007/05/05 15:21:21 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -631,6 +631,7 @@ _dl_bind(elf_object_t *object, int index) if (object->plt_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); + _dl_thread_bind_lock(0); _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_WRITE|PROT_EXEC); } @@ -641,6 +642,7 @@ _dl_bind(elf_object_t *object, int index) if (object->plt_size != 0) { _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_EXEC); + _dl_thread_bind_lock(1); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } |