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); void * alloca (size_t size);
#endif #endif
int atoi (char const *s); int atoi (char const *s);
int atexit (void (*function) (void));
void * calloc (size_t nmemb, size_t size); void * calloc (size_t nmemb, size_t size);
void exit (int); void _exit (int status);
void exit (int status);
void free (void *ptr); void free (void *ptr);
char* getenv (char const* s); char* getenv (char const* s);
int setenv (char const* s, char const* v, int overwrite_p); 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); int access (char const *s, int mode);
unsigned int alarm (unsigned int seconds); 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 close (int fd);
int execv (char const *file_name, char *const argv[]); int execv (char const *file_name, char *const argv[]);
int execve (char const *file, char *const argv[], char *const env[]); int execve (char const *file, char *const argv[], char *const env[]);

View file

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

View file

@ -22,7 +22,7 @@
#define SYS_write "0x04" #define SYS_write "0x04"
void void
exit (int code) _exit (int code)
{ {
#if !__TINYC__ #if !__TINYC__
asm ( asm (
@ -42,7 +42,17 @@ exit (int code)
); );
#endif // __TINYC__ #endif // __TINYC__
// not reached // 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 ssize_t

View file

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