KVM: nVMX: Fix returned value of MSR_IA32_VMX_VMCS_ENUM
[linux/fpc-iii.git] / arch / x86 / vdso / vdso2c.c
blob7a6bf50f9165fb6afe1a7f00537c081a9aed0024
1 #include <inttypes.h>
2 #include <stdint.h>
3 #include <unistd.h>
4 #include <stdarg.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <fcntl.h>
9 #include <err.h>
11 #include <sys/mman.h>
12 #include <sys/types.h>
14 #include <tools/le_byteshift.h>
16 #include <linux/elf.h>
17 #include <linux/types.h>
19 const char *outfilename;
21 /* Symbols that we need in vdso2c. */
22 enum {
23 sym_vvar_page,
24 sym_hpet_page,
25 sym_end_mapping,
28 const int special_pages[] = {
29 sym_vvar_page,
30 sym_hpet_page,
33 char const * const required_syms[] = {
34 [sym_vvar_page] = "vvar_page",
35 [sym_hpet_page] = "hpet_page",
36 [sym_end_mapping] = "end_mapping",
37 "VDSO32_NOTE_MASK",
38 "VDSO32_SYSENTER_RETURN",
39 "__kernel_vsyscall",
40 "__kernel_sigreturn",
41 "__kernel_rt_sigreturn",
44 __attribute__((format(printf, 1, 2))) __attribute__((noreturn))
45 static void fail(const char *format, ...)
47 va_list ap;
48 va_start(ap, format);
49 fprintf(stderr, "Error: ");
50 vfprintf(stderr, format, ap);
51 unlink(outfilename);
52 exit(1);
53 va_end(ap);
57 * Evil macros for little-endian reads and writes
59 #define GLE(x, bits, ifnot) \
60 __builtin_choose_expr( \
61 (sizeof(*(x)) == bits/8), \
62 (__typeof__(*(x)))get_unaligned_le##bits(x), ifnot)
64 extern void bad_get_le(void);
65 #define LAST_GLE(x) \
66 __builtin_choose_expr(sizeof(*(x)) == 1, *(x), bad_get_le())
68 #define GET_LE(x) \
69 GLE(x, 64, GLE(x, 32, GLE(x, 16, LAST_GLE(x))))
71 #define PLE(x, val, bits, ifnot) \
72 __builtin_choose_expr( \
73 (sizeof(*(x)) == bits/8), \
74 put_unaligned_le##bits((val), (x)), ifnot)
76 extern void bad_put_le(void);
77 #define LAST_PLE(x, val) \
78 __builtin_choose_expr(sizeof(*(x)) == 1, *(x) = (val), bad_put_le())
80 #define PUT_LE(x, val) \
81 PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val))))
84 #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
86 #define BITS 64
87 #define GOFUNC go64
88 #define Elf_Ehdr Elf64_Ehdr
89 #define Elf_Shdr Elf64_Shdr
90 #define Elf_Phdr Elf64_Phdr
91 #define Elf_Sym Elf64_Sym
92 #define Elf_Dyn Elf64_Dyn
93 #include "vdso2c.h"
94 #undef BITS
95 #undef GOFUNC
96 #undef Elf_Ehdr
97 #undef Elf_Shdr
98 #undef Elf_Phdr
99 #undef Elf_Sym
100 #undef Elf_Dyn
102 #define BITS 32
103 #define GOFUNC go32
104 #define Elf_Ehdr Elf32_Ehdr
105 #define Elf_Shdr Elf32_Shdr
106 #define Elf_Phdr Elf32_Phdr
107 #define Elf_Sym Elf32_Sym
108 #define Elf_Dyn Elf32_Dyn
109 #include "vdso2c.h"
110 #undef BITS
111 #undef GOFUNC
112 #undef Elf_Ehdr
113 #undef Elf_Shdr
114 #undef Elf_Phdr
115 #undef Elf_Sym
116 #undef Elf_Dyn
118 static void go(void *addr, size_t len, FILE *outfile, const char *name)
120 Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
122 if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
123 go64(addr, len, outfile, name);
124 } else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
125 go32(addr, len, outfile, name);
126 } else {
127 fail("unknown ELF class\n");
131 int main(int argc, char **argv)
133 int fd;
134 off_t len;
135 void *addr;
136 FILE *outfile;
137 char *name, *tmp;
138 int namelen;
140 if (argc != 3) {
141 printf("Usage: vdso2c INPUT OUTPUT\n");
142 return 1;
146 * Figure out the struct name. If we're writing to a .so file,
147 * generate raw output insted.
149 name = strdup(argv[2]);
150 namelen = strlen(name);
151 if (namelen >= 3 && !strcmp(name + namelen - 3, ".so")) {
152 name = NULL;
153 } else {
154 tmp = strrchr(name, '/');
155 if (tmp)
156 name = tmp + 1;
157 tmp = strchr(name, '.');
158 if (tmp)
159 *tmp = '\0';
160 for (tmp = name; *tmp; tmp++)
161 if (*tmp == '-')
162 *tmp = '_';
165 fd = open(argv[1], O_RDONLY);
166 if (fd == -1)
167 err(1, "%s", argv[1]);
169 len = lseek(fd, 0, SEEK_END);
170 if (len == (off_t)-1)
171 err(1, "lseek");
173 addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
174 if (addr == MAP_FAILED)
175 err(1, "mmap");
177 outfilename = argv[2];
178 outfile = fopen(outfilename, "w");
179 if (!outfile)
180 err(1, "%s", argv[2]);
182 go(addr, (size_t)len, outfile, name);
184 munmap(addr, len);
185 fclose(outfile);
187 return 0;