~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /******************************************************************************
  2  *
  3  * Copyright FUJITSU LIMITED 2010
  4  * Copyright KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
  5  *
  6  *   This program is free software;  you can redistribute it and/or modify
  7  *   it under the terms of the GNU General Public License as published by
  8  *   the Free Software Foundation; either version 2 of the License, or
  9  *   (at your option) any later version.
 10  *
 11  * DESCRIPTION
 12  *      Wait on uninitialized heap. It shold be zero and FUTEX_WAIT should
 13  *      return immediately. This test is intent to test zero page handling in
 14  *      futex.
 15  *
 16  * AUTHOR
 17  *      KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
 18  *
 19  * HISTORY
 20  *      2010-Jan-6: Initial version by KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
 21  *
 22  *****************************************************************************/
 23 
 24 #include <pthread.h>
 25 #include <stdio.h>
 26 #include <stdlib.h>
 27 #include <sys/mman.h>
 28 #include <syscall.h>
 29 #include <sys/types.h>
 30 #include <sys/stat.h>
 31 #include <unistd.h>
 32 #include <errno.h>
 33 #include <linux/futex.h>
 34 #include <libgen.h>
 35 
 36 #include "logging.h"
 37 #include "futextest.h"
 38 
 39 #define TEST_NAME "futex-wait-uninitialized-heap"
 40 #define WAIT_US 5000000
 41 
 42 static int child_blocked = 1;
 43 static int child_ret;
 44 void *buf;
 45 
 46 void usage(char *prog)
 47 {
 48         printf("Usage: %s\n", prog);
 49         printf("  -c    Use color\n");
 50         printf("  -h    Display this help message\n");
 51         printf("  -v L  Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
 52                VQUIET, VCRITICAL, VINFO);
 53 }
 54 
 55 void *wait_thread(void *arg)
 56 {
 57         int res;
 58 
 59         child_ret = RET_PASS;
 60         res = futex_wait(buf, 1, NULL, 0);
 61         child_blocked = 0;
 62 
 63         if (res != 0 && errno != EWOULDBLOCK) {
 64                 error("futex failure\n", errno);
 65                 child_ret = RET_ERROR;
 66         }
 67         pthread_exit(NULL);
 68 }
 69 
 70 int main(int argc, char **argv)
 71 {
 72         int c, ret = RET_PASS;
 73         long page_size;
 74         pthread_t thr;
 75 
 76         while ((c = getopt(argc, argv, "chv:")) != -1) {
 77                 switch (c) {
 78                 case 'c':
 79                         log_color(1);
 80                         break;
 81                 case 'h':
 82                         usage(basename(argv[0]));
 83                         exit(0);
 84                 case 'v':
 85                         log_verbosity(atoi(optarg));
 86                         break;
 87                 default:
 88                         usage(basename(argv[0]));
 89                         exit(1);
 90                 }
 91         }
 92 
 93         page_size = sysconf(_SC_PAGESIZE);
 94 
 95         buf = mmap(NULL, page_size, PROT_READ|PROT_WRITE,
 96                    MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
 97         if (buf == (void *)-1) {
 98                 error("mmap\n", errno);
 99                 exit(1);
100         }
101 
102         ksft_print_header();
103         ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n",
104                basename(argv[0]));
105 
106 
107         ret = pthread_create(&thr, NULL, wait_thread, NULL);
108         if (ret) {
109                 error("pthread_create\n", errno);
110                 ret = RET_ERROR;
111                 goto out;
112         }
113 
114         info("waiting %dus for child to return\n", WAIT_US);
115         usleep(WAIT_US);
116 
117         ret = child_ret;
118         if (child_blocked) {
119                 fail("child blocked in kernel\n");
120                 ret = RET_FAIL;
121         }
122 
123  out:
124         print_result(TEST_NAME, ret);
125         return ret;
126 }
127 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp