xref: /xnu-12377.41.6/tests/nox86exec.c (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions #include <spawn.h>
2*bbb1b6f9SApple OSS Distributions #include <sys/wait.h>
3*bbb1b6f9SApple OSS Distributions #include <darwintest.h>
4*bbb1b6f9SApple OSS Distributions #include <mach-o/dyld.h>
5*bbb1b6f9SApple OSS Distributions #include <errno.h>
6*bbb1b6f9SApple OSS Distributions 
7*bbb1b6f9SApple OSS Distributions T_DECL(nox86exec, "make sure the nox86exec boot-arg is honored", T_META_ALL_VALID_ARCHS(false), T_META_BOOTARGS_SET("nox86exec=1"))
8*bbb1b6f9SApple OSS Distributions {
9*bbb1b6f9SApple OSS Distributions #if TARGET_OS_OSX && defined(__arm64__)
10*bbb1b6f9SApple OSS Distributions 	int spawn_ret, pid;
11*bbb1b6f9SApple OSS Distributions 	char path[1024];
12*bbb1b6f9SApple OSS Distributions 	uint32_t size = sizeof(path);
13*bbb1b6f9SApple OSS Distributions 
14*bbb1b6f9SApple OSS Distributions 	T_ASSERT_EQ(_NSGetExecutablePath(path, &size), 0, NULL);
15*bbb1b6f9SApple OSS Distributions 	T_ASSERT_LT(strlcat(path, "_helper", size), (unsigned long)size, NULL);
16*bbb1b6f9SApple OSS Distributions 
17*bbb1b6f9SApple OSS Distributions 	spawn_ret = posix_spawn(&pid, path, NULL, NULL, NULL, NULL);
18*bbb1b6f9SApple OSS Distributions 	if (spawn_ret == 0) {
19*bbb1b6f9SApple OSS Distributions 		int wait_ret = 0;
20*bbb1b6f9SApple OSS Distributions 		waitpid(pid, &wait_ret, 0);
21*bbb1b6f9SApple OSS Distributions 		T_ASSERT_FALSE(WIFEXITED(wait_ret), "x86_64 helper should not run");
22*bbb1b6f9SApple OSS Distributions 	}
23*bbb1b6f9SApple OSS Distributions #else
24*bbb1b6f9SApple OSS Distributions 	T_SKIP("Skipping. Test only runs on arm64 macOS.");
25*bbb1b6f9SApple OSS Distributions #endif
26*bbb1b6f9SApple OSS Distributions }
27