eac852b7a39572e9b10bfd1df3a2488c0a52ba39
[musl] / src / env / __stack_chk_fail.c
1 #include <string.h>
2 #include <inttypes.h>
3 #include <elf.h>
4 #include "pthread_impl.h"
5 #include "atomic.h"
6
7 uintptr_t __stack_chk_guard;
8
9 void __init_ssp(size_t *auxv)
10 {
11         size_t i;
12         pthread_t self = __pthread_self_init();
13         uintptr_t canary;
14         for (i=0; auxv[i] && auxv[i]!=AT_RANDOM; i+=2);
15         if (auxv[i]) memcpy(&canary, (void *)auxv[i+1], sizeof canary);
16         else canary = (uintptr_t)&canary * 1103515245;
17         a_cas_l(&__stack_chk_guard, 0, canary);
18         self->canary = __stack_chk_guard;
19 }
20
21 void __stack_chk_fail(void)
22 {
23         a_crash();
24 }