Skip to contentSkip to conversation

target_posix_types.h

PATCH In review Thayne Harbaugh 6 participants 20 messages Nov 14, 2007 – Nov 16, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target_posix_types.h

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

linux-user/alpha/target_posix_types.h new file +55 -0
Index: qemu/linux-user/alpha/target_posix_types.h
===================================================================
@@ -0,0 +1,55 @@
+/*
+ * Borrowed with minor changes from:
+ *  linux/include/asm-alpha/posix_types.h
+ */
+
+#ifndef TARGET_POSIX_TYPES_H
+#define TARGET_POSIX_TYPES_H
+
+typedef int8_t			target_char;
+typedef int16_t			target_short;
+typedef int32_t			target_int;
+/* target_long defined in qemu/cpu-defs.h */
+typedef int64_t			target_long_long;
+
+typedef uint8_t			target_uchar;
+typedef uint16_t		target_ushort;
+typedef uint32_t		target_uint;
+/* target_ulong defined in qemu/cpu-defs.h */
+typedef uint64_t		target_ulong_long;
+
+typedef target_uint		target_ino_t;
+typedef target_uint		target_mode_t;
+typedef target_uint		target_nlink_t;
+typedef abi_long		target_off_t;
+typedef target_long_long	target_loff_t;
+typedef target_int		target_pid_t;
+typedef target_int		target_ipc_pid_t;
+typedef target_uint		target_uid_t;
+typedef target_uint		target_gid_t;
+typedef abi_ulong		target_size_t;
+typedef abi_long		target_ssize_t;
+typedef abi_long		target_ptrdiff_t;
+typedef abi_long		target_time_t;
+typedef abi_long		target_suseconds_t;
+typedef abi_long		target_clock_t;
+typedef target_int		target_daddr_t;
+typedef target_char *		target_caddr_t;
+/* typedef unsigned long	target_sigset_t; (conflicts in syscall_defs.h) */
+typedef target_ushort		target_uid16_t;
+typedef target_ushort		target_gid16_t;
+typedef target_int		target_clockid_t;
+typedef target_int		target_timer_t;
+
+typedef struct {
+	target_int	val[2];
+} target_fsid_t;
+
+typedef target_uid_t		target_old_uid_t;
+typedef target_gid_t		target_old_gid_t;
+typedef target_uid_t		target_uid32_t;
+typedef target_gid_t		target_gid32_t;
+
+typedef target_uint		target_old_dev_t;
+
+#endif /* TARGET_POSIX_TYPES_H */
linux-user/arm/target_posix_types.h new file +62 -0

62 lines not on this page · raw message

linux-user/i386/target_posix_types.h new file +55 -0

55 lines not on this page · raw message

linux-user/m68k/target_posix_types.h new file +54 -0

54 lines not on this page · raw message

linux-user/mips/target_posix_types.h new file +79 -0

79 lines not on this page · raw message

linux-user/ppc/target_posix_types.h new file +57 -0

57 lines not on this page · raw message

linux-user/sh4/target_posix_types.h new file +56 -0

56 lines not on this page · raw message

linux-user/sparc/target_posix_types.h new file +56 -0

56 lines not on this page · raw message

linux-user/sparc64/target_posix_types.h new file +58 -0

58 lines not on this page · raw message

linux-user/x86_64/target_posix_types.h new file +57 -0

57 lines not on this page · raw message

linux-user/syscall_defs.h +8 -11
Index: qemu/linux-user/syscall_defs.h
===================================================================
@@ -5,6 +5,7 @@
    necessary */
 
 #include "syscall_nr.h"
+#include "target_posix_types.h"
 
 #define SOCKOP_socket           1
 #define SOCKOP_bind             2
@@ -104,13 +105,15 @@
     uint8_t sa_data[14];
 };
 
+typedef uint32_t target_socklen_t;
+
 struct target_timeval {
-    abi_long tv_sec;
-    abi_long tv_usec;
+    target_time_t tv_sec;
+    target_suseconds_t tv_usec;
 };
 
 struct target_timespec {
-    abi_long tv_sec;
+    target_time_t tv_sec;
     abi_long tv_nsec;
 };
 
@@ -119,8 +122,6 @@
     struct target_timeval it_value;
 };
 
-typedef abi_long target_clock_t;
-
 #define TARGET_HZ 100
 
 struct target_tms {
@@ -131,8 +132,8 @@
 };
 
 struct target_utimbuf {
-    abi_long actime;
-    abi_long modtime;
+    target_time_t actime;
+    target_time_t modtime;
 };
 
 struct target_sel_arg_struct {
@@ -1481,10 +1482,6 @@
 #error unsupported CPU
 #endif
 
-typedef struct {
-        int     val[2];
-} target_fsid_t;
-
 #ifdef TARGET_MIPS
 #ifdef TARGET_MIPSN32
 struct target_statfs {
linux-user/ppc64/target_posix_types.h new file +56 -0

56 lines not on this page · raw message

linux-user/cris/target_posix_types.h new file +59 -0

59 lines not on this page · raw message

#1 lore raw

[Qemu-devel] Re: [PATCH] tget/tput deprecation

This patch deprecates tget/tput and replaces them with get_user() and put_user() which perform proper locking. It also checks return codes (in most places) and fails with EFAULT where appropriate.

linux-user/elfload.c +11 -14
Index: qemu/linux-user/elfload.c
===================================================================
@@ -179,8 +179,9 @@
       regs->ARM_cpsr |= CPSR_T;
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
-    regs->ARM_r2 = tgetl(stack + 8); /* envp */
-    regs->ARM_r1 = tgetl(stack + 4); /* envp */
+    /* FIXME - what to for failure of get_user()? */
+    get_user(regs->ARM_r2, stack + 8, abi_long); /* envp */
+    get_user(regs->ARM_r1, stack + 4, abi_long); /* envp */
     /* XXX: it seems that r0 is zeroed after ! */
     regs->ARM_r0 = 0;
     /* For uClinux PIC binaries.  */
@@ -341,7 +342,8 @@
      * but this is what the ABI wants and is needed to allow
      * execution of PPC BSD programs.
      */
-    _regs->gpr[3] = tgetl(pos);
+    /* FIXME - what to for failure of get_user()? */
+    get_user(_regs->gpr[3], pos, abi_long);
     pos += sizeof(abi_ulong);
     _regs->gpr[4] = pos;
     for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
@@ -733,7 +735,8 @@
         if (nbyte) {
 	    nbyte = qemu_host_page_size - nbyte;
 	    do {
-		tput8(elf_bss, 0);
+                /* FIXME - what to do if put_user() fails? */
+		put_user(0, elf_bss, uint8_t);
                 elf_bss++;
 	    } while (--nbyte);
         }
@@ -782,17 +785,11 @@
         /* This is correct because Linux defines
          * elf_addr_t as Elf32_Off / Elf64_Off
          */
-#if ELF_CLASS == ELFCLASS32
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput32(sp, val); \
-            sp -= n; tput32(sp, id); \
+#define NEW_AUX_ENT(id, val) do {			\
+            sp -= n; put_user(val, sp, abi_ulong);	\
+            sp -= n; put_user(id, sp, abi_ulong);	\
           } while(0)
-#else
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput64(sp, val); \
-            sp -= n; tput64(sp, id); \
-          } while(0)
-#endif
+
         NEW_AUX_ENT (AT_NULL, 0);
 
         /* There must be exactly DLINFO_ITEMS entries here.  */
linux-user/flatload.c +22 -10
Index: qemu/linux-user/flatload.c
===================================================================
@@ -598,14 +598,16 @@
         rp = datapos;
         while (1) {
             abi_ulong addr;
-            addr = tgetl(rp);
+            if (get_user(addr, rp, abi_ulong))
+                return -EFAULT;
             if (addr == -1)
                 break;
             if (addr) {
                 addr = calc_reloc(addr, libinfo, id, 0);
                 if (addr == RELOC_FAILED)
                     return -ENOEXEC;
-                tputl(rp, addr);
+                if (put_user(addr, rp, abi_ulong))
+                    return -EFAULT;
             }
             rp += sizeof(abi_ulong);
         }
@@ -629,14 +631,16 @@
             /* Get the address of the pointer to be
                relocated (of course, the address has to be
                relocated first).  */
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user(relval, reloc + i * sizeof(abi_ulong), abi_ulong))
+                return -EFAULT;
             addr = flat_get_relocate_addr(relval);
             rp = calc_reloc(addr, libinfo, id, 1);
             if (rp == RELOC_FAILED)
                 return -ENOEXEC;
 
             /* Get the pointer's value.  */
