📄 syscall.c.svn-base
字号:
/* * Linux syscalls * * Copyright (c) 2003 Fabrice Bellard * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include <string.h>#include <elf.h>#include <endian.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#include <time.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <sys/wait.h>#include <sys/time.h>#include <sys/stat.h>#include <sys/mount.h>#include <sys/prctl.h>#include <sys/resource.h>#include <sys/mman.h>#include <sys/swap.h>#include <signal.h>#include <sched.h>#include <sys/socket.h>#include <sys/uio.h>#include <sys/poll.h>#include <sys/times.h>#include <sys/shm.h>#include <sys/sem.h>#include <sys/statfs.h>#include <utime.h>#include <sys/sysinfo.h>//#include <sys/user.h>#include <netinet/ip.h>#include <netinet/tcp.h>#define termios host_termios#define winsize host_winsize#define termio host_termio#define sgttyb host_sgttyb /* same as target */#define tchars host_tchars /* same as target */#define ltchars host_ltchars /* same as target */#include <linux/termios.h>#include <linux/unistd.h>#include <linux/utsname.h>#include <linux/cdrom.h>#include <linux/hdreg.h>#include <linux/soundcard.h>#include <linux/dirent.h>#include <linux/kd.h>#include "qemu.h"//#define DEBUG#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \ || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)/* 16 bit uid wrappers emulation */#define USE_UID16#endif//#include <linux/msdos_fs.h>#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])#undef _syscall0#undef _syscall1#undef _syscall2#undef _syscall3#undef _syscall4#undef _syscall5#undef _syscall6#define _syscall0(type,name) \type name (void) \{ \ return syscall(__NR_##name); \}#define _syscall1(type,name,type1,arg1) \type name (type1 arg1) \{ \ return syscall(__NR_##name, arg1); \}#define _syscall2(type,name,type1,arg1,type2,arg2) \type name (type1 arg1,type2 arg2) \{ \ return syscall(__NR_##name, arg1, arg2); \}#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \type name (type1 arg1,type2 arg2,type3 arg3) \{ \ return syscall(__NR_##name, arg1, arg2, arg3); \}#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \{ \ return syscall(__NR_##name, arg1, arg2, arg3, arg4); \}#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ type5,arg5) \type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \{ \ return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \}#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ type5,arg5,type6,arg6) \type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \{ \ return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \}#define __NR_sys_uname __NR_uname#define __NR_sys_faccessat __NR_faccessat#define __NR_sys_fchmodat __NR_fchmodat#define __NR_sys_fchownat __NR_fchownat#define __NR_sys_getcwd1 __NR_getcwd#define __NR_sys_getdents __NR_getdents#define __NR_sys_getdents64 __NR_getdents64#define __NR_sys_getpriority __NR_getpriority#define __NR_sys_linkat __NR_linkat#define __NR_sys_mkdirat __NR_mkdirat#define __NR_sys_mknodat __NR_mknodat#define __NR_sys_openat __NR_openat#define __NR_sys_readlinkat __NR_readlinkat#define __NR_sys_renameat __NR_renameat#define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo#define __NR_sys_symlinkat __NR_symlinkat#define __NR_sys_syslog __NR_syslog#define __NR_sys_tgkill __NR_tgkill#define __NR_sys_tkill __NR_tkill#define __NR_sys_unlinkat __NR_unlinkat#define __NR_sys_utimensat __NR_utimensat#if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)#define __NR__llseek __NR_lseek#endif#ifdef __NR_gettid_syscall0(int, gettid)#else/* This is a replacement for the host gettid() and must return a host errno. */static int gettid(void) { return -ENOSYS;}#endif_syscall1(int,sys_uname,struct new_utsname *,buf)#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)_syscall4(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode,int,flags)#endif#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)_syscall4(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode,int,flags)#endif#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)_syscall5(int,sys_fchownat,int,dirfd,const char *,pathname, uid_t,owner,gid_t,group,int,flags)#endif_syscall2(int,sys_getcwd1,char *,buf,size_t,size)_syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count);#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)_syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);#endif_syscall2(int, sys_getpriority, int, which, int, who);_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, loff_t *, res, uint, wh);#if defined(TARGET_NR_linkat) && defined(__NR_linkat)_syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath, int,newdirfd,const char *,newpath,int,flags)#endif#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)_syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode)#endif#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)_syscall4(int,sys_mknodat,int,dirfd,const char *,pathname, mode_t,mode,dev_t,dev)#endif#if defined(TARGET_NR_openat) && defined(__NR_openat)_syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)#endif#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)_syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname, char *,buf,size_t,bufsize)#endif#if defined(TARGET_NR_renameat) && defined(__NR_renameat)_syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath, int,newdirfd,const char *,newpath)#endif_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)_syscall3(int,sys_symlinkat,const char *,oldpath, int,newdirfd,const char *,newpath)#endif_syscall3(int,sys_syslog,int,type,char*,bufp,int,len)#if defined(TARGET_NR_tgkill) && defined(__NR_tgkill)_syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig)#endif#if defined(TARGET_NR_tkill) && defined(__NR_tkill)_syscall2(int,sys_tkill,int,tid,int,sig)#endif#ifdef __NR_exit_group_syscall1(int,exit_group,int,error_code)#endif#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)_syscall1(int,set_tid_address,int *,tidptr)#endif#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)_syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)#endif#if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)_syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, const struct timespec *,tsp,int,flags)#endifextern int personality(int);extern int flock(int, int);extern int setfsuid(int);extern int setfsgid(int);extern int setresuid(uid_t, uid_t, uid_t);extern int getresuid(uid_t *, uid_t *, uid_t *);extern int setresgid(gid_t, gid_t, gid_t);extern int getresgid(gid_t *, gid_t *, gid_t *);extern int setgroups(int, gid_t *);#define ERRNO_TABLE_SIZE 1200/* target_to_host_errno_table[] is initialized from * host_to_target_errno_table[] in syscall_init(). */static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = {};/* * This list is the union of errno values overridden in asm-<arch>/errno.h * minus the errnos that are not actually generic to all archs. */static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { [EIDRM] = TARGET_EIDRM, [ECHRNG] = TARGET_ECHRNG, [EL2NSYNC] = TARGET_EL2NSYNC, [EL3HLT] = TARGET_EL3HLT, [EL3RST] = TARGET_EL3RST, [ELNRNG] = TARGET_ELNRNG, [EUNATCH] = TARGET_EUNATCH, [ENOCSI] = TARGET_ENOCSI, [EL2HLT] = TARGET_EL2HLT, [EDEADLK] = TARGET_EDEADLK, [ENOLCK] = TARGET_ENOLCK, [EBADE] = TARGET_EBADE, [EBADR] = TARGET_EBADR, [EXFULL] = TARGET_EXFULL, [ENOANO] = TARGET_ENOANO, [EBADRQC] = TARGET_EBADRQC, [EBADSLT] = TARGET_EBADSLT, [EBFONT] = TARGET_EBFONT, [ENOSTR] = TARGET_ENOSTR, [ENODATA] = TARGET_ENODATA, [ETIME] = TARGET_ETIME, [ENOSR] = TARGET_ENOSR, [ENONET] = TARGET_ENONET, [ENOPKG] = TARGET_ENOPKG, [EREMOTE] = TARGET_EREMOTE, [ENOLINK] = TARGET_ENOLINK, [EADV] = TARGET_EADV, [ESRMNT] = TARGET_ESRMNT, [ECOMM] = TARGET_ECOMM, [EPROTO] = TARGET_EPROTO, [EDOTDOT] = TARGET_EDOTDOT, [EMULTIHOP] = TARGET_EMULTIHOP, [EBADMSG] = TARGET_EBADMSG, [ENAMETOOLONG] = TARGET_ENAMETOOLONG, [EOVERFLOW] = TARGET_EOVERFLOW, [ENOTUNIQ] = TARGET_ENOTUNIQ, [EBADFD] = TARGET_EBADFD, [EREMCHG] = TARGET_EREMCHG, [ELIBACC] = TARGET_ELIBACC, [ELIBBAD] = TARGET_ELIBBAD, [ELIBSCN] = TARGET_ELIBSCN, [ELIBMAX] = TARGET_ELIBMAX, [ELIBEXEC] = TARGET_ELIBEXEC, [EILSEQ] = TARGET_EILSEQ, [ENOSYS] = TARGET_ENOSYS, [ELOOP] = TARGET_ELOOP, [ERESTART] = TARGET_ERESTART, [ESTRPIPE] = TARGET_ESTRPIPE, [ENOTEMPTY] = TARGET_ENOTEMPTY, [EUSERS] = TARGET_EUSERS, [ENOTSOCK] = TARGET_ENOTSOCK, [EDESTADDRREQ] = TARGET_EDESTADDRREQ, [EMSGSIZE] = TARGET_EMSGSIZE, [EPROTOTYPE] = TARGET_EPROTOTYPE, [ENOPROTOOPT] = TARGET_ENOPROTOOPT, [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT, [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT, [EOPNOTSUPP] = TARGET_EOPNOTSUPP, [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT, [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT, [EADDRINUSE] = TARGET_EADDRINUSE, [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL, [ENETDOWN] = TARGET_ENETDOWN, [ENETUNREACH] = TARGET_ENETUNREACH, [ENETRESET] = TARGET_ENETRESET, [ECONNABORTED] = TARGET_ECONNABORTED, [ECONNRESET] = TARGET_ECONNRESET, [ENOBUFS] = TARGET_ENOBUFS, [EISCONN] = TARGET_EISCONN, [ENOTCONN] = TARGET_ENOTCONN, [EUCLEAN] = TARGET_EUCLEAN, [ENOTNAM] = TARGET_ENOTNAM, [ENAVAIL] = TARGET_ENAVAIL, [EISNAM] = TARGET_EISNAM, [EREMOTEIO] = TARGET_EREMOTEIO, [ESHUTDOWN] = TARGET_ESHUTDOWN, [ETOOMANYREFS] = TARGET_ETOOMANYREFS, [ETIMEDOUT] = TARGET_ETIMEDOUT, [ECONNREFUSED] = TARGET_ECONNREFUSED, [EHOSTDOWN] = TARGET_EHOSTDOWN, [EHOSTUNREACH] = TARGET_EHOSTUNREACH, [EALREADY] = TARGET_EALREADY, [EINPROGRESS] = TARGET_EINPROGRESS, [ESTALE] = TARGET_ESTALE, [ECANCELED] = TARGET_ECANCELED, [ENOMEDIUM] = TARGET_ENOMEDIUM, [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE,#ifdef ENOKEY [ENOKEY] = TARGET_ENOKEY,#endif#ifdef EKEYEXPIRED [EKEYEXPIRED] = TARGET_EKEYEXPIRED,#endif#ifdef EKEYREVOKED [EKEYREVOKED] = TARGET_EKEYREVOKED,#endif#ifdef EKEYREJECTED [EKEYREJECTED] = TARGET_EKEYREJECTED,#endif#ifdef EOWNERDEAD [EOWNERDEAD] = TARGET_EOWNERDEAD,#endif#ifdef ENOTRECOVERABLE [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE,#endif};static inline int host_to_target_errno(int err){ if(host_to_target_errno_table[err]) return host_to_target_errno_table[err]; return err;}static inline int target_to_host_errno(int err){ if (target_to_host_errno_table[err]) return target_to_host_errno_table[err]; return err;}static inline abi_long get_errno(abi_long ret){ if (ret == -1) return -host_to_target_errno(errno); else return ret;}static inline int is_error(abi_long ret){ return (abi_ulong)ret >= (abi_ulong)(-4096);}char *target_strerror(int err){ return strerror(target_to_host_errno(err));}static abi_ulong target_brk;static abi_ulong target_original_brk;void target_set_brk(abi_ulong new_brk){ target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk);}/* do_brk() must return target values and target errnos. */abi_long do_brk(abi_ulong new_brk){ abi_ulong brk_page; abi_long mapped_addr; int new_alloc_size; if (!new_brk) return target_brk; if (new_brk < target_original_brk) return -TARGET_ENOMEM; brk_page = HOST_PAGE_ALIGN(target_brk); /* If the new brk is less than this, set it and we're done... */ if (new_brk < brk_page) { target_brk = new_brk; return target_brk; } /* We need to allocate more memory after the brk... */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -