~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/x86/check_initial_reg_state.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * check_initial_reg_state.c - check that execve sets the correct state
  3  * Copyright (c) 2014-2016 Andrew Lutomirski
  4  *
  5  * This program is free software; you can redistribute it and/or modify
  6  * it under the terms and conditions of the GNU General Public License,
  7  * version 2, as published by the Free Software Foundation.
  8  *
  9  * This program is distributed in the hope it will be useful, but
 10  * WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  */
 14 
 15 #define _GNU_SOURCE
 16 
 17 #include <stdio.h>
 18 
 19 unsigned long ax, bx, cx, dx, si, di, bp, sp, flags;
 20 unsigned long r8, r9, r10, r11, r12, r13, r14, r15;
 21 
 22 asm (
 23         ".pushsection .text\n\t"
 24         ".type real_start, @function\n\t"
 25         ".global real_start\n\t"
 26         "real_start:\n\t"
 27 #ifdef __x86_64__
 28         "mov %rax, ax\n\t"
 29         "mov %rbx, bx\n\t"
 30         "mov %rcx, cx\n\t"
 31         "mov %rdx, dx\n\t"
 32         "mov %rsi, si\n\t"
 33         "mov %rdi, di\n\t"
 34         "mov %rbp, bp\n\t"
 35         "mov %rsp, sp\n\t"
 36         "mov %r8, r8\n\t"
 37         "mov %r9, r9\n\t"
 38         "mov %r10, r10\n\t"
 39         "mov %r11, r11\n\t"
 40         "mov %r12, r12\n\t"
 41         "mov %r13, r13\n\t"
 42         "mov %r14, r14\n\t"
 43         "mov %r15, r15\n\t"
 44         "pushfq\n\t"
 45         "popq flags\n\t"
 46 #else
 47         "mov %eax, ax\n\t"
 48         "mov %ebx, bx\n\t"
 49         "mov %ecx, cx\n\t"
 50         "mov %edx, dx\n\t"
 51         "mov %esi, si\n\t"
 52         "mov %edi, di\n\t"
 53         "mov %ebp, bp\n\t"
 54         "mov %esp, sp\n\t"
 55         "pushfl\n\t"
 56         "popl flags\n\t"
 57 #endif
 58         "jmp _start\n\t"
 59         ".size real_start, . - real_start\n\t"
 60         ".popsection");
 61 
 62 int main()
 63 {
 64         int nerrs = 0;
 65 
 66         if (sp == 0) {
 67                 printf("[FAIL]\tTest was built incorrectly\n");
 68                 return 1;
 69         }
 70 
 71         if (ax || bx || cx || dx || si || di || bp
 72 #ifdef __x86_64__
 73             || r8 || r9 || r10 || r11 || r12 || r13 || r14 || r15
 74 #endif
 75                 ) {
 76                 printf("[FAIL]\tAll GPRs except SP should be 0\n");
 77 #define SHOW(x) printf("\t" #x " = 0x%lx\n", x);
 78                 SHOW(ax);
 79                 SHOW(bx);
 80                 SHOW(cx);
 81                 SHOW(dx);
 82                 SHOW(si);
 83                 SHOW(di);
 84                 SHOW(bp);
 85                 SHOW(sp);
 86 #ifdef __x86_64__
 87                 SHOW(r8);
 88                 SHOW(r9);
 89                 SHOW(r10);
 90                 SHOW(r11);
 91                 SHOW(r12);
 92                 SHOW(r13);
 93                 SHOW(r14);
 94                 SHOW(r15);
 95 #endif
 96                 nerrs++;
 97         } else {
 98                 printf("[OK]\tAll GPRs except SP are 0\n");
 99         }
100 
101         if (flags != 0x202) {
102                 printf("[FAIL]\tFLAGS is 0x%lx, but it should be 0x202\n", flags);
103                 nerrs++;
104         } else {
105                 printf("[OK]\tFLAGS is 0x202\n");
106         }
107 
108         return nerrs ? 1 : 0;
109 }
110 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp