Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Diuw5-0005qd-07 for qemu-devel@nongnu.org; Thu, 16 Jun 2005 10:01:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Diuvs-0005jr-CP for qemu-devel@nongnu.org; Thu, 16 Jun 2005 10:01:26 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Diuvs-0005jo-8S for qemu-devel@nongnu.org; Thu, 16 Jun 2005 10:01:24 -0400 Received: from [62.236.91.5] (helo=dmgw.movial.fi) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1Diung-0001KF-Px for qemu-devel@nongnu.org; Thu, 16 Jun 2005 09:52:57 -0400 From: Timo Savola Content-Type: multipart/mixed; boundary="=-fuvsCSWTX/2lazTUJWhr" Date: Thu, 16 Jun 2005 16:51:05 +0300 Message-Id: <1118929865.5109.7.camel@sd023.hel.movial.fi> Mime-Version: 1.0 Subject: [Qemu-devel] [PATCH] Various patches from Scratchbox Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fabrice@bellard.org, qemu-devel@nongnu.org --=-fuvsCSWTX/2lazTUJWhr Content-Type: text/plain Content-Transfer-Encoding: 7bit Hello. Here's a bunch of patches that have been developed for Scratchbox's [1] version of qemu. They make it possible to run the ARM version of the maemo [2] platform. [1] http://scratchbox.org/ [2] http://maemo.org/ The patches have been made against qemu 0.7.0, and most of them are specific to user-mode emulation. Some of them are quite evil, but I've included them for educational reasons... The following files are attached: * evil-dlclose.patch Description: This patch fixes dlopen/dlclose issues with qemu. It flags every close call and flushes the code gen buffer thus causing some performance hit. Author: Valtteri Rahkonen * ipc.patch Description: Implements SysV IPC message and semaphore IPC calls. Author: Valtteri Rahkonen * proc-hack.patch Description: Implements a /proc/self/exe readlink hack; it returns the emulated binary instead of qemu. Author: Valtteri Rahkonen * sigaction.patch Description: This patch fixes emulated sigaction behaviour with invalid signal parameters SIGKILL and SIGSTOP. EINVAL is returned for these signals. Author: Valtteri Rahkonen * sigsilent.patch Description: Modifies signal handling so that uncaught signal message is not printed to stderr. (This would screw up some applications that wants to kill their siblings...) Author: Valtteri Rahkonen * socketcall.patch Description: Fixes AF_UNIX sockets' address structure length handling so that UNIX sockets can be used. Author: Timo Savola * socketopt.patch Description: Implements SO_LINGER, SO_RCVTIMEO, SO_SNDTIMEO, SO_PEERNAME and SO_PEERCRED getsockoptions. Author: Valtteri Rahkonen * solinger-setsockopt.patch Description: Implements SO_LINGER setsockoption which is needed by some network applications. Author: Valtteri Rahkonen * sysctl.patch Description: Implements kernel version query using the sysctl syscall. Author: Timo Savola * tcpip-sockopt.patch Description: Implements the SOL_IP/IP_TOS option for setsockopt and SOL_TCP/TCP_NODELAY option for getsockopt. Author: Timo Savola * truncate64.patch Description: Implements truncate64 syscall. Author: Valtteri Rahkonen We also use the following patches by Ulrich Hecht (posted previously to qemu-devel): * qemu-arm-sigfpe.patch * qemu-jobsignals.patch * qemu-sigaltstackhack.patch * qemu-syscalls.patch timo --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=evil-dlclose.patch Content-Type: text/x-patch; name=evil-dlclose.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/main.c 2005-05-04 13:38:41.942234771 +0300 +++ linux-user/main.c 2005-05-04 10:44:52.851592991 +0300 @@ -25,4 +25,7 @@ #include #include "qemu.h" +#include "exec-all.h" + +int flush_close; @@ -467,6 +470,12 @@ abort(); } process_pending_signals(env); + + if (flush_close) + { + tb_flush(env); + flush_close = 0; + } } } @@ -1150,6 +1159,8 @@ if (argc <= 1) usage(); + flush_close = 0; + /* init debug */ cpu_set_log_filename(DEBUG_LOGFILE); --- linux-user/qemu.h 2005-05-04 13:38:41.894241261 +0300 +++ linux-user/qemu.h 2005-05-04 10:44:52.838594744 +0300 @@ -15,4 +15,6 @@ +extern int flush_close; + /* This struct is used to hold certain information about the image. * Basically, it replicates in user space what would be certain * task_struct fields in the kernel --- linux-user/syscall.c 2005-05-04 13:38:41.953233283 +0300 +++ linux-user/syscall.c 2005-05-04 12:59:27.226329045 +0300 @@ -1721,7 +1721,24 @@ arg3)); break; case TARGET_NR_close: + { + struct stat buf; + + ret = fstat(arg1, &buf); + + if ((ret == 0) && (S_ISREG(buf.st_mode)) && (buf.st_mode & S_IRUSR)) + { + char str[EI_PAD]; + + if (lseek(arg1, 0, SEEK_SET) != (off_t)-1) + if (read(arg1, str, EI_PAD) > 0) + if (str[EI_MAG0] == ELFMAG0 && str[EI_MAG1] == ELFMAG1 && + str[EI_MAG1] == ELFMAG1 && str[EI_MAG3] == ELFMAG3) + flush_close = 1; + } + ret = get_errno(close(arg1)); + } break; case TARGET_NR_brk: ret = do_brk((char *)arg1); --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=ipc.patch Content-Type: text/x-patch; name=ipc.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c 2005-04-26 10:01:22.771568612 +0300 +++ linux-user/syscall.c 2005-04-26 10:03:21.850447511 +0300 @@ -41,7 +41,10 @@ #include #include #include +#include #include +#include +#include #include #include //#include @@ -906,7 +909,6 @@ return ret; } - #define N_SHM_REGIONS 32 static struct shm_region { @@ -914,6 +916,14 @@ uint32_t size; } shm_regions[N_SHM_REGIONS]; +union semunion { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short *array; /* array for GETALL, SETALL */ + /* Linux specific part: */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; + static long do_ipc(long call, long first, long second, long third, long ptr, long fifth) { @@ -927,6 +937,53 @@ call &= 0xffff; switch (call) { + case IPCOP_semop: + ret = get_errno(semop(first,(struct sembuf *) ptr, second)); + break; + + case IPCOP_semget: + ret = get_errno(semget(first, second, third)); + break; + + case IPCOP_semctl: + /* We use syscall directly to avoid c-librarys __IPC_64 hacks */ + ret = syscall(__NR_ipc, IPCOP_semctl, first, + second, third, ptr); + break; + + case IPCOP_semtimedop: + gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version); + ret = -ENOSYS; + break; + + case IPCOP_msgget: + ret = get_errno(msgget(first, second)); + break; + + case IPCOP_msgsnd: + ret = get_errno(msgsnd(first, (struct msgbuf *) ptr, second, third)); + break; + + case IPCOP_msgctl: + ret = get_errno(msgctl(first, second, (struct msqid_ds *) ptr)); + break; + + case IPCOP_msgrcv: + { + struct ipc_kludge + { + void *__unbounded msgp; + long int msgtyp; + }; + + struct ipc_kludge *foo = (struct ipc_kludge *) ptr; + struct msgbuf *msgp = (struct msgbuf *) foo->msgp; + + ret = get_errno(msgrcv(first, msgp, second, 0, third)); + + } + break; + case IPCOP_shmat: /* SHM_* flags are the same on all linux platforms */ ret = get_errno((long) shmat(first, (void *) ptr, second)); @@ -955,6 +1012,7 @@ return -EFAULT; ret = 0; break; + case IPCOP_shmdt: for (i = 0; i < N_SHM_REGIONS; ++i) { if (shm_regions[i].start == ptr) { @@ -980,15 +1038,17 @@ ret = get_errno(shmctl(first, second, NULL)); break; default: - goto unimplemented; + ret = get_errno(shmctl(first, second, (struct shmid_ds *) ptr)); + break; } break; + default: - unimplemented: gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version); ret = -ENOSYS; break; } + return ret; } --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=proc-hack.patch Content-Type: text/x-patch; name=proc-hack.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/main.c 2005-04-20 12:09:42.788531487 +0300 +++ linux-user/main.c 2005-04-20 12:00:43.541291763 +0300 @@ -25,6 +25,8 @@ #include #include "qemu.h" + +char *exec_path; #define DEBUG_LOGFILE "/tmp/qemu.log" @@ -1139,6 +1167,7 @@ if (optind >= argc) usage(); filename = argv[optind]; + exec_path = argv[optind]; modify_env(); --- linux-user/qemu.h 2005-02-07 14:35:39.000000000 +0200 +++ linux-user/qemu.h 2005-04-20 11:59:20.800454961 +0300 @@ -9,7 +9,9 @@ #include "cpu.h" #include "syscall.h" #include "gdbstub.h" + +extern char *exec_path; /* This struct is used to hold certain information about the image. * Basically, it replicates in user space what would be certain --- linux-user/syscall.c 2005-04-20 12:09:42.800529869 +0300 +++ linux-user/syscall.c 2005-04-20 11:58:08.643189872 +0300 @@ -2282,6 +2279,9 @@ goto unimplemented; #endif case TARGET_NR_readlink: - ret = get_errno(readlink(path((const char *)arg1), (char *)arg2, arg3)); - break; + if (strncmp((const char *)arg1, "/proc/self/exe", 14) == 0) + ret = get_errno(snprintf((char *)arg2, arg3, "%s", exec_path)); + else + ret = get_errno(readlink(path((const char *)arg1), (char *)arg2, arg3)); + break; case TARGET_NR_uselib: --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=sigaction.patch Content-Type: text/x-patch; name=sigaction.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/signal.c 2005-04-27 09:44:53.534806341 +0300 +++ linux-user/signal.c 2005-04-27 09:42:52.325180111 +0300 @@ -417,6 +417,11 @@ if (sig < 1 || sig > TARGET_NSIG) return -EINVAL; + + /* no point doing the stuff as those are not allowed for sigaction */ + if ((sig == TARGET_SIGKILL) || (sig == TARGET_SIGSTOP)) + return -EINVAL; + k = &sigact_table[sig - 1]; #if defined(DEBUG_SIGNAL) fprintf(stderr, "sigaction sig=%d act=0x%08x, oact=0x%08x\n", --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=sigsilent.patch Content-Type: text/x-patch; name=sigsilent.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/signal.c 2005-04-25 14:55:48.826983293 +0300 +++ linux-user/signal.c 2005-04-25 14:55:39.165288148 +0300 @@ -310,20 +310,8 @@ { int host_sig; host_sig = target_to_host_signal(sig); - fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n", - sig, strsignal(host_sig)); -#if 1 + _exit(-host_sig); -#else - { - struct sigaction act; - sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = SIG_DFL; - sigaction(SIGABRT, &act, NULL); - abort(); - } -#endif } /* queue a signal so that it will be send to the virtual CPU as soon --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=socketcall.patch Content-Type: text/x-patch; name=socketcall.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c 1 Mar 2005 22:32:06 -0000 1.58 +++ linux-user/syscall.c 18 Mar 2005 10:17:09 -0000 @@ -47,6 +47,7 @@ //#include #include #include +#include #define termios host_termios #define winsize host_winsize @@ -427,12 +428,17 @@ static long do_select(long n, return ret; } -static inline void target_to_host_sockaddr(struct sockaddr *addr, - struct target_sockaddr *target_addr, - socklen_t len) +static inline socklen_t target_to_host_sockaddr(struct sockaddr *addr, + struct target_sockaddr *target_addr, + socklen_t len) { memcpy(addr, target_addr, len); addr->sa_family = tswap16(target_addr->sa_family); + + if (addr->sa_family == AF_UNIX) + return sizeof (struct sockaddr_un); + + return len; } static inline void host_to_target_sockaddr(struct target_sockaddr *target_addr, @@ -668,7 +679,7 @@ static long do_socketcall(int num, int32 socklen_t addrlen = tswap32(vptr[2]); void *addr = alloca(addrlen); - target_to_host_sockaddr(addr, target_addr, addrlen); + addrlen = target_to_host_sockaddr(addr, target_addr, addrlen); ret = get_errno(bind(sockfd, addr, addrlen)); } break; @@ -679,7 +690,7 @@ static long do_socketcall(int num, int32 socklen_t addrlen = tswap32(vptr[2]); void *addr = alloca(addrlen); - target_to_host_sockaddr(addr, target_addr, addrlen); + addrlen = target_to_host_sockaddr(addr, target_addr, addrlen); ret = get_errno(connect(sockfd, addr, addrlen)); } break; @@ -781,7 +792,7 @@ static long do_socketcall(int num, int32 socklen_t addrlen = tswap32(vptr[5]); void *addr = alloca(addrlen); - target_to_host_sockaddr(addr, target_addr, addrlen); + addrlen = target_to_host_sockaddr(addr, target_addr, addrlen); ret = get_errno(sendto(sockfd, msg, len, flags, addr, addrlen)); } break; --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=socketopt.patch Content-Type: text/x-patch; name=socketopt.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c 2005-04-20 10:49:39.388477429 +0300 +++ linux-user/syscall.c 2005-04-20 10:11:13.000000000 +0300 @@ -633,10 +630,21 @@ case SO_LINGER: case SO_RCVTIMEO: case SO_SNDTIMEO: - case SO_PEERCRED: case SO_PEERNAME: /* These don't just return a single integer */ - goto unimplemented; + if (get_user(len, optlen)) + return -EFAULT; + if (len < 0) + return -EINVAL; + ret = get_errno(getsockopt(sockfd, level, optname, optval, &len)); + if (put_user(len, optlen)) + return -EFAULT; + break; + + case SO_PEERCRED: + ret = get_errno(getsockopt(sockfd, level, optname, optval, optlen)); + break; + default: if (get_user(len, optlen)) return -EFAULT; --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=solinger-setsockopt.patch Content-Type: text/x-patch; name=solinger-setsockopt.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c 2005-04-29 13:18:29.426544844 +0300 +++ linux-user/syscall.c 2005-04-29 13:18:23.786305197 +0300 @@ -603,12 +603,26 @@ case SO_RCVLOWAT: case SO_RCVTIMEO: case SO_SNDTIMEO: + if (optlen < sizeof(uint32_t)) return -EINVAL; if (get_user(val, (uint32_t *)optval)) return -EFAULT; ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); break; + + case SO_LINGER: + { + struct linger tmp; + struct linger *target = (struct linger *) optval; + + tmp.l_onoff = tswapl(target->l_onoff); + tmp.l_linger = tswapl(target->l_linger); + + ret = get_errno(setsockopt(sockfd, level, optname, &tmp, sizeof(struct linger))); + } + break; + default: goto unimplemented; } --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=sysctl.patch Content-Type: text/x-patch; name=sysctl.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c.orig 2004-04-27 00:17:28.000000000 +0300 +++ linux-user/syscall.c 2004-04-27 11:02:20.000000000 +0300 @@ -51,6 +51,7 @@ #include #include #include +#include #define termios host_termios #define winsize host_winsize @@ -2572,9 +2573,31 @@ ret = get_errno(fdatasync(arg1)); break; case TARGET_NR__sysctl: - /* We don't implement this, but ENODIR is always a safe - return value. */ - return -ENOTDIR; + { + struct __sysctl_args *args = (struct __sysctl_args *) arg1; + int *name, nlen, *oldlenp, oldlen, newlen; + void *oldval, *newval; + + name = (int *) tswapl((long) args->name); + nlen = tswapl(args->nlen); + oldval = (void *) tswapl((long) args->oldval); + oldlenp = (int *) tswapl((long) args->oldlenp); + oldlen = tswapl(*oldlenp); + newval = (void *) tswapl((long) args->newval); + newlen = tswapl(args->newlen); + + if (nlen == 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION) { + ret = get_errno( + sysctl(name, nlen, oldval, &oldlen, newval, newlen)); + if (!is_error(ret)) { + *oldlenp = tswapl(oldlen); + } + } else { + gemu_log("qemu: Unsupported sysctl name\n"); + ret = -ENOSYS; + } + } + break; case TARGET_NR_sched_setparam: { struct sched_param *target_schp = (void *)arg2; --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=tcpip-sockopt.patch Content-Type: text/x-patch; name=tcpip-sockopt.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- linux-user/syscall.c 2005-05-31 11:32:12.000000000 +0300 +++ linux-user/syscall.c 2005-06-02 13:30:54.225627972 +0300 @@ -571,6 +571,17 @@ } ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); break; + case IP_TOS: + val = 0; + if (optlen >= sizeof(uint32_t)) { + if (get_user(val, (uint32_t *)optval)) + return -EFAULT; + } else if (optlen >= 1) { + if (get_user(val, (uint8_t *)optval)) + return -EFAULT; + } + ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); + break; default: goto unimplemented; } @@ -675,6 +686,22 @@ break; } break; + case SOL_TCP: + switch (optname) { + case TCP_NODELAY: + if (get_user(len, (uint32_t *)optlen)) + return -EFAULT; + if (len < 0) + return -EINVAL; + ret = get_errno(getsockopt(sockfd, level, optname, optval, &len)); + if (put_user(len, optlen)) + return -EFAULT; + break; + + default: + goto unimplemented; + } + break; default: unimplemented: gemu_log("getsockopt level=%d optname=%d not yet supported\n", --=-fuvsCSWTX/2lazTUJWhr Content-Disposition: attachment; filename=truncate64.patch Content-Type: text/x-patch; name=truncate64.patch; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit diff -Nru linux-user/syscall.c linux-user/syscall.c --- linux-user/syscall.c 2005-03-23 10:56:59.000000000 +0200 +++ linux-user/syscall.c 2005-03-23 11:22:58.000000000 +0200 @@ -2894,7 +2894,8 @@ #endif #ifdef TARGET_NR_truncate64 case TARGET_NR_truncate64: - goto unimplemented; + ret = get_errno(truncate64((const char *)arg1, arg2)); + break; #endif #ifdef TARGET_NR_ftruncate64 case TARGET_NR_ftruncate64: --=-fuvsCSWTX/2lazTUJWhr--