History log of /openbsd-current/lib/libc/stdlib/atexit.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.29 27-Dec-2022 jmc

spelling fixes; from paul tagliamonte
any changes not taken noted on tech, but chiefly here i did not take the
cancelation - cancellation changes;


# 1.28 22-Oct-2022 deraadt

In __cxa_atexit(), there is no need to initialize local pointer before
the lock, when it is correctly initialized after the lock
ok otto millert


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 16-Dec-2017 guenther

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@


# 1.26 05-Dec-2017 kettenis

Remove DEF_STRONG(__cxa_thread_atexit_impl). This produces an unwanted
_libc___cxa_thread_atexit_impl reference on gcc architectures that breaks
the build.


# 1.25 05-Dec-2017 kettenis

Implement __cxa_thread_atexit to support C++11 thread_local scope. The
interface is also made available as __cxa_thread_atexit_impl to satisfy the
needs of GNU libstdc++.

ok guenther@, millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.24 10-Nov-2015 guenther

libc.so can't be unloaded, so move the hidden atexit() and pthread_atfork()
stubs for the executable from crtbegin.o into libc, which lets them be
excluded from static links that don't use them.
For this, drop the normal crt{begin,end}S.o from libc.so: the .init and .fini
sections for libc aren't called at the right times anyway, so it's good that
they're unused. libc.so just needs __guard_local and the .note.openbsd.ident
section, so add them to stack_protector.c for now (this will be improved)

"good time" deraadt@


# 1.23 25-Oct-2015 guenther

Move the _atfork_list definition to atexit.c so that the fork syscall stub
doesn't get pulled into all static executables

ok millert@ jca@


# 1.22 25-Oct-2015 guenther

Hide __atexit and __atexit_register_cleanup()
Wrap __cxa_{atexit,finalize}() so the call from exit() goes direct
Switch regress/lib/libc/atexit/ to be built with -static so that it can
still access __atexit*

ok millert@ jca@


Revision tags: OPENBSD_5_8_BASE
# 1.21 07-Apr-2015 guenther

Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback
handling from libpthread to libc, though libpthread still overrides the
inner call to handle locking and thread-library reinitialization.
Major version bump for both libc and libpthread.

verification that this fixes various ports ajacoutot@
asm assistance miod@; ok millert@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.20 11-Jul-2014 kettenis

Add locking for __cxa_finalize() as it modifies the page permissions of the
__atexit tables and touches global variables. From Srinavasa Nagaraju
through Android/Elliott Hughes.

ok tedu@, guenther@


# 1.19 10-Jul-2014 tedu

as noted by google/android via kettenis, atexit handlers can install new
handlers. if this happens, restart the loop.
ok kettenis matthew millert miod


# 1.18 18-Jun-2014 kettenis

Always call atexit handlers as if they were registered with __cxa_atexit.
The extra argument doesn't hurt genuine atexit handlers and this fixes a
bug where we didn't provide the argument (effectively passing garbage) for
functions registered with __cxa_atexit in the main executable.

Pointed out by Dmitriy Ivanov <dimitry@google.com> and Elliott Hughes
<enh@google.com>.

ok matthew@


Revision tags: OPENBSD_5_5_BASE
# 1.17 28-Dec-2013 kettenis

Move atexit(3) into crtbegin.c and certbeginS.c such that we can pass the
right __dso_handle and have dlopen'ed shared objects run their atexit handlers
when they get unloaded. This is what Linux does, and several ports depend on
this behaviour (and will crash upon exit without this chang).

Based on an earlier diff from matthew@
Tested by ajacoutot@
ok deraadt@


Revision tags: OPENBSD_5_4_BASE
# 1.16 02-Jun-2013 matthew

Two small cleanups to atexit: remove unneeded __atexit_invalid, and
move the call_depth decrement so it happens unconditionally and can
still return to 0 when called with dso!=NULL.

ok millert


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 02-Mar-2011 matthew

Fix __cxa_finalize() so that calling __cxa_finalize(NULL) properly
invokes handlers registered with __cxa_atexit().

