syscall.c (66fb9763af9cd743158957e8c9c2559d922b1c22) syscall.c (9de5e440b9f6a6c6305c0b81d1df4ddcc5a4b966)
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

--- 24 unchanged lines hidden (view full) ---

33#include <sys/mount.h>
34#include <sys/resource.h>
35#include <sys/mman.h>
36#include <sys/swap.h>
37#include <signal.h>
38#include <sched.h>
39#include <sys/socket.h>
40#include <sys/uio.h>
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

--- 24 unchanged lines hidden (view full) ---

33#include <sys/mount.h>
34#include <sys/resource.h>
35#include <sys/mman.h>
36#include <sys/swap.h>
37#include <signal.h>
38#include <sched.h>
39#include <sys/socket.h>
40#include <sys/uio.h>
41#include <sys/poll.h>
41//#include <sys/user.h>
42
43#define termios host_termios
44#define winsize host_winsize
45#define termio host_termio
46#define sgttyb host_sgttyb /* same as target */
47#define tchars host_tchars /* same as target */
48#define ltchars host_ltchars /* same as target */

--- 14 unchanged lines hidden (view full) ---

63#define PAGE_SIZE 4096
64#define PAGE_MASK ~(PAGE_SIZE - 1)
65#endif
66
67//#include <linux/msdos_fs.h>
68#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
69#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
70
42//#include <sys/user.h>
43
44#define termios host_termios
45#define winsize host_winsize
46#define termio host_termio
47#define sgttyb host_sgttyb /* same as target */
48#define tchars host_tchars /* same as target */
49#define ltchars host_ltchars /* same as target */

--- 14 unchanged lines hidden (view full) ---

64#define PAGE_SIZE 4096
65#define PAGE_MASK ~(PAGE_SIZE - 1)
66#endif
67
68//#include <linux/msdos_fs.h>
69#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
70#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
71
71#include "syscall_defs.h"
72
73#ifdef TARGET_I386
74#include "cpu-i386.h"
75#include "syscall-i386.h"
76#endif
77
78void host_to_target_siginfo(target_siginfo_t *tinfo, siginfo_t *info);
79void target_to_host_siginfo(siginfo_t *info, target_siginfo_t *tinfo);
72void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
73void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
80long do_sigreturn(CPUX86State *env);
81long do_rt_sigreturn(CPUX86State *env);
82
83#define __NR_sys_uname __NR_uname
84#define __NR_sys_getcwd1 __NR_getcwd
85#define __NR_sys_statfs __NR_statfs
86#define __NR_sys_fstatfs __NR_fstatfs
87#define __NR_sys_getdents __NR_getdents

--- 13 unchanged lines hidden (view full) ---

101_syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
102_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
103 loff_t *, res, uint, wh);
104_syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf)
105_syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf)
106_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
107
108extern int personality(int);
74long do_sigreturn(CPUX86State *env);
75long do_rt_sigreturn(CPUX86State *env);
76
77#define __NR_sys_uname __NR_uname
78#define __NR_sys_getcwd1 __NR_getcwd
79#define __NR_sys_statfs __NR_statfs
80#define __NR_sys_fstatfs __NR_fstatfs
81#define __NR_sys_getdents __NR_getdents

--- 13 unchanged lines hidden (view full) ---

95_syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
96_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
97 loff_t *, res, uint, wh);
98_syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf)
99_syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf)
100_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
101
102extern int personality(int);
103extern int flock(int, int);
104extern int setfsuid(int);
105extern int setfsgid(int);
109
110static inline long get_errno(long ret)
111{
112 if (ret == -1)
113 return -errno;
114 else
115 return ret;
116}

--- 315 unchanged lines hidden (view full) ---

432 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
433 return -ENOSYS;
434 }
435 if (ie->target_cmd == cmd)
436 break;
437 ie++;
438 }
439 arg_type = ie->arg_type;
106
107static inline long get_errno(long ret)
108{
109 if (ret == -1)
110 return -errno;
111 else
112 return ret;
113}