-            addr = tgetl(rp);
+            if (get_user(addr, rp, abi_ulong))
+                return -EFAULT;
             if (addr != 0) {
                 /*
                  * Do the relocation.  PIC relocs in the data section are
@@ -652,13 +656,15 @@
                     return -ENOEXEC;
 
                 /* Write back the relocated pointer.  */
-                tputl(rp, addr);
+                if (put_user(addr, rp, abi_ulong))
+                    return -EFAULT;
             }
         }
     } else {
         for (i = 0; i < relocs; i++) {
             abi_ulong relval;
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user(relval, reloc + i * sizeof(abi_ulong), abi_ulong))
+                return -EFAULT;
             old_reloc(&libinfo[0], relval);
         }
     }
@@ -744,9 +750,13 @@
             p = libinfo[i].start_data;
             for (j=0; j<MAX_SHARED_LIBS; j++) {
                 p -= 4;
-                tput32(p, libinfo[j].loaded
-                          ? libinfo[j].start_data
-                          : UNLOADED_LIB);
+                /* FIXME - handle put_user() failures */
+                if (put_user(libinfo[j].loaded
+                             ? libinfo[j].start_data
+                             : UNLOADED_LIB,
+                             p,
+                             abi_ulong))
+                    return -EFAULT;
             }
         }
     }
@@ -779,7 +789,9 @@
     for (i = MAX_SHARED_LIBS-1; i>0; i--) {
             if (libinfo[i].loaded) {
                     /* Push previos first to call address */
-                    --sp;	put_user(start_addr, sp);
+                    --sp;
+                    if (put_user(start_addr, sp, abi_ulong))
+                        return -EFAULT;
                     start_addr = libinfo[i].entry;
             }
     }
linux-user/main.c +19 -11
Index: qemu/linux-user/main.c
===================================================================
@@ -342,7 +342,8 @@
 
                 /* we handle the FPU emulation here, as Linux */
                 /* we get the opcode */
-                opcode = tget32(env->regs[15]);
+                /* FIXME - what to do if get_user() fails? */
+                get_user(opcode, env->regs[15], uint32_t);
 
                 if (EmulateAll(opcode, &ts->fpa, env) == 0) {
                     info.si_signo = SIGILL;
@@ -363,20 +364,24 @@
                 /* system call */
                 if (trapnr == EXCP_BKPT) {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15], uint16_t);
                         n = insn & 0xff;
                         env->regs[15] += 2;
                     } else {
-                        insn = tget32(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15], uint32_t);
                         n = (insn & 0xf) | ((insn >> 4) & 0xff0);
                         env->regs[15] += 4;
                     }
                 } else {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15] - 2);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15] - 2, uint16_t);
                         n = insn & 0xff;
                     } else {
-                        insn = tget32(env->regs[15] - 4);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15] - 4, uint32_t);
                         n = insn & 0xffffff;
                     }
                 }
@@ -482,7 +487,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        tputl(sp_ptr, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
+        /* FIXME - what to do if put_user() fails? */
+        put_user(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr, abi_ulong);
         sp_ptr += sizeof(abi_ulong);
     }
 }
@@ -518,7 +524,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        env->regbase[get_reg_index(env, cwp1, 8 + i)] = tgetl(sp_ptr);
+        /* FIXME - what to do if get_user() fails? */
+        get_user(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr, abi_ulong);
         sp_ptr += sizeof(abi_ulong);
     }
     env->wim = new_wim;
@@ -1495,10 +1502,11 @@
                 sp_reg = env->gpr[29][env->current_tc];
                 switch (nb_args) {
                 /* these arguments are taken from the stack */
-                case 8: arg8 = tgetl(sp_reg + 28);
-                case 7: arg7 = tgetl(sp_reg + 24);
-                case 6: arg6 = tgetl(sp_reg + 20);
-                case 5: arg5 = tgetl(sp_reg + 16);
+                /* FIXME - what to do if get_user() fails? */
+                case 8: get_user(arg8, sp_reg + 28, abi_ulong);
+                case 7: get_user(arg7, sp_reg + 24, abi_ulong);
+                case 6: get_user(arg6, sp_reg + 20, abi_ulong);
+                case 5: get_user(arg5, sp_reg + 16, abi_ulong);
                 default:
                     break;
                 }
linux-user/qemu.h +7 -18
Index: qemu/linux-user/qemu.h
===================================================================
@@ -217,7 +217,7 @@
     int size = sizeof(*hptr);\
     switch(size) {\
     case 1:\
-        *(uint8_t *)(hptr) = (typeof(*hptr))(x);\
+        *(uint8_t *)(hptr) = (uint8_t)(typeof(*hptr))(x);\
         break;\
     case 2:\
         *(uint16_t *)(hptr) = tswap16((typeof(*hptr))(x));\
@@ -251,6 +251,8 @@
         x = (typeof(*hptr))tswap64(*(uint64_t *)(hptr));\
         break;\
     default:\
+        /* avoid warning */\
+        x = 0;\
         abort();\
     }\
     0;\
@@ -282,8 +284,11 @@
     if ((__hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1))) { \
         __ret = __get_user((x), __hptr);				\
         unlock_user(__hptr, __gaddr, 0);				\
-    } else								\
+    } else {								\
+        /* avoid warning */						\
+        (x) = 0;							\
         __ret = -TARGET_EFAULT;						\
+    }									\
     __ret;								\
 })
 
@@ -354,20 +359,4 @@
 #define unlock_user_struct(host_ptr, guest_addr, copy)		\
     unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
 
-#define tget8(addr) ldub(addr)
-#define tput8(addr, val) stb(addr, val)
-#define tget16(addr) lduw(addr)
-#define tput16(addr, val) stw(addr, val)
-#define tget32(addr) ldl(addr)
-#define tput32(addr, val) stl(addr, val)
-#define tget64(addr) ldq(addr)
-#define tput64(addr, val) stq(addr, val)
-#if TARGET_ABI_BITS == 64
-#define tgetl(addr) ldq(addr)
-#define tputl(addr, val) stq(addr, val)
-#else
-#define tgetl(addr) ldl(addr)
-#define tputl(addr, val) stl(addr, val)
-#endif
-
 #endif /* QEMU_H */
linux-user/syscall.c +297 -143

748 lines not on this page · raw message

arm-semi.c +13 -3
Index: qemu/arm-semi.c
===================================================================
@@ -165,8 +165,14 @@
 #endif
 }
 
