Patchwork linux-user: define ipc_perm and shmid_ds per arch and fix shmctl issue

login
register
mail settings
Submitter Petar Jovanovic
Date Oct. 7, 2013, 3:54 p.m.
Message ID <1381161287-40027-1-git-send-email-petar.jovanovic@rt-rk.com>
Download mbox | patch
Permalink /patch/281172/
State New
Headers show

Comments

Petar Jovanovic - Oct. 7, 2013, 3:54 p.m.
From: Petar Jovanovic <petar.jovanovic@imgtec.com>

Structs ipc_perm and shmid_ds are specific for each architecture and should
be defined accordingly. This change does that, and it also fix shmctl issue
by passing correct parameter buf to do_shmctl().

Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
 linux-user/syscall.c      |   78 +++++++----------
 linux-user/syscall_defs.h |  211 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 240 insertions(+), 49 deletions(-)
Peter Maydell - Oct. 7, 2013, 4:08 p.m.
On 8 October 2013 00:54, Petar Jovanovic <petar.jovanovic@rt-rk.com> wrote:
> From: Petar Jovanovic <petar.jovanovic@imgtec.com>
>
> Structs ipc_perm and shmid_ds are specific for each architecture and should
> be defined accordingly. This change does that, and it also fix shmctl issue
> by passing correct parameter buf to do_shmctl().

Please can you separate out these two things into separate patches?
It's much harder to review the code changes for the do_shmctl changes
when they're swamped by the code motion for making the structs per-arch.

> Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
> ---
>  linux-user/syscall.c      |   78 +++++++----------
>  linux-user/syscall_defs.h |  211 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 240 insertions(+), 49 deletions(-)

Rather than adding another big ifdef ladder to syscall_defs.h, I think
we should create a new file linux-user/$arch/target_structs.h
for each target arch as a place to put "depends on the architecture"
struct definitions. We could then clean up some of the ifdef ladders
in the existing syscall_defs.h too...

thanks
-- PMM
Petar Jovanovic - Oct. 7, 2013, 6 p.m.

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4a14a43..abaffde 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2417,21 +2417,6 @@  static struct shm_region {
     abi_ulong	size;
 } shm_regions[N_SHM_REGIONS];
 
-struct target_ipc_perm
-{
-    abi_long __key;
-    abi_ulong uid;
-    abi_ulong gid;
-    abi_ulong cuid;
-    abi_ulong cgid;
-    unsigned short int mode;
-    unsigned short int __pad1;
-    unsigned short int __seq;
-    unsigned short int __pad2;
-    abi_ulong __unused1;
-    abi_ulong __unused2;
-};
-
 struct target_semid_ds
 {
   struct target_ipc_perm sem_perm;
@@ -2453,12 +2438,21 @@  static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
         return -TARGET_EFAULT;
     target_ip = &(target_sd->sem_perm);
-    host_ip->__key = tswapal(target_ip->__key);
-    host_ip->uid = tswapal(target_ip->uid);
-    host_ip->gid = tswapal(target_ip->gid);
-    host_ip->cuid = tswapal(target_ip->cuid);
-    host_ip->cgid = tswapal(target_ip->cgid);
+    host_ip->__key = tswap32(target_ip->__key);
+    host_ip->uid = tswap32(target_ip->uid);
+    host_ip->gid = tswap32(target_ip->gid);
+    host_ip->cuid = tswap32(target_ip->cuid);
+    host_ip->cgid = tswap32(target_ip->cgid);
+#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
+    host_ip->mode = tswap32(target_ip->mode);
+#else
     host_ip->mode = tswap16(target_ip->mode);
+#endif
+#if defined(TARGET_PPC)
+    host_ip->__seq = tswap32(target_ip->__seq);
+#else
+    host_ip->__seq = tswap16(target_ip->__seq);
+#endif
     unlock_user_struct(target_sd, target_addr, 0);
     return 0;
 }
@@ -2472,12 +2466,21 @@  static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr,
     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
         return -TARGET_EFAULT;
     target_ip = &(target_sd->sem_perm);
-    target_ip->__key = tswapal(host_ip->__key);
-    target_ip->uid = tswapal(host_ip->uid);
-    target_ip->gid = tswapal(host_ip->gid);
-    target_ip->cuid = tswapal(host_ip->cuid);
-    target_ip->cgid = tswapal(host_ip->cgid);
+    target_ip->__key = tswap32(host_ip->__key);
+    target_ip->uid = tswap32(host_ip->uid);
+    target_ip->gid = tswap32(host_ip->gid);
+    target_ip->cuid = tswap32(host_ip->cuid);
+    target_ip->cgid = tswap32(host_ip->cgid);
+#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
+    target_ip->mode = tswap32(host_ip->mode);
+#else
     target_ip->mode = tswap16(host_ip->mode);
+#endif
+#if defined(TARGET_PPC)
+    target_ip->__seq = tswap32(host_ip->__seq);
+#else
+    target_ip->__seq = tswap16(host_ip->__seq);
+#endif
     unlock_user_struct(target_sd, target_addr, 1);
     return 0;
 }
@@ -2908,29 +2911,6 @@  end:
     return ret;
 }
 
