diff options
| author | guenther <> | 2017-12-16 20:06:56 +0000 |
|---|---|---|
| committer | guenther <> | 2017-12-16 20:06:56 +0000 |
| commit | 09687c04dc436ea29235c588185e43443b906e9f (patch) | |
| tree | 2fa5dfadabf13e01a2eeaa103c96c8e3c59c40c9 /src/lib/libc/stdlib/thread_atexit.c | |
| parent | 95bd5261c689f60078c0b683fa28a76360fb28e4 (diff) | |
| download | openbsd-09687c04dc436ea29235c588185e43443b906e9f.tar.gz openbsd-09687c04dc436ea29235c588185e43443b906e9f.tar.bz2 openbsd-09687c04dc436ea29235c588185e43443b906e9f.zip | |
Move __cxa_thread_atexit* to its own .c file to avoid pulling the code
(w/ _dlctl reference) into static executables. It's all Mark's code so
put his preferred copyright on it.
ok kettenis@
Diffstat (limited to 'src/lib/libc/stdlib/thread_atexit.c')
| -rw-r--r-- | src/lib/libc/stdlib/thread_atexit.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/thread_atexit.c b/src/lib/libc/stdlib/thread_atexit.c new file mode 100644 index 0000000000..2e00428eba --- /dev/null +++ b/src/lib/libc/stdlib/thread_atexit.c | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* $OpenBSD: thread_atexit.c,v 1.1 2017/12/16 20:06:56 guenther Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <dlfcn.h> | ||
| 19 | #include <elf.h> | ||
| 20 | #pragma weak _DYNAMIC | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <tib.h> | ||
| 23 | |||
| 24 | #include "atexit.h" | ||
| 25 | |||
| 26 | typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak)); | ||
| 27 | |||
| 28 | __weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl); | ||
| 29 | |||
| 30 | int | ||
| 31 | __cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso) | ||
| 32 | { | ||
| 33 | struct thread_atexit_fn *fnp; | ||
| 34 | struct tib *tib = TIB_GET(); | ||
| 35 | |||
| 36 | fnp = calloc(1, sizeof(struct thread_atexit_fn)); | ||
| 37 | if (fnp == NULL) | ||
| 38 | return -1; | ||
| 39 | |||
| 40 | if (_DYNAMIC) | ||
| 41 | dlctl(NULL, DL_REFERENCE, dso); | ||
| 42 | |||
| 43 | fnp->func = func; | ||
| 44 | fnp->arg = arg; | ||
| 45 | fnp->next = tib->tib_atexit; | ||
| 46 | tib->tib_atexit = fnp; | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