-#define ARG(n) tget32(args + (n) * 4)
-#define SET_ARG(n, val) tput32(args + (n) * 4,val)
+#define ARG(n)						\
+({							\
+    abi_ulong __arg_addr;				\
+    /* FIXME - handle get_user() failure */		\
+    get_user(__arg_addr, args + (n) * 4, abi_ulong);	\
+    __arg_addr;						\
+})
+#define SET_ARG(n, val) put_user(val, args + (n) * 4, abi_ulong)
 uint32_t do_arm_semihosting(CPUState *env)
 {
     target_ulong args;
@@ -213,7 +219,11 @@
         }
     case SYS_WRITEC:
         {
-          char c = tget8(args);
+          char c;
+
+          if (get_user(c, args, target_char))
+              /* FIXME - should this error code be -TARGET_EFAULT ? */
+              return (uint32_t)-1;
           /* Write to debug console.  stderr is near enough.  */
           if (use_gdb_syscalls()) {
                 gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
target-arm/nwfpe/fpa11_cpdt.c +37 -27

132 lines not on this page · raw message

linux-user/linuxload.c +19 -8
Index: qemu/linux-user/linuxload.c
===================================================================
@@ -126,21 +126,32 @@
     sp -= (argc + 1) * n;
     argv = sp;
     if (push_ptr) {
-        sp -= n; tputl(sp, envp);
-        sp -= n; tputl(sp, argv);
-    }
-    sp -= n; tputl(sp, argc);
+        /* FIXME - handle put_user() failures */
+        sp -= n;
+        put_user(envp, sp, abi_ulong);
+        sp -= n;
+        put_user(argv, sp, abi_ulong);
+    }
+    sp -= n;
+    /* FIXME - handle put_user() failures */
+    put_user(argc, sp, abi_ulong);
 
     while (argc-- > 0) {
-        tputl(argv, stringp); argv += n;
+        /* FIXME - handle put_user() failures */
+        put_user(stringp, argv, abi_ulong);
+        argv += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(argv, 0);
+    /* FIXME - handle put_user() failures */
+    put_user(0, argv, abi_ulong);
     while (envc-- > 0) {
-        tputl(envp, stringp); envp += n;
+        /* FIXME - handle put_user() failures */
+        put_user(stringp, envp, abi_ulong);
+        envp += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(envp, 0);
+    /* FIXME - handle put_user() failures */
+    put_user(0, envp, abi_ulong);
 
     return sp;
 }
#2 lore raw

Re: [Qemu-devel] Re: [PATCH] tget/tput deprecation

I didn't mention that this patch depends on the previous 44_target_posix_types.patch.

Quoted 3 lines · Thayne Harbaugh

This patch deprecates tget/tput and replaces them with get_user() and put_user() which perform proper locking. It also checks return codes (in most places) and fails with EFAULT where appropriate.

#3 lore raw

Re: [Qemu-devel] Re: [PATCH] tget/tput deprecation

In reply to Thayne Harbaugh
Quoted 3 lines · Thayne Harbaugh

This patch deprecates tget/tput and replaces them with get_user() and put_user() which perform proper locking. It also checks return codes (in most places) and fails with EFAULT where appropriate.

I just noticed that I missed m68k-semi.c. New patch is forthcoming.

#4 lore raw

Re: [Qemu-devel] Re: [PATCH] tget/tput deprecation

Quoted 6 lines · Thayne Harbaugh
Quoted 3 lines · Thayne Harbaugh

This patch deprecates tget/tput and replaces them with get_user() and put_user() which perform proper locking. It also checks return codes (in most places) and fails with EFAULT where appropriate.

I just noticed that I missed m68k-semi.c. New patch is forthcoming.

Updated patch.

linux-user/elfload.c +11 -14
Index: qemu/linux-user/elfload.c
===================================================================
@@ -179,8 +179,9 @@
       regs->ARM_cpsr |= CPSR_T;
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
-    regs->ARM_r2 = tgetl(stack + 8); /* envp */
-    regs->ARM_r1 = tgetl(stack + 4); /* envp */
+    /* FIXME - what to for failure of get_user()? */
+    get_user(regs->ARM_r2, stack + 8, abi_long); /* envp */
+    get_user(regs->ARM_r1, stack + 4, abi_long); /* envp */
     /* XXX: it seems that r0 is zeroed after ! */
     regs->ARM_r0 = 0;
     /* For uClinux PIC binaries.  */
@@ -341,7 +342,8 @@
      * but this is what the ABI wants and is needed to allow
      * execution of PPC BSD programs.
      */
-    _regs->gpr[3] = tgetl(pos);
+    /* FIXME - what to for failure of get_user()? */
+    get_user(_regs->gpr[3], pos, abi_long);
     pos += sizeof(abi_ulong);
     _regs->gpr[4] = pos;
     for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
@@ -733,7 +735,8 @@
         if (nbyte) {
 	    nbyte = qemu_host_page_size - nbyte;
 	    do {
-		tput8(elf_bss, 0);
+                /* FIXME - what to do if put_user() fails? */
+		put_user(0, elf_bss, uint8_t);
                 elf_bss++;
 	    } while (--nbyte);
         }
@@ -782,17 +785,11 @@
         /* This is correct because Linux defines
          * elf_addr_t as Elf32_Off / Elf64_Off
          */
-#if ELF_CLASS == ELFCLASS32
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput32(sp, val); \
-            sp -= n; tput32(sp, id); \
+#define NEW_AUX_ENT(id, val) do {			\
+            sp -= n; put_user(val, sp, abi_ulong);	\
+            sp -= n; put_user(id, sp, abi_ulong);	\
           } while(0)
-#else
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput64(sp, val); \
-            sp -= n; tput64(sp, id); \
-          } while(0)
-#endif
+
         NEW_AUX_ENT (AT_NULL, 0);
 
         /* There must be exactly DLINFO_ITEMS entries here.  */
linux-user/flatload.c +22 -10
Index: qemu/linux-user/flatload.c
===================================================================
@@ -598,14 +598,16 @@
         rp = datapos;
         while (1) {
             abi_ulong addr;
-            addr = tgetl(rp);
+            if (get_user(addr, rp, abi_ulong))
+                return -EFAULT;
             if (addr == -1)
                 break;
             if (addr) {
                 addr = calc_reloc(addr, libinfo, id, 0);
                 if (addr == RELOC_FAILED)
                     return -ENOEXEC;
-                tputl(rp, addr);
+                if (put_user(addr, rp, abi_ulong))
+                    return -EFAULT;
             }
             rp += sizeof(abi_ulong);
         }
@@ -629,14 +631,16 @@
             /* Get the address of the pointer to be
                relocated (of course, the address has to be
                relocated first).  */
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user(relval, reloc + i * sizeof(abi_ulong), abi_ulong))
+                return -EFAULT;
             addr = flat_get_relocate_addr(relval);
             rp = calc_reloc(addr, libinfo, id, 1);
             if (rp == RELOC_FAILED)
                 return -ENOEXEC;
 
             /* Get the pointer's value.  */
-            addr = tgetl(rp);
+            if (get_user(addr, rp, abi_ulong))
+                return -EFAULT;
             if (addr != 0) {
                 /*
                  * Do the relocation.  PIC relocs in the data section are
@@ -652,13 +656,15 @@
                     return -ENOEXEC;
 
                 /* Write back the relocated pointer.  */
-                tputl(rp, addr);
+                if (put_user(addr, rp, abi_ulong))
+                    return -EFAULT;
             }
         }
     } else {
         for (i = 0; i < relocs; i++) {
             abi_ulong relval;
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user(relval, reloc + i * sizeof(abi_ulong), abi_ulong))
+                return -EFAULT;
             old_reloc(&libinfo[0], relval);
         }
     }
@@ -744,9 +750,13 @@
             p = libinfo[i].start_data;
             for (j=0; j<MAX_SHARED_LIBS; j++) {
                 p -= 4;
-                tput32(p, libinfo[j].loaded
-                          ? libinfo[j].start_data
-                          : UNLOADED_LIB);
+                /* FIXME - handle put_user() failures */
+                if (put_user(libinfo[j].loaded
+                             ? libinfo[j].start_data
+                             : UNLOADED_LIB,
+                             p,
+                             abi_ulong))
+                    return -EFAULT;
             }
         }
     }
@@ -779,7 +789,9 @@
     for (i = MAX_SHARED_LIBS-1; i>0; i--) {
             if (libinfo[i].loaded) {
                     /* Push previos first to call address */
-                    --sp;	put_user(start_addr, sp);
+                    --sp;
+                    if (put_user(start_addr, sp, abi_ulong))
+                        return -EFAULT;
                     start_addr = libinfo[i].entry;
             }
     }
linux-user/main.c +19 -11
Index: qemu/linux-user/main.c
===================================================================
@@ -342,7 +342,8 @@
 
                 /* we handle the FPU emulation here, as Linux */
                 /* we get the opcode */
-                opcode = tget32(env->regs[15]);
+                /* FIXME - what to do if get_user() fails? */
+                get_user(opcode, env->regs[15], uint32_t);
 
                 if (EmulateAll(opcode, &ts->fpa, env) == 0) {
                     info.si_signo = SIGILL;
@@ -363,20 +364,24 @@
                 /* system call */
                 if (trapnr == EXCP_BKPT) {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15], uint16_t);
                         n = insn & 0xff;
                         env->regs[15] += 2;
                     } else {
-                        insn = tget32(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15], uint32_t);
                         n = (insn & 0xf) | ((insn >> 4) & 0xff0);
                         env->regs[15] += 4;
                     }
                 } else {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15] - 2);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15] - 2, uint16_t);
                         n = insn & 0xff;
                     } else {
-                        insn = tget32(env->regs[15] - 4);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user(insn, env->regs[15] - 4, uint32_t);
                         n = insn & 0xffffff;
                     }
                 }
@@ -482,7 +487,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        tputl(sp_ptr, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
+        /* FIXME - what to do if put_user() fails? */
+        put_user(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr, abi_ulong);
         sp_ptr += sizeof(abi_ulong);
     }
 }
