1*699cd480SApple OSS Distributions #include <darwintest.h> 2*699cd480SApple OSS Distributions #include <mach/mach.h> 3*699cd480SApple OSS Distributions #include <mach/mach_types.h> 4*699cd480SApple OSS Distributions #include <unistd.h> 5*699cd480SApple OSS Distributions #include <sys/types.h> 6*699cd480SApple OSS Distributions #include <sys/wait.h> 7*699cd480SApple OSS Distributions #include <stdlib.h> 8*699cd480SApple OSS Distributions 9*699cd480SApple OSS Distributions #include <stdio.h> 10*699cd480SApple OSS Distributions #include <assert.h> 11*699cd480SApple OSS Distributions #include <err.h> 12*699cd480SApple OSS Distributions #include <libproc.h> 13*699cd480SApple OSS Distributions 14*699cd480SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 15*699cd480SApple OSS Distributions 16*699cd480SApple OSS Distributions T_DECL(proc_info_44873309, "ensure new proc_pidinfo flavor returns correct table sizes", 17*699cd480SApple OSS Distributions T_META_CHECK_LEAKS(false), T_META_ASROOT(true)) 18*699cd480SApple OSS Distributions { 19*699cd480SApple OSS Distributions mach_port_t port; 20*699cd480SApple OSS Distributions int retval; 21*699cd480SApple OSS Distributions 22*699cd480SApple OSS Distributions pid_t pid = getpid(); 23*699cd480SApple OSS Distributions struct proc_ipctableinfo table_info = {}; 24*699cd480SApple OSS Distributions retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info, (uint32_t)sizeof(table_info)); 25*699cd480SApple OSS Distributions T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval); 26*699cd480SApple OSS Distributions T_EXPECT_EQ(retval, (int)sizeof(table_info), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size = %u, table_free = %u", 27*699cd480SApple OSS Distributions table_info.table_size, table_info.table_free); 28*699cd480SApple OSS Distributions 29*699cd480SApple OSS Distributions kern_return_t ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port); 30*699cd480SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE"); 31*699cd480SApple OSS Distributions 32*699cd480SApple OSS Distributions struct proc_ipctableinfo table_info2 = {}; 33*699cd480SApple OSS Distributions retval = proc_pidinfo(pid, PROC_PIDIPCTABLEINFO, 0, (void *)&table_info2, (uint32_t)sizeof(table_info2)); 34*699cd480SApple OSS Distributions T_WITH_ERRNO; T_EXPECT_GT(retval, 0, "proc_pidinfo(PROC_PIDIPCTABLEINFO) returned %d", retval); 35*699cd480SApple OSS Distributions T_EXPECT_EQ(retval, (int)sizeof(table_info2), "proc_pidinfo(PROC_PIDIPCTABLEINFO) table_size2 = %u, table_free2 = %u", 36*699cd480SApple OSS Distributions table_info2.table_size, table_info2.table_free); 37*699cd480SApple OSS Distributions 38*699cd480SApple OSS Distributions T_EXPECT_EQ(table_info.table_free, table_info2.table_free + 1, "Comparing the table_free values"); 39*699cd480SApple OSS Distributions } 40