All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] RFC: fix fcntl support in linux-user - new try
@ 2009-06-03 12:35 Arnaud Patard
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaud Patard @ 2009-06-03 12:35 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

Hi,

This is a new try to fix the fcntl support in linux-user. I tried to
adress all comments but as the previous version is several weeks old,
it's possible that I've missed some.

This patch doesn't handle linux specific fcntl flags. My plan is to get
this version of the patch reviewed/fixed and then, add them if wanted.

Thanks,
Arnaud


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix_fcntl-3.patch --]
[-- Type: text/x-diff, Size: 5995 bytes --]

Index: qemu/linux-user/syscall.c
===================================================================
--- qemu.orig/linux-user/syscall.c
+++ qemu/linux-user/syscall.c
@@ -3358,6 +3358,44 @@ static int do_fork(CPUState *env, unsign
     return ret;
 }
 
+/* warning : doesn't handle linux specific flags... */
+static int target_to_host_fcntl_cmd(int cmd)
+{
+    switch(cmd) {
+	case TARGET_F_DUPFD:
+	case TARGET_F_GETFD:
+	case TARGET_F_SETFD:
+	case TARGET_F_GETFL:
+	case TARGET_F_SETFL:
+            return cmd;
+        case TARGET_F_GETLK:
+	    return F_GETLK;
+	case TARGET_F_SETLK:
+	    return F_SETLK;
+	case TARGET_F_SETLKW:
+	    return F_SETLKW;
+	case TARGET_F_GETOWN:
+	    return F_GETOWN;
+	case TARGET_F_SETOWN:
+	    return F_SETOWN;
+	case TARGET_F_GETSIG:
+	    return F_GETSIG;
+	case TARGET_F_SETSIG:
+	    return F_SETSIG;
+#if TARGET_ABI_BITS == 32
+        case TARGET_F_GETLK64:
+	    return F_GETLK64;
+	case TARGET_F_SETLK64:
+	    return F_SETLK64;
+	case TARGET_F_SETLKW64:
+	    return F_SETLKW64;
+#endif
+	default:
+            return -TARGET_EINVAL;
+    }
+    return -TARGET_EINVAL;
+}
+
 static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
 {
     struct flock fl;
@@ -3365,6 +3403,10 @@ static abi_long do_fcntl(int fd, int cmd
     struct flock64 fl64;
     struct target_flock64 *target_fl64;
     abi_long ret;
+    int host_cmd = target_to_host_fcntl_cmd(cmd);
+
+    if (host_cmd == -TARGET_EINVAL)
+	    return host_cmd;
 
     switch(cmd) {
     case TARGET_F_GETLK:
@@ -3376,7 +3418,7 @@ static abi_long do_fcntl(int fd, int cmd
         fl.l_len = tswapl(target_fl->l_len);
         fl.l_pid = tswapl(target_fl->l_pid);
         unlock_user_struct(target_fl, arg, 0);
-        ret = get_errno(fcntl(fd, cmd, &fl));
+        ret = get_errno(fcntl(fd, host_cmd, &fl));
         if (ret == 0) {
             if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0))
                 return -TARGET_EFAULT;
@@ -3399,7 +3441,7 @@ static abi_long do_fcntl(int fd, int cmd
         fl.l_len = tswapl(target_fl->l_len);
         fl.l_pid = tswapl(target_fl->l_pid);
         unlock_user_struct(target_fl, arg, 0);
-        ret = get_errno(fcntl(fd, cmd, &fl));
+        ret = get_errno(fcntl(fd, host_cmd, &fl));
         break;
 
     case TARGET_F_GETLK64:
@@ -3411,7 +3453,7 @@ static abi_long do_fcntl(int fd, int cmd
         fl64.l_len = tswapl(target_fl64->l_len);
         fl64.l_pid = tswap16(target_fl64->l_pid);
         unlock_user_struct(target_fl64, arg, 0);
-        ret = get_errno(fcntl(fd, cmd >> 1, &fl64));
+        ret = get_errno(fcntl(fd, host_cmd, &fl64));
         if (ret == 0) {
             if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0))
                 return -TARGET_EFAULT;
@@ -3433,18 +3475,25 @@ static abi_long do_fcntl(int fd, int cmd
         fl64.l_len = tswapl(target_fl64->l_len);
         fl64.l_pid = tswap16(target_fl64->l_pid);
         unlock_user_struct(target_fl64, arg, 0);
-        ret = get_errno(fcntl(fd, cmd >> 1, &fl64));
+        ret = get_errno(fcntl(fd, host_cmd, &fl64));
         break;
 
-    case F_GETFL:
-        ret = get_errno(fcntl(fd, cmd, arg));
+    case TARGET_F_GETFL:
+        ret = get_errno(fcntl(fd, host_cmd, arg));
         if (ret >= 0) {
             ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
         }
         break;
 
-    case F_SETFL:
-        ret = get_errno(fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
+    case TARGET_F_SETFL:
+        ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
+        break;
+
+    case TARGET_F_SETOWN:
+    case TARGET_F_GETOWN:
+    case TARGET_F_SETSIG:
+    case TARGET_F_GETSIG:
+        ret = get_errno(fcntl(fd, host_cmd, arg));
         break;
 
     default:
@@ -6222,20 +6271,9 @@ abi_long do_syscall(void *cpu_env, int n
 	struct target_eabi_flock64 *target_efl;
 #endif
 
-        switch(arg2){
-        case TARGET_F_GETLK64:
-            cmd = F_GETLK64;
-            break;
-        case TARGET_F_SETLK64:
-            cmd = F_SETLK64;
-            break;
-        case TARGET_F_SETLKW64:
-            cmd = F_SETLK64;
-            break;
-        default:
-            cmd = arg2;
-            break;
-        }
+	cmd = target_to_host_fcntl_cmd(arg2);
+	if (cmd == -TARGET_EINVAL)
+		return cmd;
 
         switch(arg2) {
         case TARGET_F_GETLK64:
@@ -6315,7 +6353,7 @@ abi_long do_syscall(void *cpu_env, int n
             ret = get_errno(fcntl(arg1, cmd, &fl));
 	    break;
         default:
-            ret = do_fcntl(arg1, cmd, arg3);
+            ret = do_fcntl(arg1, arg2, arg3);
             break;
         }
 	break;
Index: qemu/linux-user/syscall_defs.h
===================================================================
--- qemu.orig/linux-user/syscall_defs.h
+++ qemu/linux-user/syscall_defs.h
@@ -1717,6 +1717,12 @@ struct target_statfs64 {
 #define TARGET_F_SETLKW        9
 #define TARGET_F_SETOWN        5       /*  for sockets. */
 #define TARGET_F_GETOWN        6       /*  for sockets. */
+#elif defined(TARGET_MIPS)
+#define TARGET_F_GETLK         14
+#define TARGET_F_SETLK         6
+#define TARGET_F_SETLKW        7
+#define TARGET_F_SETOWN        24       /*  for sockets. */
+#define TARGET_F_GETOWN        25       /*  for sockets. */
 #else
 #define TARGET_F_GETLK         5
 #define TARGET_F_SETLK         6
@@ -1728,10 +1734,15 @@ struct target_statfs64 {
 #define TARGET_F_SETSIG        10      /*  for sockets. */
 #define TARGET_F_GETSIG        11      /*  for sockets. */
 
+#if defined(TARGET_MIPS)
+#define TARGET_F_GETLK64       33      /*  using 'struct flock64' */
+#define TARGET_F_SETLK64       34
+#define TARGET_F_SETLKW64      35
+#else
 #define TARGET_F_GETLK64       12      /*  using 'struct flock64' */
 #define TARGET_F_SETLK64       13
 #define TARGET_F_SETLKW64      14
-
+#endif
 #if defined (TARGET_ARM)
 #define TARGET_O_ACCMODE          0003
 #define TARGET_O_RDONLY             00

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] RFC: fix fcntl support in linux-user - new try
  2009-06-03 12:47 Laurent Vivier
@ 2009-06-03 13:09 ` Arnaud Patard
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaud Patard @ 2009-06-03 13:09 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-devel

Laurent Vivier <laurent@vivier.eu> writes:

Hi,

>>Hi,
>>
>>This is a new try to fix the fcntl support in linux-user. I tried to
>>adress all comments but as the previous version is several weeks old,
>>it's possible that I've missed some.
>>
>>This patch doesn't handle linux specific fcntl flags. My plan is to get
>>this version of the patch reviewed/fixed and then, add them if wanted.
>>
>>Thanks,
>>Arnaud
>>
>
> I didn't follow the discussion, but for target_to_host_fnctl_cmd(), why not an array like host_to_target_signal_table[], in linux-user/signal.c ?

See the thread at
http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01208.html.

I was using an array but the problem is that it doesn't check for all
possible wrong input. For instance you may end up passing 0 as command
which is not want you want if the flag is not F_DUPFD.


Arnaud

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [Qemu-devel] [PATCH] RFC: fix fcntl support in linux-user - new try
@ 2009-06-03 12:47 Laurent Vivier
  2009-06-03 13:09 ` Arnaud Patard
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Vivier @ 2009-06-03 12:47 UTC (permalink / raw)
  To: qemu-devel, arnaud.patard

>Hi,
>
>This is a new try to fix the fcntl support in linux-user. I tried to
>adress all comments but as the previous version is several weeks old,
>it's possible that I've missed some.
>
>This patch doesn't handle linux specific fcntl flags. My plan is to get
>this version of the patch reviewed/fixed and then, add them if wanted.
>
>Thanks,
>Arnaud
>

I didn't follow the discussion, but for target_to_host_fnctl_cmd(), why not an array like host_to_target_signal_table[], in linux-user/signal.c ?

Laurent
-- 
--------------------- Laurent@vivier.eu  ---------------------
"Tout ce qui est impossible reste à accomplir"    Jules Verne
"Things are only impossible until they're not" Jean-Luc Picard

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-06-03 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-03 12:35 [Qemu-devel] [PATCH] RFC: fix fcntl support in linux-user - new try Arnaud Patard
2009-06-03 12:47 Laurent Vivier
2009-06-03 13:09 ` Arnaud Patard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.