@@ -518,7 +524,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        env->regbase[get_reg_index(env, cwp1, 8 + i)] = tgetl(sp_ptr);
+        /* FIXME - what to do if get_user() fails? */
+        get_user(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr, abi_ulong);
         sp_ptr += sizeof(abi_ulong);
     }
     env->wim = new_wim;
@@ -1495,10 +1502,11 @@
                 sp_reg = env->gpr[29][env->current_tc];
                 switch (nb_args) {
                 /* these arguments are taken from the stack */
-                case 8: arg8 = tgetl(sp_reg + 28);
-                case 7: arg7 = tgetl(sp_reg + 24);
-                case 6: arg6 = tgetl(sp_reg + 20);
-                case 5: arg5 = tgetl(sp_reg + 16);
+                /* FIXME - what to do if get_user() fails? */
+                case 8: get_user(arg8, sp_reg + 28, abi_ulong);
+                case 7: get_user(arg7, sp_reg + 24, abi_ulong);
+                case 6: get_user(arg6, sp_reg + 20, abi_ulong);
+                case 5: get_user(arg5, sp_reg + 16, abi_ulong);
                 default:
                     break;
                 }
linux-user/qemu.h +7 -18
Index: qemu/linux-user/qemu.h
===================================================================
@@ -217,7 +217,7 @@
     int size = sizeof(*hptr);\
     switch(size) {\
     case 1:\
-        *(uint8_t *)(hptr) = (typeof(*hptr))(x);\
+        *(uint8_t *)(hptr) = (uint8_t)(typeof(*hptr))(x);\
         break;\
     case 2:\
         *(uint16_t *)(hptr) = tswap16((typeof(*hptr))(x));\
@@ -251,6 +251,8 @@
         x = (typeof(*hptr))tswap64(*(uint64_t *)(hptr));\
         break;\
     default:\
+        /* avoid warning */\
+        x = 0;\
         abort();\
     }\
     0;\
@@ -282,8 +284,11 @@
     if ((__hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1))) { \
         __ret = __get_user((x), __hptr);				\
         unlock_user(__hptr, __gaddr, 0);				\
-    } else								\
+    } else {								\
+        /* avoid warning */						\
+        (x) = 0;							\
         __ret = -TARGET_EFAULT;						\
+    }									\
     __ret;								\
 })
 
@@ -354,20 +359,4 @@
 #define unlock_user_struct(host_ptr, guest_addr, copy)		\
     unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
 
-#define tget8(addr) ldub(addr)
-#define tput8(addr, val) stb(addr, val)
-#define tget16(addr) lduw(addr)
-#define tput16(addr, val) stw(addr, val)
-#define tget32(addr) ldl(addr)
-#define tput32(addr, val) stl(addr, val)
-#define tget64(addr) ldq(addr)
-#define tput64(addr, val) stq(addr, val)
-#if TARGET_ABI_BITS == 64
-#define tgetl(addr) ldq(addr)
-#define tputl(addr, val) stq(addr, val)
-#else
-#define tgetl(addr) ldl(addr)
-#define tputl(addr, val) stl(addr, val)
-#endif
-
 #endif /* QEMU_H */
linux-user/syscall.c +297 -143

748 lines not on this page · raw message

arm-semi.c +13 -3
Index: qemu/arm-semi.c
===================================================================
@@ -165,8 +165,14 @@
 #endif
 }
 
-#define ARG(n) tget32(args + (n) * 4)
-#define SET_ARG(n, val) tput32(args + (n) * 4,val)
+#define ARG(n)					\
+({						\
+    abi_ulong __arg;				\
+    /* FIXME - handle get_user() failure */	\
+    get_user(__arg, args + (n) * 4, abi_ulong);	\
+    __arg;					\
+})
+#define SET_ARG(n, val) put_user(val, args + (n) * 4, abi_ulong)
 uint32_t do_arm_semihosting(CPUState *env)
 {
     target_ulong args;
@@ -213,7 +219,11 @@
         }
     case SYS_WRITEC:
         {
-          char c = tget8(args);
+          char c;
+
+          if (get_user(c, args, target_char))
+              /* FIXME - should this error code be -TARGET_EFAULT ? */
+              return (uint32_t)-1;
           /* Write to debug console.  stderr is near enough.  */
           if (use_gdb_syscalls()) {
                 gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
target-arm/nwfpe/fpa11_cpdt.c +37 -27

132 lines not on this page · raw message

linux-user/linuxload.c +19 -8
Index: qemu/linux-user/linuxload.c
===================================================================
@@ -126,21 +126,32 @@
     sp -= (argc + 1) * n;
     argv = sp;
     if (push_ptr) {
-        sp -= n; tputl(sp, envp);
-        sp -= n; tputl(sp, argv);
-    }
-    sp -= n; tputl(sp, argc);
+        /* FIXME - handle put_user() failures */
+        sp -= n;
+        put_user(envp, sp, abi_ulong);
+        sp -= n;
+        put_user(argv, sp, abi_ulong);
+    }
+    sp -= n;
+    /* FIXME - handle put_user() failures */
+    put_user(argc, sp, abi_ulong);
 
     while (argc-- > 0) {
-        tputl(argv, stringp); argv += n;
+        /* FIXME - handle put_user() failures */
+        put_user(stringp, argv, abi_ulong);
+        argv += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(argv, 0);
+    /* FIXME - handle put_user() failures */
+    put_user(0, argv, abi_ulong);
     while (envc-- > 0) {
-        tputl(envp, stringp); envp += n;
+        /* FIXME - handle put_user() failures */
+        put_user(stringp, envp, abi_ulong);
+        envp += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(envp, 0);
+    /* FIXME - handle put_user() failures */
+    put_user(0, envp, abi_ulong);
 
     return sp;
 }
m68k-semi.c +19 -9
Index: qemu/m68k-semi.c
===================================================================
@@ -142,15 +142,23 @@
     if (m68k_semi_is_fseek) {
         /* FIXME: We've already lost the high bits of the fseek
            return value.  */
-        tput32(args, 0);
+        /* FIXME - handle get_user() failure */
+        put_user(0, args, uint32_t);
         args += 4;
         m68k_semi_is_fseek = 0;
     }
-    tput32(args, ret);
-    tput32(args + 4, errno);
+    /* FIXME - handle get_user() failure */
+    put_user(ret, args, uint32_t);
+    put_user(errno, args + 4, uint32_t);
 }
 
-#define ARG(x) tget32(args + (x) * 4)
+#define ARG(n)					\
+({						\
+    abi_ulong __arg;				\
+    /* FIXME - handle get_user() failure */	\
+    get_user(__arg, args + (n) * 4, abi_ulong);	\
+    __arg;					\
+})
 #define PARG(x) ((unsigned long)ARG(x))
 void do_m68k_semihosting(CPUM68KState *env, int nr)
 {
@@ -234,9 +245,10 @@
                                ARG(0), off, ARG(3));
             } else {
                 off = lseek(ARG(0), off, ARG(3));
-                tput32(args, off >> 32);
-                tput32(args + 4, off);
-                tput32(args + 8, errno);
+                /* FIXME - handle get_user() failure */
+                put_user(off >> 32, args, uint32_t);
+                put_user(off, args + 4, uint32_t);
+                put_user(errno, args + 8, uint32_t);
             }
             return;
         }
@@ -382,6 +399,7 @@
         cpu_abort(env, "Unsupported semihosting syscall %d\n", nr);
         result = 0;
     }
-    tput32(args, result);
-    tput32(args + 4, errno);
+    /* FIXME - handle get_user() failure */
+    put_user(result, args, uint32_t);
+    put_user(errno, args + 4, uint32_t);
 }
#5 lore raw

Re: [Qemu-devel] Re: [PATCH] tget/tput deprecation

In reply to Thayne Harbaugh
Quoted 3 lines · Thayne Harbaugh

This patch deprecates tget/tput and replaces them with get_user() and put_user() which perform proper locking. It also checks return codes (in most places) and fails with EFAULT where appropriate.

This version doesn't depend on 44_target_posix_types.patch.

linux-user/elfload.c +11 -14
Index: qemu/linux-user/elfload.c
===================================================================
@@ -179,8 +179,9 @@
       regs->ARM_cpsr |= CPSR_T;
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
-    regs->ARM_r2 = tgetl(stack + 8); /* envp */
-    regs->ARM_r1 = tgetl(stack + 4); /* envp */
+    /* FIXME - what to for failure of get_user()? */
+    get_user_ual(regs->ARM_r2, stack + 8); /* envp */
+    get_user_ual(regs->ARM_r1, stack + 4); /* envp */
     /* XXX: it seems that r0 is zeroed after ! */
     regs->ARM_r0 = 0;
     /* For uClinux PIC binaries.  */
