Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 1 | /* |
Cyril Hrubis | 5efee33 | 2013-06-04 20:14:58 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010 Red Hat, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it 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 |
| 17 | * with other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write the Free Software Foundation, |
| 21 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | */ |
| 23 | /* |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 24 | * munmap() don't check sysctl_max_mapcount |
| 25 | * |
| 26 | * From http://lkml.org/lkml/2009/10/2/85: |
| 27 | * |
| 28 | * On ia64, the following test program exit abnormally, because glibc |
| 29 | * thread library called abort(). |
| 30 | * |
| 31 | * ======================================================== |
| 32 | * (gdb) bt |
| 33 | * #0 0xa000000000010620 in __kernel_syscall_via_break () |
| 34 | * #1 0x20000000003208e0 in raise () from /lib/libc.so.6.1 |
| 35 | * #2 0x2000000000324090 in abort () from /lib/libc.so.6.1 |
| 36 | * #3 0x200000000027c3e0 in __deallocate_stack () from |
| 37 | * /lib/libpthread.so.0 |
| 38 | * #4 0x200000000027f7c0 in start_thread () from /lib/libpthread.so.0 |
| 39 | * #5 0x200000000047ef60 in __clone2 () from /lib/libc.so.6.1 |
| 40 | * ======================================================== |
| 41 | * The fact is, glibc call munmap() when thread exitng time for freeing |
| 42 | * stack, and it assume munlock() never fail. However, munmap() often |
| 43 | * make vma splitting and it with many mapcount make -ENOMEM. |
| 44 | * |
| 45 | * Oh well, stack unfreeing is not reasonable option. Also munlock() via |
| 46 | * free() shouldn't failed. |
| 47 | * |
| 48 | * Thus, munmap() shoudn't check max-mapcount. |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 49 | */ |
| 50 | #include<stdio.h> |
| 51 | #include<stdlib.h> |
| 52 | #include<string.h> |
| 53 | #include<pthread.h> |
| 54 | #include<errno.h> |
| 55 | #include<unistd.h> |
| 56 | #include "test.h" |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 57 | |
| 58 | char *TCID = "mmap11"; |
| 59 | int TST_TOTAL = 1; |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 60 | |
| 61 | #define MAL_SIZE (100*1024) |
| 62 | |
| 63 | static void *wait_thread(void *args); |
| 64 | static void *wait_thread2(void *args); |
| 65 | static void setup(void); |
Garrett Cooper | eb16c91 | 2010-12-19 10:04:37 -0800 | [diff] [blame] | 66 | static void cleanup(void); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 67 | static void check(void); |
| 68 | |
| 69 | int main(int argc, char *argv[]) |
| 70 | { |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 71 | const char *msg; |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 72 | |
| 73 | msg = parse_opts(argc, argv, NULL, NULL); |
| 74 | if (msg != NULL) |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 75 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 76 | setup(); |
| 77 | check(); |
| 78 | cleanup(); |
Garrett Cooper | eb16c91 | 2010-12-19 10:04:37 -0800 | [diff] [blame] | 79 | tst_exit(); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void setup(void) |
| 83 | { |
Garrett Cooper | 40495b8 | 2011-01-19 00:48:39 -0800 | [diff] [blame] | 84 | tst_require_root(NULL); |
| 85 | |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 86 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 87 | TEST_PAUSE; |
| 88 | } |
| 89 | |
| 90 | void cleanup(void) |
| 91 | { |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void check(void) |
| 95 | { |
| 96 | int lc; |
| 97 | pthread_t *thread, th; |
| 98 | int ret, count = 0; |
| 99 | pthread_attr_t attr; |
| 100 | |
| 101 | ret = pthread_attr_init(&attr); |
| 102 | if (ret) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | tst_brkm(TBROK | TERRNO, cleanup, "pthread_attr_init"); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 104 | ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 105 | if (ret) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 106 | tst_brkm(TBROK | TERRNO, cleanup, |
| 107 | "pthread_attr_setdetachstate"); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 108 | thread = malloc(STD_LOOP_COUNT * sizeof(pthread_t)); |
| 109 | if (thread == NULL) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | tst_brkm(TBROK | TERRNO, cleanup, "malloc"); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 111 | |
| 112 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 113 | tst_count = 0; |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 114 | ret = pthread_create(&th, &attr, wait_thread, NULL); |
| 115 | if (ret) { |
| 116 | tst_resm(TINFO, "[%d] ", count); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 117 | tst_brkm(TBROK | TERRNO, cleanup, "pthread_create"); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 118 | } |
| 119 | count++; |
| 120 | ret = pthread_create(&thread[lc], &attr, wait_thread2, NULL); |
| 121 | if (ret) { |
| 122 | tst_resm(TINFO, "[%d] ", count); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | tst_brkm(TBROK | TERRNO, cleanup, "pthread_create"); |
Garrett Cooper | 60bb3f5 | 2010-12-08 01:01:52 -0800 | [diff] [blame] | 124 | } |
| 125 | count++; |
| 126 | } |
| 127 | tst_resm(TPASS, "test completed."); |
| 128 | free(thread); |
| 129 | } |
| 130 | |
| 131 | void *wait_thread(void *args) |
| 132 | { |
| 133 | void *addr; |
| 134 | |
| 135 | addr = malloc(MAL_SIZE); |
| 136 | if (addr) |
| 137 | memset(addr, 1, MAL_SIZE); |
| 138 | sleep(1); |
| 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | void *wait_thread2(void *args) |
| 143 | { |
| 144 | return NULL; |
Garrett Cooper | eb16c91 | 2010-12-19 10:04:37 -0800 | [diff] [blame] | 145 | } |