Fabrice Bellard wrote:
Another point is that doing:

+    target_long args[6];
+
+    tputl(args, arg1);
+    tputl(args+1, arg2);
+    tputl(args+2, arg3);
+    tputl(args+3, arg4);
+    tputl(args+4, arg5);
+    tputl(args+5, arg6);

at the start of every syscall is not acceptable. You should add a specific socket call wrapper which takes arg1... arg6 as arguments.

Regards,

Fabrice.
Thanks for reviewing it, the new attached version should be much cleaner.

Regards,
Raphaël

Index: linux-user/qemu.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/qemu.h,v
retrieving revision 1.28
diff -u -r1.28 qemu.h
--- linux-user/qemu.h   17 Jun 2006 18:30:42 -0000      1.28
+++ linux-user/qemu.h   20 Jun 2006 08:46:54 -0000
@@ -6,6 +6,7 @@
 #include <signal.h>
 #include <string.h>
 #include "syscall_defs.h"
+#include "socket.h"
 
 #include "cpu.h"
 #include "syscall.h"
Index: linux-user/socket.h
===================================================================
RCS file: linux-user/socket.h
diff -N linux-user/socket.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ linux-user/socket.h 20 Jun 2006 08:46:55 -0000
@@ -0,0 +1,138 @@
+
+#if defined(TARGET_MIPS)
+       // MIPS special values for constants
+
+       /*
+        * For setsockopt(2)
+        *
+        * This defines are ABI conformant as far as Linux supports these ...
+        */
+       #define TARGET_SOL_SOCKET      0xffff
+
+       #define TARGET_SO_DEBUG        0x0001  /* Record debugging information. 
 */
+       #define TARGET_SO_REUSEADDR    0x0004  /* Allow reuse of local 
addresses.  */
+       #define TARGET_SO_KEEPALIVE    0x0008  /* Keep connections alive and 
send
+                                         SIGPIPE when they die.  */
+       #define TARGET_SO_DONTROUTE    0x0010  /* Don't do local routing.  */
+       #define TARGET_SO_BROADCAST    0x0020  /* Allow transmission of
+                                         broadcast messages.  */
+       #define TARGET_SO_LINGER       0x0080  /* Block on close of a reliable
+                                         socket to transmit pending data.  */
+       #define TARGET_SO_OOBINLINE 0x0100     /* Receive out-of-band data 
in-band.  */
+       #if 0
+       To add: #define TARGET_SO_REUSEPORT 0x0200     /* Allow local address 
and port reuse.  */
+       #endif
+
+       #define TARGET_SO_TYPE         0x1008  /* Compatible name for SO_STYLE. 
 */
