Revision 5fafdf24 linux-user/syscall.c

b/linux-user/syscall.c
1 1
/*
2 2
 *  Linux syscalls
3
 * 
3
 *
4 4
 *  Copyright (c) 2003 Fabrice Bellard
5 5
 *
6 6
 *  This program is free software; you can redistribute it and/or modify
......
339 339
        return target_brk;
340 340
    if (new_brk < target_original_brk)
341 341
        return -ENOMEM;
342
    
342
   
343 343
    brk_page = HOST_PAGE_ALIGN(target_brk);
344 344

  
345 345
    /* If the new brk is less than this, set it and we're done... */
......
350 350

  
351 351
    /* We need to allocate more memory after the brk... */
352 352
    new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
353
    mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, 
353
    mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
354 354
                                        PROT_READ|PROT_WRITE,
355 355
                                        MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0));
356 356
    if (is_error(mapped_addr)) {
......
361 361
    }
362 362
}
363 363

  
364
static inline fd_set *target_to_host_fds(fd_set *fds, 
364
static inline fd_set *target_to_host_fds(fd_set *fds,
365 365
                                         target_long *target_fds, int n)
366 366
{
367 367
#if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
......
383 383
#endif
384 384
}
385 385

  
386
static inline void host_to_target_fds(target_long *target_fds, 
386
static inline void host_to_target_fds(target_long *target_fds,
387 387
                                      fd_set *fds, int n)
388 388
{
389 389
#if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
......
472 472
}
473 473

  
474 474

  
475
static long do_select(long n, 
476
                      target_ulong rfd_p, target_ulong wfd_p, 
475
static long do_select(long n,
476
                      target_ulong rfd_p, target_ulong wfd_p,
477 477
                      target_ulong efd_p, target_ulong target_tv)
478 478
{
479 479
    fd_set rfds, wfds, efds;
......
504 504
        target_efds = NULL;
505 505
        efds_ptr = NULL;
506 506
    }
507
            
507
           
508 508
    if (target_tv) {
509 509
        target_to_host_timeval(&tv, target_tv);
510 510
        tv_ptr = &tv;
......
569 569
        void *data = CMSG_DATA(cmsg);
570 570
        void *target_data = TARGET_CMSG_DATA(target_cmsg);
571 571

  
572
        int len = tswapl(target_cmsg->cmsg_len) 
572
        int len = tswapl(target_cmsg->cmsg_len)
573 573
                  - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));
574 574

  
575 575
        space += CMSG_SPACE(len);
......
646 646
    msgh->msg_controllen = tswapl(space);
647 647
}
648 648

  
649
static long do_setsockopt(int sockfd, int level, int optname, 
649
static long do_setsockopt(int sockfd, int level, int optname,
650 650
                          target_ulong optval, socklen_t optlen)
651 651
{
652 652
    int val, ret;
653
            
653
           
654 654
    switch(level) {
655 655
    case SOL_TCP:
656 656
        /* TCP options all take an 'int' value.  */
657 657
        if (optlen < sizeof(uint32_t))
658 658
            return -EINVAL;
659
        
659
       
660 660
        val = tget32(optval);
661 661
        ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
662 662
        break;
......
766 766
    return ret;
767 767
}
768 768

  
769
static long do_getsockopt(int sockfd, int level, int optname, 
769
static long do_getsockopt(int sockfd, int level, int optname,
770 770
                          target_ulong optval, target_ulong optlen)
771 771
{
772 772
    int len, lv, val, ret;
......
916 916
                    socklen_t addrlen)
917 917
{
918 918
    void *addr = alloca(addrlen);
919
    
919
   
920 920
    target_to_host_sockaddr(addr, target_addr, addrlen);
921 921
    return get_errno(bind(sockfd, addr, addrlen));
922 922
}
......
925 925
                    socklen_t addrlen)
926 926
{
927 927
    void *addr = alloca(addrlen);
928
    
928
   
929 929
    target_to_host_sockaddr(addr, target_addr, addrlen);
930 930
    return get_errno(connect(sockfd, addr, addrlen));
931 931
}
......
953 953
    msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
954 954
    msg.msg_control = alloca(msg.msg_controllen);
955 955
    msg.msg_flags = tswap32(msgp->msg_flags);
956
    
956
   
957 957
    count = tswapl(msgp->msg_iovlen);
958 958
    vec = alloca(count * sizeof(struct iovec));
959 959
    target_vec = tswapl(msgp->msg_iov);
960 960
    lock_iovec(vec, target_vec, count, send);
961 961
    msg.msg_iovlen = count;
962 962
    msg.msg_iov = vec;
963
    
963
   
964 964
    if (send) {
965 965
        target_to_host_cmsg(&msg, msgp);
966 966
        ret = get_errno(sendmsg(fd, &msg, flags));
......
1209 1209
            target_msg = tgetl(vptr + n);
1210 1210
            flags = tgetl(vptr + 2 * n);
1211 1211

  
1212
            ret = do_sendrecvmsg(fd, target_msg, flags, 
1212
            ret = do_sendrecvmsg(fd, target_msg, flags,
1213 1213
                                 (num == SOCKOP_sendmsg));
1214 1214
        }
1215 1215
        break;
......
1634 1634
            break;
1635 1635
        raddr = ret;
1636 1636
	/* find out the length of the shared memory segment */
1637
        
1637
       
1638 1638
        ret = get_errno(shmctl(first, IPC_STAT, &shm_info));
1639 1639
        if (is_error(ret)) {
1640 1640
            /* can't get length, bail out */
......
1908 1908
{
1909 1909
    struct host_termios *host = dst;
1910 1910
    const struct target_termios *target = src;
1911
    
1912
    host->c_iflag = 
1911
   
1912
    host->c_iflag =
1913 1913
        target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl);
1914
    host->c_oflag = 
1914
    host->c_oflag =
1915 1915
        target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl);
1916
    host->c_cflag = 
1916
    host->c_cflag =
1917 1917
        target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl);
1918
    host->c_lflag = 
1918
    host->c_lflag =
1919 1919
        target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
1920 1920
    host->c_line = target->c_line;
1921
    
1922
    host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; 
1923
    host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; 
1924
    host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];       
1925
    host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; 
1926
    host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];   
1927
    host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; 
1928
    host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];   
