blob: 1b45ed134db3d29c38f7fbd0ae89b2c5f11f7c21 [file] [log] [blame]
Garrett Cooper60bb3f52010-12-08 01:01:52 -08001/*
Cyril Hrubis5efee332013-06-04 20:14:58 +02002 * 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 Cooper60bb3f52010-12-08 01:01:52 -080024 * 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 Cooper60bb3f52010-12-08 01:01:52 -080049 */
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 Cooper60bb3f52010-12-08 01:01:52 -080057
58char *TCID = "mmap11";
59int TST_TOTAL = 1;
Garrett Cooper60bb3f52010-12-08 01:01:52 -080060
61#define MAL_SIZE (100*1024)
62
63static void *wait_thread(void *args);
64static void *wait_thread2(void *args);
65static void setup(void);
Garrett Coopereb16c912010-12-19 10:04:37 -080066static void cleanup(void);
Garrett Cooper60bb3f52010-12-08 01:01:52 -080067static void check(void);
68
69int main(int argc, char *argv[])
70{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020071 const char *msg;
Garrett Cooper60bb3f52010-12-08 01:01:52 -080072
73 msg = parse_opts(argc, argv, NULL, NULL);
74 if (msg != NULL)
Garrett Cooper53740502010-12-16 00:04:01 -080075 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper60bb3f52010-12-08 01:01:52 -080076 setup();
77 check();
78 cleanup();
Garrett Coopereb16c912010-12-19 10:04:37 -080079 tst_exit();
Garrett Cooper60bb3f52010-12-08 01:01:52 -080080}
81
82void setup(void)
83{
Garrett Cooper40495b82011-01-19 00:48:39 -080084 tst_require_root(NULL);
85
Garrett Cooper60bb3f52010-12-08 01:01:52 -080086 tst_sig(FORK, DEF_HANDLER, cleanup);
87 TEST_PAUSE;
88}
89
90void cleanup(void)
91{
Garrett Cooper60bb3f52010-12-08 01:01:52 -080092}
93
94void 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 Gao354ebb42012-12-07 10:10:04 +0800103 tst_brkm(TBROK | TERRNO, cleanup, "pthread_attr_init");
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800104 ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
105 if (ret)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800106 tst_brkm(TBROK | TERRNO, cleanup,
107 "pthread_attr_setdetachstate");
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800108 thread = malloc(STD_LOOP_COUNT * sizeof(pthread_t));
109 if (thread == NULL)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800110 tst_brkm(TBROK | TERRNO, cleanup, "malloc");
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800111
112 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800113 tst_count = 0;
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800114 ret = pthread_create(&th, &attr, wait_thread, NULL);
115 if (ret) {
116 tst_resm(TINFO, "[%d] ", count);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800117 tst_brkm(TBROK | TERRNO, cleanup, "pthread_create");
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800118 }
119 count++;
120 ret = pthread_create(&thread[lc], &attr, wait_thread2, NULL);
121 if (ret) {
122 tst_resm(TINFO, "[%d] ", count);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123 tst_brkm(TBROK | TERRNO, cleanup, "pthread_create");
Garrett Cooper60bb3f52010-12-08 01:01:52 -0800124 }
125 count++;
126 }
127 tst_resm(TPASS, "test completed.");
128 free(thread);
129}
130
131void *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
142void *wait_thread2(void *args)
143{
144 return NULL;
Garrett Coopereb16c912010-12-19 10:04:37 -0800145}