summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/thread_atexit.c
diff options
context:
space:
mode:
authorguenther <>2017-12-16 20:06:56 +0000
committerguenther <>2017-12-16 20:06:56 +0000
commit2eba43d0c1c78cf2d13b896bb9a608c482a585df (patch)
tree2fa5dfadabf13e01a2eeaa103c96c8e3c59c40c9 /src/lib/libc/stdlib/thread_atexit.c
parentcfcd6a9a82fccae3c7538bacdf933acc3f90fea2 (diff)
downloadopenbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.tar.gz
openbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.tar.bz2
openbsd-2eba43d0c1c78cf2d13b896bb9a608c482a585df.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.c49
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
26typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
27
28__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
29
30int
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}