|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
1 | 2 | /*
|
| 3 | + * Copyright (C) 2010 Red Hat, Inc. |
| 4 | + */ |
| 5 | + |
| 6 | +/*\ |
| 7 | + * [Description] |
| 8 | + * |
| 9 | + * This case is a regression test on old RHEL5. |
| 10 | + * |
2 | 11 | * Stack size mapping is decreased through mlock/munlock call.
|
| 12 | + * See the following url: |
| 13 | + * https://bugzilla.redhat.com/show_bug.cgi?id=643426 |
3 | 14 | *
|
4 | 15 | * This is to test kernel if it has a problem with shortening [stack]
|
5 | 16 | * mapping through several loops of mlock/munlock of /proc/self/maps.
|
|
11 | 22 | * munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
|
12 | 23 | *
|
13 | 24 | * with more iterations - could drop to 0KiB.
|
14 |
| - * |
15 |
| - * Copyright (C) 2010 Red Hat, Inc. |
16 |
| - * This program is free software; you can redistribute it and/or |
17 |
| - * modify it under the terms of version 2 of the GNU General Public |
18 |
| - * License as published by the Free Software Foundation. |
19 |
| - * |
20 |
| - * This program is distributed in the hope that it would be useful, |
21 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
23 |
| - * |
24 |
| - * Further, this software is distributed without any warranty that it |
25 |
| - * is free of the rightful claim of any third person regarding |
26 |
| - * infringement or the like. Any license provided herein, whether |
27 |
| - * implied or otherwise, applies only to this software file. Patent |
28 |
| - * licenses, if any, provided herein do not apply to combinations of |
29 |
| - * this program with other software, or any other product whatsoever. |
30 |
| - * |
31 |
| - * You should have received a copy of the GNU General Public License |
32 |
| - * along with this program; if not, write the Free Software |
33 |
| - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
34 |
| - * 02110-1301, USA. |
35 | 25 | */
|
| 26 | + |
36 | 27 | #include <sys/mman.h>
|
37 | 28 | #include <stdio.h>
|
38 | 29 | #include <string.h>
|
39 |
| -#include "test.h" |
| 30 | +#include <pwd.h> |
| 31 | +#include "tst_test.h" |
| 32 | +#include "tst_safe_stdio.h" |
40 | 33 |
|
41 | 34 | #define KB 1024
|
42 | 35 |
|
43 |
| -char *TCID = "mlock03"; |
44 |
| -int TST_TOTAL = 1; |
45 |
| - |
46 |
| -static void setup(void); |
47 |
| -static void cleanup(void); |
48 |
| - |
49 |
| -int main(int argc, char *argv[]) |
| 36 | +static void verify_mlock(void) |
50 | 37 | {
|
51 |
| - int lc; |
52 | 38 | long from, to;
|
53 | 39 | long first = -1, last = -1;
|
54 | 40 | char b[KB];
|
55 | 41 | FILE *fp;
|
56 | 42 |
|
57 |
| - tst_parse_opts(argc, argv, NULL, NULL); |
58 |
| - |
59 |
| - setup(); |
| 43 | + fp = SAFE_FOPEN("/proc/self/maps", "r"); |
| 44 | + while (!feof(fp)) { |
| 45 | + if (!fgets(b, KB - 1, fp)) |
| 46 | + break; |
| 47 | + b[strlen(b) - 1] = '\0'; |
| 48 | + if (sscanf(b, "%lx-%lx", &from, &to) != 2) { |
| 49 | + tst_brk(TBROK, "parse %s start and end address failed", |
| 50 | + b); |
| 51 | + continue; |
| 52 | + } |
60 | 53 |
|
61 |
| - for (lc = 0; TEST_LOOPING(lc); lc++) { |
62 |
| - fp = fopen("/proc/self/maps", "r"); |
63 |
| - if (fp == NULL) |
64 |
| - tst_brkm(TBROK | TERRNO, cleanup, "fopen"); |
65 |
| - while (!feof(fp)) { |
66 |
| - if (!fgets(b, KB - 1, fp)) |
67 |
| - break; |
68 |
| - b[strlen(b) - 1] = '\0'; |
69 |
| - sscanf(b, "%lx-%lx", &from, &to); |
| 54 | + /* Record the initial stack size. */ |
| 55 | + if (strstr(b, "[stack]") != NULL) |
| 56 | + first = (to - from) / KB; |
70 | 57 |
|
71 |
| - /* Record the initial stack size. */ |
72 |
| - if (lc == 0 && strstr(b, "[stack]") != NULL) |
73 |
| - first = (to - from) / KB; |
| 58 | + tst_res(TINFO, "mlock [%lx,%lx]", from, to); |
| 59 | + if (mlock((const void *)from, to - from) == -1) |
| 60 | + tst_res(TINFO | TERRNO, "mlock failed"); |
74 | 61 |
|
75 |
| - switch (lc & 1) { |
76 |
| - case 0: |
77 |
| - if (mlock((const void *)from, to - from) == -1) |
78 |
| - tst_resm(TINFO | TERRNO, |
79 |
| - "mlock failed"); |
80 |
| - break; |
81 |
| - case 1: |
82 |
| - if (munlock((void *)from, to - from) == -1) |
83 |
| - tst_resm(TINFO | TERRNO, |
84 |
| - "munlock failed"); |
85 |
| - break; |
86 |
| - default: |
87 |
| - break; |
88 |
| - } |
89 |
| - tst_resm(TINFO, "%s from %lx to %0lx", |
90 |
| - (lc & 1) ? "munlock" : "mlock", from, to); |
| 62 | + tst_res(TINFO, "munlock [%lx,%lx]", from, to); |
| 63 | + if (munlock((void *)from, to - from) == -1) |
| 64 | + tst_res(TINFO | TERRNO, "munlock failed"); |
91 | 65 |
|
92 |
| - /* Record the final stack size. */ |
93 |
| - if (strstr(b, "[stack]") != NULL) |
94 |
| - last = (to - from) / KB; |
95 |
| - } |
96 |
| - fclose(fp); |
| 66 | + /* Record the final stack size. */ |
| 67 | + if (strstr(b, "[stack]") != NULL) |
| 68 | + last = (to - from) / KB; |
97 | 69 | }
|
98 |
| - tst_resm(TINFO, "starting stack size is %ld", first); |
99 |
| - tst_resm(TINFO, "final stack size is %ld", last); |
| 70 | + SAFE_FCLOSE(fp); |
| 71 | + |
| 72 | + tst_res(TINFO, "starting stack size is %ld", first); |
| 73 | + tst_res(TINFO, "final stack size is %ld", last); |
100 | 74 | if (last < first)
|
101 |
| - tst_resm(TFAIL, "stack size is decreased."); |
| 75 | + tst_res(TFAIL, "stack size is decreased."); |
102 | 76 | else
|
103 |
| - tst_resm(TPASS, "stack size is not decreased."); |
104 |
| - |
105 |
| - cleanup(); |
106 |
| - tst_exit(); |
| 77 | + tst_res(TPASS, "stack size is not decreased."); |
107 | 78 | }
|
108 | 79 |
|
109 |
| -void setup(void) |
110 |
| -{ |
111 |
| - tst_require_root(); |
112 |
| - |
113 |
| - tst_sig(FORK, DEF_HANDLER, cleanup); |
114 |
| - TEST_PAUSE; |
115 |
| -} |
116 |
| - |
117 |
| -void cleanup(void) |
118 |
| -{ |
119 |
| -} |
| 80 | +static struct tst_test test = { |
| 81 | + .test_all = verify_mlock, |
| 82 | +}; |
0 commit comments