tagged release 0.6.4
[parrot.git] / config / auto / jit / test_exec_cygwin.in
blob68962663cc2c7e745056d115e9871bbc41952386
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/mman.h>
4 #include <limits.h>
5 #include <errno.h>
6 #include <malloc.h>
7 #include <unistd.h>
8 #ifndef PAGE_SIZE
9 #  define PAGE_SIZE getpagesize()
10 #endif
12 /* test for exec privs */
15  * c equiv:
16   int t() {
17   return 1;
21 char code[] = {
22    0xB8,0x01,0,0,0,      /* movl $1, %eax */
23    0xC3                  /* ret */
26 typedef int (*pf)(void);
28 int main(int argc, char *argv[])
30     pf t;
31     char *p;
32     int rc;
33     int prot = PROT_READ;
35     if (argc != 2) {
36         fprintf(stderr, "usage: test 0 | 1\n");
37         exit(1);
38     }
40     if (atoi(argv[1]))
41         prot |= PROT_EXEC;
43     p = memalign(PAGE_SIZE, sizeof(code));
44     memcpy(p, code, sizeof(code));
46     t  = (pf) p;
47     rc = mprotect(p, PAGE_SIZE, prot);
49     if (rc) {
50         fprintf(stderr, "p = %p  PAGE_SIZE = %d (0x%x)\n", p,
51             PAGE_SIZE, PAGE_SIZE);
52         perror("failure");
53     }
55     if (t() == 1)
56         puts("ok");
58     else
59         return 1;
61     return 0;