-#include <bsdtests.h>
#include <stdlib.h>
#include <unistd.h>
+#include <signal.h>
+#include <setjmp.h>
-char *heap;
-volatile int pass;
-sigjmp_buf jbuf;
+#include <darwintest.h>
-void
+static char *heap;
+static volatile int pass;
+static sigjmp_buf jbuf;
+
+static void __dead2
action(int signo, struct __siginfo *info, void *uap __attribute__((unused)))
{
if (info) {
pass = (signo == SIGBUS && info->si_addr == heap);
}
- return siglongjmp(jbuf, 0);
+ siglongjmp(jbuf, 0);
}
-int
-main(void)
+T_DECL(nxheap, "Non-executable heap", T_META_CHECK_LEAKS(NO))
{
- int ret;
-
struct sigaction sa = {
.__sigaction_u.__sa_sigaction = action,
.sa_flags = SA_SIGINFO,
};
- test_start("Non-executable heap");
-
- ret = sigaction(SIGBUS, &sa, NULL);
- assert(ret == 0);
- test_long("sigaction", ret, 0);
+ T_ASSERT_POSIX_ZERO(sigaction(SIGBUS, &sa, NULL), NULL);
if (sigsetjmp(jbuf, 0)) {
- // PASS
- test_long("SIGBUS", 1, 1);
- test_stop();
- return EXIT_FAILURE;
+ T_PASS("SIGBUS");
+ T_END;
}
- heap = malloc(1);
- test_ptr_notnull("malloc", heap);
+ T_QUIET; T_ASSERT_NOTNULL((heap = malloc(1)), NULL);
- *heap = 0xc3; // retq
+ *heap = (char)0xc3; // retq
((void (*)(void))heap)(); // call *%eax
- // FAIL
- test_long("SIGBUS", 0, 1);
-
- test_stop();
-
- return EXIT_SUCCESS;
+ T_FAIL("SIGBUS");
}