From: MrStrcmp Date: Tue, 11 May 2010 00:41:51 +0000 (+0200) Subject: slightly cleaner way to test 'NUM.FIELD' X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=testub10.git;a=commitdiff_plain;h=74fb84fbb5a8783ff5d582eb2ec797a3590f7655 slightly cleaner way to test 'NUM.FIELD' --- diff --git a/codea/lewurm_11.0 b/codea/lewurm_11.0 index 6cca523..ac14b1a 100644 --- a/codea/lewurm_11.0 +++ b/codea/lewurm_11.0 @@ -1,5 +1,13 @@ struct a b c end; -method wfoo() - /* passt die addresse jedes mal? */ - return 0x600ac0.c; + +method try0() + return 0x00100000.c; +end; + +method try1() + return 0x01000000.c; +end; + +method try2() + return 0xA0000000.c; end; diff --git a/codea/lewurm_11.call b/codea/lewurm_11.call index 08c981d..067edca 100644 --- a/codea/lewurm_11.call +++ b/codea/lewurm_11.call @@ -1,6 +1,46 @@ -long wfoo(long); -static long s[3]; -s[0] = 5; -s[1] = 1; -s[2] = 1337; -RET(wfoo(0xcafebabe) == 1337); +#define TRIES 3 + +/* ugly. copied from 'bits/mman.h' */ +#define PROT_READ 0x1 +#define PROT_WRITE 0x2 +#define MAP_PRIVATE 0x02 +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); + +long try0(long); +long try1(long); +long try2(long); + +/* try these adresses until one is free */ +long *tries[TRIES] = { + (long *)0x00100000, + (long *)0x01000000, + (long *)0xA0000000 +}; + +int t = 0; +long *addr = NULL; + +for (t = 0; t < TRIES; t++) { + addr = mmap(tries[t], 4096, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + + if (tries[t] == addr) + break; +} + +if ((void *)-1 == addr) { + puts("unable to map memory"); + RET(1); /* keep the statistic clean */ +} + +addr[2] = 1337; + +switch (t) { +case 0: RET(try0(0xcafebabe) == 1337); +case 1: RET(try1(0xcafebabe) == 1337); +case 2: RET(try2(0xcafebabe) == 1337); +} +