-# $OpenBSD: Makefile.inc,v 1.63 2017/03/24 16:15:31 otto Exp $
+# $OpenBSD: Makefile.inc,v 1.64 2017/12/16 20:06:55 guenther Exp $
# stdlib sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/stdlib ${LIBCSRCDIR}/stdlib
merge.c posix_pty.c qsort.c radixsort.c rand.c random.c \
realpath.c remque.c setenv.c strtoimax.c \
strtol.c strtoll.c strtonum.c strtoul.c strtoull.c strtoumax.c \
- system.c tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c \
+ system.c \
+ tfind.c thread_atexit.c tsearch.c \
+ _rand48.c drand48.c erand48.c jrand48.c \
lcong48.c lrand48.c mrand48.c nrand48.c seed48.c srand48.c \
_Exit.c icdb.c
-/* $OpenBSD: atexit.c,v 1.26 2017/12/05 21:11:10 kettenis Exp $ */
+/* $OpenBSD: atexit.c,v 1.27 2017/12/16 20:06:56 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
#include <sys/types.h>
#include <sys/mman.h>
-#include <dlfcn.h>
-#include <elf.h>
-#pragma weak _DYNAMIC
#include <stdlib.h>
#include <string.h>
+#include <tib.h>
#include <unistd.h>
+
#include "atexit.h"
#include "atfork.h"
#include "thread_private.h"
-#include "tib.h"
-
-typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
-
-struct thread_atexit_fn {
- void (*func)(void *);
- void *arg;
- struct thread_atexit_fn *next;
-};
struct atexit *__atexit;
static int restartloop;
}
DEF_STRONG(atexit);
-__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
-
-int
-__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
-{
- struct thread_atexit_fn *fnp;
- struct tib *tib = TIB_GET();
-
- fnp = calloc(1, sizeof(struct thread_atexit_fn));
- if (fnp == NULL)
- return -1;
-
- if (_DYNAMIC)
- dlctl(NULL, DL_REFERENCE, dso);
-
- fnp->func = func;
- fnp->arg = arg;
- fnp->next = tib->tib_atexit;
- tib->tib_atexit = fnp;
-
- return 0;
-}
-
void
_thread_finalize(void)
{
-/* $OpenBSD: atexit.h,v 1.11 2017/12/05 13:45:31 kettenis Exp $ */
+/* $OpenBSD: atexit.h,v 1.12 2017/12/16 20:06:56 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
} fns[1]; /* the table itself */
};
+/* a chain of these are hung off each thread's TIB's tib_atexit member */
+struct thread_atexit_fn {
+ void (*func)(void *);
+ void *arg;
+ struct thread_atexit_fn *next;
+};
+
__BEGIN_HIDDEN_DECLS
extern struct atexit *__atexit; /* points to head of LIFO stack */
__END_HIDDEN_DECLS
--- /dev/null
+/* $OpenBSD: thread_atexit.c,v 1.1 2017/12/16 20:06:56 guenther Exp $ */
+/*
+ * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dlfcn.h>
+#include <elf.h>
+#pragma weak _DYNAMIC
+#include <stdlib.h>
+#include <tib.h>
+
+#include "atexit.h"
+
+typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
+
+__weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl);
+
+int
+__cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso)
+{
+ struct thread_atexit_fn *fnp;
+ struct tib *tib = TIB_GET();
+
+ fnp = calloc(1, sizeof(struct thread_atexit_fn));
+ if (fnp == NULL)
+ return -1;
+
+ if (_DYNAMIC)
+ dlctl(NULL, DL_REFERENCE, dso);
+
+ fnp->func = func;
+ fnp->arg = arg;
+ fnp->next = tib->tib_atexit;
+ tib->tib_atexit = fnp;
+
+ return 0;
+}