This seems to work-,-
authorMart Lubbers <mart@martlubbers.net>
Sat, 28 Feb 2015 09:01:30 +0000 (10:01 +0100)
committerMart Lubbers <mart@martlubbers.net>
Sat, 28 Feb 2015 09:01:30 +0000 (10:01 +0100)
ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c
ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.c [new file with mode: 0644]
ass3/mart/sws1-assignment3-s4109503-s4202015/magicfunction.h [new file with mode: 0644]

index beb6c5a..28d6a2c 100644 (file)
@@ -1,7 +1,36 @@
 #include <stdio.h>
+#include <stdint.h>
+#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 (file)
index 0000000..56c1850
--- /dev/null
@@ -0,0 +1,9 @@
+#include <stdint.h>
+#include <stddef.h>
+
+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 (file)
index 0000000..eeff23e
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef MAGIC_FUNCTION_H
+#define MAGIC_FUNCTION_H
+#include <stdint.h>
+
+size_t magic_function();
+
+#endif