1929
    host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; 
1930
    host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];       
1931
    host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; 
1932
    host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; 
1933
    host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];   
1934
    host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];   
1935
    host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];   
1936
    host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];     
1937
    host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];       
1938
    host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; 
1921
   
1922
    host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
1923
    host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
1924
    host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];      
1925
    host->c_cc[VKILL] = target->c_cc[TARGET_VKILL];
1926
    host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];  
1927
    host->c_cc[VTIME] = target->c_cc[TARGET_VTIME];
1928
    host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];  
1929
    host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC];
1930
    host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];      
1931
    host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP];
1932
    host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP];
1933
    host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];  
1934
    host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];  
1935
    host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];  
1936
    host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];    
1937
    host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];      
1938
    host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2];
1939 1939
}
1940
  
1940
 
1941 1941
static void host_to_target_termios (void *dst, const void *src)
1942 1942
{
1943 1943
    struct target_termios *target = dst;
1944 1944
    const struct host_termios *host = src;
1945 1945

  
1946
    target->c_iflag = 
1946
    target->c_iflag =
1947 1947
        tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl));
1948
    target->c_oflag = 
1948
    target->c_oflag =
1949 1949
        tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl));
1950
    target->c_cflag = 
1950
    target->c_cflag =
1951 1951
        tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl));
1952
    target->c_lflag = 
1952
    target->c_lflag =
1953 1953
        tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
1954 1954
    target->c_line = host->c_line;
1955
  
1955
 
1956 1956
    target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
1957 1957
    target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
1958 1958
    target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
......
2033 2033
}
2034 2034

  
2035 2035
/* XXX: add locking support */
2036
static int write_ldt(CPUX86State *env, 
2036
static int write_ldt(CPUX86State *env,
2037 2037
                     target_ulong ptr, unsigned long bytecount, int oldmode)
2038 2038
{
2039 2039
    struct target_modify_ldt_ldt_s ldt_info;
......
2050 2050
    ldt_info.limit = tswap32(target_ldt_info->limit);
2051 2051
    ldt_info.flags = tswap32(target_ldt_info->flags);
2052 2052
    unlock_user_struct(target_ldt_info, ptr, 0);
2053
    
2053
   
2054 2054
    if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
2055 2055
        return -EINVAL;
2056 2056
    seg_32bit = ldt_info.flags & 1;
......
2091 2091
            goto install;
2092 2092
        }
2093 2093
    }
2094
    
2094
   
2095 2095
    entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
2096 2096
        (ldt_info.limit & 0x0ffff);
2097 2097
    entry_2 = (ldt_info.base_addr & 0xff000000) |
