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