# HG changeset patch # User anatofuz # Date 1594624206 -32400 # Node ID a0d6f7124b9b2cb034eb212fb106baf496587a06 # Parent 297515214d9b8942e2557f1a7c9b24bc4e394ab5 add ReadSyscall interface diff -r 297515214d9b -r a0d6f7124b9b src/impl/ReadSyscallImpl.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/impl/ReadSyscallImpl.cbc Mon Jul 13 16:10:06 2020 +0900 @@ -0,0 +1,84 @@ +#include "../context.h" +#interface "ReadSyscall.h" + +// ---- +// typedef struct ReadSyscallImpl impl ReadSyscall { +// __code next(....); +// } ReadSyscallImpl; +// ---- + +ReadSyscall* createReadSyscallImpl(struct Context* cbc_context) { + struct ReadSyscall* read_syscall = new ReadSyscall(); + struct ReadSyscallImpl* read_syscall_impl = new ReadSyscallImpl(); + read_syscall->read_syscall = (union Data*)read_syscall_impl; + read_syscall->consoleread = C_consolereadReadSyscallImpl; + read_syscall->consoleread1 = C_consoleread1ReadSyscallImpl; + read_syscall->consoleread2 = C_consoleread2ReadSyscallImpl; + read_syscall->piperead = C_pipereadReadSyscallImpl; + read_syscall->piperead1 = C_piperead1ReadSyscallImpl; + read_syscall->piperead2 = C_piperead2ReadSyscallImpl; + read_syscall->piperead3 = C_piperead3ReadSyscallImpl; + read_syscall->fileread = C_filereadReadSyscallImpl; + read_syscall->fileread1 = C_fileread1ReadSyscallImpl; + return read_syscall; +} +__code consolereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct inode* ip, char* dst, int n, __code next(int ret, ...)) { + + goto next(ret, ...); +} + +__code consoleread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,int n, int target, char* dst, struct inode* ip, __code next(...)) { + + goto next(...); +} + +__code consoleread2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,struct inode* ip, __code next(...)) { + + goto next(...); +} + +__code pipereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p,char* addr, int n, __code next(int ret,...)) { + + goto next(ret,...); +} + +__code piperead1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, __code next(int ret,...)) { + + goto next(ret,...); +} + +__code piperead2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, int i, int n, struct pipe* p, char* addr, __code next(int ret,...)) { + + goto next(ret,...); +} + +__code piperead3ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, int i, __code next(int ret,...)) { + + goto next(ret,...); +} + +__code filereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, char* addr, int n, __code next(int ret, ...)) { + if (f->readable == 0) { + ret = -1; + goto next(ret); + } + + if (f->type == FD_PIPE) { + goto read_syscall->piperead(f->pipe, addr, n, next); + } + + if (f->type == FD_INODE) { + ilock(f->ip); + goto read_syscall->cbc_readi(f->ip, addr, f->off, n, readsys_call->fileread1); + } + + goto cbc_panic("fileread"); +} + +__code fileread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, int ret, __code next(ret, ...)) { + if (ret > 0) + f->off += ret; + iunlock(f->ip); + goto next(ret); +} + diff -r 297515214d9b -r a0d6f7124b9b src/impl/ReadSyscallImpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/impl/ReadSyscallImpl.h Mon Jul 13 16:10:06 2020 +0900 @@ -0,0 +1,3 @@ +typedef struct ReadSyscallImpl impl ReadSyscall { + __code next(....); +} ReadSyscallImpl; diff -r 297515214d9b -r a0d6f7124b9b src/interface/ReadSyscall.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/interface/ReadSyscall.h Mon Jul 13 16:10:06 2020 +0900 @@ -0,0 +1,15 @@ +typedef struct ReadSyscall { + __code consoleread(Impl* read_syscall, struct inode* ip, char* dst, int n, __code next(int ret, ...)); + __code consoleread1(Impl* read_syscall,int n, int target, char* dst, struct inode* ip, __code next(...)); + __code consoleread2(Impl* read_syscall,struct inode* ip, __code next(...)); + + __code piperead(Impl* read_syscall, struct pipe* p,char* addr, int n, __code next(int ret,...)); + __code piperead1(Impl* read_syscall, struct pipe* p, __code next(int ret,...)); + __code piperead2(Impl* read_syscall, int i, int n, struct pipe* p, char* addr, __code next(int ret,...)); + __code piperead3(Impl* read_syscall, struct pipe* p, int i, __code next(int ret,...)); + + __code fileread(Impl* read_syscall, struct file* f, char* addr, int n, __code next(int ret, ...)); + __code fileread1(Impl* read_syscall, struct file* f, int ret, __code next(ret, ...)); + + __code next(....); +} ReadSyscall;