@@ -341,7 +342,8 @@
      * but this is what the ABI wants and is needed to allow
      * execution of PPC BSD programs.
      */
-    _regs->gpr[3] = tgetl(pos);
+    /* FIXME - what to for failure of get_user()? */
+    get_user_ual(_regs->gpr[3], pos);
     pos += sizeof(abi_ulong);
     _regs->gpr[4] = pos;
     for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
@@ -733,7 +735,8 @@
         if (nbyte) {
 	    nbyte = qemu_host_page_size - nbyte;
 	    do {
-		tput8(elf_bss, 0);
+                /* FIXME - what to do if put_user() fails? */
+		put_user_u8(0, elf_bss);
                 elf_bss++;
 	    } while (--nbyte);
         }
@@ -782,17 +785,11 @@
         /* This is correct because Linux defines
          * elf_addr_t as Elf32_Off / Elf64_Off
          */
-#if ELF_CLASS == ELFCLASS32
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput32(sp, val); \
-            sp -= n; tput32(sp, id); \
+#define NEW_AUX_ENT(id, val) do {		\
+            sp -= n; put_user_ual(val, sp);	\
+            sp -= n; put_user_ual(id, sp);	\
           } while(0)
-#else
-#define NEW_AUX_ENT(id, val) do { \
-            sp -= n; tput64(sp, val); \
-            sp -= n; tput64(sp, id); \
-          } while(0)
-#endif
+
         NEW_AUX_ENT (AT_NULL, 0);
 
         /* There must be exactly DLINFO_ITEMS entries here.  */
linux-user/flatload.c +21 -10
Index: qemu/linux-user/flatload.c
===================================================================
@@ -598,14 +598,16 @@
         rp = datapos;
         while (1) {
             abi_ulong addr;
-            addr = tgetl(rp);
+            if (get_user_ual(addr, rp))
+                return -EFAULT;
             if (addr == -1)
                 break;
             if (addr) {
                 addr = calc_reloc(addr, libinfo, id, 0);
                 if (addr == RELOC_FAILED)
                     return -ENOEXEC;
-                tputl(rp, addr);
+                if (put_user_ual(addr, rp))
+                    return -EFAULT;
             }
             rp += sizeof(abi_ulong);
         }
@@ -629,14 +631,16 @@
             /* Get the address of the pointer to be
                relocated (of course, the address has to be
                relocated first).  */
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user_ual(relval, reloc + i * sizeof(abi_ulong)))
+                return -EFAULT;
             addr = flat_get_relocate_addr(relval);
             rp = calc_reloc(addr, libinfo, id, 1);
             if (rp == RELOC_FAILED)
                 return -ENOEXEC;
 
             /* Get the pointer's value.  */
-            addr = tgetl(rp);
+            if (get_user_ual(addr, rp))
+                return -EFAULT;
             if (addr != 0) {
                 /*
                  * Do the relocation.  PIC relocs in the data section are
@@ -652,13 +656,15 @@
                     return -ENOEXEC;
 
                 /* Write back the relocated pointer.  */
-                tputl(rp, addr);
+                if (put_user_ual(addr, rp))
+                    return -EFAULT;
             }
         }
     } else {
         for (i = 0; i < relocs; i++) {
             abi_ulong relval;
-            relval = tgetl(reloc + i * sizeof (abi_ulong));
+            if (get_user_ual(relval, reloc + i * sizeof(abi_ulong)))
+                return -EFAULT;
             old_reloc(&libinfo[0], relval);
         }
     }
@@ -744,9 +750,12 @@
             p = libinfo[i].start_data;
             for (j=0; j<MAX_SHARED_LIBS; j++) {
                 p -= 4;
-                tput32(p, libinfo[j].loaded
-                          ? libinfo[j].start_data
-                          : UNLOADED_LIB);
+                /* FIXME - handle put_user() failures */
+                if (put_user_ual(libinfo[j].loaded
+                                 ? libinfo[j].start_data
+                                 : UNLOADED_LIB,
+                                 p))
+                    return -EFAULT;
             }
         }
     }
@@ -779,7 +788,9 @@
     for (i = MAX_SHARED_LIBS-1; i>0; i--) {
             if (libinfo[i].loaded) {
                     /* Push previos first to call address */
-                    --sp;	put_user(start_addr, sp);
+                    --sp;
+                    if (put_user_ual(start_addr, sp))
+                        return -EFAULT;
                     start_addr = libinfo[i].entry;
             }
     }
linux-user/main.c +19 -11
Index: qemu/linux-user/main.c
===================================================================
@@ -342,7 +342,8 @@
 
                 /* we handle the FPU emulation here, as Linux */
                 /* we get the opcode */
-                opcode = tget32(env->regs[15]);
+                /* FIXME - what to do if get_user() fails? */
+                get_user_u32(opcode, env->regs[15]);
 
                 if (EmulateAll(opcode, &ts->fpa, env) == 0) {
                     info.si_signo = SIGILL;
@@ -363,20 +364,24 @@
                 /* system call */
                 if (trapnr == EXCP_BKPT) {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user_u16(insn, env->regs[15]);
                         n = insn & 0xff;
                         env->regs[15] += 2;
                     } else {
-                        insn = tget32(env->regs[15]);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user_u32(insn, env->regs[15]);
                         n = (insn & 0xf) | ((insn >> 4) & 0xff0);
                         env->regs[15] += 4;
                     }
                 } else {
                     if (env->thumb) {
-                        insn = tget16(env->regs[15] - 2);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user_u16(insn, env->regs[15] - 2);
                         n = insn & 0xff;
                     } else {
-                        insn = tget32(env->regs[15] - 4);
+                        /* FIXME - what to do if get_user() fails? */
+                        get_user_u32(insn, env->regs[15] - 4);
                         n = insn & 0xffffff;
                     }
                 }
@@ -482,7 +487,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        tputl(sp_ptr, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
+        /* FIXME - what to do if put_user() fails? */
+        put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
     }
 }
@@ -518,7 +524,8 @@
            (int)sp_ptr, cwp1);
 #endif
     for(i = 0; i < 16; i++) {
-        env->regbase[get_reg_index(env, cwp1, 8 + i)] = tgetl(sp_ptr);
+        /* FIXME - what to do if get_user() fails? */
+        get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
     }
     env->wim = new_wim;
@@ -1495,10 +1502,11 @@
                 sp_reg = env->gpr[29][env->current_tc];
                 switch (nb_args) {
                 /* these arguments are taken from the stack */
-                case 8: arg8 = tgetl(sp_reg + 28);
-                case 7: arg7 = tgetl(sp_reg + 24);
-                case 6: arg6 = tgetl(sp_reg + 20);
-                case 5: arg5 = tgetl(sp_reg + 16);
+                /* FIXME - what to do if get_user() fails? */
+                case 8: get_user_ual(arg8, sp_reg + 28);
+                case 7: get_user_ual(arg7, sp_reg + 24);
+                case 6: get_user_ual(arg6, sp_reg + 20);
+                case 5: get_user_ual(arg5, sp_reg + 16);
                 default:
                     break;
                 }
linux-user/qemu.h +29 -18

73 lines not on this page · raw message

linux-user/syscall.c +300 -146

772 lines not on this page · raw message

arm-semi.c +13 -3
Index: qemu/arm-semi.c
===================================================================
@@ -165,8 +165,14 @@
 #endif
 }
 
