1 /*
2 * Copyright (c) 2014 Fujitsu Ltd.
3 * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program.
15 */
16 /*
17 * DESCRIPTION
18 * Basic test for modify_ldt(2) using func=0 argument.
19 */
20
21 #include "config.h"
22 #include "test.h"
23
24 char *TCID = "modify_ldt03";
25 int TST_TOTAL = 1;
26
27 #if defined(__i386__) && defined(HAVE_MODIFY_LDT)
28
29 #ifdef HAVE_ASM_LDT_H
30 # include <asm/ldt.h>
31 #endif
32 extern int modify_ldt(int, void *, unsigned long);
33
34 #include <asm/unistd.h>
35 #include <string.h>
36 #include <sys/wait.h>
37 #include <errno.h>
38 #include "safe_macros.h"
39
40 #ifdef HAVE_STRUCT_USER_DESC
41 # define SIZE sizeof(struct user_desc)
42 #else
43 # define SIZE 16
44 #endif
45
46 static char buf[SIZE];
47 static void cleanup(void);
48 static void setup(void);
49
main(int ac,char ** av)50 int main(int ac, char **av)
51 {
52 int lc;
53
54 tst_parse_opts(ac, av, NULL, NULL);
55
56 setup();
57
58 for (lc = 0; TEST_LOOPING(lc); lc++) {
59
60 tst_count = 0;
61
62 TEST(modify_ldt(0, buf, SIZE));
63
64 if (TEST_RETURN < 0) {
65 tst_resm(TFAIL | TTERRNO,
66 "modify_ldt() failed with errno: %s",
67 strerror(TEST_ERRNO));
68 } else {
69 tst_resm(TPASS, "modify_ldt() tested success");
70 }
71 }
72
73 cleanup();
74 tst_exit();
75 }
76
setup(void)77 static void setup(void)
78 {
79 tst_sig(NOFORK, DEF_HANDLER, cleanup);
80
81 TEST_PAUSE;
82 }
83
cleanup(void)84 static void cleanup(void)
85 {
86 }
87
88 #elif HAVE_MODIFY_LDT
89
main(void)90 int main(void)
91 {
92 tst_brkm(TCONF,
93 NULL, "modify_ldt is available but not tested on the platform than "
94 "__i386__");
95 }
96
97 #else /* if defined(__i386__) */
98
main(void)99 int main(void)
100 {
101 tst_resm(TINFO, "modify_ldt03 test only for ix86");
102 tst_exit();
103 }
104
105 #endif /* if defined(__i386__) */
106