af381177dd9a037a8a0fd73eb17ddcd42601ad23
[xfstests-dev.git] / src / aio-dio-regress / aio-io-setup-with-nonwritable-context-pointer.c
1 /*
2  *   aio-io-setup-with-nonwritable-context-pointer -
3  *   Test what happens when a non-writable context pointer is passed to io_setup
4  *   Copyright (C) 2007 Jeff Moyer
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  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20  
21 /*
22  *  Author:  Jeff Moyer
23  *
24  *  Description: Pass a non-writable context pointer to io_setup to see if
25  *  the kernel deals with it correctly.  In the past, the reference counting
26  *  in this particular error path was off and this operation would cause an
27  *  oops.
28  *
29  *  This is a destructive test.
30  */
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/mman.h>
34 #include <libgen.h>
35 #include <libaio.h>
36
37 int
38 main(int __attribute__((unused)) argc, char **argv)
39 {
40         void *addr;
41
42         addr = mmap(NULL, 4096, PROT_READ, MAP_SHARED|MAP_ANONYMOUS, 0, 0);
43         if (addr == MAP_FAILED) {
44                 perror("mmap");
45                 exit(1);
46         }
47         io_setup(1, addr /* un-writable pointer */);
48
49         printf("%s: Success!\n", basename(argv[0]));
50         return 0;
51 }