"seems right" deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.14 05-Sep-2007 chl

Add missing header to avoid warning

ok millert@ ray@


# 1.13 03-Sep-2007 millert

Add __cxa_atexit() support for gcc3. This provides support for shared object destructors called at dlclose() time. Inspired by similar changes in FreeBSD and NetBSD.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.12 22-Feb-2006 otto

Avouid a race in atexit() handling by introducing a lock. Problem
originally reported by Gergely Kovacs; help from dhartmei@;
ok tedu@ millert@


# 1.11 26-Oct-2005 otto

Remove obsolete comment. ok deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.9 17-Jun-2005 deraadt

no longer a need for the free(malloc(1)) hack, because the brk stuff
no longer needs initializing (we use mmap for malloc entirely now)
noticed by kjell, ok dhartmei, tested by me


# 1.8 30-Mar-2005 pat

ansi + de-register

ok otto deraadt


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.7 14-Sep-2002 dhartmei

Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@


# 1.6 06-Sep-2002 henning

missing include, ok theo


# 1.5 30-Aug-2002 dhartmei

re-enable function pointer table protection, this time make sure that
malloc.c gets the first mmap() call (since it depends on that, for its
sbrk(0) use). ok deraadt@


# 1.4 31-Jul-2002 dhartmei

Back it out, it breaks something in perl (seen with spamassassin), debug
first.


# 1.3 29-Jul-2002 dhartmei

Replace atexit handler. mprotect() the pages so an attempt to modify the
function pointers from the outside will segfault. Idea, hints and feedback
from deraadt. ok deraadt.


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.28 22-Oct-2022 deraadt

In __cxa_atexit(), there is no need to initialize local pointer before
the lock, when it is correctly initialized after the lock
ok otto millert


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.27 16-Dec-2017 guenther

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@


# 1.26 05-Dec-2017 kettenis

Remove DEF_STRONG(__cxa_thread_atexit_impl). This produces an unwanted
_libc___cxa_thread_atexit_impl reference on gcc architectures that breaks
the build.


# 1.25 05-Dec-2017 kettenis

Implement __cxa_thread_atexit to support C++11 thread_local scope. The
interface is also made available as __cxa_thread_atexit_impl to satisfy the
needs of GNU libstdc++.

ok guenther@, millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.24 10-Nov-2015 guenther

libc.so can't be unloaded, so move the hidden atexit() and pthread_atfork()
stubs for the executable from crtbegin.o into libc, which lets them be
excluded from static links that don't use them.
For this, drop the normal crt{begin,end}S.o from libc.so: the .init and .fini
sections for libc aren't called at the right times anyway, so it's good that
they're unused. libc.so just needs __guard_local and the .note.openbsd.ident
section, so add them to stack_protector.c for now (this will be improved)

"good time" deraadt@


# 1.23 25-Oct-2015 guenther

Move the _atfork_list definition to atexit.c so that the fork syscall stub
doesn't get pulled into all static executables

ok millert@ jca@


# 1.22 25-Oct-2015 guenther

Hide __atexit and __atexit_register_cleanup()
Wrap __cxa_{atexit,finalize}() so the call from exit() goes direct
Switch regress/lib/libc/atexit/ to be built with -static so that it can
still access __atexit*

ok millert@ jca@


Revision tags: OPENBSD_5_8_BASE
# 1.21 07-Apr-2015 guenther

Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback
handling from libpthread to libc, though libpthread still overrides the
inner call to handle locking and thread-library reinitialization.
Major version bump for both libc and libpthread.

verification that this fixes various ports ajacoutot@
asm assistance miod@; ok millert@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.20 11-Jul-2014 kettenis

Add locking for __cxa_finalize() as it modifies the page permissions of the
__atexit tables and touches global variables. From Srinavasa Nagaraju
through Android/Elliott Hughes.

ok tedu@, guenther@


# 1.19 10-Jul-2014 tedu

as noted by google/android via kettenis, atexit handlers can install new
handlers. if this happens, restart the loop.
ok kettenis matthew millert miod


# 1.18 18-Jun-2014 kettenis

