diff options
author | comex | 2015-01-24 20:04:20 -0500 |
---|---|---|
committer | comex | 2015-01-24 20:06:46 -0500 |
commit | d89af8f6d5f3b971dda663081c03d790437c2f03 (patch) | |
tree | 2c17f0247ff3eef7d4338cadb069b1334ba785c6 /test | |
parent | Current version of generic-dis-*, for posterity (I'm sure it'll need to be ch... (diff) | |
download | substitute-d89af8f6d5f3b971dda663081c03d790437c2f03.tar.gz |
Add function to deal with mprotecting RW and back. A bit more complex than the minimum would be...
(and minor build fixes)
Diffstat (limited to 'test')
-rw-r--r-- | test/test-execmem.c | 37 | ||||
-rw-r--r-- | test/test-stop-threads.c | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/test/test-execmem.c b/test/test-execmem.c new file mode 100644 index 0000000..5ec64e9 --- /dev/null +++ b/test/test-execmem.c @@ -0,0 +1,37 @@ +#include "substitute-internal.h" +#include "execmem.h" +#include <stdio.h> +#include <search.h> /* for the victim */ +#include <errno.h> +#define NOP_SLED \ + __asm__ volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" \ + "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" \ + "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;") +#define OTHER_SIZE 32 /* guess */ + +int other(size_t a) { + if (__builtin_expect(!a, 1)) + return 6; + NOP_SLED; + return 0; +} + +__attribute__((section("__TEST,__test"), noinline)) +int test(size_t a) { + NOP_SLED; + if (!a) + return 5; + else + return 1000; +} + +int main() { + printf("this should be 5: %d\n", test(0)); + printf("=> %d\n", execmem_write(test, other, OTHER_SIZE)); + printf(" %s\n", strerror(errno)); + printf("this should be 6: %d\n", test(0)); + printf("=> %d\n", execmem_write(hcreate, other, OTHER_SIZE)); + printf(" %s\n", strerror(errno)); + printf("modified shared cache func: %d\n", hcreate(0)); + +} diff --git a/test/test-stop-threads.c b/test/test-stop-threads.c index be0787d..829e73e 100644 --- a/test/test-stop-threads.c +++ b/test/test-stop-threads.c @@ -1,4 +1,5 @@ #include "substitute-internal.h" +#include "stop-other-threads.h" #include <stdio.h> #include <unistd.h> #include <pthread.h> |