From a41c4af4ae30e963f6bc370efad60dacc39b0275 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Fri, 30 Nov 2012 14:49:21 +0800 Subject: [PATCH] Usermode - More syscall renaming --- KernelLand/Kernel/bin/elf.c | 2 +- KernelLand/Kernel/include/syscalls.h | 50 +++++++++++-------- KernelLand/Kernel/include/syscalls.inc.asm | 41 ++++++++------- KernelLand/Kernel/syscalls.lst | 5 +- Usermode/Applications/CLIShell_src/main.c | 11 ++-- Usermode/Applications/axwin3_src/WM/ipc.c | 6 +-- .../axwin3_src/libaxwin3.so_src/msg.c | 10 ++-- Usermode/Applications/bomb_src/main.c | 4 +- Usermode/Applications/dhcpclient_src/main.c | 35 ++++++++----- Usermode/Applications/init_src/main.c | 4 +- Usermode/Applications/login_src/main.c | 34 ++++--------- Usermode/Libraries/ld-acess.so_src/Makefile | 2 +- Usermode/Libraries/ld-acess.so_src/_stublib.c | 1 + .../ld-acess.so_src/arch/syscalls.s.h | 24 ++++----- Usermode/Libraries/ld-acess.so_src/common.h | 5 -- Usermode/Libraries/ld-acess.so_src/elf.c | 4 +- .../include_exp/acess/intdefs.h | 39 --------------- .../ld-acess.so_src/include_exp/acess/sys.h | 36 ++++++------- Usermode/Libraries/ld-acess.so_src/loadlib.c | 5 +- Usermode/Libraries/libposix.so_src/unistd.c | 4 +- 20 files changed, 145 insertions(+), 177 deletions(-) delete mode 100644 Usermode/Libraries/ld-acess.so_src/include_exp/acess/intdefs.h diff --git a/KernelLand/Kernel/bin/elf.c b/KernelLand/Kernel/bin/elf.c index 4456a2c8..f4c73e29 100644 --- a/KernelLand/Kernel/bin/elf.c +++ b/KernelLand/Kernel/bin/elf.c @@ -29,7 +29,7 @@ static int GetSymbol(const char *Name, void **Value, size_t *Size) { } #define AddLoaded(a,b) do{}while(0) #define LoadLibrary(a,b,c) (Log_Debug("ELF", "Module requested lib '%s'",a),0) -#define SysSetMemFlags(ad,f,m) do{}while(0) +#define _SysSetMemFlags(ad,f,m) do{}while(0) #include "../../../Usermode/Libraries/ld-acess.so_src/elf.c" // ---- / ---- diff --git a/KernelLand/Kernel/include/syscalls.h b/KernelLand/Kernel/include/syscalls.h index 5ce28149..601a7f4f 100644 --- a/KernelLand/Kernel/include/syscalls.h +++ b/KernelLand/Kernel/include/syscalls.h @@ -42,30 +42,34 @@ #define SYS_SETGID 42 // Set current Group ID #define SYS_OPEN 64 // Open a file #define SYS_REOPEN 65 // Close a file and reuse its handle -#define SYS_CLOSE 66 // Close a file -#define SYS_READ 67 // Read from an open file -#define SYS_WRITE 68 // Write to an open file -#define SYS_IOCTL 69 // Perform an IOCtl Call -#define SYS_SEEK 70 // Seek to a new position in the file -#define SYS_READDIR 71 // Read from an open directory -#define SYS_OPENCHILD 72 // Open a child entry in a directory -#define SYS_GETACL 73 // Get an ACL Value -#define SYS_SETACL 74 // Set an ACL Value -#define SYS_FINFO 75 // Get file information -#define SYS_MKDIR 76 // Create a new directory -#define SYS_LINK 77 // Create a new link to a file -#define SYS_SYMLINK 78 // Create a symbolic link -#define SYS_UNLINK 79 // Delete a file -#define SYS_TELL 80 // Return the current file position -#define SYS_CHDIR 81 // Change current directory -#define SYS_GETCWD 82 // Get current directory -#define SYS_MOUNT 83 // Mount a filesystem -#define SYS_SELECT 84 // Wait for file handles +#define SYS_OPENCHILD 66 // Open a child entry in a directory +#define SYS_OPENPIPE 67 // Open a FIFO pipe pair +#define SYS_CLOSE 68 // Close a file +#define SYS_COPYFD 69 // Create a copy of a file handle +#define SYS_FDCTL 70 // Modify properties 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 NUM_SYSCALLS 85 +#define NUM_SYSCALLS 88 #define SYS_DEBUG 0x100 #ifndef __ASSEMBLER__ +#ifndef NO_SYSCALL_STRS static const char *cSYSCALL_NAMES[] = { "SYS_EXIT", "SYS_CLONE", @@ -133,13 +137,16 @@ static const char *cSYSCALL_NAMES[] = { "", "SYS_OPEN", "SYS_REOPEN", + "SYS_OPENCHILD", + "SYS_OPENPIPE", "SYS_CLOSE", + "SYS_COPYFD", + "SYS_FDCTL", "SYS_READ", "SYS_WRITE", "SYS_IOCTL", "SYS_SEEK", "SYS_READDIR", - "SYS_OPENCHILD", "SYS_GETACL", "SYS_SETACL", "SYS_FINFO", @@ -156,5 +163,6 @@ static const char *cSYSCALL_NAMES[] = { "" }; #endif +#endif #endif diff --git a/KernelLand/Kernel/include/syscalls.inc.asm b/KernelLand/Kernel/include/syscalls.inc.asm index 149fe373..55f8fee8 100644 --- a/KernelLand/Kernel/include/syscalls.inc.asm +++ b/KernelLand/Kernel/include/syscalls.inc.asm @@ -36,22 +36,25 @@ %define SYS_SETGID 42 ;Set current Group ID %define SYS_OPEN 64 ;Open a file %define SYS_REOPEN 65 ;Close a file and reuse its handle -%define SYS_CLOSE 66 ;Close a file -%define SYS_READ 67 ;Read from an open file -%define SYS_WRITE 68 ;Write to an open file -%define SYS_IOCTL 69 ;Perform an IOCtl Call -%define SYS_SEEK 70 ;Seek to a new position in the file -%define SYS_READDIR 71 ;Read from an open directory -%define SYS_OPENCHILD 72 ;Open a child entry in a directory -%define SYS_GETACL 73 ;Get an ACL Value -%define SYS_SETACL 74 ;Set an ACL Value -%define SYS_FINFO 75 ;Get file information -%define SYS_MKDIR 76 ;Create a new directory -%define SYS_LINK 77 ;Create a new link to a file -%define SYS_SYMLINK 78 ;Create a symbolic link -%define SYS_UNLINK 79 ;Delete a file -%define SYS_TELL 80 ;Return the current file position -%define SYS_CHDIR 81 ;Change current directory -%define SYS_GETCWD 82 ;Get current directory -%define SYS_MOUNT 83 ;Mount a filesystem -%define SYS_SELECT 84 ;Wait for file handles +%define SYS_OPENCHILD 66 ;Open a child entry in a directory +%define SYS_OPENPIPE 67 ;Open a FIFO pipe pair +%define SYS_CLOSE 68 ;Close a file +%define SYS_COPYFD 69 ;Create a copy of a file handle +%define SYS_FDCTL 70 ;Modify properties 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 diff --git a/KernelLand/Kernel/syscalls.lst b/KernelLand/Kernel/syscalls.lst index 283caf9c..b1392171 100644 --- a/KernelLand/Kernel/syscalls.lst +++ b/KernelLand/Kernel/syscalls.lst @@ -43,13 +43,16 @@ SYS_SETGID Set current Group ID 64 SYS_OPEN Open a file SYS_REOPEN Close a file and reuse its handle +SYS_OPENCHILD Open a child entry in a directory +SYS_OPENPIPE Open a FIFO pipe pair SYS_CLOSE Close a file +SYS_COPYFD Create a copy of a file handle +SYS_FDCTL Modify properties of a file descriptor SYS_READ Read from an open file SYS_WRITE Write to an open file SYS_IOCTL Perform an IOCtl Call SYS_SEEK Seek to a new position in the file SYS_READDIR Read from an open directory -SYS_OPENCHILD Open a child entry in a directory SYS_GETACL Get an ACL Value SYS_SETACL Set an ACL Value SYS_FINFO Get file information diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index be621c40..28007e12 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -206,19 +206,14 @@ void CallCommand(char **Args) } // Create new process - pid = clone(CLONE_VM, 0); - // Start Task - if(pid == 0) { - execve(sTmpBuffer, Args, gasEnvironment); - printf("Execve returned, ... oops\n"); - exit(-1); - } + int fds[] = {0, 1, 2}; + pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL); if(pid <= 0) { printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message } else { int status; - waittid(pid, &status); + _SysWaitTID(pid, &status); } } diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index 17956a0c..5b600ee8 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -115,10 +115,10 @@ void IPC_HandleSelect(fd_set *set) size_t len; int tid; - while( (len = SysGetMessage(&tid, 0, NULL)) ) + while( (len = _SysGetMessage(&tid, 0, NULL)) ) { char data[len]; - SysGetMessage(NULL, len, data); + _SysGetMessage(NULL, len, data); IPC_Handle(&gIPC_Type_SysMessage, &tid, len, (void*)data); // _SysDebug("IPC_HandleSelect: Message handled"); @@ -160,7 +160,7 @@ int IPC_Type_Sys_Compare(const void *Ident1, const void *Ident2) void IPC_Type_Sys_Send(const void *Ident, size_t Length, const void *Data) { - SysSendMessage( *(const tid_t*)Ident, Length, Data ); + _SysSendMessage( *(const tid_t*)Ident, Length, Data ); } // --- Client -> Window Mappings diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c index a1f5b78e..a9a79a30 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -100,7 +100,7 @@ void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) switch(giConnectionType) { case CONNTYPE_SENDMESSAGE: - SysSendMessage(giConnectionNum, size, Msg); + _SysSendMessage(giConnectionNum, size, Msg); break; case CONNTYPE_UDP: { // Create UDP header @@ -127,7 +127,7 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) _SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG); // Clear out IPC messages - while( (len = SysGetMessage(&tid, 0, NULL)) ) + while( (len = _SysGetMessage(&tid, 0, NULL)) ) { if( giConnectionType != CONNTYPE_SENDMESSAGE || tid != giConnectionNum ) { @@ -136,7 +136,7 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) if( gAxWin3_MessageCallback ) gAxWin3_MessageCallback(tid, len); else - SysGetMessage(NULL, 0, GETMSG_IGNORE); + _SysGetMessage(NULL, 0, GETMSG_IGNORE); continue ; } @@ -144,10 +144,10 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) ret = malloc(len); if(ret == NULL) { _SysDebug("malloc() failed, ignoring message"); - SysGetMessage(NULL, 0, GETMSG_IGNORE); + _SysGetMessage(NULL, 0, GETMSG_IGNORE); return NULL; } - SysGetMessage(NULL, len, ret); + _SysGetMessage(NULL, len, ret); break; } diff --git a/Usermode/Applications/bomb_src/main.c b/Usermode/Applications/bomb_src/main.c index f19f4622..b5cac3c5 100644 --- a/Usermode/Applications/bomb_src/main.c +++ b/Usermode/Applications/bomb_src/main.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) if( gbForkBomb ) { - for(;;) clone(CLONE_VM, 0); + for(;;) _SysClone(CLONE_VM, 0); } else { for(;;) @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) printf("Outta heap space!\n"); return 0; } - tid = clone(0, stack+stackSize-stackOffset); + tid = _SysClone(0, stack+stackSize-stackOffset); //_SysDebug("tid = %i", tid); if( tid == 0 ) { diff --git a/Usermode/Applications/dhcpclient_src/main.c b/Usermode/Applications/dhcpclient_src/main.c index 5b122d8d..aaf8de7c 100644 --- a/Usermode/Applications/dhcpclient_src/main.c +++ b/Usermode/Applications/dhcpclient_src/main.c @@ -34,7 +34,7 @@ enum eStates STATE_PREINIT, STATE_DISCOVER_SENT, STATE_REQUEST_SENT, - STATE_COMPLETE + STATE_COMPLETE, }; // === STRUCTURES === @@ -72,6 +72,7 @@ typedef struct sInterface char HWAddr[6]; int64_t Timeout; + int nTimeouts; } tInterface; // === PROTOTYPES === @@ -80,8 +81,8 @@ void Scan_Dir(tInterface **IfaceList, const char *Directory); int Start_Interface(tInterface *Iface); void Send_DHCPDISCOVER(tInterface *Iface); void Send_DHCPREQUEST(tInterface *Iface, void *OfferBuffer, int TypeOffset); -int Handle_Packet(tInterface *Iface); -void Handle_Timeout(tInterface *Iface); + int Handle_Packet(tInterface *Iface); + int Handle_Timeout(tInterface *Iface); void Update_State(tInterface *Iface, int newState); void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router); @@ -145,19 +146,24 @@ int main(int argc, char *argv[]) if( FD_ISSET(i->SocketFD, &fds) ) { if( Handle_Packet( i ) ) - { - _SysClose(i->SocketFD); - _SysClose(i->IfaceFD); - p->Next = i->Next; - free(i); - i = p; - } + goto _remove; } if( _SysTimestamp() > i->Timeout ) { - Handle_Timeout(i); + if( Handle_Timeout(i) ) + { + fprintf(stderr, "%s timed out\n", i->Adapter); + goto _remove; + } } + continue ; + _remove: + _SysClose(i->SocketFD); + _SysClose(i->IfaceFD); + p->Next = i->Next; + free(i); + i = p; } } return 0; @@ -439,8 +445,10 @@ int Handle_Packet(tInterface *Iface) return 0; } -void Handle_Timeout(tInterface *Iface) +int Handle_Timeout(tInterface *Iface) { + if( Iface->nTimeouts == 3 ) + return 1; switch(Iface->State) { case STATE_DISCOVER_SENT: @@ -450,6 +458,7 @@ void Handle_Timeout(tInterface *Iface) _SysDebug("Timeout with state = %i", Iface->State); break; } + return 0; } void Update_State(tInterface *Iface, int newState) @@ -458,11 +467,13 @@ void Update_State(tInterface *Iface, int newState) { Iface->Timeout = _SysTimestamp() + 500; Iface->State = newState; + Iface->nTimeouts = 0; } else { // TODO: Exponential backoff Iface->Timeout = _SysTimestamp() + 3000; + Iface->nTimeouts ++; _SysDebug("State %i repeated, timeout is 3000ms now", newState); } } diff --git a/Usermode/Applications/init_src/main.c b/Usermode/Applications/init_src/main.c index 5a4633c2..51b91942 100644 --- a/Usermode/Applications/init_src/main.c +++ b/Usermode/Applications/init_src/main.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) // - Start virtual terminals for( i = 0; i < NUM_TERMS; i++ ) { - tid = clone(CLONE_VM, 0); + tid = _SysClone(CLONE_VM, 0); if(tid == 0) { termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i; @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) _SysOpen(termpath, OPENFLAG_READ); // Stdin _SysOpen(termpath, OPENFLAG_WRITE); // Stdout _SysOpen(termpath, OPENFLAG_WRITE); // Stderr - execve(DEFAULT_SHELL, child_argv, NULL); + _SysExecVE(DEFAULT_SHELL, child_argv, NULL); for(;;) ; } } diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index e859bfeb..59b4a784 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -38,36 +38,24 @@ int main(int argc, char *argv[]) break; } printf("\n"); - - // Create child process - pid = clone(CLONE_VM, 0); + + uinfo = GetUserInfo(uid); + struct s_sys_spawninfo spawninfo; + spawninfo.flags = 0; + spawninfo.gid = uinfo->GID; + spawninfo.uid = uinfo->UID; + const char *child_argv[2] = {"-", 0}; + const char **child_envp = NULL; + int fds[] = {0, 1, 2}; + pid = _SysSpawn(uinfo->Shell, child_argv, child_envp, 3, fds, &spawninfo); // Error check if(pid == -1) { fprintf(stderr, "Unable to fork the login process!\n"); return -1; } - // Spawn shell in a child process - if(pid == 0) - { - char *child_argv[2] = {NULL, 0}; - char **child_envp = NULL; - - // Get user information - uinfo = GetUserInfo(uid); - - child_argv[0] = uinfo->Shell; - // Set Environment - setgid(uinfo->GID); - //setuid(uid); - setuid(uinfo->UID); - - execve(uinfo->Shell, child_argv, child_envp); - exit(-1); - } - // Wait for child to terminate - waittid(pid, &status); + _SysWaitTID(pid, &status); } return 0; diff --git a/Usermode/Libraries/ld-acess.so_src/Makefile b/Usermode/Libraries/ld-acess.so_src/Makefile index d451b2c1..c77ff05b 100644 --- a/Usermode/Libraries/ld-acess.so_src/Makefile +++ b/Usermode/Libraries/ld-acess.so_src/Makefile @@ -12,7 +12,7 @@ EXTRACLEAN := $(_OBJPREFIX)_stublib.o INCFILES := sys/sys.h CFLAGS = -g -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC -CFLAGS += $(CPPFLAGS) +CFLAGS += $(CPPFLAGS) -Werror LDFLAGS = -g -T arch/$(ARCHDIR).ld -Map map.txt --export-dynamic include ../Makefile.tpl diff --git a/Usermode/Libraries/ld-acess.so_src/_stublib.c b/Usermode/Libraries/ld-acess.so_src/_stublib.c index 11362261..69a392dd 100644 --- a/Usermode/Libraries/ld-acess.so_src/_stublib.c +++ b/Usermode/Libraries/ld-acess.so_src/_stublib.c @@ -11,6 +11,7 @@ int _errno; #define SYSCALL5(name,num) void name(void){} #define SYSCALL6(name,num) void name(void){} +#define NO_SYSCALL_STRS #include "arch/syscalls.s.h" // libgcc functions 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 77d88cef..78d34bf7 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -3,12 +3,12 @@ // --- Process Control --- SYSCALL1(_exit, SYS_EXIT) -SYSCALL2(clone, SYS_CLONE) -SYSCALL2(kill, SYS_KILL) +SYSCALL2(_SysClone, SYS_CLONE) +SYSCALL2(_SysKill, SYS_KILL) //SYSCALL0(yield, SYS_YIELD) //SYSCALL0(sleep, SYS_SLEEP) SYSCALL1(_SysWaitEvent, SYS_WAITEVENT) -SYSCALL2(waittid, SYS_WAITTID) +SYSCALL2(_SysWaitTID, SYS_WAITTID) SYSCALL0(gettid, SYS_GETTID) SYSCALL0(getpid, SYS_GETPID) @@ -18,26 +18,26 @@ SYSCALL0(getgid, SYS_GETGID) SYSCALL1(setuid, SYS_SETUID) SYSCALL1(setgid, SYS_SETGID) -SYSCALL1(SysSetName, SYS_SETNAME) -SYSCALL2(SysGetName, SYS_GETNAME) +SYSCALL1(_SysSetName, SYS_SETNAME) +SYSCALL2(_SysGetName, SYS_GETNAME) SYSCALL0(_SysTimestamp, SYS_GETTIME) -SYSCALL1(SysSetPri, SYS_SETPRI) +SYSCALL1(_SysSetPri, SYS_SETPRI) -SYSCALL3(SysSendMessage, SYS_SENDMSG) -SYSCALL3(SysGetMessage, SYS_GETMSG) +SYSCALL3(_SysSendMessage, SYS_SENDMSG) +SYSCALL3(_SysGetMessage, SYS_GETMSG) SYSCALL5(_SysSpawn, SYS_SPAWN) -SYSCALL3(execve, SYS_EXECVE) -SYSCALL2(SysLoadBin, SYS_LOADBIN) -SYSCALL1(SysUnloadBin, SYS_UNLOADBIN) +SYSCALL3(_SysExecVE, SYS_EXECVE) +SYSCALL2(_SysLoadBin, SYS_LOADBIN) +SYSCALL1(_SysUnloadBin, SYS_UNLOADBIN) SYSCALL1(_SysSetFaultHandler, SYS_SETFAULTHANDLER) SYSCALL6(_SysDebug, 0x100) SYSCALL1(_SysGetPhys, SYS_GETPHYS) // uint64_t _SysGetPhys(uint addr) SYSCALL1(_SysAllocate, SYS_ALLOCATE) // uint64_t _SysAllocate(uint addr) -SYSCALL3(SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, uint flags, uint mask) +SYSCALL3(_SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, uint flags, uint mask) // VFS System calls SYSCALL2(_SysOpen, SYS_OPEN) // char*, int SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int diff --git a/Usermode/Libraries/ld-acess.so_src/common.h b/Usermode/Libraries/ld-acess.so_src/common.h index fa1957f6..125d1e52 100644 --- a/Usermode/Libraries/ld-acess.so_src/common.h +++ b/Usermode/Libraries/ld-acess.so_src/common.h @@ -52,11 +52,6 @@ extern int file_exists(const char *filename); extern void *memcpy(void *dest, const void *src, size_t len); // === System Calls === -extern void SysDebug(const char *fmt, ...); //!< Now implemented in main.c -extern void SysDebugV(const char *fmt, ...); -extern void *SysLoadBin(const char *path, void **entry); -extern int SysUnloadBin(void *Base); -extern void SysSetFaultHandler(int (*Hanlder)(int)); // === ELF Loader === extern void *ElfRelocate(void *Base, char **envp, const char *Filename); diff --git a/Usermode/Libraries/ld-acess.so_src/elf.c b/Usermode/Libraries/ld-acess.so_src/elf.c index dd64ab0f..13347a64 100644 --- a/Usermode/Libraries/ld-acess.so_src/elf.c +++ b/Usermode/Libraries/ld-acess.so_src/elf.c @@ -269,7 +269,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) uintptr_t addr = phtab[i].VAddr + iBaseDiff; uintptr_t end = addr + phtab[i].MemSize; for( ; addr < end; addr += PAGE_SIZE ) - SysSetMemFlags(addr, 0, 1); // Unset RO + _SysSetMemFlags(addr, 0, 1); // Unset RO } } @@ -455,7 +455,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) uintptr_t addr = phtab[i].VAddr + iBaseDiff; uintptr_t end = addr + phtab[i].MemSize; for( ; addr < end; addr += PAGE_SIZE ) - SysSetMemFlags(addr, 1, 1); // Unset RO + _SysSetMemFlags(addr, 1, 1); // Unset RO } } diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/intdefs.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/intdefs.h deleted file mode 100644 index 4214b5a9..00000000 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/intdefs.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - */ -#ifndef _ACESS_INTDEFS_H_ -#define _ACESS_INTDEFS_H_ - -#include -#include - -#if 0 -#define INT_MIN -0x80000000 -#define INT_MAX 0x7FFFFFFF - -typedef unsigned char __uint8_t; -typedef unsigned short __uint16_t; -typedef unsigned int __uint32_t; -typedef unsigned long long __uint64_t; - -typedef signed char __int8_t; -typedef signed short __int16_t; -typedef signed int __int32_t; -typedef signed long long __int64_t; - -#if defined(ARCHDIR_is_x86) -typedef __int32_t __intptr_t; -typedef __uint32_t __uintptr_t; -#elif defined(ARCHDIR_is_x86_64) -typedef __int64_t __intptr_t; -typedef __uint64_t __uintptr_t; -#elif defined(ARCHDIR_is_armv7) | defined(ARCHDIR_is_armv6) -typedef __int32_t __intptr_t; -typedef __uint32_t __uintptr_t; -#else -# error "Unknown pointer size" -#endif - -#endif - -#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 0f9a5f99..c7987027 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 @@ -43,21 +43,19 @@ extern int _errno; extern void _SysDebug(const char *format, ...); // --- Proc --- extern void _exit(int status) __attribute__((noreturn)); -//extern void sleep(void); -//extern void yield(void); -extern int kill(int pid, int sig); -//extern void wait(int miliseconds); +extern int _SysKill(int pid, int sig); extern int _SysWaitEvent(int EventMask); -extern int waittid(int id, int *status); -extern int clone(int flags, void *stack); -extern int execve(const char *path, char **argv, char **envp); +extern int _SysWaitTID(int id, int *status); +extern int _SysClone(int flags, void *stack); +extern int _SysExecVE(const char *path, char **argv, char **envp); extern int _SysSpawn(const char *Path, const char **argv, const char **envp, int nFDs, int *FDs, struct s_sys_spawninfo *info); extern int gettid(void); extern int getpid(void); extern int _SysSetFaultHandler(int (*Handler)(int)); -extern void SysSetName(const char *Name); -extern int SysGetName(char *NameDest); -extern int SysSetPri(int Priority); +extern void _SysSetName(const char *Name); +extern int _SysGetName(char *NameDest); +extern int _SysSetPri(int Priority); +// --- Timekeeping --- extern int64_t _SysTimestamp(void); // --- Permissions --- @@ -68,15 +66,16 @@ extern void setgid(int id); // --- VFS --- extern int _SysChdir(const char *dir); -extern int _SysRoot(const char *dir); +extern int _SysChroot(const char *dir); extern int _SysOpen(const char *path, int flags, ...); extern int _SysOpenChild(int fd, const char *name, int flags); extern int _SysOpenPipe(int *read, int *write, int flags); extern int _SysReopen(int fd, const char *path, int flags); extern int _SysCopyFD(int srcfd, int dstfd); -extern int _SysClose(int fd); extern size_t _SysRead(int fd, void *buffer, size_t length); +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 int _SysSeek(int fd, int64_t offset, int whence); extern uint64_t _SysTell(int fd); @@ -90,12 +89,15 @@ extern int _SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *err, int64_ extern int _SysUnlink(const char *pathname); // --- IPC --- -extern int SysSendMessage(int dest, size_t length, const void *Data); -extern int SysGetMessage(int *src, size_t buflen, void *Data); +extern int _SysSendMessage(int dest, size_t length, const void *Data); +extern int _SysGetMessage(int *src, size_t buflen, void *Data); // --- MEMORY --- -uint64_t _SysGetPhys(uintptr_t vaddr); -uint64_t _SysAllocate(uintptr_t vaddr); -uint32_t SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask); +extern uint64_t _SysGetPhys(uintptr_t vaddr); +extern uint64_t _SysAllocate(uintptr_t vaddr); +extern uint32_t _SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask); +extern void *_SysLoadBin(const char *path, void **entry); +extern int _SysUnloadBin(void *base); +extern void SysSetFaultHandler(int (*Hanlder)(int)); #endif diff --git a/Usermode/Libraries/ld-acess.so_src/loadlib.c b/Usermode/Libraries/ld-acess.so_src/loadlib.c index f59caf2e..dcacd8a8 100644 --- a/Usermode/Libraries/ld-acess.so_src/loadlib.c +++ b/Usermode/Libraries/ld-acess.so_src/loadlib.c @@ -4,6 +4,7 @@ */ #include "common.h" #include +#include #define DEBUG 0 @@ -77,7 +78,7 @@ void *LoadLibrary(const char *SoName, const char *SearchDir, char **envp) DEBUGS(" LoadLibrary: SysLoadBin()"); // Load Library - base = SysLoadBin(filename, (void**)&fEntry); + base = _SysLoadBin(filename, (void**)&fEntry); if(!base) { DEBUGS("LoadLibrary: RETURN 0"); return 0; @@ -172,7 +173,7 @@ void Unload(void *Base) if(id == MAX_LOADED_LIBRARIES) return; // Unload Binary - SysUnloadBin( Base ); + _SysUnloadBin( Base ); // Save String Pointer str = gLoadedLibraries[id].Name; diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 1a5b7beb..c1d4908d 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -62,10 +62,10 @@ ssize_t read(int fd, void *buf, size_t count) int fork(void) { - return clone(CLONE_VM, 0); + return _SysClone(CLONE_VM, 0); } int execv(const char *b, char *v[]) { - return execve(b, v, NULL); + return _SysExecVE(b, v, NULL); } -- 2.20.1