summaryrefslogtreecommitdiff
path: root/tools/include/nolibc/stackprotector.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/include/nolibc/stackprotector.h')
-rw-r--r--tools/include/nolibc/stackprotector.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h
index 1d0d5259ec41..ae8b1d3a374d 100644
--- a/tools/include/nolibc/stackprotector.h
+++ b/tools/include/nolibc/stackprotector.h
@@ -9,6 +9,7 @@
#include "compiler.h"
+#ifndef NOLIBC_NO_RUNTIME
#if defined(_NOLIBC_STACKPROTECTOR)
#include "sys.h"
@@ -18,16 +19,18 @@
* triggering stack protector errors themselves
*/
+void __stack_chk_fail(void);
__attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk")))
void __stack_chk_fail(void)
{
pid_t pid;
- my_syscall3(__NR_write, STDERR_FILENO, "!!Stack smashing detected!!\n", 28);
- pid = my_syscall0(__NR_getpid);
- my_syscall2(__NR_kill, pid, SIGABRT);
+ __nolibc_syscall3(__NR_write, STDERR_FILENO, "!!Stack smashing detected!!\n", 28);
+ pid = __nolibc_syscall0(__NR_getpid);
+ __nolibc_syscall2(__NR_kill, pid, SIGABRT);
for (;;);
}
+void __stack_chk_fail_local(void);
__attribute__((weak,noreturn,section(".text.nolibc_stack_chk")))
void __stack_chk_fail_local(void)
{
@@ -39,7 +42,7 @@ uintptr_t __stack_chk_guard;
static __no_stack_protector void __stack_chk_init(void)
{
- my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0);
+ __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0);
/* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */
if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard)
__stack_chk_guard ^= (uintptr_t) &__stack_chk_guard;
@@ -47,5 +50,6 @@ static __no_stack_protector void __stack_chk_init(void)
#else /* !defined(_NOLIBC_STACKPROTECTOR) */
static void __stack_chk_init(void) {}
#endif /* defined(_NOLIBC_STACKPROTECTOR) */
+#endif /* NOLIBC_NO_RUNTIME */
#endif /* _NOLIBC_STACKPROTECTOR_H */