......
2118 2118
int do_modify_ldt(CPUX86State *env, int func, target_ulong ptr, unsigned long bytecount)
2119 2119
{
2120 2120
    int ret = -ENOSYS;
2121
    
2121
   
2122 2122
    switch (func) {
2123 2123
    case 0:
2124 2124
        ret = read_ldt(ptr, bytecount);
......
2153 2153
    TaskState *ts;
2154 2154
    uint8_t *new_stack;
2155 2155
    CPUState *new_env;
2156
    
2156
   
2157 2157
    if (flags & CLONE_VM) {
2158 2158
        ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
2159 2159
        memset(ts, 0, sizeof(TaskState));
......
2195 2195
        if (!newsp)
2196 2196
            newsp = env->gpr[1];
2197 2197
        new_env->gpr[1] = newsp;
2198
        { 
2198
        {
2199 2199
            int i;
2200 2200
            for (i = 7; i < 32; i++)
2201 2201
                new_env->gpr[i] = 0;
......
2261 2261
            unlock_user_struct(target_fl, arg, 1);
2262 2262
        }
2263 2263
        break;
2264
        
2264
       
2265 2265
    case TARGET_F_SETLK:
2266 2266
    case TARGET_F_SETLKW:
2267 2267
        lock_user_struct(target_fl, arg, 1);
......
2273 2273
        unlock_user_struct(target_fl, arg, 0);
2274 2274
        ret = fcntl(fd, cmd, &fl);
2275 2275
        break;
2276
        
2276
       
2277 2277
    case TARGET_F_GETLK64:
2278 2278
        lock_user_struct(target_fl64, arg, 1);
2279 2279
        fl64.l_type = tswap16(target_fl64->l_type) >> 1;
......
2363 2363
    const argtype *arg_type;
2364 2364
    int size;
2365 2365

  
2366
#define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); 
2367
#define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); 
2366
#define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
2367
#define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
2368 2368
#include "syscall_types.h"
2369 2369
#undef STRUCT
2370 2370
#undef STRUCT_SPECIAL
......
2377 2377
            TARGET_IOC_SIZEMASK) {
2378 2378
            arg_type = ie->arg_type;
2379 2379
            if (arg_type[0] != TYPE_PTR) {
2380
                fprintf(stderr, "cannot patch size for ioctl 0x%x\n", 
2380
                fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
2381 2381
                        ie->target_cmd);
2382 2382
                exit(1);
2383 2383
            }
2384 2384
            arg_type++;
2385 2385
            size = thunk_type_size(arg_type, 0);
2386
            ie->target_cmd = (ie->target_cmd & 
2386
            ie->target_cmd = (ie->target_cmd &
2387 2387
                              ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) |
2388 2388
                (size << TARGET_IOC_SIZESHIFT);
2389 2389
        }
2390 2390
        /* automatic consistency check if same arch */
2391 2391
#if defined(__i386__) && defined(TARGET_I386)
2392 2392
        if (ie->target_cmd != ie->host_cmd) {
2393
            fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n", 
2393
            fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n",
2394 2394
                    ie->target_cmd, ie->host_cmd);
2395 2395
        }
2396 2396
#endif
......
2459 2459
    unlock_user_struct(target_ts, target_addr, 1);
2460 2460
}
2461 2461

  
2462
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, 
2462
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2463 2463
                long arg4, long arg5, long arg6)
2464 2464
{
2465 2465
    long ret;
2466 2466
    struct stat st;
2467 2467
    struct statfs stfs;
2468 2468
    void *p;
2469
    
2469
   
2470 2470
#ifdef DEBUG
2471 2471
    gemu_log("syscall %d", num);
2472 2472
#endif
......
2978 2978
        {
2979 2979
            int how = arg1;
2980 2980
            sigset_t set, oldset, *set_ptr;
2981
            
2981
           
2982 2982
            if (arg2) {
2983 2983
                switch(how) {
2984 2984
                case TARGET_SIG_BLOCK:
......
3015 3015
        {
3016 3016
            int how = arg1;
3017 3017
            sigset_t set, oldset, *set_ptr;
3018
            
3018
           
3019 3019
            if (arg2) {
3020 3020
                switch(how) {
3021 3021
                case TARGET_SIG_BLOCK:
......
3096 3096
            sigset_t set;
3097 3097
            struct timespec uts, *puts;
3098 3098
            siginfo_t uinfo;
3099
            
3099
           
3100 3100
            p = lock_user(arg1, sizeof(target_sigset_t), 1);
3101 3101
            target_to_host_sigset(&set, p);
3102 3102
            unlock_user(p, arg1, 0);
......
3157 3157
            int resource = arg1;
3158 3158
            struct target_rlimit *target_rlim;
3159 3159
            struct rlimit rlim;
3160
            
3160
           
3161 3161
            ret = get_errno(getrlimit(resource, &rlim));
3162 3162
            if (!is_error(ret)) {
3163 3163
                lock_user_struct(target_rlim, arg2, 0);
......
3265 3265
            v5 = tswapl(v[4]);
3266 3266
            v6 = tswapl(v[5]);
3267 3267
            unlock_user(v, arg1, 0);
3268
            ret = get_errno(target_mmap(v1, v2, v3, 
3268
            ret = get_errno(target_mmap(v1, v2, v3,
3269 3269
                                        target_to_host_bitmask(v4, mmap_flags_tbl),
3270 3270
                                        v5, v6));
3271 3271
        }
3272 3272
#else
3273
        ret = get_errno(target_mmap(arg1, arg2, arg3, 
3274
                                    target_to_host_bitmask(arg4, mmap_flags_tbl), 
3273
        ret = get_errno(target_mmap(arg1, arg2, arg3,
3274
                                    target_to_host_bitmask(arg4, mmap_flags_tbl),
3275 3275
                                    arg5,
3276 3276
                                    arg6));
3277 3277
#endif
......
3284 3284
#else
3285 3285
#define MMAP_SHIFT TARGET_PAGE_BITS
3286 3286
#endif
3287
        ret = get_errno(target_mmap(arg1, arg2, arg3, 
3288
                                    target_to_host_bitmask(arg4, mmap_flags_tbl), 
3287
        ret = get_errno(target_mmap(arg1, arg2, arg3,
3288
                                    target_to_host_bitmask(arg4, mmap_flags_tbl),
3289 3289
                                    arg5,
3290 3290
                                    arg6 << MMAP_SHIFT));
3291 3291
        break;
......
3355 3355
    convert_statfs:
3356 3356
        if (!is_error(ret)) {
3357 3357
            struct target_statfs *target_stfs;
3358
            
3358
           
3359 3359
            lock_user_struct(target_stfs, arg2, 0);
3360 3360
            /* ??? put_user is probably wrong.  */
3361 3361
            put_user(stfs.f_type, &target_stfs->f_type);
......
3382 3382
    convert_statfs64:
3383 3383
        if (!is_error(ret)) {
3384 3384
            struct target_statfs64 *target_stfs;
3385
            
3385
           
3386 3386
            lock_user_struct(target_stfs, arg3, 0);
3387 3387
            /* ??? put_user is probably wrong.  */
3388 3388
            put_user(stfs.f_type, &target_stfs->f_type);
......
3509 3509

  
3510 3510
            if (arg2) {
3511 3511
                pvalue = &value;
3512
                target_to_host_timeval(&pvalue->it_interval, 
3512
                target_to_host_timeval(&pvalue->it_interval,
3513 3513
                                       arg2);
3514
                target_to_host_timeval(&pvalue->it_value, 
3514
                target_to_host_timeval(&pvalue->it_value,
3515 3515
                                       arg2 + sizeof(struct target_timeval));
3516 3516
            } else {
3517 3517
                pvalue = NULL;
......
3528 3528
    case TARGET_NR_getitimer:
3529 3529
        {
3530 3530
            struct itimerval value;
3531
            
3531
           
3532 3532
            ret = get_errno(getitimer(arg1, &value));
3533 3533
            if (!is_error(ret) && arg2) {
3534 3534
                host_to_target_timeval(arg2,
......
3697 3697
        /* no need to transcode because we use the linux syscall */
3698 3698
        {
3699 3699
            struct new_utsname * buf;
3700
    
3700
   
3701 3701
            lock_user_struct(buf, arg1, 0);
3702 3702
            ret = get_errno(sys_uname(buf));
3703 3703
            if (!is_error(ret)) {
......
3784 3784
	    dirp = malloc(count);
3785 3785
	    if (!dirp)
3786 3786
                return -ENOMEM;
3787
            
3787
           
3788 3788
            ret = get_errno(sys_getdents(arg1, dirp, count));
3789 3789
            if (!is_error(ret)) {
3790 3790
                struct dirent *de;
......
4232 4232
        break;
4233 4233
#ifdef TARGET_NR_setresuid
4234 4234
    case TARGET_NR_setresuid:
4235
        ret = get_errno(setresuid(low2highuid(arg1), 
4236
                                  low2highuid(arg2), 
4235
        ret = get_errno(setresuid(low2highuid(arg1),
4236
                                  low2highuid(arg2),
4237 4237
                                  low2highuid(arg3)));
4238 4238
        break;
4239 4239
#endif
......
4252 4252
#endif
4253 4253
#ifdef TARGET_NR_getresgid
4254 4254
    case TARGET_NR_setresgid:
4255
        ret = get_errno(setresgid(low2highgid(arg1), 
4256
                                  low2highgid(arg2), 
4255
        ret = get_errno(setresgid(low2highgid(arg1),
4256
                                  low2highgid(arg2),
4257 4257
                                  low2highgid(arg3)));
4258 4258
        break;
4259 4259
#endif
......
4352 4352
            uint32_t *target_grouplist;
4353 4353
            gid_t *grouplist;
4354 4354
            int i;
4355
            
4355
           
4356 4356
            grouplist = alloca(gidsetsize * sizeof(gid_t));
4357 4357
            target_grouplist = lock_user(arg2, gidsetsize * 4, 1);
4358 4358
            for(i = 0;i < gidsetsize; i++)

Also available in: Unified diff