-struct target_shmid_ds
-{
-    struct target_ipc_perm shm_perm;
-    abi_ulong shm_segsz;
-    abi_ulong shm_atime;
-#if TARGET_ABI_BITS == 32
-    abi_ulong __unused1;
-#endif
-    abi_ulong shm_dtime;
-#if TARGET_ABI_BITS == 32
-    abi_ulong __unused2;
-#endif
-    abi_ulong shm_ctime;
-#if TARGET_ABI_BITS == 32
-    abi_ulong __unused3;
-#endif
-    int shm_cpid;
-    int shm_lpid;
-    abi_ulong shm_nattch;
-    unsigned long int __unused4;
-    unsigned long int __unused5;
-};
-
 static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
                                                abi_ulong target_addr)
 {
@@ -3216,7 +3196,7 @@  static abi_long do_ipc(unsigned int call, int first,
 
 	/* IPC_* and SHM_* command values are the same on all linux platforms */
     case IPCOP_shmctl:
-        ret = do_shmctl(first, second, third);
+        ret = do_shmctl(first, second, ptr);
         break;
     default:
 	gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 5f53a28..079156e 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2513,3 +2513,214 @@  struct target_ucred {
 };
 
 #endif
+
+#if defined(TARGET_ALPHA)
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+    abi_uint mode;
+    abi_ushort __seq;
+    abi_ushort __pad1;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+    abi_long shm_segsz;
+    abi_ulong shm_atime;
+    abi_ulong shm_dtime;
+    abi_ulong shm_ctime;
+    abi_int shm_cpid;
+    abi_int shm_lpid;
+    abi_ulong shm_nattch;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+#elif defined(TARGET_ARM)
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+    abi_ushort mode;
+    abi_ushort __pad1;
+    abi_ushort __seq;
+    abi_ushort __pad2;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+    abi_long shm_segsz;
+    abi_ulong shm_atime;
+    abi_ulong __unused1;
+    abi_ulong shm_dtime;
+    abi_ulong __unused2;
+    abi_ulong shm_ctime;
+    abi_ulong __unused3;
+    abi_int shm_cpid;
+    abi_int shm_lpid;
+    abi_ulong shm_nattch;
+    abi_ulong __unused4;
+    abi_ulong __unused5;
+};
+
+#elif defined(TARGET_MIPS)
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+    abi_uint mode;
+    abi_ushort __seq;
+    abi_ushort __pad1;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+    abi_long shm_segsz;
+    abi_ulong shm_atime;
+    abi_ulong shm_dtime;
+    abi_ulong shm_ctime;
+    abi_int shm_cpid;
+    abi_int shm_lpid;
+    abi_ulong shm_nattch;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+#elif defined(TARGET_PPC)
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+    abi_uint mode;
+    uint32_t __seq;
+    uint32_t __pad1;
+    uint64_t __unused1;
+    uint64_t __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+#if TARGET_ABI_BITS == 32
+    abi_uint __unused1;
+#endif
+    abi_ulong shm_atime;
+#if TARGET_ABI_BITS == 32
+    abi_uint __unused2;
+#endif
+    abi_ulong shm_dtime;
+#if TARGET_ABI_BITS == 32
+    abi_uint __unused3;
+#endif
+    abi_ulong shm_ctime;
+#if TARGET_ABI_BITS == 32
+    abi_uint __unused4;
+#endif
+    abi_long shm_segsz;
+    abi_int shm_cpid;
+    abi_int shm_lpid;
+    abi_ulong shm_nattch;
+    abi_ulong __unused5;
+    abi_ulong __unused6;
+};
+
+#elif defined(TARGET_SPARC)
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+#if TARGET_ABI_BITS == 32
+    abi_ushort __pad1;
+    abi_ushort mode;
+    abi_ushort __pad2;
+#else
+    abi_ushort mode;
+    abi_ushort __pad1;
+#endif
+    abi_ushort __seq;
+    uint64_t __unused1;
+    uint64_t __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+#if TARGET_ABI_BITS == 32
+    abi_uint __pad1;
+#endif
+    abi_ulong shm_atime;
+#if TARGET_ABI_BITS == 32
+    abi_uint __pad2;
+#endif
+    abi_ulong shm_dtime;
+#if TARGET_ABI_BITS == 32
+    abi_uint __pad3;
+#endif
+    abi_ulong shm_ctime;
+    abi_long shm_segsz;
+    abi_ulong shm_cpid;
+    abi_ulong shm_lpid;
+    abi_long shm_nattch;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+#else
+
+struct target_ipc_perm {
+    abi_int __key;
+    abi_uint uid;
+    abi_uint gid;
+    abi_uint cuid;
+    abi_uint cgid;
+    abi_ushort mode;
+    abi_ushort __pad1;
+    abi_ushort __seq;
+    abi_ushort __pad2;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;
+    abi_long shm_segsz;
+    abi_ulong shm_atime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused1;
+#endif
+    abi_ulong shm_dtime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused2;
+#endif
+    abi_ulong shm_ctime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused3;
+#endif
+    abi_int shm_cpid;
+    abi_int shm_lpid;
+    abi_ulong shm_nattch;
+    abi_ulong __unused4;
+    abi_ulong __unused5;
+};
+
+#endif