1*1b191cb5SApple OSS Distributions #include <darwintest.h> 2*1b191cb5SApple OSS Distributions #include "../bsd/sys/proc_info.h" 3*1b191cb5SApple OSS Distributions #include "../libsyscall/wrappers/libproc/libproc.h" 4*1b191cb5SApple OSS Distributions #include <stdio.h> 5*1b191cb5SApple OSS Distributions #include <unistd.h> 6*1b191cb5SApple OSS Distributions #include <TargetConditionals.h> 7*1b191cb5SApple OSS Distributions 8*1b191cb5SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 9*1b191cb5SApple OSS Distributions 10*1b191cb5SApple OSS Distributions T_DECL(proc_udata_info, "Get and set a proc udata token"){ 11*1b191cb5SApple OSS Distributions uint64_t token = mach_absolute_time(); 12*1b191cb5SApple OSS Distributions proc_info_udata_t udata; 13*1b191cb5SApple OSS Distributions int ret; 14*1b191cb5SApple OSS Distributions 15*1b191cb5SApple OSS Distributions udata = token; 16*1b191cb5SApple OSS Distributions ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata)); 17*1b191cb5SApple OSS Distributions 18*1b191cb5SApple OSS Distributions #if !TARGET_OS_OSX 19*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 20*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET returns error on non-supported platforms"); 21*1b191cb5SApple OSS Distributions T_SKIP("Remaining tests are only supported on platforms with CONFIG_PROC_UDATA_STORAGE configured"); 22*1b191cb5SApple OSS Distributions #endif 23*1b191cb5SApple OSS Distributions 24*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 25*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_SET"); 26*1b191cb5SApple OSS Distributions 27*1b191cb5SApple OSS Distributions T_LOG("udata set to %#llx", udata); 28*1b191cb5SApple OSS Distributions 29*1b191cb5SApple OSS Distributions bzero(&udata, sizeof(udata)); 30*1b191cb5SApple OSS Distributions ret = proc_udata_info(getpid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata)); 31*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 32*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, 0, "proc_udata_info PROC_UDATA_INFO_GET"); 33*1b191cb5SApple OSS Distributions 34*1b191cb5SApple OSS Distributions T_ASSERT_EQ_ULLONG(token, udata, "proc_udata_info(): retrieved value matches token"); 35*1b191cb5SApple OSS Distributions 36*1b191cb5SApple OSS Distributions ret = proc_udata_info(getpid(), PROC_UDATA_INFO_SET, &udata, sizeof(uint32_t)); 37*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 38*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned -1"); 39*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(errno, EINVAL, "proc_udata_info PROC_UDATA_INFO_SET with invalid size returned EINVAL"); 40*1b191cb5SApple OSS Distributions 41*1b191cb5SApple OSS Distributions ret = proc_udata_info(getppid(), PROC_UDATA_INFO_GET, &udata, sizeof(udata)); 42*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 43*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_GET returned -1 on attempt against non-self pid"); 44*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(errno, EACCES, "proc_udata_info PROC_UDATA_INFO_GET set errno to EACCES on attempt against non-self pid"); 45*1b191cb5SApple OSS Distributions 46*1b191cb5SApple OSS Distributions ret = proc_udata_info(getppid(), PROC_UDATA_INFO_SET, &udata, sizeof(udata)); 47*1b191cb5SApple OSS Distributions T_WITH_ERRNO; 48*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(ret, -1, "proc_udata_info PROC_UDATA_INFO_SET returned -1 on attempt against non-self pid"); 49*1b191cb5SApple OSS Distributions T_ASSERT_EQ_INT(errno, EACCES, "proc_udata_info PROC_UDATA_INFO_SET set errno to EACCES on attempt against non-self pid"); 50*1b191cb5SApple OSS Distributions } 51