Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/vm/mmap_test.c
| Show All 30 Lines | |||||
| #include <atf-c.h> | #include <atf-c.h> | ||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <fcntl.h> | #include <fcntl.h> | ||||
| #include <stdarg.h> | #include <stdarg.h> | ||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| static const struct { | |||||
| void *addr; | |||||
| int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */ | |||||
| } map_at_zero_tests[] = { | |||||
| { (void *)0, { 0, 1 } }, /* Test sysctl. */ | |||||
| { (void *)1, { 0, 0 } }, | |||||
| { (void *)(PAGE_SIZE - 1), { 0, 0 } }, | |||||
| { (void *)PAGE_SIZE, { 1, 1 } }, | |||||
| { (void *)-1, { 0, 0 } }, | |||||
| { (void *)(-PAGE_SIZE), { 0, 0 } }, | |||||
| { (void *)(-1 - PAGE_SIZE), { 0, 0 } }, | |||||
| { (void *)(-1 - PAGE_SIZE - 1), { 0, 0 } }, | |||||
| { (void *)(0x1000 * PAGE_SIZE), { 1, 1 } }, | |||||
| }; | |||||
| #define MAP_AT_ZERO "security.bsd.map_at_zero" | #define MAP_AT_ZERO "security.bsd.map_at_zero" | ||||
| #ifdef __LP64__ | #ifdef __LP64__ | ||||
| #define ALLOW_WX "kern.elf64.allow_wx" | #define ALLOW_WX "kern.elf64.allow_wx" | ||||
| #else | #else | ||||
| #define ALLOW_WX "kern.elf32.allow_wx" | #define ALLOW_WX "kern.elf32.allow_wx" | ||||
| #endif | #endif | ||||
| ATF_TC_WITHOUT_HEAD(mmap__map_at_zero); | ATF_TC_WITHOUT_HEAD(mmap__map_at_zero); | ||||
| ATF_TC_BODY(mmap__map_at_zero, tc) | ATF_TC_BODY(mmap__map_at_zero, tc) | ||||
| { | { | ||||
| void *p; | void *p; | ||||
| size_t len; | size_t len; | ||||
| unsigned int i; | unsigned int i; | ||||
| int map_at_zero; | int map_at_zero; | ||||
| bool allow_wx; | bool allow_wx; | ||||
| int prot_flags; | int prot_flags; | ||||
| size_t pgsz = getpagesize(); | |||||
| const struct { | |||||
| void *addr; | |||||
| int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */ | |||||
| } map_at_zero_tests[] = { | |||||
| { (void *)0, { 0, 1 } }, /* Test sysctl. */ | |||||
| { (void *)1, { 0, 0 } }, | |||||
| { (void *)(pgsz - 1), { 0, 0 } }, | |||||
| { (void *)pgsz, { 1, 1 } }, | |||||
| { (void *)-1, { 0, 0 } }, | |||||
| { (void *)(-pgsz), { 0, 0 } }, | |||||
| { (void *)(-1 - pgsz), { 0, 0 } }, | |||||
| { (void *)(-1 - pgsz - 1), { 0, 0 } }, | |||||
| { (void *)(0x1000 * pgsz), { 1, 1 } }, | |||||
| }; | |||||
| len = sizeof(map_at_zero); | len = sizeof(map_at_zero); | ||||
| if (sysctlbyname(MAP_AT_ZERO, &map_at_zero, &len, NULL, 0) == -1) { | if (sysctlbyname(MAP_AT_ZERO, &map_at_zero, &len, NULL, 0) == -1) { | ||||
| atf_tc_skip("sysctl for %s failed: %s\n", MAP_AT_ZERO, | atf_tc_skip("sysctl for %s failed: %s\n", MAP_AT_ZERO, | ||||
| strerror(errno)); | strerror(errno)); | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines | |||||