mescc: Support gcc-3.0: Implement atexit.

This commit is contained in:
Jan Nieuwenhuizen 2018-06-07 18:02:21 +02:00
parent 93cb6375ae
commit ef0a39547c
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
5 changed files with 34 additions and 7 deletions

View File

@ -40,8 +40,10 @@ void * alloca (unsigned size);
void * alloca (size_t size);
#endif
int atoi (char const *s);
int atexit (void (*function) (void));
void * calloc (size_t nmemb, size_t size);
void exit (int);
void _exit (int status);
void exit (int status);
void free (void *ptr);
char* getenv (char const* s);
int setenv (char const* s, char const* v, int overwrite_p);

View File

@ -90,9 +90,6 @@ typedef int pid_t;
int access (char const *s, int mode);
unsigned int alarm (unsigned int seconds);
#define alarm(x) {eputs ("alarm x="); eputs (itoa (x)); eputs ("\n"); kill (getpid (), 14);}
#define atexit(x) eputs ("atexit\n")
int close (int fd);
int execv (char const *file_name, char *const argv[]);
int execve (char const *file, char *const argv[], char *const env[]);

View File

@ -80,3 +80,11 @@ unsetenv (char const *name)
p++;
}
}
// gcc-3.0
int
atexit (void (*function) (void))
{
__call_at_exit = function;
}

View File

@ -22,7 +22,7 @@
#define SYS_write "0x04"
void
exit (int code)
_exit (int code)
{
#if !__TINYC__
asm (
@ -42,7 +42,17 @@ exit (int code)
);
#endif // __TINYC__
// not reached
exit (0);
_exit (0);
}
void (*__call_at_exit) (void);
void
exit (int code)
{
if (__call_at_exit)
(*__call_at_exit) ();
_exit (code);
}
ssize_t

View File

@ -19,13 +19,23 @@
*/
void
exit ()
_exit ()
{
asm ("mov____$i32,%eax SYS_exit");
asm ("mov____0x8(%ebp),%ebx !8");
asm ("int____$0x80");
}
void (*__call_at_exit) (void);
void
exit (int code)
{
if (__call_at_exit)
(*__call_at_exit) ();
_exit (code);
}
void
write ()
{