report user mode gdb exit codes (Paul Brook)
[qemu] / linux-user / syscall.c
index 37d644d..0a4f07e 100644 (file)
@@ -43,6 +43,7 @@
 #include <sys/times.h>
 #include <sys/shm.h>
 #include <utime.h>
+#include <sys/sysinfo.h>
 //#include <sys/user.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
@@ -263,7 +264,7 @@ void target_set_brk(char *new_brk)
     target_original_brk = new_brk;
 }
 
-static long do_brk(char *new_brk)
+long do_brk(char *new_brk)
 {
     char *brk_page;
     long mapped_addr;
@@ -576,7 +577,9 @@ static long do_setsockopt(int sockfd, int level, int optname,
         case SO_OOBINLINE:
         case SO_NO_CHECK:
         case SO_PRIORITY:
+#ifdef SO_BSDCOMPAT
         case SO_BSDCOMPAT:
+#endif
         case SO_PASSCRED:
         case SO_TIMESTAMP:
         case SO_RCVLOWAT:
@@ -1325,7 +1328,7 @@ static int write_ldt(CPUX86State *env,
         if (!ldt_table)
             return -ENOMEM;
         memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
-        env->ldt.base = ldt_table;
+        env->ldt.base = (long)ldt_table;
         env->ldt.limit = 0xffff;
     }
 
@@ -1600,6 +1603,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
 #ifdef HAVE_GPROF
         _mcleanup();
 #endif
+        gdb_exit(cpu_env, arg1);
         /* XXX: should free thread stack and CPU env */
         _exit(arg1);
         ret = 0; /* avoid warning */
@@ -1673,6 +1677,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
     case TARGET_NR_chdir:
         ret = get_errno(chdir((const char *)arg1));
         break;
+#ifdef TARGET_NR_time
     case TARGET_NR_time:
         {
             int *time_ptr = (int *)arg1;
@@ -1681,6 +1686,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
                 tswap32s(time_ptr);
         }
         break;
+#endif
     case TARGET_NR_mknod:
         ret = get_errno(mknod((const char *)arg1, arg2, arg3));
         break;
@@ -1741,6 +1747,20 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
             ret = get_errno(utime((const char *)arg1, tbuf1));
         }
         break;
+    case TARGET_NR_utimes:
+        {
+            struct target_timeval *target_tvp = (struct target_timeval *)arg2;
+            struct timeval *tvp, tv[2];
+            if (target_tvp) {
+                target_to_host_timeval(&tv[0], &target_tvp[0]);
+                target_to_host_timeval(&tv[1], &target_tvp[1]);
+                tvp = tv;
+            } else {
+                tvp = NULL;
+            }
+            ret = get_errno(utimes((const char *)arg1, tvp));
+        }
+        break;
 #ifdef TARGET_NR_stty
     case TARGET_NR_stty:
         goto unimplemented;
@@ -2153,6 +2173,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
                                     arg6));
 #endif
         break;
+#ifdef TARGET_NR_mmap2
     case TARGET_NR_mmap2:
 #if defined(TARGET_SPARC)
 #define MMAP_SHIFT 12
@@ -2164,6 +2185,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
                                     arg5,
                                     arg6 << MMAP_SHIFT));
         break;
+#endif
     case TARGET_NR_munmap:
         ret = get_errno(target_munmap(arg1, arg2));
         break;
@@ -2324,6 +2346,11 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
     case TARGET_NR_idle:
         goto unimplemented;
 #endif
