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
45 extern void abort (void);
46 extern void exit (int);
51 extern void REAL_EXIT ();
52 extern void REAL_ABORT ();
53 extern int REAL_MAIN (int argc
, char **argv
, char **envp
);
56 extern void REAL__EXIT ();
59 static int done_exit_message
= 0;
63 static void __runexit();
77 ptr
= write_int (val
/10, ptr
);
94 strcpy (buf
, "\n*** EXIT code ");
95 ptr
= write_int (code
, buf
+ strlen(buf
));
97 write (1, buf
, ptr
-buf
);
98 done_exit_message
= 1;
111 /* Since exit may call _exit, we need to avoid a second message. */
112 if (! done_exit_message
)
114 strcpy (buf
, "\n*** EXIT code ");
115 ptr
= write_int (code
, buf
+ strlen(buf
));
117 write (1, buf
, ptr
-buf
);
128 write (1, "\n*** EXIT code 4242\n", 20);
136 ORIG_MAIN (argc
, argv
, envp
)
141 #ifdef WRAP_FILE_ARGS
143 extern char *__args
[];
145 exit (REAL_MAIN (__argc
,__args
,envp
));
147 exit (REAL_MAIN (argc
, argv
, envp
));
161 typedef (*PFV
)(void);
163 static PFV __list
[32];
164 static int __listcnt
= 0;
165 static int __running
= 0;
170 __list
[__listcnt
++] = func
;
180 for (i
= 0; i
< __listcnt
; i
++)