>From 7936ff2c763154f05588e0d35e0cd231774e8aa9 Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Thu, 9 Jun 2011 20:20:17 +0900 Subject: [PATCH] FUTEX_WAIT read only Signed-off-by: KOSAKI Motohiro --- functional/Makefile | 3 +- functional/futex_wait_ro.c | 152 ++++++++++++++++++++++++++++++++++++++++++++ functional/run.sh | 2 + 3 files changed, 156 insertions(+), 1 deletions(-) create mode 100644 functional/futex_wait_ro.c diff --git a/functional/Makefile b/functional/Makefile index 6ecb42c..aec23e5 100644 --- a/functional/Makefile +++ b/functional/Makefile @@ -10,7 +10,8 @@ TARGETS := \ futex_requeue_pi_signal_restart \ futex_requeue_pi_mismatched_ops \ futex_wait_uninitialized_heap \ - futex_wait_private_mapped_file + futex_wait_private_mapped_file \ + futex_wait_ro .PHONY: all clean all: $(TARGETS) diff --git a/functional/futex_wait_ro.c b/functional/futex_wait_ro.c new file mode 100644 index 0000000..59bf2e7 --- /dev/null +++ b/functional/futex_wait_ro.c @@ -0,0 +1,152 @@ +/****************************************************************************** + * + * Copyright FUJITSU LIMITED 2011 + * Copyright KOSAKI Motohiro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * NAME + * futex_wait_ro.c + * + * DESCRIPTION + * + * AUTHOR + * KOSAKI Motohiro + * + * HISTORY + * 2011-Jun-9: Initial version by KOSAKI Motohiro + * + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "logging.h" +#include "futextest.h" + +#define WAIT_US 500000 + +static int child_blocked = 1; +static int child_ret; + + +void usage(char *prog) +{ + printf("Usage: %s\n", prog); + printf(" -c Use color\n"); + printf(" -h Display this help message\n"); + printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", + VQUIET, VCRITICAL, VINFO); +} + +void *wait_thread(void *arg) +{ + int res; + int fd = (int)(unsigned long)arg; + futex_t *futex; + int i; + + futex = mmap(0, sizeof(int), PROT_READ, MAP_SHARED, fd, 0); + child_ret = RET_PASS; + + res = futex_wait(futex, *futex, NULL, 0); + child_blocked = 0; + + if (res != 0) { + error("futex failure\n", errno); + child_ret = RET_ERROR; + } + pthread_exit(NULL); +} + + +int main(int argc, char **argv) +{ + int c, ret = RET_PASS; + long page_size; + pthread_t thr; + futex_t *futex; + int fd; + + while ((c = getopt(argc, argv, "chv:")) != -1) { + switch(c) { + case 'c': + log_color(1); + break; + case 'h': + usage(basename(argv[0])); + exit(0); + case 'v': + log_verbosity(atoi(optarg)); + break; + default: + usage(basename(argv[0])); + exit(1); + } + } + + page_size = sysconf(_SC_PAGESIZE); + + fd = open("/tmp/futex_test", O_RDWR|O_CREAT, 0644); + write(fd, "\1\1\1\1", 4); + + + printf("%s: Test FUTEX_WAIT read only mapping futex \n", + basename(argv[0])); + + ret = pthread_create(&thr, NULL, wait_thread, (void*)(unsigned long)fd); + if (ret) { + error("pthread_create\n", errno); + ret = RET_ERROR; + goto out; + } + + usleep(1000); + + futex = mmap(NULL, page_size, PROT_READ|PROT_WRITE, + MAP_SHARED, fd, 0); + if (futex == (void *)-1) { + error("mmap\n", errno); + exit(1); + } + *futex = 0; + futex_wake(futex, 1, 0); + + info("waiting %dus for child to return\n", WAIT_US); + usleep(WAIT_US); + + if (child_blocked) { + fail("child blocked in kernel\n"); + ret = RET_FAIL; + } else { + ret = child_ret; + } + + out: + print_result(ret); + return ret; +} diff --git a/functional/run.sh b/functional/run.sh index 571a4a4..b82c32d 100755 --- a/functional/run.sh +++ b/functional/run.sh @@ -90,3 +90,5 @@ echo ./futex_wait_uninitialized_heap $COLOR ./futex_wait_private_mapped_file $COLOR +echo +./futex_wait_ro $COLOR \ No newline at end of file -- 1.7.3.1