-#define ARG(n) tget32(args + (n) * 4)
-#define SET_ARG(n, val) tput32(args + (n) * 4,val)
+#define ARG(n)					\
+({						\
+    abi_ulong __arg;				\
+    /* FIXME - handle get_user() failure */	\
+    get_user_ual(__arg, args + (n) * 4);	\
+    __arg;					\
+})
+#define SET_ARG(n, val) put_user_ual(val, args + (n) * 4)
 uint32_t do_arm_semihosting(CPUState *env)
 {
     target_ulong args;
@@ -213,7 +219,11 @@
         }
     case SYS_WRITEC:
         {
-          char c = tget8(args);
+          char c;
+
+          if (get_user_u8(c, args))
+              /* FIXME - should this error code be -TARGET_EFAULT ? */
+              return (uint32_t)-1;
           /* Write to debug console.  stderr is near enough.  */
           if (use_gdb_syscalls()) {
                 gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
target-arm/nwfpe/fpa11_cpdt.c +37 -27

132 lines not on this page · raw message

linux-user/linuxload.c +19 -8
Index: qemu/linux-user/linuxload.c
===================================================================
@@ -126,21 +126,32 @@
     sp -= (argc + 1) * n;
     argv = sp;
     if (push_ptr) {
-        sp -= n; tputl(sp, envp);
-        sp -= n; tputl(sp, argv);
-    }
-    sp -= n; tputl(sp, argc);
+        /* FIXME - handle put_user() failures */
+        sp -= n;
+        put_user_ual(envp, sp);
+        sp -= n;
+        put_user_ual(argv, sp);
+    }
+    sp -= n;
+    /* FIXME - handle put_user() failures */
+    put_user_ual(argc, sp);
 
     while (argc-- > 0) {
-        tputl(argv, stringp); argv += n;
+        /* FIXME - handle put_user() failures */
+        put_user_ual(stringp, argv);
+        argv += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(argv, 0);
+    /* FIXME - handle put_user() failures */
+    put_user_ual(0, argv);
     while (envc-- > 0) {
-        tputl(envp, stringp); envp += n;
+        /* FIXME - handle put_user() failures */
+        put_user_ual(stringp, envp);
+        envp += n;
         stringp += target_strlen(stringp) + 1;
     }
-    tputl(envp, 0);
+    /* FIXME - handle put_user() failures */
+    put_user_ual(0, envp);
 
     return sp;
 }
m68k-semi.c +19 -9
Index: qemu/m68k-semi.c
===================================================================
@@ -142,15 +142,23 @@
     if (m68k_semi_is_fseek) {
         /* FIXME: We've already lost the high bits of the fseek
            return value.  */
-        tput32(args, 0);
+        /* FIXME - handle put_user() failure */
+        put_user_u32(0, args);
         args += 4;
         m68k_semi_is_fseek = 0;
     }
-    tput32(args, ret);
-    tput32(args + 4, errno);
+    /* FIXME - handle put_user() failure */
+    put_user_u32(ret, args);
+    put_user_u32(errno, args + 4);
 }
 
-#define ARG(x) tget32(args + (x) * 4)
+#define ARG(n)					\
+({						\
+    abi_ulong __arg;				\
+    /* FIXME - handle get_user() failure */	\
+    get_user_ual(__arg, args + (n) * 4);	\
+    __arg;					\
+})
 #define PARG(x) ((unsigned long)ARG(x))
 void do_m68k_semihosting(CPUM68KState *env, int nr)
 {
@@ -234,9 +242,10 @@
                                ARG(0), off, ARG(3));
             } else {
                 off = lseek(ARG(0), off, ARG(3));
-                tput32(args, off >> 32);
-                tput32(args + 4, off);
-                tput32(args + 8, errno);
+                /* FIXME - handle put_user() failure */
+                put_user_u32(off >> 32, args);
+                put_user_u32(off, args + 4);
+                put_user_u32(errno, args + 8);
             }
             return;
         }
@@ -382,6 +391,7 @@
         cpu_abort(env, "Unsupported semihosting syscall %d\n", nr);
         result = 0;
     }
-    tput32(args, result);
-    tput32(args + 4, errno);
+    /* FIXME - handle put_user() failure */
+    put_user_u32(result, args);
+    put_user_u32(errno, args + 4);
 }
#6 lore raw
In reply to Thayne Harbaugh
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Hi,

This seems not OK for ppc/ppc64. There is no ppc64 subdirectory anymore in the linux-user directory. ppc and ppc64 targets have been merged, as it is in recent kernels, so all the definitions should go in the ppc subdirectory, using #ifdef TARGET_PPC64 when there are differences; but there should be very few: there are only 2 ifdef __powerpc64__ in the linux-2.6.23/include/asm-powerpc/posix_types.h file.

Signature · 1 line
Jocelyn Mayer <[email protected]>
#7 lore raw
Quoted 7 lines · Jocelyn Mayer
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Quoted 8 lines

Hi,

This seems not OK for ppc/ppc64. There is no ppc64 subdirectory anymore in the linux-user directory. ppc and ppc64 targets have been merged, as it is in recent kernels, so all the definitions should go in the ppc subdirectory, using #ifdef TARGET_PPC64 when there are differences; but there should be very few: there are only 2 ifdef __powerpc64__ in the linux-2.6.23/include/asm-powerpc/posix_types.h file.

I figure some conditionals went missing, on 32-bit Linux/ppc it fails to compile.

Thiemo

[...]
gcc-3.4 -Wall -O2 -g -fno-strict-aliasing -fno-reorder-blocks -fno-gcse -fno-optimize-sibling-calls -fno-crossjumping -fno-align-labels -fno-align-jumps -fno-align-functions -I. -I.. -I/home/ths/qemu/qemu-write/target-ppc -I/home/ths/qemu/qemu-write -MMD -MP -DNEED_CPU_H -I/home/ths/qemu/qemu-write/linux-user -I/home/ths/qemu/qemu-write/linux-user/ppc -D__powerpc__ -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/home/ths/qemu/qemu-write/fpu -DHAS_AUDIO -DHAS_AUDIO_CHOICE -I/home/ths/qemu/qemu-write/slirp -c -o op.o /home/ths/qemu/qemu-write/target-ppc/op.c
In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:30:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr0':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr0':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:33:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr1':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr1':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:36:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr2':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr2':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:39:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr3':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr3':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:42:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr4':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr4':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:45:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr5':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr5':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:48:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr6':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr6':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:51:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr7':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr7':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:54:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr8':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr8':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:57:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr9':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr9':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:60:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr10':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr10':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:63:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr11':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr11':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:66:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr12':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr12':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:69:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr13':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr13':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:72:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr14':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr14':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:75:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr15':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr15':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:78:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr16':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr16':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:81:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr17':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr17':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:84:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr18':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr18':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:87:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr19':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr19':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:90:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr20':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr20':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:93:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr21':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr21':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:96:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr22':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr22':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:99:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr23':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr23':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:102:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr24':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr24':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:105:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr25':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr25':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:108:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr26':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr26':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:111:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr27':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr27':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:114:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr28':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr28':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:117:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr29':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr29':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:120:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr30':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr30':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type In file included from /home/ths/qemu/qemu-write/target-ppc/op.c:123:
/home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T0_gpr64_gpr31':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:85: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op_template.h: In function `op_store_T1_gpr64_gpr31':
/home/ths/qemu/qemu-write/target-ppc/op_template.h:92: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_splatw_T1_64':
/home/ths/qemu/qemu-write/target-ppc/op.c:2726: warning: left shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_sli32_T1_64':
/home/ths/qemu/qemu-write/target-ppc/op.c:2760: warning: left shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_srli32_T1_64':
/home/ths/qemu/qemu-write/target-ppc/op.c:2766: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_evextsh':
/home/ths/qemu/qemu-write/target-ppc/op.c:2802: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_evextsb':
/home/ths/qemu/qemu-write/target-ppc/op.c:2809: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_evmergelo':
/home/ths/qemu/qemu-write/target-ppc/op.c:2912: warning: left shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_evmergehi':
/home/ths/qemu/qemu-write/target-ppc/op.c:2918: warning: right shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c: In function `op_evmergelohi':
/home/ths/qemu/qemu-write/target-ppc/op.c:2924: warning: left shift count >= width of type /home/ths/qemu/qemu-write/target-ppc/op.c:2924: warning: right shift count >= width of type ../dyngen -o op.h op.o
dyngen: empty code for op_efdnabs
make[1]: *** [op.h] Error 1
make[1]: Leaving directory `/home/ths/qemu/qemu-write/ppc-linux-user'
make: *** [subdir-ppc-linux-user] Error 2

#8 lore raw
Quoted 17 lines · Thiemo Seufer
Quoted 7 lines · Jocelyn Mayer
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Quoted 8 lines

Hi,

This seems not OK for ppc/ppc64. There is no ppc64 subdirectory anymore in the linux-user directory. ppc and ppc64 targets have been merged, as it is in recent kernels, so all the definitions should go in the ppc subdirectory, using #ifdef TARGET_PPC64 when there are differences; but there should be very few: there are only 2 ifdef __powerpc64__ in the linux-2.6.23/include/asm-powerpc/posix_types.h file.

