]> git.proxmox.com Git - mirror_qemu.git/blobdiff - linux-user/flatload.c
Fix input-linux reading from device
[mirror_qemu.git] / linux-user / flatload.c
index 1062da3852106effbb6c6a259429b39c6e0b0e3a..a35a560904917d086e52b97c8294e1d3e2d52e55 100644 (file)
 
 /****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <unistd.h>
+#include "qemu/osdep.h"
 
 #include "qemu.h"
 #include "flat.h"
-#define ntohl(x) be32_to_cpu(x)
-#include <target_flat.h>
+#include "target_flat.h"
 
 //#define DEBUG
 
@@ -100,7 +95,13 @@ static int target_pread(int fd, abi_ulong ptr, abi_ulong len,
     int ret;
 
     buf = lock_user(VERIFY_WRITE, ptr, len, 0);
+    if (!buf) {
+        return -EFAULT;
+    }
     ret = pread(fd, buf, len, offset);
+    if (ret < 0) {
+        ret = -errno;
+    }
     unlock_user(buf, ptr, len);
     return ret;
 }
@@ -575,7 +576,7 @@ static int load_flat_file(struct linux_binprm * bprm,
      * help simplify all this mumbo jumbo
      *
      * We've got two different sections of relocation entries.
-     * The first is the GOT which resides at the begining of the data segment
+     * The first is the GOT which resides at the beginning of the data segment
      * and is terminated with a -1.  This one can be relocated in place.
      * The second is the extra relocation entries tacked after the image's
      * data segment. These require a little more processing as the entry is
@@ -633,7 +634,7 @@ static int load_flat_file(struct linux_binprm * bprm,
             /* Get the pointer's value.  */
             if (get_user_ual(addr, rp))
                 return -EFAULT;
-            addr = flat_get_addr_from_rp(rp, relval, flags, &persistent);
+            addr = flat_get_addr_from_rp(addr, relval, flags, &persistent);
             if (addr != 0) {
                 /*
                  * Do the relocation.  PIC relocs in the data section are
@@ -660,7 +661,7 @@ static int load_flat_file(struct linux_binprm * bprm,
     }
 
     /* zero the BSS.  */
-    memset((void *)((unsigned long)datapos + data_len), 0, bss_len);
+    memset(g2h(datapos + data_len), 0, bss_len);
 
     return 0;
 }
@@ -704,11 +705,10 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
 
 #endif /* CONFIG_BINFMT_SHARED_FLAT */
 
-int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info)
+int load_flt_binary(struct linux_binprm *bprm, struct image_info *info)
 {
     struct lib_info libinfo[MAX_SHARED_LIBS];
-    abi_ulong p = bprm->p;
+    abi_ulong p;
     abi_ulong stack_len;
     abi_ulong start_addr;
     abi_ulong sp;