Last change
on this file since 444 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
976 bytes
|
Line | |
---|
1 | #include <sys/cdefs.h> |
---|
2 | #include <sys/param.h> |
---|
3 | #include <signal.h> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <string.h> |
---|
6 | #include <unistd.h> |
---|
7 | |
---|
8 | uintptr_t __stack_chk_guard = 0; |
---|
9 | |
---|
10 | void |
---|
11 | __attribute__((__constructor__)) |
---|
12 | __stack_chk_init (void) |
---|
13 | { |
---|
14 | if (__stack_chk_guard != 0) |
---|
15 | return; |
---|
16 | |
---|
17 | #if defined(__CYGWIN__) || defined(__rtems__) |
---|
18 | arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard)); |
---|
19 | #else |
---|
20 | /* If getentropy is not available, use the "terminator canary". */ |
---|
21 | ((unsigned char *)&__stack_chk_guard)[0] = 0; |
---|
22 | ((unsigned char *)&__stack_chk_guard)[1] = 0; |
---|
23 | ((unsigned char *)&__stack_chk_guard)[2] = '\n'; |
---|
24 | ((unsigned char *)&__stack_chk_guard)[3] = 255; |
---|
25 | #endif |
---|
26 | } |
---|
27 | |
---|
28 | void |
---|
29 | __attribute__((__noreturn__)) |
---|
30 | __stack_chk_fail (void) |
---|
31 | { |
---|
32 | char msg[] = "*** stack smashing detected ***: terminated\n"; |
---|
33 | write (2, msg, strlen (msg)); |
---|
34 | raise (SIGABRT); |
---|
35 | _exit (127); |
---|
36 | } |
---|
37 | |
---|
38 | #ifdef __ELF__ |
---|
39 | void |
---|
40 | __attribute__((visibility ("hidden"))) |
---|
41 | __stack_chk_fail_local (void) |
---|
42 | { |
---|
43 | __stack_chk_fail(); |
---|
44 | } |
---|
45 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.