Support for -fstack-protector

This commit is contained in:
bumbread 2022-08-08 23:39:43 +11:00
parent e5f2711091
commit b426c0f2ee
7 changed files with 37 additions and 1 deletions

15
src/_win/cookie.c Normal file
View File

@ -0,0 +1,15 @@
u64 __security_cookie;
void __security_init_cookie() {
// They say it's a random number so I generated
// one using numbergenerator.org
__security_cookie = 0xb26e04cc62ba48a;
}
void __security_check_cookie(u64 retrieved) {
if(__security_cookie != retrieved) {
printf("Bro you've got a buffer overrun\n");
abort();
}
}

View File

@ -12,6 +12,7 @@ _Noreturn void mainCRTStartup() {
_setup_heap();
_setup_timer();
_setup_io();
__security_init_cookie();
srand(0);
setlocale(LC_ALL, "C");
@ -28,6 +29,7 @@ _Noreturn void WinMainCRTStartup() {
_setup_heap();
_setup_timer();
_setup_io();
__security_init_cookie();
srand(0);
setlocale(LC_ALL, "C");

View File

@ -12,3 +12,4 @@ void _setup_eh();
void _setup_heap();
void _setup_io();
void _close_io();
void __security_init_cookie();

View File

@ -66,6 +66,7 @@
// Windows stuff
#if defined(CIABATTA_WIN)
#include "_win/win.h"
#include "_win/cookie.c"
#include "_win/assert.c"
#include "_win/cmdline.c"
#include "_win/entry.c"

View File

@ -1,2 +1,2 @@
clang -std=c11 test\%1 utf8.obj -Iinc -g -lciabatta.lib -nostdlib
clang -std=c11 test\%1 utf8.obj -Iinc -g -lciabatta.lib -nostdlib -fstack-protector

10
test/alloca.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdint.h>
int main() {
uint8_t *sp = _alloca(512);
for(int i = 0; i != 550; ++i) {
sp[i] = 0;
}
printf("%p\n", sp);
return 0;
}

7
test/helloworld.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}