+#ifdef TARGET_NR_syscall
+    case TARGET_NR_syscall:
+       ret = do_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
+       break;
+#endif
     case TARGET_NR_wait4:
         {
             int status;
@@ -2348,7 +2375,29 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
         ret = get_errno(swapoff((const char *)arg1));
         break;
     case TARGET_NR_sysinfo:
-        goto unimplemented;
+        {
+            struct target_sysinfo *target_value = (void *)arg1;
+            struct sysinfo value;
+            ret = get_errno(sysinfo(&value));
+            if (!is_error(ret) && target_value)
+            {
+                __put_user(value.uptime, &target_value->uptime);
+                __put_user(value.loads[0], &target_value->loads[0]);
+                __put_user(value.loads[1], &target_value->loads[1]);
+                __put_user(value.loads[2], &target_value->loads[2]);
+                __put_user(value.totalram, &target_value->totalram);
+                __put_user(value.freeram, &target_value->freeram);
+                __put_user(value.sharedram, &target_value->sharedram);
+                __put_user(value.bufferram, &target_value->bufferram);
+                __put_user(value.totalswap, &target_value->totalswap);
+                __put_user(value.freeswap, &target_value->freeswap);
+                __put_user(value.procs, &target_value->procs);
+                __put_user(value.totalhigh, &target_value->totalhigh);
+                __put_user(value.freehigh, &target_value->freehigh);
+                __put_user(value.mem_unit, &target_value->mem_unit);
+            }
+        }
+        break;
     case TARGET_NR_ipc:
        ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6);
        break;
@@ -2361,6 +2410,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
 #ifdef __NR_exit_group
         /* new thread calls */
     case TARGET_NR_exit_group:
+        gdb_exit(cpu_env, arg1);
         ret = get_errno(exit_group(arg1));
         break;
 #endif
@@ -2369,7 +2419,17 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
         break;
     case TARGET_NR_uname:
         /* no need to transcode because we use the linux syscall */
-        ret = get_errno(sys_uname((struct new_utsname *)arg1));
+        {
+            struct new_utsname * buf;
+    
+            buf = (struct new_utsname *)arg1;
+            ret = get_errno(sys_uname(buf));
+            if (!is_error(ret)) {
+                /* Overrite the native machine name with whatever is being
+                   emulated. */
+                strcpy (buf->machine, UNAME_MACHINE);
+            }
+        }
         break;
 #ifdef TARGET_I386
     case TARGET_NR_modify_ldt:
@@ -2419,7 +2479,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
         break;
     case TARGET_NR_getdents:
 #if TARGET_LONG_SIZE != 4
-#error not supported
+#warning not supported
 #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8
         {
             struct target_dirent *target_dirp = (void *)arg2;
@@ -2450,6 +2510,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
                    tnamelen = treclen - (2 * sizeof(target_long) + 2);
                    if (tnamelen > 256)
                         tnamelen = 256;
+                    /* XXX: may not be correct */
                    strncpy(tde->d_name, de->d_name, tnamelen);
                     de = (struct dirent *)((char *)de + reclen);
                     len -= reclen;
@@ -2577,7 +2638,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
         ret = get_errno(fdatasync(arg1));
         break;
     case TARGET_NR__sysctl:
-        goto unimplemented;
+        /* We don't implement this, but ENODIR is always a safe
+           return value. */
+        return -ENOTDIR;
     case TARGET_NR_sched_setparam:
         {
             struct sched_param *target_schp = (void *)arg2;
@@ -2691,16 +2754,25 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
        break;
     }
 #endif
+#ifdef TARGET_NR_truncate64
     case TARGET_NR_truncate64:
         goto unimplemented;
+#endif
+#ifdef TARGET_NR_ftruncate64
     case TARGET_NR_ftruncate64:
         goto unimplemented;
+#endif
+#ifdef TARGET_NR_stat64
     case TARGET_NR_stat64:
         ret = get_errno(stat(path((const char *)arg1), &st));
         goto do_stat64;
+#endif
+#ifdef TARGET_NR_lstat64
     case TARGET_NR_lstat64:
         ret = get_errno(lstat(path((const char *)arg1), &st));
         goto do_stat64;
+#endif
+#ifdef TARGET_NR_fstat64
     case TARGET_NR_fstat64:
         {
             ret = get_errno(fstat(arg1, &st));
@@ -2728,7 +2800,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
             }
         }
         break;
-
+#endif
 #ifdef USE_UID16
     case TARGET_NR_lchown:
         ret = get_errno(lchown((const char *)arg1, low2highuid(arg2), low2highgid(arg3)));
@@ -2839,37 +2911,84 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
         break;
 #endif /* USE_UID16 */
 
+#ifdef TARGET_NR_lchown32
     case TARGET_NR_lchown32:
         ret = get_errno(lchown((const char *)arg1, arg2, arg3));
         break;
