| 1 |
/** |
| 2 |
* Architecture Detector |
| 3 |
* |
| 4 |
* Copyright (c) 2013 Red Hat <[email protected]> |
| 5 |
* Author: Paul Moore <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* This library is free software; you can redistribute it and/or modify it |
| 10 |
* under the terms of version 2.1 of the GNU Lesser General Public License as |
| 11 |
* published by the Free Software Foundation. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, but WITHOUT |
| 14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 16 |
* for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with this library; if not, see <http://www.gnu.org/licenses>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <errno.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <unistd.h> |
| 26 |
|
| 27 |
#include <seccomp.h> |
| 28 |
|
| 29 |
/** |
| 30 |
* Print the usage information to stderr and exit |
| 31 |
* @param program the name of the current program being invoked |
| 32 |
* |
| 33 |
* Print the usage information and exit with EINVAL. |
| 34 |
* |
| 35 |
*/ |
| 36 |
static void exit_usage(const char *program) |
| 37 |
{ |
| 38 |
fprintf(stderr, |
| 39 |
"usage: %s [-h] [-t]\n", |
| 40 |
program); |
| 41 |
exit(EINVAL); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* main |
| 46 |
*/ |
| 47 |
int main(int argc, char *argv[]) |
| 48 |
{ |
| 49 |
int opt; |
| 50 |
int token = 0; |
| 51 |
uint32_t arch; |
| 52 |
|
| 53 |
/* parse the command line */ |
| 54 |
while ((opt = getopt(argc, argv, "ht")) > 0) { |
| 55 |
switch (opt) { |
| 56 |
case 't': |
| 57 |
token = 1; |
| 58 |
break; |
| 59 |
case 'h': |
| 60 |
default: |
| 61 |
/* usage information */ |
| 62 |
exit_usage(argv[0]); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
arch = seccomp_arch_native(); |
| 67 |
if (token == 0) { |
| 68 |
switch (arch) { |
| 69 |
case SCMP_ARCH_X86: |
| 70 |
printf("x86\n"); |
| 71 |
break; |
| 72 |
case SCMP_ARCH_X86_64: |
| 73 |
printf("x86_64\n"); |
| 74 |
break; |
| 75 |
case SCMP_ARCH_X32: |
| 76 |
printf("x32\n"); |
| 77 |
break; |
| 78 |
case SCMP_ARCH_ARM: |
| 79 |
printf("arm\n"); |
| 80 |
break; |
| 81 |
case SCMP_ARCH_AARCH64: |
| 82 |
printf("aarch64\n"); |
| 83 |
break; |
| 84 |
case SCMP_ARCH_LOONGARCH64: |
| 85 |
printf("loongarch64\n"); |
| 86 |
break; |
| 87 |
case SCMP_ARCH_M68K: |
| 88 |
printf("m68k\n"); |
| 89 |
break; |
| 90 |
case SCMP_ARCH_MIPS: |
| 91 |
printf("mips\n"); |
| 92 |
break; |
| 93 |
case SCMP_ARCH_MIPSEL: |
| 94 |
printf("mipsel\n"); |
| 95 |
break; |
| 96 |
case SCMP_ARCH_MIPS64: |
| 97 |
printf("mips64\n"); |
| 98 |
break; |
| 99 |
case SCMP_ARCH_MIPSEL64: |
| 100 |
printf("mipsel64\n"); |
| 101 |
break; |
| 102 |
case SCMP_ARCH_MIPS64N32: |
| 103 |
printf("mips64n32\n"); |
| 104 |
break; |
| 105 |
case SCMP_ARCH_MIPSEL64N32: |
| 106 |
printf("mipsel64n32\n"); |
| 107 |
break; |
| 108 |
case SCMP_ARCH_PARISC: |
| 109 |
printf("parisc\n"); |
| 110 |
break; |
| 111 |
case SCMP_ARCH_PARISC64: |
| 112 |
printf("parisc64\n"); |
| 113 |
break; |
| 114 |
case SCMP_ARCH_PPC: |
| 115 |
printf("ppc\n"); |
| 116 |
break; |
| 117 |
case SCMP_ARCH_PPC64: |
| 118 |
printf("ppc64\n"); |
| 119 |
break; |
| 120 |
case SCMP_ARCH_PPC64LE: |
| 121 |
printf("ppc64le\n"); |
| 122 |
break; |
| 123 |
case SCMP_ARCH_S390: |
| 124 |
printf("s390\n"); |
| 125 |
break; |
| 126 |
case SCMP_ARCH_S390X: |
| 127 |
printf("s390x\n"); |
| 128 |
break; |
| 129 |
case SCMP_ARCH_RISCV64: |
| 130 |
printf("riscv64\n"); |
| 131 |
break; |
| 132 |
case SCMP_ARCH_SHEB: |
| 133 |
printf("sheb\n"); |
| 134 |
break; |
| 135 |
case SCMP_ARCH_SH: |
| 136 |
printf("sh\n"); |
| 137 |
break; |
| 138 |
default: |
| 139 |
printf("unknown\n"); |
| 140 |
} |
| 141 |
} else |
| 142 |
printf("%d\n", arch); |
| 143 |
|
| 144 |
return 0; |
| 145 |
} |