Introduce __cxa_thread_atexit()

This commit is contained in:
Justine Tunney 2023-10-31 19:56:55 -07:00
parent a699cda5c8
commit ee82f90bba
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
6 changed files with 98 additions and 0 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/cxaatexit.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/subprocess.h"
#include "libc/testlib/testlib.h"
@ -66,3 +67,21 @@ TEST(pthread_exit, detachedOrphanedChild_runsAtexitHandlers) {
pthread_exit(0);
EXITS(CHILD);
}
void OnMainThreadExit(void *arg) {
_Exit((long)arg);
}
TEST(__cxa_thread_atexit, exit_wontInvokeThreadDestructors) {
SPAWN(fork);
__cxa_thread_atexit(OnMainThreadExit, (void *)123L, 0);
exit(0);
EXITS(0);
}
TEST(__cxa_thread_atexit, pthread_exit_willInvokeThreadDestructors) {
SPAWN(fork);
__cxa_thread_atexit(OnMainThreadExit, (void *)123L, 0);
pthread_exit(0);
EXITS(123);
}