4 #include <sys/unistd.h>
7 /* A simple glue file for embedded targets so we can get the real exit
8 status from the program. This assumes we're using GNU ld and can use
9 the -wrap option, and that write(1, ...) does something useful. */
11 /* There is a bunch of weird cruft with #ifdef UNDERSCORES. This is needed
12 because currently GNU ld doesn't deal well with a.out targets and
13 the -wrap option. When GNU ld is fixed, this should definitely be
14 removed. Note that we actually wrap __exit, not _exit on a target
15 that has UNDERSCORES defined. On non-UNDERSCORE targets, we
16 wrap _exit separately; it's actually a different function. */
19 #define REAL_EXIT(code) asm ( "trap %0" : : "i" (0) );
20 #define REAL_ABORT() REAL_EXIT(6)
21 #define ORIG_EXIT _exit
22 #define ORIG_ABORT abort
25 #define REAL_EXIT _real___exit
26 #define REAL_MAIN _real__main
27 #define REAL_ABORT _real__abort
28 #define ORIG_EXIT _wrap___exit
29 #define ORIG_ABORT _wrap__abort
30 #define ORIG_MAIN _wrap__main
32 #define REAL_EXIT __real_exit
34 #define REAL__EXIT __real__exit
36 #define REAL_MAIN __real_main
37 #define REAL_ABORT __real_abort
38 #define ORIG_EXIT __wrap_exit
39 #define ORIG__EXIT __wrap__exit
40 #define ORIG_ABORT __wrap_abort
41 #define ORIG_MAIN __wrap_main
46 extern void REAL_EXIT ();
47 extern void REAL_ABORT ();
48 extern int REAL_MAIN (int argc
, char **argv
, char **envp
);
51 extern void REAL__EXIT ();
54 static int done_exit_message
= 0;
58 static void __runexit();
72 ptr
= write_int (val
/10, ptr
);
89 strcpy (buf
, "\n*** EXIT code ");
90 ptr
= write_int (code
, buf
+ strlen(buf
));
92 write (1, buf
, ptr
-buf
);
93 done_exit_message
= 1;
106 /* Since exit may call _exit, we need to avoid a second message. */
107 if (! done_exit_message
)
109 strcpy (buf
, "\n*** EXIT code ");
110 ptr
= write_int (code
, buf
+ strlen(buf
));
112 write (1, buf
, ptr
-buf
);
123 write (1, "\n*** EXIT code 4242\n", 20);
131 ORIG_MAIN (argc
, argv
, envp
)
136 #ifdef WRAP_FILE_ARGS
138 extern char *__args
[];
140 exit (REAL_MAIN (__argc
,__args
,envp
));
142 exit (REAL_MAIN (argc
, argv
, envp
));
156 typedef (*PFV
)(void);
158 static PFV __list
[32];
159 static int __listcnt
= 0;
160 static int __running
= 0;
165 __list
[__listcnt
++] = func
;
175 for (i
= 0; i
< __listcnt
; i
++)