Quoted 2 lines

I figure some conditionals went missing, on 32-bit Linux/ppc it fails to compile.

[...]

Ooops... Thanks for the report, it looks like T0_64, ..., are not properly declared in this case. I'll take a look.

Signature · 1 line
Jocelyn Mayer <[email protected]>
#9 lore raw
In reply to Jocelyn Mayer
Quoted 6 lines · Jocelyn Mayer
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Quoted 8 lines

Hi,

This seems not OK for ppc/ppc64. There is no ppc64 subdirectory anymore in the linux-user directory. ppc and ppc64 targets have been merged, as it is in recent kernels, so all the definitions should go in the ppc subdirectory, using #ifdef TARGET_PPC64 when there are differences; but there should be very few: there are only 2 ifdef __powerpc64__ in the linux-2.6.23/include/asm-powerpc/posix_types.h file.

How is this?

linux-user/alpha/target_posix_types.h new file +55 -0
Index: qemu/linux-user/alpha/target_posix_types.h
===================================================================
@@ -0,0 +1,55 @@
+/*
+ * Borrowed with minor changes from:
+ *  linux/include/asm-alpha/posix_types.h
+ */
+
+#ifndef TARGET_POSIX_TYPES_H
+#define TARGET_POSIX_TYPES_H
+
+typedef int8_t			target_char;
+typedef int16_t			target_short;
+typedef int32_t			target_int;
+/* target_long defined in qemu/cpu-defs.h */
+typedef int64_t			target_long_long;
+
+typedef uint8_t			target_uchar;
+typedef uint16_t		target_ushort;
+typedef uint32_t		target_uint;
+/* target_ulong defined in qemu/cpu-defs.h */
+typedef uint64_t		target_ulong_long;
+
+typedef target_uint		target_ino_t;
+typedef target_uint		target_mode_t;
+typedef target_uint		target_nlink_t;
+typedef abi_long		target_off_t;
+typedef target_long_long	target_loff_t;
+typedef target_int		target_pid_t;
+typedef target_int		target_ipc_pid_t;
+typedef target_uint		target_uid_t;
+typedef target_uint		target_gid_t;
+typedef abi_ulong		target_size_t;
+typedef abi_long		target_ssize_t;
+typedef abi_long		target_ptrdiff_t;
+typedef abi_long		target_time_t;
+typedef abi_long		target_suseconds_t;
+typedef abi_long		target_clock_t;
+typedef target_int		target_daddr_t;
+typedef target_char *		target_caddr_t;
+/* typedef unsigned long	target_sigset_t; (conflicts in syscall_defs.h) */
+typedef target_ushort		target_uid16_t;
+typedef target_ushort		target_gid16_t;
+typedef target_int		target_clockid_t;
+typedef target_int		target_timer_t;
+
+typedef struct {
+	target_int	val[2];
+} target_fsid_t;
+
+typedef target_uid_t		target_old_uid_t;
+typedef target_gid_t		target_old_gid_t;
+typedef target_uid_t		target_uid32_t;
+typedef target_gid_t		target_gid32_t;
+
+typedef target_uint		target_old_dev_t;
+
+#endif /* TARGET_POSIX_TYPES_H */
linux-user/arm/target_posix_types.h new file +62 -0

62 lines not on this page · raw message

linux-user/i386/target_posix_types.h new file +55 -0

55 lines not on this page · raw message

linux-user/m68k/target_posix_types.h new file +54 -0

54 lines not on this page · raw message

linux-user/mips/target_posix_types.h new file +79 -0

79 lines not on this page · raw message

linux-user/ppc/target_posix_types.h new file +65 -0

65 lines not on this page · raw message

linux-user/sh4/target_posix_types.h new file +56 -0

56 lines not on this page · raw message

linux-user/sparc/target_posix_types.h new file +56 -0

56 lines not on this page · raw message

linux-user/sparc64/target_posix_types.h new file +58 -0

58 lines not on this page · raw message

linux-user/x86_64/target_posix_types.h new file +57 -0

57 lines not on this page · raw message

linux-user/syscall_defs.h +8 -11
Index: qemu/linux-user/syscall_defs.h
===================================================================
@@ -5,6 +5,7 @@
    necessary */
 
 #include "syscall_nr.h"
+#include "target_posix_types.h"
 
 #define SOCKOP_socket           1
 #define SOCKOP_bind             2
@@ -104,13 +105,15 @@
     uint8_t sa_data[14];
 };
 
+typedef uint32_t target_socklen_t;
+
 struct target_timeval {
-    abi_long tv_sec;
-    abi_long tv_usec;
+    target_time_t tv_sec;
+    target_suseconds_t tv_usec;
 };
 
 struct target_timespec {
-    abi_long tv_sec;
+    target_time_t tv_sec;
     abi_long tv_nsec;
 };
 
@@ -119,8 +122,6 @@
     struct target_timeval it_value;
 };
 
