From 8e1a304d72208ce4f1aa9cd896a0ac1179d162a9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 8 Jun 2014 21:18:27 +0800 Subject: [PATCH] Usermode/Syscalls - Add WriteAt/ReadAt syscalls --- KernelLand/Kernel/include/syscalls.h | 38 ++++++++++--------- KernelLand/Kernel/include/syscalls.inc.asm | 34 +++++++++-------- KernelLand/Kernel/syscalls.c | 27 ++++++++++++- KernelLand/Kernel/syscalls.lst | 2 + .../ld-acess.so_src/arch/syscalls.s.h | 2 + .../include_exp/acess/devices/pty_cmds.h | 7 ++++ .../ld-acess.so_src/include_exp/acess/sys.h | 2 + 7 files changed, 78 insertions(+), 34 deletions(-) diff --git a/KernelLand/Kernel/include/syscalls.h b/KernelLand/Kernel/include/syscalls.h index b040fc92..2a23031f 100644 --- a/KernelLand/Kernel/include/syscalls.h +++ b/KernelLand/Kernel/include/syscalls.h @@ -53,24 +53,26 @@ #define SYS_COPYFD 69 // Create a copy of a file handle #define SYS_FDCTL 70 // Modify flags of a file descriptor #define SYS_READ 71 // Read from an open file -#define SYS_WRITE 72 // Write to an open file -#define SYS_IOCTL 73 // Perform an IOCtl Call -#define SYS_SEEK 74 // Seek to a new position in the file -#define SYS_READDIR 75 // Read from an open directory -#define SYS_GETACL 76 // Get an ACL Value -#define SYS_SETACL 77 // Set an ACL Value -#define SYS_FINFO 78 // Get file information -#define SYS_MKDIR 79 // Create a new directory -#define SYS_LINK 80 // Create a new link to a file -#define SYS_SYMLINK 81 // Create a symbolic link -#define SYS_UNLINK 82 // Delete a file -#define SYS_TELL 83 // Return the current file position -#define SYS_CHDIR 84 // Change current directory -#define SYS_GETCWD 85 // Get current directory -#define SYS_MOUNT 86 // Mount a filesystem -#define SYS_SELECT 87 // Wait for file handles +#define SYS_READAT 72 // Read from an open file (with offset) +#define SYS_WRITE 73 // Write to an open file +#define SYS_WRITEAT 74 // Write to an open file (with offset) +#define SYS_IOCTL 75 // Perform an IOCtl Call +#define SYS_SEEK 76 // Seek to a new position in the file +#define SYS_READDIR 77 // Read from an open directory +#define SYS_GETACL 78 // Get an ACL Value +#define SYS_SETACL 79 // Set an ACL Value +#define SYS_FINFO 80 // Get file information +#define SYS_MKDIR 81 // Create a new directory +#define SYS_LINK 82 // Create a new link to a file +#define SYS_SYMLINK 83 // Create a symbolic link +#define SYS_UNLINK 84 // Delete a file +#define SYS_TELL 85 // Return the current file position +#define SYS_CHDIR 86 // Change current directory +#define SYS_GETCWD 87 // Get current directory +#define SYS_MOUNT 88 // Mount a filesystem +#define SYS_SELECT 89 // Wait for file handles -#define NUM_SYSCALLS 88 +#define NUM_SYSCALLS 90 #define SYS_DEBUG 0x100 #define SYS_DEBUGHEX 0x101 @@ -148,7 +150,9 @@ static const char *cSYSCALL_NAMES[] = { "SYS_COPYFD", "SYS_FDCTL", "SYS_READ", + "SYS_READAT", "SYS_WRITE", + "SYS_WRITEAT", "SYS_IOCTL", "SYS_SEEK", "SYS_READDIR", diff --git a/KernelLand/Kernel/include/syscalls.inc.asm b/KernelLand/Kernel/include/syscalls.inc.asm index ee3c8870..748d01da 100644 --- a/KernelLand/Kernel/include/syscalls.inc.asm +++ b/KernelLand/Kernel/include/syscalls.inc.asm @@ -45,19 +45,21 @@ %define SYS_COPYFD 69 ;Create a copy of a file handle %define SYS_FDCTL 70 ;Modify flags of a file descriptor %define SYS_READ 71 ;Read from an open file -%define SYS_WRITE 72 ;Write to an open file -%define SYS_IOCTL 73 ;Perform an IOCtl Call -%define SYS_SEEK 74 ;Seek to a new position in the file -%define SYS_READDIR 75 ;Read from an open directory -%define SYS_GETACL 76 ;Get an ACL Value -%define SYS_SETACL 77 ;Set an ACL Value -%define SYS_FINFO 78 ;Get file information -%define SYS_MKDIR 79 ;Create a new directory -%define SYS_LINK 80 ;Create a new link to a file -%define SYS_SYMLINK 81 ;Create a symbolic link -%define SYS_UNLINK 82 ;Delete a file -%define SYS_TELL 83 ;Return the current file position -%define SYS_CHDIR 84 ;Change current directory -%define SYS_GETCWD 85 ;Get current directory -%define SYS_MOUNT 86 ;Mount a filesystem -%define SYS_SELECT 87 ;Wait for file handles +%define SYS_READAT 72 ;Read from an open file (with offset) +%define SYS_WRITE 73 ;Write to an open file +%define SYS_WRITEAT 74 ;Write to an open file (with offset) +%define SYS_IOCTL 75 ;Perform an IOCtl Call +%define SYS_SEEK 76 ;Seek to a new position in the file +%define SYS_READDIR 77 ;Read from an open directory +%define SYS_GETACL 78 ;Get an ACL Value +%define SYS_SETACL 79 ;Set an ACL Value +%define SYS_FINFO 80 ;Get file information +%define SYS_MKDIR 81 ;Create a new directory +%define SYS_LINK 82 ;Create a new link to a file +%define SYS_SYMLINK 83 ;Create a symbolic link +%define SYS_UNLINK 84 ;Delete a file +%define SYS_TELL 85 ;Return the current file position +%define SYS_CHDIR 86 ;Change current directory +%define SYS_GETCWD 87 ;Get current directory +%define SYS_MOUNT 88 ;Mount a filesystem +%define SYS_SELECT 89 ;Wait for file handles diff --git a/KernelLand/Kernel/syscalls.c b/KernelLand/Kernel/syscalls.c index 6b970d6a..ccbe6774 100644 --- a/KernelLand/Kernel/syscalls.c +++ b/KernelLand/Kernel/syscalls.c @@ -37,6 +37,12 @@ if(tmp[i]) break;\ } while(0) +#if BITS==64 +#define ARG64(idx1,idx2) ***ARG64 not used on 64-bit*** +#else +#define ARG64(idx1, idx2) (Regs->Arg##idx1|(((Uint64)Regs->Arg##idx2)<<32)) +#endif + // === IMPORTS === extern Uint Binary_Load(const char *file, Uint *entryPoint); @@ -250,7 +256,7 @@ void SyscallHandler(tSyscallRegs *Regs) #if BITS == 64 ret = VFS_Seek( Regs->Arg1, Regs->Arg2, Regs->Arg3 ); #else - ret = VFS_Seek( Regs->Arg1, Regs->Arg2|(((Uint64)Regs->Arg3)<<32), Regs->Arg4 ); + ret = VFS_Seek( Regs->Arg1, ARG64(2, 3), Regs->Arg4 ); #endif break; @@ -262,11 +268,30 @@ void SyscallHandler(tSyscallRegs *Regs) CHECK_NUM_NONULL( (void*)Regs->Arg2, Regs->Arg3 ); ret = VFS_Write( Regs->Arg1, Regs->Arg3, (void*)Regs->Arg2 ); break; + case SYS_WRITEAT: + #if BITS == 64 + CHECK_NUM_NONULL( (void*)Regs->Arg5, Regs->Arg3 ); + ret = VFS_WriteAt( Regs->Arg1, Regs->Arg2, Regs->Arg3, (void*)Regs->Arg4 ); + #else + CHECK_NUM_NONULL( (void*)Regs->Arg5, Regs->Arg4 ); + Debug("VFS_WriteAt(%i, %lli, %i, %p)", + Regs->Arg1, ARG64(2, 3), Regs->Arg4, (void*)Regs->Arg5); + ret = VFS_WriteAt( Regs->Arg1, ARG64(2, 3), Regs->Arg4, (void*)Regs->Arg5 ); + #endif + break; case SYS_READ: CHECK_NUM_NONULL( (void*)Regs->Arg2, Regs->Arg3 ); ret = VFS_Read( Regs->Arg1, Regs->Arg3, (void*)Regs->Arg2 ); break; + case SYS_READAT: + CHECK_NUM_NONULL( (void*)Regs->Arg5, Regs->Arg2 ); + #if BITS == 64 + ret = VFS_ReadAt( Regs->Arg1, Regs->Arg2, Regs->Arg3, (void*)Regs->Arg4 ); + #else + ret = VFS_ReadAt( Regs->Arg1, Regs->Arg2, ARG64(3, 4), (void*)Regs->Arg5 ); + #endif + break; case SYS_FINFO: CHECK_NUM_NONULL( (void*)Regs->Arg2, sizeof(tFInfo) + Regs->Arg3*sizeof(tVFS_ACL) ); diff --git a/KernelLand/Kernel/syscalls.lst b/KernelLand/Kernel/syscalls.lst index 42ae03c3..6947daaa 100644 --- a/KernelLand/Kernel/syscalls.lst +++ b/KernelLand/Kernel/syscalls.lst @@ -53,7 +53,9 @@ SYS_CLOSE Close a file SYS_COPYFD Create a copy of a file handle SYS_FDCTL Modify flags of a file descriptor SYS_READ Read from an open file +SYS_READAT Read from an open file (with offset) SYS_WRITE Write to an open file +SYS_WRITEAT Write to an open file (with offset) SYS_IOCTL Perform an IOCtl Call SYS_SEEK Seek to a new position in the file SYS_READDIR Read from an open directory diff --git a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h index aa09b3ba..4eeafad6 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -52,7 +52,9 @@ SYSCALL2(_SysCopyFD, SYS_COPYFD) // int, int SYSCALL3(_SysFDFlags, SYS_FDCTL) // int, int, int SYSCALL1(_SysClose, SYS_CLOSE) // int SYSCALL3(_SysRead, SYS_READ) // int, uint, void* +SYSCALL5(_SysReadAt, SYS_READAT) // int, uint, uint64, void* SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void* +SYSCALL5(_SysWriteAt, SYS_WRITEAT) // int, uint, uint64, void* SYSCALL4(_SysSeek, SYS_SEEK) // int, uint64_t, int SYSCALL1(_SysTell, SYS_TELL) // int SYSCALL3(_SysFInfo, SYS_FINFO) // int, void*, int diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/pty_cmds.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/pty_cmds.h index 2ec0cd07..fde5d837 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/pty_cmds.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/devices/pty_cmds.h @@ -25,6 +25,7 @@ enum struct ptycmd_header { uint8_t cmd; + // NOTE: Length is encoded as a count of 32-bit words uint8_t len_low; uint16_t len_hi; } PACKED; @@ -44,5 +45,11 @@ struct ptycmd_setcursorbmp char data[]; } PACKED; +struct ptycmd_senddata +{ + struct ptycmd_header hdr; + uint32_t ofs; +} PACKED; + #endif diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h index 21b575fb..31d74c4a 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h @@ -89,9 +89,11 @@ extern int _SysReopen(int fd, const char *path, int flags); extern int _SysCopyFD(int srcfd, int dstfd); extern int _SysFDFlags(int fd, int mask, int newflags); extern size_t _SysRead(int fd, void *buffer, size_t length); +extern size_t _SysReadAt(int fd, uint64_t offset, size_t length, void *buffer); extern int _SysClose(int fd); extern int _SysFDCtl(int fd, int option, ...); extern size_t _SysWrite(int fd, const void *buffer, size_t length); +extern size_t _SysWriteAt(int fd, uint64_t offset, size_t length, const void *buffer); extern int _SysSeek(int fd, int64_t offset, int whence); extern uint64_t _SysTell(int fd); extern int _SysIOCtl(int fd, int id, void *data); -- 2.20.1