#ifndef INT80_H #define INT80_H #include "unistd.h" #ifndef _I386_FCNTL_H #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 0100 #define O_TRUNC 01000 #define O_APPEND 02000 #define F_DUPFD 0 /* Duplicate file descriptor. */ #define F_GETFD 1 /* Get file descriptor flags. */ #define F_SETFD 2 /* Set file descriptor flags. */ #define F_GETFL 3 /* Get file status flags. */ #define F_SETFL 4 /* Set file status flags. */ #endif /* from bits/termios.h */ #define TCGETS 0x5401 #define TCSETS 0x5402 #define TCSETSW 0x5403 #define TCSETSF 0x5404 #define ISIG 0000001 #define ECHO 0000010 /* wait bits */ #define WNOHANG 0x01 #define WUNTRACED 0x02 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) /* If WIFSIGNALED(STATUS), the terminating signal. */ #define WTERMSIG(status) ((status) & 0x7f) /* If WIFSTOPPED(STATUS), the signal that stopped the child. */ #define WSTOPSIG(status) WEXITSTATUS(status) /* Nonzero if STATUS indicates normal termination. */ #define WIFEXITED(status) (WTERMSIG(status) == 0) #define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status)) /* Nonzero if STATUS indicates the child is stopped. */ #define WIFSTOPPED(status) (((status) & 0xff) == 0x7f) /* Nonzero if STATUS indicates the child dumped core. */ #define WCOREDUMP(status) ((status) & WCOREFLAG) /* Macros for constructing status values. */ #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) #define WCOREFLAG 0x80 typedef unsigned char cc_t; typedef unsigned int speed_t; typedef unsigned int tcflag_t; #define NCCS 32 typedef struct { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ speed_t c_ispeed; /* input speed */ speed_t c_ospeed; /* output speed */ } termios; /* from bits/utsname.h and sys/utsname.h */ #define _UTSNAME_LENGTH 65 #define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH #define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH struct utsname { char sysname[_UTSNAME_LENGTH]; char nodename[_UTSNAME_NODENAME_LENGTH]; char release[_UTSNAME_LENGTH]; char version[_UTSNAME_LENGTH]; char machine[_UTSNAME_LENGTH]; char domainname[_UTSNAME_DOMAIN_LENGTH]; }; typedef struct { unsigned long __val[2]; } __u_quad_t; struct stat { unsigned char space1[6 * 4]; /* __uid_t */ unsigned int st_uid; /* User ID of the file's owner. */ /* __gid_t */ unsigned int st_gid; /* Group ID of the file's group. */ unsigned char space2[8 * 4]; /* __time_t */ long int st_atime; /* Time of last access. */ unsigned long int __unused1; /* __time_t */ long int st_mtime; /* Time of last modification. */ unsigned long int __unused2; /* __time_t */ long int st_ctime; /* Time of last status change. */ unsigned long int space3[8 * 4]; /* safety margin */ }; #if 0 struct stat { /* __dev_t */ __u_quad_t st_dev; /* Device. */ unsigned short int __pad1; /* __ino_t */ unsigned long st_ino; /* File serial number. */ /* __mode_t */ unsigned int st_mode; /* File mode. */ /* __nlink_t */ unsigned int st_nlink; /* Link count. */ /* __uid_t */ unsigned int st_uid; /* User ID of the file's owner. */ /* __gid_t */ unsigned int st_gid; /* Group ID of the file's group. */ /* __dev_t */ __u_quad_t st_rdev; /* Device number, if device. */ unsigned short int __pad2; /* __off_t */ long int st_size; /* Size of file, in bytes. */ /* __blksize_t*/long int st_blksize; /* Optimal block size for I/O. */ /* __blkcnt_t */long int st_blocks; /* Number 512-byte blocks allocated. */ /* __time_t */ long int st_atime; /* Time of last access. */ unsigned long int __unused1; /* __time_t */ long int st_mtime; /* Time of last modification. */ unsigned long int __unused2; /* __time_t */ long int st_ctime; /* Time of last status change. */ unsigned long int __unused3; unsigned long int __unused4; unsigned long int __unused5; }; #endif struct utimbuf { /* time_t */ long int actime; /* access time */ /* time_t */ long int modtime; /* modification time */ }; struct timeval { long int tv_sec; /* seconds */ long int tv_usec; /* microseconds */ }; struct dirent { long d_ino; int d_off; unsigned short d_reclen; char d_name[256]; }; /* from bits/mman.h */ #define PROT_READ 0x1 #define PROT_WRITE 0x2 #define PROT_EXEC 0x4 #define PROT_NONE 0x0 #define MAP_SHARED 0x01 #define MAP_PRIVATE 0x02 #define MAP_TYPE 0x0f #define MAP_FIXED 0x10 #define MAP_ANONYMOUS 0x20 /* from unistd.h */ #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 extern int errno; static inline int getdents (int fd, struct dirent *dirp, unsigned int count) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_getdents), "b" ((long) fd), "c" ((long) dirp), "d" ((long) count)); return ret; } static inline int settimeofday (struct timeval *tv, void *tz) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_settimeofday), "b" ((long) tv), "c" ((long) tz)); return ret; } static inline int gettimeofday (struct timeval *tv, void *tz) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_gettimeofday), "b" ((long) tv), "c" ((long) tz)); return ret; } static inline int stat (char *filename, struct stat *sst) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_stat64), "b" ((long) filename), "c" ((long) sst)); return ret; } static inline int utime (char *filename, struct utimbuf *buf) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_utime), "b" ((long) filename), "c" ((long) buf)); return ret; } static inline int munmap (char *start, int length) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_munmap), "b" ((long) start), "c" ((int) length)); return ret; } #if 0 static inline int ioctl (int d, int request, int argp) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_ioctl), "S" ((long)d), "c" ((long)request), "d" ((long)argp): "bx"); return ret; } static inline int fcntl (int fd, int cmd, long arg) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_fcntl), "S" ((long)fd), "c" ((long)cmd), "d" ((long)arg): "bx"); return ret; } #endif static inline int lseek (int fd, unsigned long int offset, int whence) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_lseek), "b" ((long) fd), "c" ((long) offset), "d" ((long) whence)); return ret; } #if 0 static inline int mprotect(void *addr, long len, int prot) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_mprotect), "S" ((long)addr), "c" ((long)len), "d" ((long)prot): "bx"); return ret; } #endif static inline int read(int fd, void *buf, long count) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_read), "b" ((long) fd), "c" ((long) buf), "d" ((long) count)); return ret; } static inline int write(int fd, void *buf, long count) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_write), "b" ((long) fd), "c" ((long) buf), "d" ((long) count)); return ret; } static inline int waitpid (int pid, int *status, int options) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_waitpid), "b" ((long) pid), "c" ((long) status), "d" ((long) options)); return ret; } #define wait(status) waitpid(-1,status,0) static inline int unlink (char *pathname) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_unlink), "b" ((long)pathname)); return ret; } static inline int uname(struct utsname *un) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_uname), "b" ((long) un)); return ret; } static inline int execve(char *s, char **argv, char **envp) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"a" (__NR_execve), "b" ((long)s), "c" ((long)argv), "d" ((long)envp)); return ret; } #if 0 static inline int setreuid(int reuid, int euid) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_setreuid), "S" ((long)reuid), "c" ((long)euid): "bx"); return ret; } static inline int chroot(char *path) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_chroot), "S" ((long)path): "bx"); return ret; } static inline int brk(void *addr) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_brk), "S" (addr): "bx"); return (ret); } static inline int dup(int fd) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_dup), "S" (fd): "bx"); return ret; } #endif static inline int _exit(int level) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"a" (__NR_exit), "b" (level)); return (ret); } static inline int dup2(int ofd, int nfd) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"a" (__NR_dup2), "b" (ofd), "c" (nfd)); return ret; } static inline int open(char *path, int mode, int flags) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_open), "b" ((long) path), "c" ((int) mode), "d" ((int) flags)); return ret; } #if 0 static inline int chdir(char *path) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_chdir), "S" ((long)path): "bx"); return ret; } #endif static inline int close(int fd) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"a" (__NR_close), "b" ((int)fd)); return ret; } static inline int chown(char *path, int uid, int gid) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_chown), "b" ((long)path), "c" ((int)uid), "d" ((int)gid)); return ret; } static inline int rename(char *oldpath, char *newpath) { long ret; __asm__ __volatile__ ("int $0x80" : "=a" (ret) : "a" (__NR_rename), "b" ((long)oldpath), "c" ((int) newpath)); return ret; } #if 0 static inline int chmod(char *path, int mode) { long ret; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%esi, %%ebx\n\t" "int $0x80" :"=a" (ret) :"0" (__NR_chmod), "S" ((long)path), "c" ((int)mode): "bx"); return ret; } static inline int sync(void) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"0" (__NR_sync)); return (ret); } static inline int antistrace(void) { long ret; __asm__ __volatile__ ("int $0x03\n\t" :"=a" (ret) : ); return (ret); } #endif #define SIG_DFL 0 #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 #define SIGILL 4 #define SIGTRAP 5 #define SIGABRT 6 #define SIGFPE 8 #define SIGKILL 9 #define SIGUSR1 10 #define SIGSEGV 11 #define SIGUSR2 12 #define SIGPIPE 13 #define SIGALRM 14 #define SIGTERM 15 #define SIGCHLD 17 #define SIGCONT 18 #define SIGSTOP 19 static inline int signal(int signum, void *handler) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"a" (__NR_signal), "b" ((long)signum), "c" ((int)handler)); return ret; } static inline int fork(void) { long ret; __asm__ __volatile__ ("int $0x80" :"=a" (ret) :"0" (__NR_fork)); return (ret); } #endif