From 9ab3c11a4f79597580c92c4cf309fdb560fc3f67 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sat, 28 Feb 2015 10:01:30 +0100 Subject: [PATCH] This seems to work-,- --- .../exercise1.c | 31 ++++++++++++++++++- .../magicfunction.c | 9 ++++++ .../magicfunction.h | 7 +++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.c create mode 100644 ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.h diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c b/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c index beb6c5a..28d6a2c 100644 --- a/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c +++ b/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c @@ -1,7 +1,36 @@ #include +#include +#include "magicfunction.h" + +#define MAX 4194304/sizeof(uint64_t) + +uint64_t determine_start() +{ + return 0x567856785678; +} int main(void) { - printf("Ik snap hier nog even niks van...\n"); + uint64_t filler = 0x123412341234; + uint64_t *p; + uint64_t *q; + uint64_t stack = 0; + /*Fill the stack with a filler value*/ + for(p = &stack -1; p >= &stack - 1 - MAX; p--) + *p = filler; + + /*Find the beginning of the function stack with the function*/ + determine_start(); + for(q = &stack -1; q>=&stack-1-MAX; q--) + if(*q == 0x567856785678) + break; + + /*Run the function and find the last occurance of non stack filler */ + magic_function(); + for(p = &stack - 1 - MAX; p <= q; p++) + if(*p != filler) + break; + + printf("%td byte stack size used\n", (char*)p-(char*)q); return 0; } diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.c b/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.c new file mode 100644 index 0000000..56c1850 --- /dev/null +++ b/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.c @@ -0,0 +1,9 @@ +#include +#include + +size_t magic_function(void) +{ + size_t a = 0xdeadbeef; + size_t b[2] = {0xdeadbeef, 0xdeadbeef}; + return a; +} diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.h b/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.h new file mode 100644 index 0000000..eeff23e --- /dev/null +++ b/ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.h @@ -0,0 +1,7 @@ +#ifndef MAGIC_FUNCTION_H +#define MAGIC_FUNCTION_H +#include + +size_t magic_function(); + +#endif -- 2.20.1