+       #define TARGET_SO_STYLE        SO_TYPE /* Synonym */
+       #define TARGET_SO_ERROR        0x1007  /* get error status and clear */
+       #define TARGET_SO_SNDBUF       0x1001  /* Send buffer size. */
+       #define TARGET_SO_RCVBUF       0x1002  /* Receive buffer. */
+       #define TARGET_SO_SNDLOWAT     0x1003  /* send low-water mark */
+       #define TARGET_SO_RCVLOWAT     0x1004  /* receive low-water mark */
+       #define TARGET_SO_SNDTIMEO     0x1005  /* send timeout */
+       #define TARGET_SO_RCVTIMEO     0x1006  /* receive timeout */
+       #define TARGET_SO_ACCEPTCONN   0x1009
+
+       /* linux-specific, might as well be the same as on i386 */
+       #define TARGET_SO_NO_CHECK     11
+       #define TARGET_SO_PRIORITY     12
+       #define TARGET_SO_BSDCOMPAT    14
+
+       #define TARGET_SO_PASSCRED     17
+       #define TARGET_SO_PEERCRED     18
+
+       /* Security levels - as per NRL IPv6 - don't actually do anything */
+       #define TARGET_SO_SECURITY_AUTHENTICATION              22
+       #define TARGET_SO_SECURITY_ENCRYPTION_TRANSPORT        23
+       #define TARGET_SO_SECURITY_ENCRYPTION_NETWORK          24
+
+       #define TARGET_SO_BINDTODEVICE         25
+
+       /* Socket filtering */
+       #define TARGET_SO_ATTACH_FILTER        26
+       #define TARGET_SO_DETACH_FILTER        27
+
+       #define TARGET_SO_PEERNAME             28
+       #define TARGET_SO_TIMESTAMP            29
+       #define SCM_TIMESTAMP          SO_TIMESTAMP
+
+       #define TARGET_SO_PEERSEC              30
+       #define TARGET_SO_SNDBUFFORCE          31
+       #define TARGET_SO_RCVBUFFORCE          33
+
+       /** sock_type - Socket types
+        *
+        * Please notice that for binary compat reasons MIPS has to
+        * override the enum sock_type in include/linux/net.h, so
+        * we define ARCH_HAS_SOCKET_TYPES here.
+        *
+        * @SOCK_DGRAM - datagram (conn.less) socket
+        * @SOCK_STREAM - stream (connection) socket
+        * @SOCK_RAW - raw socket
+        * @SOCK_RDM - reliably-delivered message
+        * @SOCK_SEQPACKET - sequential packet socket
+        * @SOCK_PACKET - linux specific way of getting packets at the dev 
level.
+        *               For writing rarp and other similar things on the user 
level.
+        */
+       enum sock_type {
+              TARGET_SOCK_DGRAM       = 1,
+              TARGET_SOCK_STREAM      = 2,
+              TARGET_SOCK_RAW = 3,
+              TARGET_SOCK_RDM = 4,
+              TARGET_SOCK_SEQPACKET   = 5,
+              TARGET_SOCK_DCCP        = 6,
+              TARGET_SOCK_PACKET      = 10,
+       };
+
+       #define TARGET_SOCK_MAX (SOCK_PACKET + 1)
+
+#else
+
+       /* For setsockopt(2) */
+       #define TARGET_SOL_SOCKET      1
+
+       #define TARGET_SO_DEBUG        1
+       #define TARGET_SO_REUSEADDR    2
+       #define TARGET_SO_TYPE         3
+       #define TARGET_SO_ERROR        4
+       #define TARGET_SO_DONTROUTE    5
+       #define TARGET_SO_BROADCAST    6
+       #define TARGET_SO_SNDBUF       7
+       #define TARGET_SO_RCVBUF       8
+       #define TARGET_SO_SNDBUFFORCE  32
+       #define TARGET_SO_RCVBUFFORCE  33
+       #define TARGET_SO_KEEPALIVE    9
+       #define TARGET_SO_OOBINLINE    10
+       #define TARGET_SO_NO_CHECK     11
+       #define TARGET_SO_PRIORITY     12
+       #define TARGET_SO_LINGER       13
+       #define TARGET_SO_BSDCOMPAT    14
+       /* To add :#define TARGET_SO_REUSEPORT 15 */
+       #define TARGET_SO_PASSCRED     16
+       #define TARGET_SO_PEERCRED     17
+       #define TARGET_SO_RCVLOWAT     18
+       #define TARGET_SO_SNDLOWAT     19
+       #define TARGET_SO_RCVTIMEO     20
+       #define TARGET_SO_SNDTIMEO     21
+
+       /* Security levels - as per NRL IPv6 - don't actually do anything */
+       #define TARGET_SO_SECURITY_AUTHENTICATION              22
+       #define TARGET_SO_SECURITY_ENCRYPTION_TRANSPORT        23
+       #define TARGET_SO_SECURITY_ENCRYPTION_NETWORK          24
+
+       #define TARGET_SO_BINDTODEVICE 25
+
+       /* Socket filtering */
+       #define TARGET_SO_ATTACH_FILTER        26
+       #define TARGET_SO_DETACH_FILTER        27
+
+       #define TARGET_SO_PEERNAME             28
+       #define TARGET_SO_TIMESTAMP            29
+       #define TARGET_SCM_TIMESTAMP           TARGET_SO_TIMESTAMP
+
+       #define TARGET_SO_ACCEPTCONN           30
+
+       #define TARGET_SO_PEERSEC              31
+
+#endif
Index: linux-user/syscall.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/syscall.c,v
retrieving revision 1.72
diff -u -r1.72 syscall.c
--- linux-user/syscall.c        14 Jun 2006 13:36:59 -0000      1.72
+++ linux-user/syscall.c        20 Jun 2006 08:46:55 -0000
@@ -446,7 +446,7 @@
         cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
         cmsg->cmsg_len = CMSG_LEN(len);
 
