/* stdlib */
_Exit
__cxa_atexit
+__cxa_thread_atexit
+__cxa_thread_atexit_impl
__cxa_finalize
__isthreaded
a64l
-/* $OpenBSD: thread_private.h,v 1.32 2017/11/04 22:53:57 jca Exp $ */
+/* $OpenBSD: thread_private.h,v 1.33 2017/12/05 13:45:31 kettenis Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
void _rthread_debug(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
pid_t _thread_dofork(pid_t (*_sys_fork)(void));
+void _thread_finalize(void);
/*
* Threading syscalls not declared in system headers
major=92
-minor=0
+minor=1
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then librthread/shlib_version also be updated.
-/* $OpenBSD: atexit.c,v 1.24 2015/11/10 04:14:03 guenther Exp $ */
+/* $OpenBSD: atexit.c,v 1.25 2017/12/05 13:45:31 kettenis 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 <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;
+}
+DEF_STRONG(__cxa_thread_atexit_impl);
+
+void
+_thread_finalize(void)
+{
+ struct tib *tib = TIB_GET();
+
+ while (tib->tib_atexit) {
+ struct thread_atexit_fn *fnp = tib->tib_atexit;
+ tib->tib_atexit = fnp->next;
+ fnp->func(fnp->arg);
+ free(fnp);
+ }
+}
+
/*
* Call all handlers registered with __cxa_atexit() for the shared
* object owning 'dso'.
int n, pgsize = getpagesize();
static int call_depth;
+ if (dso == NULL)
+ _thread_finalize();
+
_ATEXIT_LOCK();
call_depth++;
-/* $OpenBSD: atexit.h,v 1.10 2015/10/25 18:01:24 guenther Exp $ */
+/* $OpenBSD: atexit.h,v 1.11 2017/12/05 13:45:31 kettenis Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
__END_HIDDEN_DECLS
int __cxa_atexit(void (*)(void *), void *, void *);
+int __cxa_thread_atexit(void (*)(void *), void *, void *);
void __cxa_finalize(void *);
PROTO_NORMAL(__cxa_atexit);
+PROTO_STD_DEPRECATED(__cxa_thread_atexit);
PROTO_NORMAL(__cxa_finalize);
-/* $OpenBSD: rthread.c,v 1.6 2017/11/04 22:53:57 jca Exp $ */
+/* $OpenBSD: rthread.c,v 1.7 2017/12/05 13:45:31 kettenis Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
oclfn->fn(oclfn->arg);
free(oclfn);
}
+ _thread_finalize();
_rthread_tls_destructors(thread);
if (_thread_cb.tc_thread_release != NULL)