--- 315 unchanged lines hidden (view full) ---

429 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
430 return -ENOSYS;
431 }
432 if (ie->target_cmd == cmd)
433 break;
434 ie++;
435 }
436 arg_type = ie->arg_type;
440#ifdef DEBUG
437#if defined(DEBUG)
441 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
442#endif
443 switch(arg_type[0]) {
444 case TYPE_NULL:
445 /* no argument */
446 ret = get_errno(ioctl(fd, ie->host_cmd));
447 break;
448 case TYPE_PTRVOID:

--- 790 unchanged lines hidden (view full) ---

1239 break;
1240 case TARGET_NR_setregid:
1241 ret = get_errno(setregid(arg1, arg2));
1242 break;
1243 case TARGET_NR_sethostname:
1244 ret = get_errno(sethostname((const char *)arg1, arg2));
1245 break;
1246 case TARGET_NR_setrlimit:
438 gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
439#endif
440 switch(arg_type[0]) {
441 case TYPE_NULL:
442 /* no argument */
443 ret = get_errno(ioctl(fd, ie->host_cmd));
444 break;
445 case TYPE_PTRVOID:

--- 790 unchanged lines hidden (view full) ---

1236 break;
1237 case TARGET_NR_setregid:
1238 ret = get_errno(setregid(arg1, arg2));
1239 break;
1240 case TARGET_NR_sethostname:
1241 ret = get_errno(sethostname((const char *)arg1, arg2));
1242 break;
1243 case TARGET_NR_setrlimit:
1247 goto unimplemented;
1244 {
1245 /* XXX: convert resource ? */
1246 int resource = arg1;
1247 struct target_rlimit *target_rlim = (void *)arg2;
1248 struct rlimit rlim;
1249 rlim.rlim_cur = tswapl(target_rlim->rlim_cur);
1250 rlim.rlim_max = tswapl(target_rlim->rlim_max);
1251 ret = get_errno(setrlimit(resource, &rlim));
1252 }
1253 break;
1248 case TARGET_NR_getrlimit:
1254 case TARGET_NR_getrlimit:
1249 goto unimplemented;
1255 {
1256 /* XXX: convert resource ? */
1257 int resource = arg1;
1258 struct target_rlimit *target_rlim = (void *)arg2;
1259 struct rlimit rlim;
1260
1261 ret = get_errno(getrlimit(resource, &rlim));
1262 if (!is_error(ret)) {
1263 target_rlim->rlim_cur = tswapl(rlim.rlim_cur);
1264 target_rlim->rlim_max = tswapl(rlim.rlim_max);
1265 }
1266 }
1267 break;
1250 case TARGET_NR_getrusage:
1251 goto unimplemented;
1252 case TARGET_NR_gettimeofday:
1253 {
1254 struct target_timeval *target_tv = (void *)arg1;
1255 struct timeval tv;
1256 ret = get_errno(gettimeofday(&tv, NULL));
1257 if (!is_error(ret)) {

--- 54 unchanged lines hidden (view full) ---

1312#else
1313 case TARGET_NR_mmap:
1314#endif
1315 ret = get_errno((long)mmap((void *)arg1, arg2, arg3, arg4, arg5, arg6));
1316 break;
1317 case TARGET_NR_munmap:
1318 ret = get_errno(munmap((void *)arg1, arg2));
1319 break;
1268 case TARGET_NR_getrusage:
1269 goto unimplemented;
1270 case TARGET_NR_gettimeofday:
1271 {
1272 struct target_timeval *target_tv = (void *)arg1;
1273 struct timeval tv;
1274 ret = get_errno(gettimeofday(&tv, NULL));
1275 if (!is_error(ret)) {

--- 54 unchanged lines hidden (view full) ---

1330#else
1331 case TARGET_NR_mmap:
1332#endif
1333 ret = get_errno((long)mmap((void *)arg1, arg2, arg3, arg4, arg5, arg6));
1334 break;
1335 case TARGET_NR_munmap:
1336 ret = get_errno(munmap((void *)arg1, arg2));
1337 break;
1338 case TARGET_NR_mprotect:
1339 ret = get_errno(mprotect((void *)arg1, arg2, arg3));
1340 break;
1341 case TARGET_NR_mremap:
1342 ret = get_errno((long)mremap((void *)arg1, arg2, arg3, arg4));
1343 break;
1344 case TARGET_NR_msync:
1345 ret = get_errno(msync((void *)arg1, arg2, arg3));
1346 break;
1347 case TARGET_NR_mlock:
1348 ret = get_errno(mlock((void *)arg1, arg2));
1349 break;
1350 case TARGET_NR_munlock:
1351 ret = get_errno(munlock((void *)arg1, arg2));
1352 break;
1353 case TARGET_NR_mlockall:
1354 ret = get_errno(mlockall(arg1));
1355 break;
1356 case TARGET_NR_munlockall:
1357 ret = get_errno(munlockall());
1358 break;
1320 case TARGET_NR_truncate:
1321 ret = get_errno(truncate((const char *)arg1, arg2));
1322 break;
1323 case TARGET_NR_ftruncate:
1324 ret = get_errno(ftruncate(arg1, arg2));
1325 break;
1326 case TARGET_NR_fchmod:
1327 ret = get_errno(fchmod(arg1, arg2));

--- 173 unchanged lines hidden (view full) ---

1501 break;
1502#ifdef TARGET_I386
1503 case TARGET_NR_modify_ldt:
1504 ret = get_errno(gemu_modify_ldt(cpu_env, arg1, (void *)arg2, arg3));
1505 break;
1506#endif
1507 case TARGET_NR_adjtimex:
1508 goto unimplemented;
1359 case TARGET_NR_truncate:
1360 ret = get_errno(truncate((const char *)arg1, arg2));
1361 break;
1362 case TARGET_NR_ftruncate:
1363 ret = get_errno(ftruncate(arg1, arg2));
1364 break;
1365 case TARGET_NR_fchmod:
1366 ret = get_errno(fchmod(arg1, arg2));

--- 173 unchanged lines hidden (view full) ---

1540 break;
1541#ifdef TARGET_I386
1542 case TARGET_NR_modify_ldt:
1543 ret = get_errno(gemu_modify_ldt(cpu_env, arg1, (void *)arg2, arg3));
1544 break;
1545#endif
1546 case TARGET_NR_adjtimex:
1547 goto unimplemented;
1509 case TARGET_NR_mprotect:
1510 ret = get_errno(mprotect((void *)arg1, arg2, arg3));
1511 break;
1512 case TARGET_NR_create_module:
1513 case TARGET_NR_init_module:
1514 case TARGET_NR_delete_module:
1515 case TARGET_NR_get_kernel_syms:
1516 goto unimplemented;
1517 case TARGET_NR_quotactl:
1518 goto unimplemented;
1519 case TARGET_NR_getpgid:

--- 7 unchanged lines hidden (view full) ---

1527 case TARGET_NR_sysfs:
1528 goto unimplemented;
1529 case TARGET_NR_personality:
1530 ret = get_errno(personality(arg1));
1531 break;
1532 case TARGET_NR_afs_syscall:
1533 goto unimplemented;
1534 case TARGET_NR_setfsuid:
1548 case TARGET_NR_create_module:
1549 case TARGET_NR_init_module:
1550 case TARGET_NR_delete_module:
1551 case TARGET_NR_get_kernel_syms:
1552 goto unimplemented;
1553 case TARGET_NR_quotactl:
1554 goto unimplemented;
1555 case TARGET_NR_getpgid:

--- 7 unchanged lines hidden (view full) ---

1563 case TARGET_NR_sysfs:
1564 goto unimplemented;
1565 case TARGET_NR_personality:
1566 ret = get_errno(personality(arg1));
1567 break;
1568 case TARGET_NR_afs_syscall:
1569 goto unimplemented;
1570 case TARGET_NR_setfsuid:
1535 goto unimplemented;
1571 ret = get_errno(setfsuid(arg1));
1572 break;
1536 case TARGET_NR_setfsgid:
1573 case TARGET_NR_setfsgid:
1537 goto unimplemented;
1574 ret = get_errno(setfsgid(arg1));
1575 break;
1538 case TARGET_NR__llseek:
1539 {
1540 int64_t res;
1541 ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
1542 *(int64_t *)arg4 = tswap64(res);
1543 }
1544 break;
1545 case TARGET_NR_getdents:

--- 45 unchanged lines hidden (view full) ---

1591 }
1592 }
1593 }
1594 break;
1595 case TARGET_NR__newselect:
1596 ret = do_select(arg1, (void *)arg2, (void *)arg3, (void *)arg4,
1597 (void *)arg5);
1598 break;
1576 case TARGET_NR__llseek:
1577 {
1578 int64_t res;
1579 ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
1580 *(int64_t *)arg4 = tswap64(res);
1581 }
1582 break;
1583 case TARGET_NR_getdents:

--- 45 unchanged lines hidden (view full) ---

1629 }
1630 }
1631 }
1632 break;
1633 case TARGET_NR__newselect:
1634 ret = do_select(arg1, (void *)arg2, (void *)arg3, (void *)arg4,
1635 (void *)arg5);
1636 break;
1637 case TARGET_NR_poll:
1638 {
1639 struct target_pollfd *target_pfd = (void *)arg1;
1640 unsigned int nfds = arg2;
1641 int timeout = arg3;
1642 struct pollfd *pfd;
1643 int i;
1644
1645 pfd = alloca(sizeof(struct pollfd) * nfds);
1646 for(i = 0; i < nfds; i++) {
1647 pfd->fd = tswap32(target_pfd->fd);
1648 pfd->events = tswap16(target_pfd->events);
1649 }
1650 ret = get_errno(poll(pfd, nfds, timeout));
1651 if (!is_error(ret)) {
1652 for(i = 0; i < nfds; i++) {
1653 target_pfd->revents = tswap16(pfd->revents);
1654 }
1655 }
1656 }
1657 break;
1599 case TARGET_NR_flock:
1658 case TARGET_NR_flock:
1600 goto unimplemented;
1601 case TARGET_NR_msync:
1602 ret = get_errno(msync((void *)arg1, arg2, arg3));
1659 /* NOTE: the flock constant seems to be the same for every
1660 Linux platform */
1661 ret = get_errno(flock(arg1, arg2));
1603 break;
1604 case TARGET_NR_readv:
1605 {
1606 int count = arg3;
1607 int i;
1608 struct iovec *vec;
1609 struct target_iovec *target_vec = (void *)arg2;
1610

--- 22 unchanged lines hidden (view full) ---

1633 break;
1634 case TARGET_NR_getsid:
1635 ret = get_errno(getsid(arg1));
1636 break;
1637 case TARGET_NR_fdatasync:
1638 goto unimplemented;
1639 case TARGET_NR__sysctl:
1640 goto unimplemented;
1662 break;
1663 case TARGET_NR_readv:
1664 {
1665 int count = arg3;
1666 int i;
1667 struct iovec *vec;
1668 struct target_iovec *target_vec = (void *)arg2;
1669

--- 22 unchanged lines hidden (view full) ---

1692 break;
1693 case TARGET_NR_getsid:
1694 ret = get_errno(getsid(arg1));
1695 break;
1696 case TARGET_NR_fdatasync:
1697 goto unimplemented;
1698 case TARGET_NR__sysctl:
1699 goto unimplemented;
1641 case TARGET_NR_mlock:
1642 ret = get_errno(mlock((void *)arg1, arg2));
1643 break;
1644 case TARGET_NR_munlock:
1645 ret = get_errno(munlock((void *)arg1, arg2));
1646 break;
1647 case TARGET_NR_mlockall:
1648 ret = get_errno(mlockall(arg1));
1649 break;
1650 case TARGET_NR_munlockall:
1651 ret = get_errno(munlockall());
1652 break;
1653 case TARGET_NR_sched_setparam:
1654 goto unimplemented;
1655 case TARGET_NR_sched_getparam:
1656 goto unimplemented;
1657 case TARGET_NR_sched_setscheduler:
1658 goto unimplemented;
1659 case TARGET_NR_sched_getscheduler:
1660 goto unimplemented;

--- 15 unchanged lines hidden (view full) ---

1676 ret = get_errno(nanosleep(&req, &rem));
1677 if (target_rem) {
1678 target_rem->tv_sec = tswapl(rem.tv_sec);
1679 target_rem->tv_nsec = tswapl(rem.tv_nsec);
1680 }
1681 }
1682 break;
1683
1700 case TARGET_NR_sched_setparam:
1701 goto unimplemented;
1702 case TARGET_NR_sched_getparam:
1703 goto unimplemented;
1704 case TARGET_NR_sched_setscheduler:
1705 goto unimplemented;
1706 case TARGET_NR_sched_getscheduler:
1707 goto unimplemented;

--- 15 unchanged lines hidden (view full) ---

1723 ret = get_errno(nanosleep(&req, &rem));
1724 if (target_rem) {
1725 target_rem->tv_sec = tswapl(rem.tv_sec);
1726 target_rem->tv_nsec = tswapl(rem.tv_nsec);
1727 }
1728 }
1729 break;
1730
1684 case TARGET_NR_mremap:
1685 case TARGET_NR_setresuid:
1686 case TARGET_NR_getresuid:
1687 case TARGET_NR_vm86:
1688 case TARGET_NR_query_module:
1731 case TARGET_NR_setresuid:
1732 case TARGET_NR_getresuid:
1733 case TARGET_NR_vm86:
1734 case TARGET_NR_query_module:
1689 case TARGET_NR_poll:
1690 case TARGET_NR_nfsservctl:
1691 case TARGET_NR_setresgid:
1692 case TARGET_NR_getresgid:
1693 case TARGET_NR_prctl:
1694 case TARGET_NR_pread:
1695 case TARGET_NR_pwrite:
1696 goto unimplemented;
1697 case TARGET_NR_chown:

--- 97 unchanged lines hidden (view full) ---

1795 case TARGET_NR_llistxattr:
1796 case TARGET_NR_flistxattr:
1797 case TARGET_NR_removexattr:
1798 case TARGET_NR_lremovexattr:
1799 case TARGET_NR_fremovexattr:
1800 goto unimplemented;
1801 default:
1802 unimplemented:
1735 case TARGET_NR_nfsservctl:
1736 case TARGET_NR_setresgid:
1737 case TARGET_NR_getresgid:
1738 case TARGET_NR_prctl:
1739 case TARGET_NR_pread:
1740 case TARGET_NR_pwrite:
1741 goto unimplemented;
1742 case TARGET_NR_chown:

--- 97 unchanged lines hidden (view full) ---

1840 case TARGET_NR_llistxattr:
1841 case TARGET_NR_flistxattr:
1842 case TARGET_NR_removexattr:
1843 case TARGET_NR_lremovexattr:
1844 case TARGET_NR_fremovexattr:
1845 goto unimplemented;
1846 default:
1847 unimplemented:
1803 gemu_log("Unsupported syscall: %d\n", num);
1848 gemu_log("gemu: Unsupported syscall: %d\n", num);
1804 ret = -ENOSYS;
1805 break;
1806 }
1807 fail:
1808 return ret;
1809}
1810
1849 ret = -ENOSYS;
1850 break;
1851 }
1852 fail:
1853 return ret;
1854}
1855