-        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != 
SCM_RIGHTS) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, 
cmsg->cmsg_type);
             memcpy(data, target_data, len);
         } else {
@@ -490,7 +490,7 @@
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != 
SCM_RIGHTS) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, 
cmsg->cmsg_type);
             memcpy(target_data, data, len);
         } else {
@@ -552,38 +552,74 @@
             goto unimplemented;
         }
         break;
-    case SOL_SOCKET:
+    case TARGET_SOL_SOCKET:
         switch (optname) {
             /* Options with 'int' argument.  */
-        case SO_DEBUG:
-        case SO_REUSEADDR:
-        case SO_TYPE:
-        case SO_ERROR:
-        case SO_DONTROUTE:
-        case SO_BROADCAST:
-        case SO_SNDBUF:
-        case SO_RCVBUF:
-        case SO_KEEPALIVE:
-        case SO_OOBINLINE:
-        case SO_NO_CHECK:
-        case SO_PRIORITY:
+        case TARGET_SO_DEBUG:
+               optname = SO_DEBUG;
+               break;
+        case TARGET_SO_REUSEADDR:
+               optname = SO_REUSEADDR;
+               break;
+        case TARGET_SO_TYPE:
+               optname = SO_TYPE;
+               break;
+        case TARGET_SO_ERROR:
+               optname = SO_ERROR;
+               break;
+        case TARGET_SO_DONTROUTE:
+               optname = SO_DONTROUTE;
+               break;
+        case TARGET_SO_BROADCAST:
+               optname = SO_BROADCAST;
+               break;
+        case TARGET_SO_SNDBUF:
+               optname = SO_SNDBUF;
+               break;
+        case TARGET_SO_RCVBUF:
+               optname = SO_RCVBUF;
+               break;
+        case TARGET_SO_KEEPALIVE:
+               optname = SO_KEEPALIVE;
+               break;
+        case TARGET_SO_OOBINLINE:
+               optname = SO_OOBINLINE;
+               break;
+        case TARGET_SO_NO_CHECK:
+               optname = SO_NO_CHECK;
+               break;
+        case TARGET_SO_PRIORITY:
+               optname = SO_PRIORITY;
+               break;
 #ifdef SO_BSDCOMPAT
-        case SO_BSDCOMPAT:
+        case TARGET_SO_BSDCOMPAT:
+               optname = SO_BSDCOMPAT;
+               break;
 #endif
-        case SO_PASSCRED:
-        case SO_TIMESTAMP:
-        case SO_RCVLOWAT:
-        case SO_RCVTIMEO:
-        case SO_SNDTIMEO:
-            if (optlen < sizeof(uint32_t))
-                return -EINVAL;
-
-            val = tget32(optval);
-            ret = get_errno(setsockopt(sockfd, level, optname, &val, 
sizeof(val)));
+        case TARGET_SO_PASSCRED:
+               optname = SO_PASSCRED;
+               break;
+        case TARGET_SO_TIMESTAMP:
+               optname = SO_TIMESTAMP;
+               break;
+        case TARGET_SO_RCVLOWAT:
+               optname = SO_RCVLOWAT;
+               break;
+        case TARGET_SO_RCVTIMEO:
+               optname = SO_RCVTIMEO;
+               break;
+        case TARGET_SO_SNDTIMEO:
+               optname = SO_SNDTIMEO;
+               break;
             break;
         default:
             goto unimplemented;
         }
+       if (optlen < sizeof(uint32_t))
+       return -EINVAL;
+
+       val = tget32(optval);
+       ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, 
sizeof(val)));
         break;
     default:
     unimplemented:
