/* * Test sharing via fork() * Test whether seal-modifications work as expected with forked childs. */ static void test_share_fork(char *banner, char *b_suffix) { int fd; pid_t pid; printf("%s %s %s\n", memfd_str, banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_fork", mfd_def_size, MFD_CLOEXEC | MFD_ALLOW_SEALING); mfd_assert_has_seals(fd, 0); pid = spawn_idle_thread(0); mfd_assert_add_seals(fd, F_SEAL_SEAL); mfd_assert_has_seals(fd, F_SEAL_SEAL); mfd_fail_add_seals(fd, F_SEAL_WRITE); mfd_assert_has_seals(fd, F_SEAL_SEAL); join_idle_thread(pid); mfd_fail_add_seals(fd, F_SEAL_WRITE); mfd_assert_has_seals(fd, F_SEAL_SEAL); close(fd); }
int main(int argc, char **argv) { pid_t pid; if (argc == 2) { if (!strcmp(argv[1], "hugetlbfs")) { unsigned long hpage_size = default_huge_page_size(); if (!hpage_size) { printf("Unable to determine huge page size\n"); abort(); } hugetlbfs_test = 1; memfd_str = MEMFD_HUGE_STR; mfd_def_size = hpage_size * 2; } else { printf("Unknown option: %s\n", argv[1]); abort(); } } test_create(); test_basic(); test_seal_write(); test_seal_future_write(); test_seal_shrink(); test_seal_grow(); test_seal_resize(); test_share_dup("SHARE-DUP", ""); test_share_mmap("SHARE-MMAP", ""); test_share_open("SHARE-OPEN", ""); test_share_fork("SHARE-FORK", ""); /* Run test-suite in a multi-threaded environment with a shared * file-table. */ pid = spawn_idle_thread(CLONE_FILES | CLONE_FS | CLONE_VM); test_share_dup("SHARE-DUP", SHARED_FT_STR); test_share_mmap("SHARE-MMAP", SHARED_FT_STR); test_share_open("SHARE-OPEN", SHARED_FT_STR); test_share_fork("SHARE-FORK", SHARED_FT_STR); join_idle_thread(pid); printf("memfd: DONE\n"); return 0; }
int main(int argc, char **argv) { pid_t pid; printf("memfd: CREATE\n"); test_create(); printf("memfd: BASIC\n"); test_basic(); printf("memfd: SEAL-WRITE\n"); test_seal_write(); printf("memfd: SEAL-SHRINK\n"); test_seal_shrink(); printf("memfd: SEAL-GROW\n"); test_seal_grow(); printf("memfd: SEAL-RESIZE\n"); test_seal_resize(); printf("memfd: SHARE-DUP\n"); test_share_dup(); printf("memfd: SHARE-MMAP\n"); test_share_mmap(); printf("memfd: SHARE-OPEN\n"); test_share_open(); printf("memfd: SHARE-FORK\n"); test_share_fork(); /* Run test-suite in a multi-threaded environment with a shared * file-table. */ pid = spawn_idle_thread(CLONE_FILES | CLONE_FS | CLONE_VM); printf("memfd: SHARE-DUP (shared file-table)\n"); test_share_dup(); printf("memfd: SHARE-MMAP (shared file-table)\n"); test_share_mmap(); printf("memfd: SHARE-OPEN (shared file-table)\n"); test_share_open(); printf("memfd: SHARE-FORK (shared file-table)\n"); test_share_fork(); join_idle_thread(pid); printf("memfd: DONE\n"); return 0; }
/* * Test sharing via fork() * Test whether seal-modifications work as expected with forked childs. */ static void test_share_fork(void) { int fd; pid_t pid; fd = mfd_assert_new("kern_memfd_share_fork", MFD_DEF_SIZE, MFD_CLOEXEC | MFD_ALLOW_SEALING); mfd_assert_has_seals(fd, 0); pid = spawn_idle_thread(0); mfd_assert_add_seals(fd, F_SEAL_SEAL); mfd_assert_has_seals(fd, F_SEAL_SEAL); mfd_fail_add_seals(fd, F_SEAL_WRITE); mfd_assert_has_seals(fd, F_SEAL_SEAL); join_idle_thread(pid); mfd_fail_add_seals(fd, F_SEAL_WRITE); mfd_assert_has_seals(fd, F_SEAL_SEAL); close(fd); }