+#endif
+#ifdef TARGET_NR_getuid32
     case TARGET_NR_getuid32:
         ret = get_errno(getuid());
         break;
+#endif
+#ifdef TARGET_NR_getgid32
     case TARGET_NR_getgid32:
         ret = get_errno(getgid());
         break;
+#endif
+#ifdef TARGET_NR_geteuid32
     case TARGET_NR_geteuid32:
         ret = get_errno(geteuid());
         break;
+#endif
+#ifdef TARGET_NR_getegid32
     case TARGET_NR_getegid32:
         ret = get_errno(getegid());
         break;
+#endif
+#ifdef TARGET_NR_setreuid32
     case TARGET_NR_setreuid32:
         ret = get_errno(setreuid(arg1, arg2));
         break;
+#endif
+#ifdef TARGET_NR_setregid32
     case TARGET_NR_setregid32:
         ret = get_errno(setregid(arg1, arg2));
         break;
+#endif
+#ifdef TARGET_NR_getgroups32
     case TARGET_NR_getgroups32:
-        goto unimplemented;
+        {
+            int gidsetsize = arg1;
+            uint32_t *target_grouplist = (void *)arg2;
+            gid_t *grouplist;
+            int i;
+
+            grouplist = alloca(gidsetsize * sizeof(gid_t));
+            ret = get_errno(getgroups(gidsetsize, grouplist));
+            if (!is_error(ret)) {
+                for(i = 0;i < gidsetsize; i++)
+                    put_user(grouplist[i], &target_grouplist[i]);
+            }
+        }
+        break;
+#endif
+#ifdef TARGET_NR_setgroups32
     case TARGET_NR_setgroups32:
-        goto unimplemented;
+        {
+            int gidsetsize = arg1;
+            uint32_t *target_grouplist = (void *)arg2;
+            gid_t *grouplist;
+            int i;
+            
+            grouplist = alloca(gidsetsize * sizeof(gid_t));
+            for(i = 0;i < gidsetsize; i++)
+                get_user(grouplist[i], &target_grouplist[i]);
+            ret = get_errno(setgroups(gidsetsize, grouplist));
+        }
+        break;
+#endif
+#ifdef TARGET_NR_fchown32
     case TARGET_NR_fchown32:
         ret = get_errno(fchown(arg1, arg2, arg3));
         break;
+#endif
+#ifdef TARGET_NR_setresuid32
     case TARGET_NR_setresuid32:
         ret = get_errno(setresuid(arg1, arg2, arg3));
         break;
+#endif
+#ifdef TARGET_NR_getresuid32
     case TARGET_NR_getresuid32:
         {
             int ruid, euid, suid;
@@ -2881,9 +3000,13 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
             }
         }
         break;
+#endif
+#ifdef TARGET_NR_setresgid32
     case TARGET_NR_setresgid32:
         ret = get_errno(setresgid(arg1, arg2, arg3));
         break;
+#endif
+#ifdef TARGET_NR_getresgid32
     case TARGET_NR_getresgid32:
         {
             int rgid, egid, sgid;
@@ -2895,21 +3018,32 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
             }
         }
         break;
+#endif
+#ifdef TARGET_NR_chown32
     case TARGET_NR_chown32:
         ret = get_errno(chown((const char *)arg1, arg2, arg3));
         break;
+#endif
+#ifdef TARGET_NR_setuid32
     case TARGET_NR_setuid32:
         ret = get_errno(setuid(arg1));
         break;
+#endif
+#ifdef TARGET_NR_setgid32
     case TARGET_NR_setgid32:
         ret = get_errno(setgid(arg1));
         break;
+#endif
+#ifdef TARGET_NR_setfsuid32
     case TARGET_NR_setfsuid32:
         ret = get_errno(setfsuid(arg1));
         break;
+#endif
+#ifdef TARGET_NR_setfsgid32
     case TARGET_NR_setfsgid32:
         ret = get_errno(setfsgid(arg1));
         break;
+#endif
 
     case TARGET_NR_pivot_root:
         goto unimplemented;
@@ -2992,7 +3126,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
+#if defined(TARGET_NR_setxattr) || defined(TARGET_NR_set_thread_area)
     unimplemented_nowarn:
+#endif
         ret = -ENOSYS;
         break;
     }