1 #include <darwintest.h> 2 #include <darwintest_utils.h> 3 #include <dispatch/dispatch.h> 4 #include <sys/guarded.h> 5 #include <sys/types.h> 6 #include <sys/uio.h> 7 #include <unistd.h> 8 #include <fcntl.h> 9 10 T_GLOBAL_META( 11 T_META_NAMESPACE("xnu.fd"), 12 T_META_RUN_CONCURRENTLY(true)); 13 14 T_DECL(fd_guard_monitored, "Test that we can guard fds in kevent") 15 { 16 static int pfd[2]; 17 static dispatch_source_t ds; 18 guardid_t guard = (uintptr_t)&pfd; 19 20 T_ASSERT_POSIX_SUCCESS(pipe(pfd), "pipe"); 21 22 ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, 23 (uintptr_t)pfd[0], 0, NULL); 24 dispatch_source_set_event_handler(ds, ^{ }); 25 dispatch_activate(ds); 26 27 T_EXPECT_POSIX_SUCCESS(change_fdguard_np(pfd[0], NULL, 0, 28 &guard, GUARD_DUP | GUARD_CLOSE, NULL), "change_fdguard_np"); 29 } 30