1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * Copyright FUJITSU LIMITED 2010
8 * Wait on uninitialized heap. It shold be zero and FUTEX_WAIT should
9 * return immediately. This test is intent to test zero page handling in
18 *****************************************************************************/
25 #include <sys/types.h>
29 #include <linux/futex.h>
33 #include "futextest.h"
35 #define TEST_NAME "futex-wait-uninitialized-heap"
36 #define WAIT_US 5000000
38 static int child_blocked = 1;
42 void usage(char *prog)
44 printf("Usage: %s\n", prog);
45 printf(" -c Use color\n");
46 printf(" -h Display this help message\n");
47 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
48 VQUIET, VCRITICAL, VINFO);
51 void *wait_thread(void *arg)
56 res = futex_wait(buf, 1, NULL, 0);
59 if (res != 0 && errno != EWOULDBLOCK) {
60 error("futex failure\n", errno);
61 child_ret = RET_ERROR;
66 int main(int argc, char **argv)
68 int c, ret = RET_PASS;
72 while ((c = getopt(argc, argv, "chv:")) != -1) {
78 usage(basename(argv[0]));
81 log_verbosity(atoi(optarg));
84 usage(basename(argv[0]));
89 page_size = sysconf(_SC_PAGESIZE);
91 buf = mmap(NULL, page_size, PROT_READ|PROT_WRITE,
92 MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
93 if (buf == (void *)-1) {
94 error("mmap\n", errno);
100 ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n",
104 ret = pthread_create(&thr, NULL, wait_thread, NULL);
106 error("pthread_create\n", errno);
111 info("waiting %dus for child to return\n", WAIT_US);
116 fail("child blocked in kernel\n");
121 print_result(TEST_NAME, ret);