@@ -599,13 +635,14 @@
     int len, lv, val, ret;
 
     switch(level) {
-    case SOL_SOCKET:
+    case TARGET_SOL_SOCKET:
+       level = SOL_SOCKET;
        switch (optname) {
-       case SO_LINGER:
-       case SO_RCVTIMEO:
-       case SO_SNDTIMEO:
-       case SO_PEERCRED:
-       case SO_PEERNAME:
+       case TARGET_SO_LINGER:
+       case TARGET_SO_RCVTIMEO:
+       case TARGET_SO_SNDTIMEO:
+       case TARGET_SO_PEERCRED:
+       case TARGET_SO_PEERNAME:
            /* These don't just return a single integer */
            goto unimplemented;
         default:
@@ -723,6 +760,29 @@
             int type = tgetl(vptr + n);
             int protocol = tgetl(vptr + 2 * n);
 
+#if defined(TARGET_MIPS)
+           switch(type) {
+                       case TARGET_SOCK_DGRAM:
+                               type = SOCK_DGRAM;
+                               break;
+                       case TARGET_SOCK_STREAM:
+                               type = SOCK_STREAM;
+                               break;
+                       case TARGET_SOCK_RAW:
+                               type = SOCK_RAW;
+                               break;
+                       case TARGET_SOCK_RDM:
+                               type = SOCK_RDM;
+                               break;
+                       case TARGET_SOCK_SEQPACKET:
+                               type = SOCK_SEQPACKET;
+                               break;
+                       case TARGET_SOCK_PACKET:
+                               type = SOCK_PACKET;
+                               break;
+           }
+#endif
+
             ret = get_errno(socket(domain, type, protocol));
        }
         break;
@@ -968,6 +1028,21 @@
 }
 
 
+static long do_socketcallwrapper(int num, long arg1, long arg2, long arg3,
+                                long arg4, long arg5, long arg6)
+{
+    target_long args[6];
+
+    tputl(args, arg1);
+    tputl(args+1, arg2);
+    tputl(args+2, arg3);
+    tputl(args+3, arg4);
+    tputl(args+4, arg5);
+    tputl(args+5, arg6);
+
+    return do_socketcall(num, (target_ulong) args);
+}
+
 #define N_SHM_REGIONS  32
 
 static struct shm_region {
@@ -2611,6 +2686,104 @@
     case TARGET_NR_socketcall:
         ret = do_socketcall(arg1, arg2);
         break;
+
+#ifdef TARGET_NR_accept
+    case TARGET_NR_accept:
+       ret = do_socketcallwrapper(SOCKOP_accept, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_bind
+    case TARGET_NR_bind:
+       ret = do_socketcallwrapper(SOCKOP_bind, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_connect
+    case TARGET_NR_connect:
+       ret = do_socketcallwrapper(SOCKOP_connect, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_getpeername
+    case TARGET_NR_getpeername:
+       ret = do_socketcallwrapper(SOCKOP_getpeername, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_getsockname
+    case TARGET_NR_getsockname:
+       ret = do_socketcallwrapper(SOCKOP_getsockname, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_listen
+    case TARGET_NR_listen:
+       ret = do_socketcallwrapper(SOCKOP_listen, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+
+#ifdef TARGET_NR_recv
+    case TARGET_NR_recv:
+       ret = do_socketcallwrapper(SOCKOP_recv, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_recvfrom
+    case TARGET_NR_recvfrom:
+       ret = do_socketcallwrapper(SOCKOP_recvfrom, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_recvmsg
+    case TARGET_NR_recvmsg:
+       ret = do_socketcallwrapper(SOCKOP_recvmsg, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_send
+    case TARGET_NR_send:
+       ret = do_socketcallwrapper(SOCKOP_send, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_sendmsg
+    case TARGET_NR_sendmsg:
+       ret = do_socketcallwrapper(SOCKOP_sendmsg, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_sendto
+    case TARGET_NR_sendto:
+       ret = do_socketcallwrapper(SOCKOP_sendto, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_shutdown
+    case TARGET_NR_shutdown:
+       ret = do_socketcallwrapper(SOCKOP_shutdown, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_socket
+    case TARGET_NR_socket:
+       ret = do_socketcallwrapper(SOCKOP_socket, arg1, arg2, arg3, arg4, arg5, 
arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_socketpair
+    case TARGET_NR_socketpair:
+       ret = do_socketcallwrapper(SOCKOP_socketpair, arg1, arg2, arg3, arg4, 
arg5, arg6);
+       break;
+#endif
+
+#ifdef TARGET_NR_setsockopt
+    case TARGET_NR_setsockopt:
+       ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
+       break;
+#endif
+       
     case TARGET_NR_syslog:
         goto unimplemented;
     case TARGET_NR_setitimer:
_______________________________________________
Qemu-devel mailing list
Qemu-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Reply via email to