Skip to contentSkip to conversation

thunk.c / thunk.h bugfix

RFC New J. Mayer 1 participant 1 message Nov 18, 2007

lore
Share & tools
lore

J. Mayer

author
#0 lore raw

RFC 1/1 thunk.c / thunk.h bugfix

There's a problem in thunk.h as 2 possibly recursive functions are declared as inline. There could be 2 solutions for this. We can never inline those functions and move them to thunk.c (see the attached patch). The drawback is that all cases that do not recurse would be less efficient. The other solution would be to call another intermediary function that would not be inlined to handle the recursive case. The second solution may be better as it would keep the "fast" cases inlined.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized

Index: thunk.c
===================================================================
RCS file: /sources/qemu/qemu/thunk.c,v
retrieving revision 1.10

thunk.c +76 -1
diff -u -d -d -p -r1.10 thunk.c
@@ -31,7 +31,7 @@
 /* XXX: make it dynamic */
 StructEntry struct_entries[MAX_STRUCTS];
 
-static inline const argtype *thunk_type_next(const argtype *type_ptr)
+static const argtype *thunk_type_next(const argtype *type_ptr)
 {
     int type;
 
@@ -267,3 +267,78 @@ unsigned int host_to_target_bitmask(unsi
     }
     return(x86_mask);
 }
+
+#ifndef NO_THUNK_TYPE_SIZE
+int thunk_type_size(const argtype *type_ptr, int is_host)
+{
+    int type, size;
+    const StructEntry *se;
+
+    type = *type_ptr;
+    switch(type) {
+    case TYPE_CHAR:
+        return 1;
+    case TYPE_SHORT:
+        return 2;
+    case TYPE_INT:
+        return 4;
+    case TYPE_LONGLONG:
+    case TYPE_ULONGLONG:
+        return 8;
+    case TYPE_LONG:
+    case TYPE_ULONG:
+    case TYPE_PTRVOID:
+    case TYPE_PTR:
+        if (is_host) {
+            return HOST_LONG_SIZE;
+        } else {
+            return TARGET_ABI_BITS / 8;
+        }
+        break;
+    case TYPE_ARRAY:
+        size = type_ptr[1];
+        return size * thunk_type_size(type_ptr + 2, is_host);
+    case TYPE_STRUCT:
+        se = struct_entries + type_ptr[1];
+        return se->size[is_host];
+    default:
+        return -1;
+    }
+}
+
+int thunk_type_align(const argtype *type_ptr, int is_host)
+{
+    int type;
+    const StructEntry *se;
+
+    type = *type_ptr;
+    switch(type) {
+    case TYPE_CHAR:
+        return 1;
+    case TYPE_SHORT:
+        return 2;
+    case TYPE_INT:
+        return 4;
+    case TYPE_LONGLONG:
+    case TYPE_ULONGLONG:
+        return 8;
+    case TYPE_LONG:
+    case TYPE_ULONG:
+    case TYPE_PTRVOID:
+    case TYPE_PTR:
+        if (is_host) {
+            return HOST_LONG_SIZE;
+        } else {
+            return TARGET_ABI_BITS / 8;
+        }
+        break;
+    case TYPE_ARRAY:
+        return thunk_type_align(type_ptr + 2, is_host);
+    case TYPE_STRUCT:
+        se = struct_entries + type_ptr[1];
+        return se->align[is_host];
+    default:
+        return -1;
+    }
+}
+#endif /* ndef NO_THUNK_TYPE_SIZE */

Index: thunk.h
===================================================================
RCS file: /sources/qemu/qemu/thunk.h,v
retrieving revision 1.15

thunk.h +2 -72

80 lines not on this page · raw message