Always call atexit handlers as if they were registered with __cxa_atexit.
The extra argument doesn't hurt genuine atexit handlers and this fixes a
bug where we didn't provide the argument (effectively passing garbage) for
functions registered with __cxa_atexit in the main executable.

Pointed out by Dmitriy Ivanov <dimitry@google.com> and Elliott Hughes
<enh@google.com>.

ok matthew@


Revision tags: OPENBSD_5_5_BASE
# 1.17 28-Dec-2013 kettenis

Move atexit(3) into crtbegin.c and certbeginS.c such that we can pass the
right __dso_handle and have dlopen'ed shared objects run their atexit handlers
when they get unloaded. This is what Linux does, and several ports depend on
this behaviour (and will crash upon exit without this chang).

Based on an earlier diff from matthew@
Tested by ajacoutot@
ok deraadt@


Revision tags: OPENBSD_5_4_BASE
# 1.16 02-Jun-2013 matthew

Two small cleanups to atexit: remove unneeded __atexit_invalid, and
move the call_depth decrement so it happens unconditionally and can
still return to 0 when called with dso!=NULL.

ok millert


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 02-Mar-2011 matthew

Fix __cxa_finalize() so that calling __cxa_finalize(NULL) properly
invokes handlers registered with __cxa_atexit().

"seems right" deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.14 05-Sep-2007 chl

Add missing header to avoid warning

ok millert@ ray@


# 1.13 03-Sep-2007 millert

Add __cxa_atexit() support for gcc3. This provides support for shared object destructors called at dlclose() time. Inspired by similar changes in FreeBSD and NetBSD.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.12 22-Feb-2006 otto

Avouid a race in atexit() handling by introducing a lock. Problem
originally reported by Gergely Kovacs; help from dhartmei@;
ok tedu@ millert@


# 1.11 26-Oct-2005 otto

Remove obsolete comment. ok deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.9 17-Jun-2005 deraadt

no longer a need for the free(malloc(1)) hack, because the brk stuff
no longer needs initializing (we use mmap for malloc entirely now)
noticed by kjell, ok dhartmei, tested by me


# 1.8 30-Mar-2005 pat

ansi + de-register

ok otto deraadt


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.7 14-Sep-2002 dhartmei

Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@


# 1.6 06-Sep-2002 henning

missing include, ok theo


# 1.5 30-Aug-2002 dhartmei

re-enable function pointer table protection, this time make sure that
malloc.c gets the first mmap() call (since it depends on that, for its
sbrk(0) use). ok deraadt@


# 1.4 31-Jul-2002 dhartmei

Back it out, it breaks something in perl (seen with spamassassin), debug
first.


# 1.3 29-Jul-2002 dhartmei

Replace atexit handler. mprotect() the pages so an attempt to modify the
function pointers from the outside will segfault. Idea, hints and feedback
from deraadt. ok deraadt.


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.27 16-Dec-2017 guenther

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@


# 1.26 05-Dec-2017 kettenis

Remove DEF_STRONG(__cxa_thread_atexit_impl). This produces an unwanted
_libc___cxa_thread_atexit_impl reference on gcc architectures that breaks
the build.


# 1.25 05-Dec-2017 kettenis

Implement __cxa_thread_atexit to support C++11 thread_local scope. The
interface is also made available as __cxa_thread_atexit_impl to satisfy the
needs of GNU libstdc++.

ok guenther@, millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.24 10-Nov-2015 guenther

libc.so can't be unloaded, so move the hidden atexit() and pthread_atfork()
stubs for the executable from crtbegin.o into libc, which lets them be
excluded from static links that don't use them.
For this, drop the normal crt{begin,end}S.o from libc.so: the .init and .fini
sections for libc aren't called at the right times anyway, so it's good that
they're unused. libc.so just needs __guard_local and the .note.openbsd.ident
section, so add them to stack_protector.c for now (this will be improved)

"good time" deraadt@


# 1.23 25-Oct-2015 guenther

Move the _atfork_list definition to atexit.c so that the fork syscall stub
doesn't get pulled into all static executables

