plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | */ |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * access(2) test for errno(s) EFAULT. |
| 27 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 28 | |
| 29 | #include <errno.h> |
| 30 | #include <string.h> |
| 31 | #include <signal.h> |
| 32 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 33 | #include <unistd.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 34 | #include <sys/mman.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 37 | static void setup(void); |
| 38 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 40 | char *TCID = "access03"; |
| 41 | int TST_TOTAL = 8; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 43 | /* XXX (garrcoop): uh, this isn't a bad address yo. */ |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 44 | static void *low_addr; |
| 45 | static void *high_addr; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 46 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 47 | #if !defined(UCLINUX) |
| 48 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | int main(int ac, char **av) |
| 50 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 51 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 52 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 54 | msg = parse_opts(ac, av, NULL, NULL); |
| 55 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 56 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 58 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 60 | #define TEST_ACCESS(addr, mode) \ |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 61 | { \ |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 62 | if (access(low_addr, mode) == -1) { \ |
| 63 | if (errno == EFAULT) { \ |
| 64 | tst_resm(TPASS, \ |
| 65 | "access(%p, %s) failed as expected with EFAULT", \ |
| 66 | addr, #mode); \ |
| 67 | } else { \ |
| 68 | tst_resm(TFAIL|TERRNO, \ |
| 69 | "access(%p, %s) failed unexpectedly; " \ |
| 70 | "expected (EFAULT)", addr, #mode); \ |
| 71 | } \ |
| 72 | } else { \ |
| 73 | tst_resm(TFAIL, \ |
| 74 | "access(%p, %s) succeeded unexpectedly", addr, #mode); \ |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 75 | } \ |
| 76 | } |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 77 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 79 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 81 | TEST_ACCESS(low_addr, R_OK); |
| 82 | TEST_ACCESS(low_addr, W_OK); |
| 83 | TEST_ACCESS(low_addr, X_OK); |
| 84 | TEST_ACCESS(low_addr, F_OK); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 85 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 86 | TEST_ACCESS(high_addr, R_OK); |
| 87 | TEST_ACCESS(high_addr, W_OK); |
| 88 | TEST_ACCESS(high_addr, X_OK); |
| 89 | TEST_ACCESS(high_addr, F_OK); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 90 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 93 | tst_exit(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 96 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 99 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 101 | low_addr = mmap(0, 1, PROT_NONE, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 103 | if (low_addr == MAP_FAILED) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | tst_brkm(TBROK | TERRNO, NULL, "mmap failed"); |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 105 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 106 | high_addr = get_high_address(); |
| 107 | if (high_addr == NULL) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | tst_brkm(TBROK | TERRNO, NULL, "get_high_address failed"); |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 109 | high_addr++; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 110 | |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 111 | tst_tmpdir(); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 112 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | |
Wanlong Gao | 41dae89 | 2013-04-26 14:55:25 +0800 | [diff] [blame] | 114 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | tst_rmdir(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 117 | } |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 118 | |
| 119 | #else |
| 120 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 121 | int main(void) |
Garrett Cooper | 187e27c | 2010-12-17 13:30:26 -0800 | [diff] [blame] | 122 | { |
| 123 | tst_brkm(TCONF, NULL, "test not available on UCLINUX"); |
| 124 | } |
| 125 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 126 | #endif /* if !defined(UCLINUX) */ |