syscall.c (59c58f96b270f5edd4ad10954c3a96556cb3a728) | syscall.c (524fa3408ed745a2fed0642fb0d92c934d10ff64) |
---|---|
1/* 2 * Linux syscalls 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 748 unchanged lines hidden (view full) --- 757safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len, 758 int, flags) 759safe_syscall2(int, nanosleep, const struct timespec *, req, 760 struct timespec *, rem) 761#ifdef TARGET_NR_clock_nanosleep 762safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags, 763 const struct timespec *, req, struct timespec *, rem) 764#endif | 1/* 2 * Linux syscalls 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 748 unchanged lines hidden (view full) --- 757safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len, 758 int, flags) 759safe_syscall2(int, nanosleep, const struct timespec *, req, 760 struct timespec *, rem) 761#ifdef TARGET_NR_clock_nanosleep 762safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags, 763 const struct timespec *, req, struct timespec *, rem) 764#endif |
765#if !defined(__NR_msgsnd) || !defined(__NR_msgrcv) || !defined(__NR_semtimedop) 766/* This host kernel architecture uses a single ipc syscall; fake up 767 * wrappers for the sub-operations to hide this implementation detail. 768 * Annoyingly we can't include linux/ipc.h to get the constant definitions 769 * for the call parameter because some structs in there conflict with the 770 * sys/ipc.h ones. So we just define them here, and rely on them being 771 * the same for all host architectures. 772 */ 773#define Q_SEMTIMEDOP 4 774#define Q_MSGSND 11 775#define Q_MSGRCV 12 776#define Q_IPCCALL(VERSION, OP) ((VERSION) << 16 | (OP)) 777 | 765#ifdef __NR_ipc |
778safe_syscall6(int, ipc, int, call, long, first, long, second, long, third, 779 void *, ptr, long, fifth) 780#endif 781#ifdef __NR_msgsnd 782safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz, 783 int, flags) | 766safe_syscall6(int, ipc, int, call, long, first, long, second, long, third, 767 void *, ptr, long, fifth) 768#endif 769#ifdef __NR_msgsnd 770safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz, 771 int, flags) |
784#else 785static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int flags) 786{ 787 return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void *)msgp, 0); 788} | |
789#endif 790#ifdef __NR_msgrcv 791safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz, 792 long, msgtype, int, flags) | 772#endif 773#ifdef __NR_msgrcv 774safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz, 775 long, msgtype, int, flags) |
793#else 794static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type, int flags) 795{ 796 return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp, type); 797} | |
798#endif 799#ifdef __NR_semtimedop 800safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, 801 unsigned, nsops, const struct timespec *, timeout) | 776#endif 777#ifdef __NR_semtimedop 778safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, 779 unsigned, nsops, const struct timespec *, timeout) |
802#else 803static int safe_semtimedop(int semid, struct sembuf *tsops, unsigned nsops, 804 const struct timespec *timeout) 805{ 806 return safe_ipc(Q_IPCCALL(0, Q_SEMTIMEDOP), semid, nsops, 0, tsops, 807 (long)timeout); 808} | |
809#endif 810#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) 811safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, 812 size_t, len, unsigned, prio, const struct timespec *, timeout) 813safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, 814 size_t, len, unsigned *, prio, const struct timespec *, timeout) 815#endif 816/* We do ioctl like this rather than via safe_syscall3 to preserve the --- 2707 unchanged lines hidden (view full) --- 3524 unlock_user(target_sembuf, target_addr, 0); 3525 3526 return 0; 3527} 3528 3529static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops) 3530{ 3531 struct sembuf sops[nsops]; | 780#endif 781#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) 782safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, 783 size_t, len, unsigned, prio, const struct timespec *, timeout) 784safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, 785 size_t, len, unsigned *, prio, const struct timespec *, timeout) 786#endif 787/* We do ioctl like this rather than via safe_syscall3 to preserve the --- 2707 unchanged lines hidden (view full) --- 3495 unlock_user(target_sembuf, target_addr, 0); 3496 3497 return 0; 3498} 3499 3500static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops) 3501{ 3502 struct sembuf sops[nsops]; |
3503 abi_long ret; |
|
3532 3533 if (target_to_host_sembuf(sops, ptr, nsops)) 3534 return -TARGET_EFAULT; 3535 | 3504 3505 if (target_to_host_sembuf(sops, ptr, nsops)) 3506 return -TARGET_EFAULT; 3507 |
3536 return get_errno(safe_semtimedop(semid, sops, nsops, NULL)); | 3508 ret = -TARGET_ENOSYS; 3509#ifdef __NR_semtimedop 3510 ret = get_errno(safe_semtimedop(semid, sops, nsops, NULL)); 3511#endif 3512#ifdef __NR_ipc 3513 if (ret == -TARGET_ENOSYS) { 3514 ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, 0)); 3515 } 3516#endif 3517 return ret; |
3537} 3538 3539struct target_msqid_ds 3540{ 3541 struct target_ipc_perm msg_perm; 3542 abi_ulong msg_stime; 3543#if TARGET_ABI_BITS == 32 3544 abi_ulong __unused1; --- 138 unchanged lines hidden (view full) --- 3683 return -TARGET_EFAULT; 3684 host_mb = g_try_malloc(msgsz + sizeof(long)); 3685 if (!host_mb) { 3686 unlock_user_struct(target_mb, msgp, 0); 3687 return -TARGET_ENOMEM; 3688 } 3689 host_mb->mtype = (abi_long) tswapal(target_mb->mtype); 3690 memcpy(host_mb->mtext, target_mb->mtext, msgsz); | 3518} 3519 3520struct target_msqid_ds 3521{ 3522 struct target_ipc_perm msg_perm; 3523 abi_ulong msg_stime; 3524#if TARGET_ABI_BITS == 32 3525 abi_ulong __unused1; --- 138 unchanged lines hidden (view full) --- 3664 return -TARGET_EFAULT; 3665 host_mb = g_try_malloc(msgsz + sizeof(long)); 3666 if (!host_mb) { 3667 unlock_user_struct(target_mb, msgp, 0); 3668 return -TARGET_ENOMEM; 3669 } 3670 host_mb->mtype = (abi_long) tswapal(target_mb->mtype); 3671 memcpy(host_mb->mtext, target_mb->mtext, msgsz); |
3672 ret = -TARGET_ENOSYS; 3673#ifdef __NR_msgsnd |
|
3691 ret = get_errno(safe_msgsnd(msqid, host_mb, msgsz, msgflg)); | 3674 ret = get_errno(safe_msgsnd(msqid, host_mb, msgsz, msgflg)); |
3675#endif 3676#ifdef __NR_ipc 3677 if (ret == -TARGET_ENOSYS) { 3678 ret = get_errno(safe_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, 3679 host_mb, 0)); 3680 } 3681#endif |
|
3692 g_free(host_mb); 3693 unlock_user_struct(target_mb, msgp, 0); 3694 3695 return ret; 3696} 3697 3698static inline abi_long do_msgrcv(int msqid, abi_long msgp, 3699 ssize_t msgsz, abi_long msgtyp, --- 11 unchanged lines hidden (view full) --- 3711 if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) 3712 return -TARGET_EFAULT; 3713 3714 host_mb = g_try_malloc(msgsz + sizeof(long)); 3715 if (!host_mb) { 3716 ret = -TARGET_ENOMEM; 3717 goto end; 3718 } | 3682 g_free(host_mb); 3683 unlock_user_struct(target_mb, msgp, 0); 3684 3685 return ret; 3686} 3687 3688static inline abi_long do_msgrcv(int msqid, abi_long msgp, 3689 ssize_t msgsz, abi_long msgtyp, --- 11 unchanged lines hidden (view full) --- 3701 if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) 3702 return -TARGET_EFAULT; 3703 3704 host_mb = g_try_malloc(msgsz + sizeof(long)); 3705 if (!host_mb) { 3706 ret = -TARGET_ENOMEM; 3707 goto end; 3708 } |
3709 ret = -TARGET_ENOSYS; 3710#ifdef __NR_msgrcv |
|
3719 ret = get_errno(safe_msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg)); | 3711 ret = get_errno(safe_msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg)); |
3712#endif 3713#ifdef __NR_ipc 3714 if (ret == -TARGET_ENOSYS) { 3715 ret = get_errno(safe_ipc(IPCOP_CALL(1, IPCOP_msgrcv), msqid, msgsz, 3716 msgflg, host_mb, msgtyp)); 3717 } 3718#endif |
|
3720 3721 if (ret > 0) { 3722 abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong); 3723 target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0); 3724 if (!target_mtext) { 3725 ret = -TARGET_EFAULT; 3726 goto end; 3727 } --- 8013 unchanged lines hidden --- | 3719 3720 if (ret > 0) { 3721 abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong); 3722 target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0); 3723 if (!target_mtext) { 3724 ret = -TARGET_EFAULT; 3725 goto end; 3726 } --- 8013 unchanged lines hidden --- |