ok millert@ jca@


# 1.22 25-Oct-2015 guenther

Hide __atexit and __atexit_register_cleanup()
Wrap __cxa_{atexit,finalize}() so the call from exit() goes direct
Switch regress/lib/libc/atexit/ to be built with -static so that it can
still access __atexit*

ok millert@ jca@


Revision tags: OPENBSD_5_8_BASE
# 1.21 07-Apr-2015 guenther

Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback
handling from libpthread to libc, though libpthread still overrides the
inner call to handle locking and thread-library reinitialization.
Major version bump for both libc and libpthread.

verification that this fixes various ports ajacoutot@
asm assistance miod@; ok millert@ deraadt@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.20 11-Jul-2014 kettenis

Add locking for __cxa_finalize() as it modifies the page permissions of the
__atexit tables and touches global variables. From Srinavasa Nagaraju
through Android/Elliott Hughes.

ok tedu@, guenther@


# 1.19 10-Jul-2014 tedu

as noted by google/android via kettenis, atexit handlers can install new
handlers. if this happens, restart the loop.
ok kettenis matthew millert miod


# 1.18 18-Jun-2014 kettenis

Always call atexit handlers as if they were registered with __cxa_atexit.
The extra argument doesn't hurt genuine atexit handlers and this fixes a
bug where we didn't provide the argument (effectively passing garbage) for
functions registered with __cxa_atexit in the main executable.

Pointed out by Dmitriy Ivanov <dimitry@google.com> and Elliott Hughes
<enh@google.com>.

ok matthew@


Revision tags: OPENBSD_5_5_BASE
# 1.17 28-Dec-2013 kettenis

Move atexit(3) into crtbegin.c and certbeginS.c such that we can pass the
right __dso_handle and have dlopen'ed shared objects run their atexit handlers
when they get unloaded. This is what Linux does, and several ports depend on
this behaviour (and will crash upon exit without this chang).

Based on an earlier diff from matthew@
Tested by ajacoutot@
ok deraadt@


Revision tags: OPENBSD_5_4_BASE
# 1.16 02-Jun-2013 matthew

Two small cleanups to atexit: remove unneeded __atexit_invalid, and
move the call_depth decrement so it happens unconditionally and can
still return to 0 when called with dso!=NULL.

ok millert


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 02-Mar-2011 matthew

Fix __cxa_finalize() so that calling __cxa_finalize(NULL) properly
invokes handlers registered with __cxa_atexit().

"seems right" deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.14 05-Sep-2007 chl

Add missing header to avoid warning

ok millert@ ray@


# 1.13 03-Sep-2007 millert

Add __cxa_atexit() support for gcc3. This provides support for shared object destructors called at dlclose() time. Inspired by similar changes in FreeBSD and NetBSD.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.12 22-Feb-2006 otto

Avouid a race in atexit() handling by introducing a lock. Problem
originally reported by Gergely Kovacs; help from dhartmei@;
ok tedu@ millert@


# 1.11 26-Oct-2005 otto

Remove obsolete comment. ok deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.9 17-Jun-2005 deraadt

no longer a need for the free(malloc(1)) hack, because the brk stuff
no longer needs initializing (we use mmap for malloc entirely now)
noticed by kjell, ok dhartmei, tested by me


# 1.8 30-Mar-2005 pat

ansi + de-register

ok otto deraadt


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.7 14-Sep-2002 dhartmei

Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@


# 1.6 06-Sep-2002 henning

missing include, ok theo


# 1.5 30-Aug-2002 dhartmei

re-enable function pointer table protection, this time make sure that
malloc.c gets the first mmap() call (since it depends on that, for its
sbrk(0) use). ok deraadt@


# 1.4 31-Jul-2002 dhartmei

Back it out, it breaks something in perl (seen with spamassassin), debug
first.


# 1.3 29-Jul-2002 dhartmei

Replace atexit handler. mprotect() the pages so an attempt to modify the
function pointers from the outside will segfault. Idea, hints and feedback
from deraadt. ok deraadt.


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision