#include #include #include /* /n/unix/usr/include/asm-generic/errno-base.h /n/unix/usr/include/asm-generic/errno.h /sys/src/9/port/error.h */ static char *errtab[] = { [1] "operation not permitted", [2] "file does not exist", [3] "no such process", [4] "interrupted", [5] "i/o error", [6] "no such device or address", [7] "argument list too long", [8] "exec format error", [9] "fd out of range or not open", [10] "no child process", [11] "try again", [12] "out of memory", [13] "permission denied", [14] "bad address", [15] "block device required", [16] "busy", [17] "file already exists", [18] "cross-device link", [19] "no such device", [20] "not a directory", [21] "file is a directory", [22] "bad arg in system call", [23] "no free file descriptors", [24] "too many open files", [25] "not a typewriter", [26] "text file busy", [27] "file too large", [28] "no space left on device", [29] "seek on a stream", [30] "read-only file system", [31] "too many links", [32] "broken pipe", [33] "argument out of domain", [34] "result out or range", [35] "would deadlock", [36] "name too long", [37] "no record locks available", [38] "not implemented", [39] "directory not empty", [40] "symlink loop", [41] "would block", [42] "no message of desired type", [43] "identifier removed", [44] "channel number out of range", [45] "level 2 not synchronized", [46] "level 3 halted", [47] "level 3 reset", [48] "link number out of range", [49] "protocol driver not attached", [88] "not a socket", [89] "destination address required", [90] "message too long", [91] "wrong protocol type", [92] "protocol not avalable", [93] "protocol not supported", [94] "socket type not supported", [95] "operation not supported on endpoint", [96] "protocol family not supported", [97] "address family not supported", [98] "address already in use", [99] "cannot assign requested address", [100] "network is down", [101] "network is unreachable", [102] "connection reset", [103] "connection aborted", [104] "connection reset by peer", [105] "no buffer space available", [106] "endpoint is already connected", [107] "endpoint is not connected", [108] "endpoint is shut down", [109] "too many references", [110] "connection timed out", [111] "connection refused", [112] "host is down", [113] "no route to host", }; extern long _syscall6(long, long, long, long, long, long, long); int _mktos(void) { _tos->cyclefreq = 0; _tos->kcycles = -1; _tos->pcycles = -1; _tos->pid = getpid(); _tos->clock = 0; return sizeof(Tos); } static long syscall6(long sys, long a1, long a2, long a3, long a4, long a5, long a6) { long r; if((r = _syscall6(sys, a1, a2, a3, a4, a5, a6)) < 0) { r = -r; if(r < nelem(errtab) && errtab[r] != nil) werrstr("%s", errtab[r]); else werrstr("errno %ld", r); return -1; } return r; } void _exits(char *msg) { ulong code; for(code = 0; msg != nil && *msg != '\0'; msg++) code = 33*code + *msg; syscall6(1, code, 0, 0, 0, 0, 0); } long read(int fd, void *buf, long n) { return syscall6(3, fd, (long)buf, n, 0, 0, 0); } long write(int fd, void *buf, long n) { return syscall6(4, fd, (long)buf, n, 0, 0, 0); } int open(char *name, int mode) { return syscall6(5, (long)name, mode, 0, 0, 0, 0); } int close(int fd) { return syscall6(6, fd, 0, 0, 0, 0, 0); } int brk_(void *addr) { if((void *)syscall6(45, (long)addr, 0, 0, 0, 0, 0) < addr) return 0; werrstr("no memory"); return -1; } long pread(int fd, void *buf, long n, vlong o) { if(o == -1LL) return read(fd, buf, n); return syscall6(180, fd, (long)buf, n, o, o>>32, 0); } long pwrite(int fd, void *buf, long n, vlong o) { if(o == -1LL) return write(fd, buf, n); return syscall6(181, fd, (long)buf, n, o, o>>32, 0); } /* /sys/src/9/port/sysproc.c:/^generrstr */ int errstr(char *buf, uint nbuf) { static char upsyserrstr[ERRMAX]; char tmp[ERRMAX]; if(nbuf == 0) { werrstr("bad arg in system call"); return -1; } if(nbuf > ERRMAX) nbuf = ERRMAX; memmove(tmp, buf, nbuf); /* make sure it's NUL-terminated */ tmp[nbuf-1] = '\0'; memmove(buf, upsyserrstr, nbuf); buf[nbuf-1] = '\0'; memmove(upsyserrstr, tmp, nbuf); return 0; } int getpid(void) { return syscall6(20, 0, 0, 0, 0, 0, 0); } int brk(void *) { sysfatal("brk"); return -1; } void * sbrk(ulong n) { uintptr b0, b; b0 = syscall6(45, 0, 0, 0, 0, 0, 0); if((b = syscall6(45, b0 + n, 0, 0, 0, 0, 0)) != b0 + n) return nil; fprint(2, "brk'ing %uldB %#ulx\n", n, n); fprint(2, "new brk is %#p; old was %#p\n", (void *)b, (void *)b0); return (void *)b; }