4 #include <spawn_private.h>
5 #include <sys/sysctl.h>
9 #ifndef _POSIX_SPAWN_FORCE_4K_PAGES
10 #define _POSIX_SPAWN_FORCE_4K_PAGES 0x1000
11 #endif /* _POSIX_SPAWN_FORCE_4K_PAGES */
14 main(int argc
, char *argv
[])
17 fprintf(stderr
, "Usage: %s </path/to/command> [<arg> ..]\n", argv
[0]);
21 char * prog_path
= argv
[1];
22 if (0 != access(prog_path
, X_OK
)) {
23 fprintf(stderr
, "%s is not an executable\n", prog_path
);
28 posix_spawn_file_actions_t fileactions
;
29 posix_spawnattr_t spawnattrs
;
30 if (posix_spawnattr_init(&spawnattrs
)) {
31 perror("posix_spawnattr_init");
34 if (posix_spawn_file_actions_init(&fileactions
)) {
35 perror("posix_spawn_file_actions_init");
38 short sp_flags
= POSIX_SPAWN_SETEXEC
;
40 /* Need to set special flags */
42 size_t supported_size
= sizeof(supported
);
44 int r
= sysctlbyname("debug.vm_mixed_pagesize_supported", &supported
, &supported_size
, NULL
, 0);
45 if (r
== 0 && supported
) {
46 sp_flags
|= _POSIX_SPAWN_FORCE_4K_PAGES
;
49 * We didnt find debug.vm.mixed_page.supported OR its set to 0.
52 printf("Hardware doesn't support 4K pages, skipping test...");
56 posix_spawnattr_setflags(&spawnattrs
, sp_flags
);
57 posix_spawn(&newpid
, prog_path
, &fileactions
, &spawnattrs
, &argv
[1], environ
);
59 /* Should not have reached here */
60 fprintf(stderr
, "should not have reached here");