-typedef abi_long target_clock_t;
-
 #define TARGET_HZ 100
 
 struct target_tms {
@@ -131,8 +132,8 @@
 };
 
 struct target_utimbuf {
-    abi_long actime;
-    abi_long modtime;
+    target_time_t actime;
+    target_time_t modtime;
 };
 
 struct target_sel_arg_struct {
@@ -1481,10 +1482,6 @@
 #error unsupported CPU
 #endif
 
-typedef struct {
-        int     val[2];
-} target_fsid_t;
-
 #ifdef TARGET_MIPS
 #ifdef TARGET_MIPSN32
 struct target_statfs {
linux-user/cris/target_posix_types.h new file +59 -0

59 lines not on this page · raw message

#10 lore raw
In reply to Thayne Harbaugh
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Why is it needed ?

Fabrice.

#11 lore raw
Quoted 7 lines · Fabrice Bellard
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Why is it needed ?

It's not *necessary*, but it makes code more readable and it simplifies having to always check for what a typedef on a target might map to. It makes target structures more comparable to their structures in the kernel.

A simple example:

struct target_timeval {
    abi_long tv_sec;
    abi_long tv_usec;
};

vs.

struct target_timeval {
    target_time_t tv_sec;
    target_suseconds_t tv_usec;
};

It also makes type conversion between target and host more obvious.

It also means that more code can be shared rather than #ifdef'ed when targets differ on their base definitions.

It's just another level of abstraction, we can always stick with abi_long, abi_ulong, etc.. I've just noticed that size and sign handling when converting between target and host are a common source of errors and this simplifies things. We use it in all our patches and it has helped simplify and fix errors.

#12 lore raw
Quoted 31 lines · Thayne Harbaugh
Quoted 6 lines · Fabrice Bellard
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Why is it needed ?

It's not *necessary*, but it makes code more readable and it simplifies having to always check for what a typedef on a target might map to. It makes target structures more comparable to their structures in the kernel.

A simple example:

struct target_timeval {
    abi_long tv_sec;
    abi_long tv_usec;
};

vs.

struct target_timeval {
    target_time_t tv_sec;
    target_suseconds_t tv_usec;
};

It also makes type conversion between target and host more obvious.

Quoted 8 lines

It also means that more code can be shared rather than #ifdef'ed when targets differ on their base definitions.

It's just another level of abstraction, we can always stick with abi_long, abi_ulong, etc.. I've just noticed that size and sign handling when converting between target and host are a common source of errors and this simplifies things. We use it in all our patches and it has helped simplify and fix errors.

I don't like adding levels of abstraction unless I am really forced. I think these types makes the code more difficult to understand without real added value. In particular, it does not help for sign conversions.

Fabrice.

#13 lore raw
Quoted 41 lines · Fabrice Bellard
Quoted 31 lines · Thayne Harbaugh
Quoted 6 lines · Fabrice Bellard
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Why is it needed ?

It's not *necessary*, but it makes code more readable and it simplifies having to always check for what a typedef on a target might map to. It makes target structures more comparable to their structures in the kernel.

A simple example:

struct target_timeval {
    abi_long tv_sec;
    abi_long tv_usec;
};

vs.

struct target_timeval {
    target_time_t tv_sec;
    target_suseconds_t tv_usec;
};

It also makes type conversion between target and host more obvious.

Quoted 8 lines

It also means that more code can be shared rather than #ifdef'ed when targets differ on their base definitions.

It's just another level of abstraction, we can always stick with abi_long, abi_ulong, etc.. I've just noticed that size and sign handling when converting between target and host are a common source of errors and this simplifies things. We use it in all our patches and it has helped simplify and fix errors.

Quoted 3 lines

I don't like adding levels of abstraction unless I am really forced. I think these types makes the code more difficult to understand without real added value. In particular, it does not help for sign conversions.

I should have provided an example:

Let's look at time_t and target_time_t which might have a size of 4 or of 8.

IMO it's easier to write this:

time_t time;
get_user(time, time_addr, target_time_t);
and
put_user(time, time_addr, target_time_t);

get_user then does the lock and calls __get_user() which uses the type information when assigning to time - that is what correctly handles any sign extending.

What is common now is this:

time_t time;
time = tget32(time_addr);
and
tput32(time_addr, time);

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Now maybe a solution is this:

time = tget1(time_addr);
and
tputl(time_addr, time);

That may fix the problem of getting the size correct depending on whether the target is 32 or 64 bit, but it still doesn't solve the problem of correctly sign-extending when assigning between the target and the host.

I've sent patches to fix this type of bug to the list. I have possibly half-a-dozen more patches in my tree that fix this same type of bug: -1 becoming a very large positive number.

Maybe I'm missing the current, correct way of doing this. Please enlighten me. If I've missed something then I apologize for wasting everyone's time.

Thank you.

#14 lore raw
Quoted 7 lines

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Is there any guarantee that time_t is a signed type? The fact that you said (time_t)-1 suggests it could be an unsigned type. If time_t is an unsigned type, then casting to a wider value is still wrong. You have to special-case the error condition.

In the case of time_t this only becomes relevant after 32-bit time_t wrap in approx. 99 years time, but I'd expect there are cases where it matters.

Paul

#15 lore raw

From: Paul Brook <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] target_posix_types.h
Date: Wed, 14 Nov 2007 20:39:36 +0000

Quoted 8 lines
Quoted 7 lines

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Quoted 7 lines

Is there any guarantee that time_t is a signed type? The fact that you said (time_t)-1 suggests it could be an unsigned type. If time_t is an unsigned type, then casting to a wider value is still wrong. You have to special-case the error condition.

In the case of time_t this only becomes relevant after 32-bit time_t wrap in approx. 99 years time, but I'd expect there are cases where it matters.

The wrap on 32-bit signed time_t happens after ~68 years since the next looming time thing in unix is 2038:

% date -r 2147483647
Mon Jan 18 20:14:07 MST 2038
% date -r 2147483648
Fri Dec 13 13:45:52 MST 1901

The standard says:

7.23 Date and time <time.h>
7.23.1 Components of time
[#3] The types declared are size_t (described in 7.17);
clock_t
and
time_t
which are arithmetic types capable of representing times;

Which is uselessly vague (no: it doesn't imply time_t is a signed number or unsigned or even an int):

       6.2.5  Types

...
[#21] Integer and floating types are collectively called arithmetic types. Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.

Traditionally, time_t is defined as

typedef long time_t;

but recently you'll see it defined like so

typedef int32_t time_t;

or

typedef int64_t time_t;

Warner

#16 lore raw
Quoted 52 lines · Warner Losh

From: Paul Brook <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] target_posix_types.h
Date: Wed, 14 Nov 2007 20:39:36 +0000

Quoted 8 lines
Quoted 7 lines

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Quoted 7 lines

Is there any guarantee that time_t is a signed type? The fact that you said (time_t)-1 suggests it could be an unsigned type. If time_t is an unsigned type, then casting to a wider value is still wrong. You have to special-case the error condition.

In the case of time_t this only becomes relevant after 32-bit time_t wrap in approx. 99 years time, but I'd expect there are cases where it matters.

The wrap on 32-bit signed time_t happens after ~68 years since the next looming time thing in unix is 2038:

% date -r 2147483647
Mon Jan 18 20:14:07 MST 2038
% date -r 2147483648
Fri Dec 13 13:45:52 MST 1901

The standard says:

7.23 Date and time <time.h>
7.23.1 Components of time
[#3] The types declared are size_t (described in 7.17);
clock_t
and
time_t
which are arithmetic types capable of representing times;

Which is uselessly vague (no: it doesn't imply time_t is a signed number or unsigned or even an int):

       6.2.5  Types

...
[#21] Integer and floating types are collectively called arithmetic types. Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.

Traditionally, time_t is defined as

typedef long time_t;

Quoted 7 lines

but recently you'll see it defined like so

typedef int32_t time_t;

or

typedef int64_t time_t;

Interesting. Thank you.

My intention wasn't to discuss time_t in particular but to point out an example of a class of bugs.

#17 lore raw
In reply to Paul Brook
Quoted 8 lines · Paul Brook
Quoted 7 lines

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Quoted 7 lines

Is there any guarantee that time_t is a signed type? The fact that you said (time_t)-1 suggests it could be an unsigned type. If time_t is an unsigned type, then casting to a wider value is still wrong. You have to special-case the error condition.

In the case of time_t this only becomes relevant after 32-bit time_t wrap in approx. 99 years time, but I'd expect there are cases where it matters.

time_t is only one example. There are similar problems with the handling of struct target_iovec. There are still other places with similar problems.

Yes, special casing can work. There's the possible problem of value truncation when moving between 32 and 64 bits.

#18 lore raw
Quoted 6 lines

time_t is only one example. There are similar problems with the handling of struct target_iovec. There are still other places with similar problems.

Yes, special casing can work. There's the possible problem of value truncation when moving between 32 and 64 bits.

My point is that I expect there the be sufficiently many special cases that you can't simply rely on get_user() doing the right thing, even if you have "proper" types everywhere.

It's also unclear whether sign extensions should depend on host or guest properties.

Paul

#19 lore raw
In reply to Fabrice Bellard
Quoted 41 lines · Fabrice Bellard
Quoted 31 lines · Thayne Harbaugh
Quoted 6 lines · Fabrice Bellard
Quoted 4 lines · Thayne Harbaugh

This patch, 44_target_posix_types.patch provides target specific posix types. These types improve target structure creation, code similarity to kernel code and improve type casting for assignment between target and host.

Why is it needed ?

It's not *necessary*, but it makes code more readable and it simplifies having to always check for what a typedef on a target might map to. It makes target structures more comparable to their structures in the kernel.

A simple example:

struct target_timeval {
    abi_long tv_sec;
    abi_long tv_usec;
};

vs.

struct target_timeval {
    target_time_t tv_sec;
    target_suseconds_t tv_usec;
};

It also makes type conversion between target and host more obvious.

Quoted 8 lines

It also means that more code can be shared rather than #ifdef'ed when targets differ on their base definitions.

It's just another level of abstraction, we can always stick with abi_long, abi_ulong, etc.. I've just noticed that size and sign handling when converting between target and host are a common source of errors and this simplifies things. We use it in all our patches and it has helped simplify and fix errors.

Quoted 3 lines

I don't like adding levels of abstraction unless I am really forced. I think these types makes the code more difficult to understand without real added value. In particular, it does not help for sign conversions.

I should have provided an example:

Let's look at time_t and target_time_t which might have a size of 4 or of 8.

IMO it's easier to write this:

time_t time;
get_user(time, time_addr, target_time_t);
and
put_user(time, time_addr, target_time_t);

get_user then does the lock and calls __get_user() which uses the type information when assigning to time - that is what correctly handles any sign extending.

What is common now is this:

time_t time;
time = tget32(time_addr);
and
tput32(time_addr, time);

This means that time_t had to be tracked down on varying architectures to find the size and there was an assumption made that time_t is 32 bits
- which isn't true for all targets. The next problem is that if the target is 32 bits but the host is 64 bits then there's a sign extension problem because (time_t)-1 is used for an error condition. If you don't correctly assign assign the 32-bit -1 to a 64-bit type then, rather than -1, you get 4294967295.

Now maybe a solution is this:

time = tget1(time_addr);
and
tputl(time_addr, time);

That means that someone still needed to track down what a target time_t is. That may fix the problem of getting the size correct, depending on whether the target is 32 or 64 bit, but it still doesn't solve the problem of correctly sign-extending when assigning between the target and the host.

I've sent patches to fix this type of bug to the list. I have possibly half-a-dozen more patches in my tree that fix this same type of bug: -1 becoming a very large positive number.

Maybe I'm missing the current, correct way of doing this. Please enlighten me. If I've missed something then I apologize for wasting everyone's time.

Thank you.