summaryrefslogtreecommitdiffstats
path: root/usr/klibc/exit.c
blob: 2368b07d793d253746c6e7b41f06f2edf0d1328e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * exit.c
 *
 * exit(), including the handling of the atexit chain.
 */

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/syscall.h>
#include "atexit.h"

/* Link chain for atexit/on_exit */
struct atexit *__atexit_list;

__noreturn exit(int rv)
{
	struct atexit *ap;

	for (ap = __atexit_list; ap; ap = ap->next) {
		/* This assumes extra args are harmless.  They should
		   be in all normal C ABIs, but if an architecture has
		   some particularly bizarre ABI this might be worth
		   watching out for. */
		ap->fctn(rv, ap->arg);
	}

	/* Handle any library destructors if we ever start using them... */
	fflush(NULL);

	_exit(rv);
}