Commit 24374901004c774e8b932a3526bda6c627942a88
1 parent
e4533c7a
fixed serious ioctl parameter conversion issue - exported type size and align functions
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@239 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
78 additions
and
77 deletions
thunk.c
@@ -29,80 +29,7 @@ | @@ -29,80 +29,7 @@ | ||
29 | #define MAX_STRUCTS 128 | 29 | #define MAX_STRUCTS 128 |
30 | 30 | ||
31 | /* XXX: make it dynamic */ | 31 | /* XXX: make it dynamic */ |
32 | -static StructEntry struct_entries[MAX_STRUCTS]; | ||
33 | - | ||
34 | -static inline int thunk_type_size(const argtype *type_ptr, int is_host) | ||
35 | -{ | ||
36 | - int type, size; | ||
37 | - const StructEntry *se; | ||
38 | - | ||
39 | - type = *type_ptr; | ||
40 | - switch(type) { | ||
41 | - case TYPE_CHAR: | ||
42 | - return 1; | ||
43 | - case TYPE_SHORT: | ||
44 | - return 2; | ||
45 | - case TYPE_INT: | ||
46 | - return 4; | ||
47 | - case TYPE_LONGLONG: | ||
48 | - case TYPE_ULONGLONG: | ||
49 | - return 8; | ||
50 | - case TYPE_LONG: | ||
51 | - case TYPE_ULONG: | ||
52 | - case TYPE_PTRVOID: | ||
53 | - case TYPE_PTR: | ||
54 | - if (is_host) { | ||
55 | - return HOST_LONG_SIZE; | ||
56 | - } else { | ||
57 | - return TARGET_LONG_SIZE; | ||
58 | - } | ||
59 | - break; | ||
60 | - case TYPE_ARRAY: | ||
61 | - size = type_ptr[1]; | ||
62 | - return size * thunk_type_size(type_ptr + 2, is_host); | ||
63 | - case TYPE_STRUCT: | ||
64 | - se = struct_entries + type_ptr[1]; | ||
65 | - return se->size[is_host]; | ||
66 | - default: | ||
67 | - return -1; | ||
68 | - } | ||
69 | -} | ||
70 | - | ||
71 | -static inline int thunk_type_align(const argtype *type_ptr, int is_host) | ||
72 | -{ | ||
73 | - int type; | ||
74 | - const StructEntry *se; | ||
75 | - | ||
76 | - type = *type_ptr; | ||
77 | - switch(type) { | ||
78 | - case TYPE_CHAR: | ||
79 | - return 1; | ||
80 | - case TYPE_SHORT: | ||
81 | - return 2; | ||
82 | - case TYPE_INT: | ||
83 | - return 4; | ||
84 | - case TYPE_LONGLONG: | ||
85 | - case TYPE_ULONGLONG: | ||
86 | - return 8; | ||
87 | - case TYPE_LONG: | ||
88 | - case TYPE_ULONG: | ||
89 | - case TYPE_PTRVOID: | ||
90 | - case TYPE_PTR: | ||
91 | - if (is_host) { | ||
92 | - return HOST_LONG_SIZE; | ||
93 | - } else { | ||
94 | - return TARGET_LONG_SIZE; | ||
95 | - } | ||
96 | - break; | ||
97 | - case TYPE_ARRAY: | ||
98 | - return thunk_type_align(type_ptr + 2, is_host); | ||
99 | - case TYPE_STRUCT: | ||
100 | - se = struct_entries + type_ptr[1]; | ||
101 | - return se->align[is_host]; | ||
102 | - default: | ||
103 | - return -1; | ||
104 | - } | ||
105 | -} | 32 | +StructEntry struct_entries[MAX_STRUCTS]; |
106 | 33 | ||
107 | static inline const argtype *thunk_type_next(const argtype *type_ptr) | 34 | static inline const argtype *thunk_type_next(const argtype *type_ptr) |
108 | { | 35 | { |
@@ -167,6 +94,7 @@ void thunk_register_struct(int id, const char *name, const argtype *types) | @@ -167,6 +94,7 @@ void thunk_register_struct(int id, const char *name, const argtype *types) | ||
167 | offset += size; | 94 | offset += size; |
168 | if (align > max_align) | 95 | if (align > max_align) |
169 | max_align = align; | 96 | max_align = align; |
97 | + type_ptr = thunk_type_next(type_ptr); | ||
170 | } | 98 | } |
171 | offset = (offset + max_align - 1) & ~(max_align - 1); | 99 | offset = (offset + max_align - 1) & ~(max_align - 1); |
172 | se->size[i] = offset; | 100 | se->size[i] = offset; |
thunk.h
@@ -61,15 +61,13 @@ | @@ -61,15 +61,13 @@ | ||
61 | 61 | ||
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | -#ifdef WORDS_BIGENDIAN | 64 | +#if defined(WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
65 | #define BSWAP_NEEDED | 65 | #define BSWAP_NEEDED |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | /* XXX: autoconf */ | 68 | /* XXX: autoconf */ |
69 | -#define TARGET_I386 | ||
70 | #define TARGET_LONG_BITS 32 | 69 | #define TARGET_LONG_BITS 32 |
71 | 70 | ||
72 | - | ||
73 | #if defined(__alpha__) || defined (__ia64__) | 71 | #if defined(__alpha__) || defined (__ia64__) |
74 | #define HOST_LONG_BITS 64 | 72 | #define HOST_LONG_BITS 64 |
75 | #else | 73 | #else |
@@ -239,6 +237,81 @@ void thunk_register_struct_direct(int id, const char *name, StructEntry *se1); | @@ -239,6 +237,81 @@ void thunk_register_struct_direct(int id, const char *name, StructEntry *se1); | ||
239 | const argtype *thunk_convert(void *dst, const void *src, | 237 | const argtype *thunk_convert(void *dst, const void *src, |
240 | const argtype *type_ptr, int to_host); | 238 | const argtype *type_ptr, int to_host); |
241 | 239 | ||
240 | +extern StructEntry struct_entries[]; | ||
241 | + | ||
242 | +static inline int thunk_type_size(const argtype *type_ptr, int is_host) | ||
243 | +{ | ||
244 | + int type, size; | ||
245 | + const StructEntry *se; | ||
246 | + | ||
247 | + type = *type_ptr; | ||
248 | + switch(type) { | ||
249 | + case TYPE_CHAR: | ||
250 | + return 1; | ||
251 | + case TYPE_SHORT: | ||
252 | + return 2; | ||
253 | + case TYPE_INT: | ||
254 | + return 4; | ||
255 | + case TYPE_LONGLONG: | ||
256 | + case TYPE_ULONGLONG: | ||
257 | + return 8; | ||
258 | + case TYPE_LONG: | ||
259 | + case TYPE_ULONG: | ||
260 | + case TYPE_PTRVOID: | ||
261 | + case TYPE_PTR: | ||
262 | + if (is_host) { | ||
263 | + return HOST_LONG_SIZE; | ||
264 | + } else { | ||
265 | + return TARGET_LONG_SIZE; | ||
266 | + } | ||
267 | + break; | ||
268 | + case TYPE_ARRAY: | ||
269 | + size = type_ptr[1]; | ||
270 | + return size * thunk_type_size(type_ptr + 2, is_host); | ||
271 | + case TYPE_STRUCT: | ||
272 | + se = struct_entries + type_ptr[1]; | ||
273 | + return se->size[is_host]; | ||
274 | + default: | ||
275 | + return -1; | ||
276 | + } | ||
277 | +} | ||
278 | + | ||
279 | +static inline int thunk_type_align(const argtype *type_ptr, int is_host) | ||
280 | +{ | ||
281 | + int type; | ||
282 | + const StructEntry *se; | ||
283 | + | ||
284 | + type = *type_ptr; | ||
285 | + switch(type) { | ||
286 | + case TYPE_CHAR: | ||
287 | + return 1; | ||
288 | + case TYPE_SHORT: | ||
289 | + return 2; | ||
290 | + case TYPE_INT: | ||
291 | + return 4; | ||
292 | + case TYPE_LONGLONG: | ||
293 | + case TYPE_ULONGLONG: | ||
294 | + return 8; | ||
295 | + case TYPE_LONG: | ||
296 | + case TYPE_ULONG: | ||
297 | + case TYPE_PTRVOID: | ||
298 | + case TYPE_PTR: | ||
299 | + if (is_host) { | ||
300 | + return HOST_LONG_SIZE; | ||
301 | + } else { | ||
302 | + return TARGET_LONG_SIZE; | ||
303 | + } | ||
304 | + break; | ||
305 | + case TYPE_ARRAY: | ||
306 | + return thunk_type_align(type_ptr + 2, is_host); | ||
307 | + case TYPE_STRUCT: | ||
308 | + se = struct_entries + type_ptr[1]; | ||
309 | + return se->align[is_host]; | ||
310 | + default: | ||
311 | + return -1; | ||
312 | + } | ||
313 | +} | ||
314 | + | ||
242 | unsigned int target_to_host_bitmask(unsigned int x86_mask, | 315 | unsigned int target_to_host_bitmask(unsigned int x86_mask, |
243 | bitmask_transtbl * trans_tbl); | 316 | bitmask_transtbl * trans_tbl); |
244 | unsigned int host_to_target_bitmask(unsigned int alpha_mask, | 317 | unsigned int host_to_target_bitmask(unsigned int alpha_mask, |