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