From 52fad670ab81459de0ff1bd0fa99a3396a6999e3 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Fri, 30 Nov 2012 00:31:40 +0800 Subject: [PATCH] Usermode - Renamed VFS syscalls to _Sys* to remove POSIX collisions --- .../Modules/Filesystems/InitRD/files.lst | 1 + Makefile | 2 +- Usermode/Applications/CLIShell_src/main.c | 40 +++++------ Usermode/Applications/Makefile.cfg | 2 +- Usermode/Applications/Makefile.tpl | 2 +- Usermode/Applications/axwin3_src/WM/input.c | 16 ++--- Usermode/Applications/axwin3_src/WM/ipc.c | 10 +-- Usermode/Applications/axwin3_src/WM/video.c | 44 +++++++----- .../axwin3_src/WM/wm_render_text.c | 1 + .../axwin3_src/libaxwin3.so_src/msg.c | 6 +- Usermode/Applications/bomb_src/main.c | 2 +- Usermode/Applications/cat_src/main.c | 12 ++-- Usermode/Applications/dhcpclient_src/main.c | 60 ++++++++-------- Usermode/Applications/gui_ate_src/main.c | 1 + Usermode/Applications/gui_shell_src/main.c | 2 +- Usermode/Applications/init_src/main.c | 11 +-- Usermode/Applications/ip_src/addr.c | 44 ++++++------ Usermode/Applications/ip_src/routes.c | 47 ++++++------ Usermode/Applications/irc_src/main.c | 20 +++--- Usermode/Applications/ls_src/main.c | 20 +++--- Usermode/Applications/lspci_src/main.c | 13 ++-- Usermode/Applications/mount_src/main.c | 8 +-- Usermode/Applications/ping_src/main.c | 8 +-- Usermode/Applications/telnet_src/main.c | 22 +++--- Usermode/Applications/telnetd_src/main.c | 27 ++++--- Usermode/Applications/wget_src/main.c | 3 +- .../ld-acess.so_src/arch/syscalls.s.h | 30 ++++---- Usermode/Libraries/ld-acess.so_src/common.h | 4 +- .../include_exp/acess/fd_set.h | 29 ++++++++ .../ld-acess.so_src/include_exp/acess/sys.h | 46 ++++++------ .../include_exp/acess/syscall_types.h | 9 +-- .../ld-acess.so_src/include_exp/sys/types.h | 47 ------------ .../ld-acess.so_src/include_exp/unistd.h | 24 ------- Usermode/Libraries/ld-acess.so_src/lib.c | 5 +- Usermode/Libraries/libc.so_src/stdio.c | 26 +++---- Usermode/Libraries/libnet.so_src/main.c | 14 ++-- Usermode/Libraries/libnet.so_src/socket.c | 10 +-- Usermode/Libraries/libposix.so_src/Makefile | 16 +++++ .../libposix.so_src/include_exp/sys/select.h | 17 +++++ .../include_exp/sys/stat.h | 1 + .../libposix.so_src/include_exp/sys/types.h | 29 ++++++++ .../libposix.so_src/include_exp/unistd.h | 47 ++++++++++++ Usermode/Libraries/libposix.so_src/main.c | 14 ++++ Usermode/Libraries/libposix.so_src/unistd.c | 71 +++++++++++++++++++ Usermode/Libraries/libpsocket.so_src/common.h | 2 + Usermode/Libraries/libpsocket.so_src/main.c | 1 + Usermode/Libraries/libpsocket.so_src/socket.c | 20 +++--- Usermode/Libraries/libreadline.so_src/main.c | 38 +++++----- Usermode/Libraries/liburi.so_src/main.c | 22 +++--- 49 files changed, 563 insertions(+), 383 deletions(-) create mode 100644 Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h delete mode 100644 Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h delete mode 100644 Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h create mode 100644 Usermode/Libraries/libposix.so_src/Makefile create mode 100644 Usermode/Libraries/libposix.so_src/include_exp/sys/select.h rename Usermode/Libraries/{ld-acess.so_src => libposix.so_src}/include_exp/sys/stat.h (98%) create mode 100644 Usermode/Libraries/libposix.so_src/include_exp/sys/types.h create mode 100644 Usermode/Libraries/libposix.so_src/include_exp/unistd.h create mode 100644 Usermode/Libraries/libposix.so_src/main.c create mode 100644 Usermode/Libraries/libposix.so_src/unistd.c create mode 100644 Usermode/Libraries/libpsocket.so_src/common.h diff --git a/KernelLand/Modules/Filesystems/InitRD/files.lst b/KernelLand/Modules/Filesystems/InitRD/files.lst index a5d524db..1e7b6f83 100644 --- a/KernelLand/Modules/Filesystems/InitRD/files.lst +++ b/KernelLand/Modules/Filesystems/InitRD/files.lst @@ -24,6 +24,7 @@ Dir "Libs" { File "liburi.so" "__BIN__/Libs/liburi.so" File "libimage_sif.so" "__BIN__/Libs/libimage_sif.so" File "libaxwin3.so" "__BIN__/Libs/libaxwin3.so" + File "libposix.so" "__BIN__/Libs/libposix.so" } Dir "Conf" { File "BootConf.cfg" "__FS__/Conf/BootConf.cfg" diff --git a/Makefile b/Makefile index 0d265c47..32f1ffb4 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SUBMAKE = $(MAKE) --no-print-directory -USRLIBS := crt0.o acess.ld ld-acess.so libc.so +USRLIBS := crt0.o acess.ld ld-acess.so libc.so libposix.so USRLIBS += libreadline.so libnet.so liburi.so libpsocket.so USRLIBS += libimage_sif.so diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 24889faf..be621c40 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -165,15 +165,15 @@ void CallCommand(char **Args) { GeneratePath(exefile, gsCurrentDirectory, sTmpBuffer); // Check file existence - fd = open(sTmpBuffer, OPENFLAG_EXEC); + fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC); if(fd == -1) { printf("Unknown Command: `%s'\n", Args[0]); // Error Message return ; } // Get File info and close file - finfo( fd, &info, 0 ); - close( fd ); + _SysFInfo( fd, &info, 0 ); + _SysClose( fd ); // Check if the file is a directory if(info.flags & FILEFLAG_DIRECTORY) { @@ -189,10 +189,10 @@ void CallCommand(char **Args) for( i = 0; i < giNumPathDirs; i++ ) { GeneratePath(exefile, gasPathDirs[i], sTmpBuffer); - fd = open(sTmpBuffer, OPENFLAG_EXEC); + fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC); if(fd == -1) continue; - finfo( fd, &info, 0 ); - close( fd ); + _SysFInfo( fd, &info, 0 ); + _SysClose( fd ); if(info.flags & FILEFLAG_DIRECTORY) continue; // Woohoo! We found a valid command break; @@ -256,7 +256,7 @@ void Command_Help(int argc, char **argv) */ void Command_Clear(int argc, char **argv) { - write(_stdout, "\x1B[2J", 4); //Clear Screen + _SysWrite(_stdout, "\x1B[2J", 4); //Clear Screen } /** @@ -277,13 +277,13 @@ void Command_Cd(int argc, char **argv) GeneratePath(argv[1], gsCurrentDirectory, tmpPath); - fp = open(tmpPath, 0); + fp = _SysOpen(tmpPath, 0); if(fp == -1) { printf("Directory does not exist\n"); return; } - finfo(fp, &stats, 0); - close(fp); + _SysFInfo(fp, &stats, 0); + _SysClose(fp); if( !(stats.flags & FILEFLAG_DIRECTORY) ) { printf("Not a Directory\n"); @@ -295,7 +295,7 @@ void Command_Cd(int argc, char **argv) strcpy(gsCurrentDirectory, tmpPath); // Register change with kernel - chdir( gsCurrentDirectory ); + _SysChdir( gsCurrentDirectory ); } /** @@ -321,7 +321,7 @@ void Command_Dir(int argc, char **argv) dirLen = strlen(tmpPath); // Open Directory - dp = open(tmpPath, OPENFLAG_READ); + dp = _SysOpen(tmpPath, OPENFLAG_READ); // Check if file opened if(dp == -1) { @@ -329,16 +329,16 @@ void Command_Dir(int argc, char **argv) return; } // Get File Stats - if( finfo(dp, &info, 0) == -1 ) + if( _SysFInfo(dp, &info, 0) == -1 ) { - close(dp); + _SysClose(dp); printf("stat Failed, Bad File Descriptor\n"); return; } // Check if it's a directory if(!(info.flags & FILEFLAG_DIRECTORY)) { - close(dp); + _SysClose(dp); printf("Unable to open directory `%s', Not a directory\n", tmpPath); return; } @@ -352,7 +352,7 @@ void Command_Dir(int argc, char **argv) fileName = (char*)(tmpPath+dirLen); // Read Directory Content - while( (fp = SysReadDir(dp, fileName)) ) + while( (fp = _SysReadDir(dp, fileName)) ) { if(fp < 0) { @@ -361,10 +361,10 @@ void Command_Dir(int argc, char **argv) break; } // Open File - fp = open(tmpPath, 0); + fp = _SysOpen(tmpPath, 0); if(fp == -1) continue; // Get File Stats - finfo(fp, &info, 0); + _SysFInfo(fp, &info, 0); if(info.flags & FILEFLAG_DIRECTORY) printf("d"); @@ -391,7 +391,7 @@ void Command_Dir(int argc, char **argv) if(acl.perms & 2) modeStr[7] = 'w'; else modeStr[7] = '-'; if(acl.perms & 8) modeStr[8] = 'x'; else modeStr[8] = '-'; printf(modeStr); - close(fp); + _SysClose(fp); // Colour Code if(info.flags & FILEFLAG_DIRECTORY) // Directory: Green @@ -412,5 +412,5 @@ void Command_Dir(int argc, char **argv) printf("\n"); } // Close Directory - close(dp); + _SysClose(dp); } diff --git a/Usermode/Applications/Makefile.cfg b/Usermode/Applications/Makefile.cfg index 0e89a7c5..5314aea8 100644 --- a/Usermode/Applications/Makefile.cfg +++ b/Usermode/Applications/Makefile.cfg @@ -8,7 +8,7 @@ ASFLAGS = -felf CPPFLAGS = -ffreestanding -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR) CPPFLAGS += $(addprefix -I,$(wildcard $(ACESSUSERDIR)Libraries/*/include_exp/)) CFLAGS = -fno-stack-protector $(CPPFLAGS) -LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o +LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o -lposix LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name) # Extra-verbose errors! diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index c1245ae2..5bf963b7 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -47,7 +47,7 @@ ifneq ($(_OBJPREFIX),) @mkdir -p $(dir $@) endif @$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ - @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $(_OBJPREFIX)$*.dep + @$(CC) -M -MP -MT $@ $(CPPFLAGS) $< -o $(_OBJPREFIX)$*.dep $(OUTPUTDIR)Libs/libld-acess.so: @make -C $(ACESSDIR)/Usermode/Libraries/ld-acess.so_src/ diff --git a/Usermode/Applications/axwin3_src/WM/input.c b/Usermode/Applications/axwin3_src/WM/input.c index 469c08eb..29ef0047 100644 --- a/Usermode/Applications/axwin3_src/WM/input.c +++ b/Usermode/Applications/axwin3_src/WM/input.c @@ -37,21 +37,21 @@ int Input_Init(void) tNumValue num_value; // Open mouse for RW - giMouseFD = open(gsMouseDevice, 3); + giMouseFD = _SysOpen(gsMouseDevice, 3); // Set mouse limits // TODO: Update these if the screen resolution changes num_value.Num = 0; num_value.Value = giScreenWidth; - ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value); + _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value); num_value.Value = giScreenWidth/2; giInput_MouseX = giScreenWidth/2; - ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value); + _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value); num_value.Num = 1; num_value.Value = giScreenHeight; - ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value); + _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value); num_value.Value = giScreenHeight/2; giInput_MouseY = giScreenHeight/2; - ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value); + _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value); return 0; } @@ -72,7 +72,7 @@ void Input_HandleSelect(fd_set *set) static uint32_t scancode; #define KEY_CODEPOINT_MASK 0x3FFFFFFF - size_t readlen = read(giTerminalFD_Input, &codepoint, sizeof(codepoint)); + size_t readlen = _SysRead(giTerminalFD_Input, &codepoint, sizeof(codepoint)); if( readlen != sizeof(codepoint) ) { // oops, error @@ -119,8 +119,8 @@ void Input_HandleSelect(fd_set *set) mouseinfo = (void*)data; - seek(giMouseFD, 0, SEEK_SET); - i = read(giMouseFD, data, sizeof(data)); + _SysSeek(giMouseFD, 0, SEEK_SET); + i = _SysRead(giMouseFD, data, sizeof(data)); i -= sizeof(*mouseinfo); if( i < 0 ) { _SysDebug("Mouse data undersized (no header)"); diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index 2917bc98..17956a0c 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -76,11 +76,11 @@ void IPC_Init(void) { int tmp; // TODO: Check this - giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ); + giNetworkFileHandle = _SysOpen("/Devices/ip/loop/udp", OPENFLAG_READ); if( giNetworkFileHandle != -1 ) { tmp = AXWIN_PORT; - ioctl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number + _SysIOCtl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number } } @@ -103,7 +103,7 @@ void IPC_HandleSelect(fd_set *set) int readlen, identlen; char *msg; - readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf)); + readlen = _SysRead(giNetworkFileHandle, staticBuf, sizeof(staticBuf)); identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] ); msg = staticBuf + identlen; @@ -114,7 +114,7 @@ void IPC_HandleSelect(fd_set *set) } size_t len; - pid_t tid; + int tid; while( (len = SysGetMessage(&tid, 0, NULL)) ) { char data[len]; @@ -145,7 +145,7 @@ void IPC_Type_Datagram_Send(const void *Ident, size_t Length, const void *Data) memcpy(tmpbuf, Ident, identlen); // Header memcpy(tmpbuf + identlen, Data, Length); // Data // TODO: Handle fragmented packets - write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf)); + _SysWrite(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf)); } int IPC_Type_Sys_GetSize(const void *Ident) diff --git a/Usermode/Applications/axwin3_src/WM/video.c b/Usermode/Applications/axwin3_src/WM/video.c index d4005684..60f2155e 100644 --- a/Usermode/Applications/axwin3_src/WM/video.c +++ b/Usermode/Applications/axwin3_src/WM/video.c @@ -38,7 +38,7 @@ void Video_Setup(void) // Open terminal #if 0 - giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE); + giTerminalFD = _SysOpen(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE); if( giTerminalFD == -1 ) { fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno); @@ -48,8 +48,8 @@ void Video_Setup(void) giTerminalFD = 1; giTerminalFD_Input = 0; // Check that the console is a VT - // - ioctl(..., 0, NULL) returns the type, which should be 2 - if( ioctl(1, 0, NULL) != 2 ) + // - _SysIOCtl(..., 0, NULL) returns the type, which should be 2 + if( _SysIOCtl(1, 0, NULL) != 2 ) { fprintf(stderr, "stdout is not an Acess VT, can't start"); _SysDebug("stdout is not an Acess VT, can't start"); @@ -59,22 +59,22 @@ void Video_Setup(void) // Set mode to video tmpInt = TERM_MODE_FB; - ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt ); + _SysIOCtl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt ); // Get dimensions - giScreenWidth = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, NULL ); - giScreenHeight = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL ); + giScreenWidth = _SysIOCtl( giTerminalFD, TERM_IOCTL_WIDTH, NULL ); + giScreenHeight = _SysIOCtl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL ); giVideo_LastDirtyLine = giScreenHeight; // Force VT to be shown - ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL ); + _SysIOCtl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL ); // Create local framebuffer (back buffer) gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 ); // Set cursor position and bitmap - ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap); + _SysIOCtl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap); Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 ); } @@ -87,9 +87,9 @@ void Video_Update(void) _SysDebug("Video_Update - Updating lines %i to %i (0x%x+0x%x px)", giVideo_FirstDirtyLine, giVideo_LastDirtyLine, ofs, size); - seek(giTerminalFD, ofs*4, 1); + _SysSeek(giTerminalFD, ofs*4, 1); _SysDebug("Video_Update - Sending FD %i %p 0x%x", giTerminalFD, gpScreenBuffer+ofs, size*4); - write(giTerminalFD, gpScreenBuffer+ofs, size*4); + _SysWrite(giTerminalFD, gpScreenBuffer+ofs, size*4); _SysDebug("Video_Update - Done"); giVideo_FirstDirtyLine = 0; giVideo_LastDirtyLine = 0; @@ -103,7 +103,7 @@ void Video_SetCursorPos(short X, short Y) } pos; pos.x = giVideo_CursorX = X; pos.y = giVideo_CursorY = Y; - ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos); + _SysIOCtl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos); } void Video_FillRect(int X, int Y, int W, int H, uint32_t Colour) @@ -136,13 +136,22 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H) if( DstX >= giScreenWidth) return ; if( DstY >= giScreenHeight) return ; - // TODO: Handle -ve X/Y by clipping - if( DstX < 0 || DstY < 0 ) return ; - // TODO: Handle out of bounds by clipping too + // Drawing oob to left/top, clip + if( DstX < 0 ) { + Source += -DstX; + drawW -= -DstX; + DstX = 0; + } + if( DstY < 0 ) { + Source += (-DstY)*W; + H -= -DstY; + DstY = 0; + } + if( drawW < 0 ) return ; + // Drawing oob to the right, clip if( DstX + drawW > giScreenWidth ) { - int oldw = drawW; + //int oldw = drawW; drawW = giScreenWidth - DstX; - _SysDebug("Video_Blit: Clipped width from %i to %i", oldw, drawW); } if( DstY + H > giScreenHeight ) H = giScreenHeight - DstY; @@ -155,7 +164,7 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H) giVideo_LastDirtyLine = DstY + H; buf = gpScreenBuffer + DstY*giScreenWidth + DstX; - if(drawW != giScreenWidth) + if(drawW != giScreenWidth || W != giScreenWidth) { while( H -- ) { @@ -166,6 +175,7 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H) } else { + // Only valid if copying full scanlines on both ends memcpy(buf, Source, giScreenWidth*H*4); } } diff --git a/Usermode/Applications/axwin3_src/WM/wm_render_text.c b/Usermode/Applications/axwin3_src/WM/wm_render_text.c index 8168c5c0..6ad72be6 100644 --- a/Usermode/Applications/axwin3_src/WM/wm_render_text.c +++ b/Usermode/Applications/axwin3_src/WM/wm_render_text.c @@ -9,6 +9,7 @@ #include #include #include +#include // INT_MAX // === TYPES === typedef struct sGlyph tGlyph; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c index 6c134a31..a1f5b78e 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -107,11 +107,11 @@ void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) char tmpbuf[giAxWin3_int_UDPHeaderLen + size]; memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen); memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size); - write(giConnectionNum, tmpbuf, sizeof(tmpbuf)); + _SysWrite(giConnectionNum, tmpbuf, sizeof(tmpbuf)); } break; case CONNTYPE_TCP: - write(giConnectionNum, Msg, size); + _SysWrite(giConnectionNum, Msg, size); break; default: break; @@ -122,7 +122,7 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) { int len; tAxWin_IPCMessage *ret = NULL; - pid_t tid; + int tid; _SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG); diff --git a/Usermode/Applications/bomb_src/main.c b/Usermode/Applications/bomb_src/main.c index af5d094a..f19f4622 100644 --- a/Usermode/Applications/bomb_src/main.c +++ b/Usermode/Applications/bomb_src/main.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) if( tid == 0 ) { // Sleep forever (TODO: Fix up the stack so it can nuke) - for(;;) sleep(); + for(;;) _SysWaitEvent(THREAD_EVENT_SIGNAL); } if( tid < 0 ) { printf("Clone failed\n"); diff --git a/Usermode/Applications/cat_src/main.c b/Usermode/Applications/cat_src/main.c index 443a5dee..3fae4c6c 100644 --- a/Usermode/Applications/cat_src/main.c +++ b/Usermode/Applications/cat_src/main.c @@ -1,7 +1,6 @@ /* * Acess2 CAT command */ -#include #include #include @@ -13,7 +12,6 @@ */ int main(int argc, char *argv[]) { - int fd; int num; char buf[BUF_SIZE]; @@ -22,19 +20,19 @@ int main(int argc, char *argv[]) return -1; } - fd = open(argv[1], OPENFLAG_READ); - if(fd == -1) { + FILE *fp = fopen(argv[1], "r"); + if(!fp) { printf("Unable to open '%s' for reading\n", argv[1]); return -1; } do { - num = read(fd, buf, BUF_SIZE); + num = fread(buf, BUF_SIZE, 1, fp); if(num < 0) break; - write(1, buf, num); + fwrite(buf, num, 1, stdout); } while(num == BUF_SIZE); - close(fd); + fclose(fp); printf("\n"); return 0; diff --git a/Usermode/Applications/dhcpclient_src/main.c b/Usermode/Applications/dhcpclient_src/main.c index 8831cd6e..5b122d8d 100644 --- a/Usermode/Applications/dhcpclient_src/main.c +++ b/Usermode/Applications/dhcpclient_src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #define FILENAME_MAX 255 // --- Translation functions --- @@ -145,8 +146,8 @@ int main(int argc, char *argv[]) { if( Handle_Packet( i ) ) { - close(i->SocketFD); - close(i->IfaceFD); + _SysClose(i->SocketFD); + _SysClose(i->IfaceFD); p->Next = i->Next; free(i); i = p; @@ -164,14 +165,15 @@ int main(int argc, char *argv[]) void Scan_Dir(tInterface **IfaceList, const char *Directory) { - int dp = open(Directory, OPENFLAG_READ); + int dp = _SysOpen(Directory, OPENFLAG_READ); char filename[FILENAME_MAX]; if( dp == -1 ) { fprintf(stderr, "Unable to open directory '%s'\n", Directory); + return ; } - while( SysReadDir(dp, filename) ) + while( _SysReadDir(dp, filename) ) { if( filename[0] == '.' ) continue ; if( strcmp(filename, "lo") == 0 ) continue ; @@ -182,7 +184,7 @@ void Scan_Dir(tInterface **IfaceList, const char *Directory) new->Next = *IfaceList; *IfaceList = new; } - close(dp); + _SysClose(dp); } // RETURN: Client FD @@ -198,52 +200,52 @@ int Start_Interface(tInterface *Iface) { char path[] = "/Devices/ip/adapters/ethXXXX"; sprintf(path, "/Devices/ip/adapters/%s", Iface->Adapter); - fd = open(path, 0); + fd = _SysOpen(path, 0); if(fd == -1) { _SysDebug("Unable to open adapter %s", path); return -1; } - ioctl(fd, 4, Iface->HWAddr); + _SysIOCtl(fd, 4, Iface->HWAddr); // TODO: Check if ioctl() failed - close(fd); + _SysClose(fd); } // Initialise an interface, with a dummy IP address (zero) - fd = open("/Devices/ip", 0); + fd = _SysOpen("/Devices/ip", 0); if( fd == -1 ) { fprintf(stderr, "ERROR: Unable to open '/Devices/ip'\n"); return -1; } - Iface->Num = ioctl(fd, 4, (void*)Iface->Adapter); // Create interface + Iface->Num = _SysIOCtl(fd, 4, (void*)Iface->Adapter); // Create interface if( Iface->Num == -1 ) { fprintf(stderr, "ERROR: Unable to create new interface\n"); return -1; } - close(fd); + _SysClose(fd); // Open new interface snprintf(path, sizeof(path), "/Devices/ip/%i", Iface->Num); - Iface->IfaceFD = fd = open(path, 0); + Iface->IfaceFD = fd = _SysOpen(path, 0); if( fd == -1 ) { fprintf(stderr, "ERROR: Unable to open '%s'\n", path); return -1; } - tmp = 4; ioctl(fd, 4, &tmp); // Set to IPv4 - ioctl(fd, 6, addr); // Set address to 0.0.0.0 - tmp = 0; ioctl(fd, 7, &tmp); // Set subnet mask to 0 + tmp = 4; _SysIOCtl(fd, 4, &tmp); // Set to IPv4 + _SysIOCtl(fd, 6, addr); // Set address to 0.0.0.0 + tmp = 0; _SysIOCtl(fd, 7, &tmp); // Set subnet mask to 0 // Open UDP Client snprintf(path, sizeof(path), "/Devices/ip/%i/udp", Iface->Num); - Iface->SocketFD = fd = open(path, O_RDWR); + Iface->SocketFD = fd = _SysOpen(path, O_RDWR); if( fd == -1 ) { fprintf(stderr, "ERROR: Unable to open '%s'\n", path); return -1; } - tmp = 68; ioctl(fd, 4, &tmp); // Local port - tmp = 67; ioctl(fd, 5, &tmp); // Remote port - tmp = 0; ioctl(fd, 7, &tmp); // Remote addr mask bits - we don't care where the reply comes from + tmp = 68; _SysIOCtl(fd, 4, &tmp); // Local port + tmp = 67; _SysIOCtl(fd, 5, &tmp); // Remote port + tmp = 0; _SysIOCtl(fd, 7, &tmp); // Remote addr mask bits - we don't care where the reply comes from addr[0] = addr[1] = addr[2] = addr[3] = 255; // 255.255.255.255 - ioctl(fd, 8, addr); // Remote address + _SysIOCtl(fd, 8, addr); // Remote address return 0; } @@ -292,7 +294,7 @@ void Send_DHCPDISCOVER(tInterface *Iface) data[2] = 4; data[3] = 0; // AddrType data[4] = 255; data[5] = 255; data[6] = 255; data[7] = 255; - write(Iface->SocketFD, data, sizeof(data)); + _SysWrite(Iface->SocketFD, data, sizeof(data)); Update_State(Iface, STATE_DISCOVER_SENT); } @@ -338,7 +340,7 @@ void Send_DHCPREQUEST(tInterface *Iface, void *OfferPacket, int TypeOffset) ((uint8_t*)OfferPacket)[6] = 255; ((uint8_t*)OfferPacket)[7] = 255; - write(Iface->SocketFD, OfferPacket, 8 + sizeof(*msg) + i); + _SysWrite(Iface->SocketFD, OfferPacket, 8 + sizeof(*msg) + i); Update_State(Iface, STATE_REQUEST_SENT); } @@ -353,7 +355,7 @@ int Handle_Packet(tInterface *Iface) void *subnet_mask = NULL; _SysDebug("Doing read on %i", Iface->SocketFD); - len = read(Iface->SocketFD, data, sizeof(data)); + len = _SysRead(Iface->SocketFD, data, sizeof(data)); _SysDebug("len = %i", len); _SysDebug("*msg = {"); @@ -510,8 +512,8 @@ void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router) ); } - ioctl(Iface->IfaceFD, 6, Addr); - ioctl(Iface->IfaceFD, 7, &mask_bits); + _SysIOCtl(Iface->IfaceFD, 6, Addr); + _SysIOCtl(Iface->IfaceFD, 7, &mask_bits); if( Router ); { @@ -520,16 +522,16 @@ void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router) // Set default route int fd; - fd = open("/Devices/ip/routes/4:00000000:0:0", OPENFLAG_CREATE); + fd = _SysOpen("/Devices/ip/routes/4:00000000:0:0", OPENFLAG_CREATE); if(fd == -1) { fprintf(stderr, "ERROR: Unable to open default route\n"); } else { char ifname[snprintf(NULL,0,"%i",Iface->Num)+1]; sprintf(ifname, "%i", Iface->Num); - ioctl(fd, ioctl(fd, 3, "set_nexthop"), Router); - ioctl(fd, ioctl(fd, 3, "set_interface"), ifname); - close(fd); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_nexthop"), Router); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_interface"), ifname); + _SysClose(fd); } } } diff --git a/Usermode/Applications/gui_ate_src/main.c b/Usermode/Applications/gui_ate_src/main.c index a6ed8aa7..032a9685 100644 --- a/Usermode/Applications/gui_ate_src/main.c +++ b/Usermode/Applications/gui_ate_src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include "strings.h" // === PROTOTYPES === int main(int argc, char *argv[]); diff --git a/Usermode/Applications/gui_shell_src/main.c b/Usermode/Applications/gui_shell_src/main.c index f5524bca..c7aac852 100644 --- a/Usermode/Applications/gui_shell_src/main.c +++ b/Usermode/Applications/gui_shell_src/main.c @@ -86,7 +86,7 @@ int main(int argc, char *argv[], const char **envp) int len = read(giChildStdout, buf, sizeof(buf)); if( len <= 0 ) break; - //Term_HandleOutput(len, buf); + Term_HandleOutput(len, buf); } } diff --git a/Usermode/Applications/init_src/main.c b/Usermode/Applications/init_src/main.c index c18e5f8c..5a4633c2 100644 --- a/Usermode/Applications/init_src/main.c +++ b/Usermode/Applications/init_src/main.c @@ -37,16 +37,17 @@ int main(int argc, char *argv[]) { termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i; - open(termpath, OPENFLAG_READ); // Stdin - open(termpath, OPENFLAG_WRITE); // Stdout - open(termpath, OPENFLAG_WRITE); // Stderr + _SysOpen(termpath, OPENFLAG_READ); // Stdin + _SysOpen(termpath, OPENFLAG_WRITE); // Stdout + _SysOpen(termpath, OPENFLAG_WRITE); // Stderr execve(DEFAULT_SHELL, child_argv, NULL); - for(;;) sleep(); + for(;;) ; } } // TODO: Implement message watching - for(;;) sleep(); + for(;;) + _SysWaitEvent(THREAD_EVENT_IPCMSG); return 42; } diff --git a/Usermode/Applications/ip_src/addr.c b/Usermode/Applications/ip_src/addr.c index cf5d5dca..2046bb09 100644 --- a/Usermode/Applications/ip_src/addr.c +++ b/Usermode/Applications/ip_src/addr.c @@ -61,9 +61,9 @@ int AddInterface(const char *Device) { int dp, ret; - dp = open(IPSTACK_ROOT, OPENFLAG_READ); - ret = ioctl(dp, 4, (void*)Device); - close(dp); + dp = _SysOpen(IPSTACK_ROOT, OPENFLAG_READ); + ret = _SysIOCtl(dp, 4, (void*)Device); + _SysClose(dp); if( ret < 0 ) { fprintf(stderr, "Unable to add '%s' as a network interface\n", Device); @@ -94,26 +94,26 @@ int SetAddress(int IFNum, const char *Address) // Open file sprintf(path, IPSTACK_ROOT"/%i", IFNum); - fd = open(path, OPENFLAG_READ); + fd = _SysOpen(path, OPENFLAG_READ); if( fd == -1 ) { fprintf(stderr, "Unable to open '%s'\n", path); return -1; } tmp = type; - tmp = ioctl(fd, ioctl(fd, 3, "getset_type"), &tmp); + tmp = _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_type"), &tmp); if( tmp != type ) { fprintf(stderr, "Error in setting address type (got %i, expected %i)\n", tmp, type); - close(fd); + _SysClose(fd); return -1; } // Set Address - ioctl(fd, ioctl(fd, 3, "set_address"), addr); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_address"), addr); // Set Subnet - ioctl(fd, ioctl(fd, 3, "getset_subnet"), &subnet); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_subnet"), &subnet); - close(fd); + _SysClose(fd); // Dump! //DumpInterface( path+sizeof(IPSTACK_ROOT)+1 ); @@ -129,15 +129,15 @@ void DumpInterfaces(void) int dp; char filename[FILENAME_MAX+1]; - dp = open(IPSTACK_ROOT, OPENFLAG_READ); + dp = _SysOpen(IPSTACK_ROOT, OPENFLAG_READ); - while( SysReadDir(dp, filename) ) + while( _SysReadDir(dp, filename) ) { if(filename[0] == '.') continue; DumpInterface(filename); } - close(dp); + _SysClose(dp); } /** @@ -151,13 +151,13 @@ void DumpInterface(const char *Name) strcat(path, Name); - fd = open(path, OPENFLAG_READ); + fd = _SysOpen(path, OPENFLAG_READ); if(fd == -1) { fprintf(stderr, "Bad interface name '%s' (%s does not exist)\t", Name, path); return ; } - type = ioctl(fd, 4, NULL); + type = _SysIOCtl(fd, 4, NULL); // Ignore -1 values if( type == -1 ) { @@ -166,10 +166,10 @@ void DumpInterface(const char *Name) printf("%s:\t", Name); { - int call_num = ioctl(fd, 3, "get_device"); - int len = ioctl(fd, call_num, NULL); + int call_num = _SysIOCtl(fd, 3, "get_device"); + int len = _SysIOCtl(fd, call_num, NULL); char *buf = malloc(len+1); - ioctl(fd, call_num, buf); + _SysIOCtl(fd, call_num, buf); printf("'%s'\n", buf); free(buf); } @@ -185,8 +185,8 @@ void DumpInterface(const char *Name) uint8_t ip[4]; int subnet; printf("IPv4\t"); - ioctl(fd, 5, ip); // Get IP Address - subnet = ioctl(fd, 7, NULL); // Get Subnet Bits + _SysIOCtl(fd, 5, ip); // Get IP Address + subnet = _SysIOCtl(fd, 7, NULL); // Get Subnet Bits printf("%i.%i.%i.%i/%i\n", ip[0], ip[1], ip[2], ip[3], subnet); } break; @@ -195,8 +195,8 @@ void DumpInterface(const char *Name) uint16_t ip[8]; int subnet; printf("IPv6\t"); - ioctl(fd, 5, ip); // Get IP Address - subnet = ioctl(fd, 7, NULL); // Get Subnet Bits + _SysIOCtl(fd, 5, ip); // Get IP Address + subnet = _SysIOCtl(fd, 7, NULL); // Get Subnet Bits printf("%x:%x:%x:%x:%x:%x:%x:%x/%i\n", ntohs(ip[0]), ntohs(ip[1]), ntohs(ip[2]), ntohs(ip[3]), ntohs(ip[4]), ntohs(ip[5]), ntohs(ip[6]), ntohs(ip[7]), @@ -208,6 +208,6 @@ void DumpInterface(const char *Name) break; } - close(fd); + _SysClose(fd); } diff --git a/Usermode/Applications/ip_src/routes.c b/Usermode/Applications/ip_src/routes.c index f074bff8..ba568135 100644 --- a/Usermode/Applications/ip_src/routes.c +++ b/Usermode/Applications/ip_src/routes.c @@ -12,7 +12,7 @@ // === PROTOTYPES === int Routes_main(int argc, char *argv[]); void DumpRoutes(void); -void DumpRoute(const char *Name); +void DumpRoute(int PFD, const char *Name); void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, int Metric, void *NextHop); // === CODE === @@ -114,33 +114,30 @@ void DumpRoutes(void) int dp; char filename[FILENAME_MAX+1]; - dp = open(IPSTACK_ROOT"/routes", OPENFLAG_READ); + dp = _SysOpen(IPSTACK_ROOT"/routes", OPENFLAG_READ); printf("Type\tNetwork \tGateway \tMetric\tIFace\n"); - while( SysReadDir(dp, filename) ) + while( _SysReadDir(dp, filename) ) { if(filename[0] == '.') continue; - DumpRoute(filename); + DumpRoute(dp, filename); } - close(dp); + _SysClose(dp); } /** * \brief Dump a route */ -void DumpRoute(const char *Name) +void DumpRoute(int PFD, const char *Name) { int fd; int type; - char path[sizeof(IPSTACK_ROOT)+8+FILENAME_MAX+1] = IPSTACK_ROOT"/routes/"; - strcat(path, Name); - - fd = open(path, OPENFLAG_READ); + fd = _SysOpenChild(PFD, Name, OPENFLAG_READ); if(fd == -1) { - printf("%s:\tUnable to open ('%s')\n", Name, path); + printf("%s:\tUnable to open\n", Name); return ; } @@ -161,7 +158,7 @@ void DumpRoute(const char *Name) subnet = atoi(Name+ofs); ofs ++; metric = atoi(Name+ofs); - ioctl(fd, ioctl(fd, 3, "get_nexthop"), gw); // Get Gateway/NextHop + _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_nexthop"), gw); // Get Gateway/NextHop // Get the address type switch(type) @@ -185,17 +182,17 @@ void DumpRoute(const char *Name) // Interface { - int call_num = ioctl(fd, 3, "get_interface"); - int len = ioctl(fd, call_num, NULL); + int call_num = _SysIOCtl(fd, 3, "get_interface"); + int len = _SysIOCtl(fd, call_num, NULL); char *buf = malloc(len+1); - ioctl(fd, call_num, buf); + _SysIOCtl(fd, call_num, buf); printf("'%s'\t", buf); free(buf); } printf("\n"); - close(fd); + _SysClose(fd); } void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, int Metric, void *NextHop) @@ -227,20 +224,20 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, // Open interface strcpy(ifacePath, IPSTACK_ROOT"/"); strcat(ifacePath, Interface); - fd = open(ifacePath, 0); + fd = _SysOpen(ifacePath, 0); if( fd == -1 ) { fprintf(stderr, "Error: Interface '%s' does not exist\n", Interface); return ; } // Get and check type - num = ioctl(fd, ioctl(fd, 3, "getset_type"), NULL); + num = _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_type"), NULL); if( num != AddressType ) { fprintf(stderr, "Error: Passed type does not match interface type (%i != %i)\n", AddressType, num); return ; } - close(fd); + _SysClose(fd); } // Create route @@ -256,23 +253,23 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, sprintf(path+ofs, ":%i:%i", MaskBits, Metric); } - fd = open(path, 0); + fd = _SysOpen(path, 0); if( fd != -1 ) { - close(fd); + _SysClose(fd); fprintf(stderr, "Unable to create route '%s', already exists\n", path); return ; } - fd = open(path, OPENFLAG_CREATE, 0); + fd = _SysOpen(path, OPENFLAG_CREATE, 0); if( fd == -1 ) { fprintf(stderr, "Unable to create '%s'\n", path); return ; } if( NextHop ) - ioctl(fd, ioctl(fd, 3, "set_nexthop"), NextHop); - ioctl(fd, ioctl(fd, 3, "set_interface"), (void*)Interface); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_nexthop"), NextHop); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_interface"), (void*)Interface); - close(fd); + _SysClose(fd); // Check if the interface name was allocated by us if( ifaceToFree ) diff --git a/Usermode/Applications/irc_src/main.c b/Usermode/Applications/irc_src/main.c index 901e8ac1..9e5a0757 100644 --- a/Usermode/Applications/irc_src/main.c +++ b/Usermode/Applications/irc_src/main.c @@ -102,8 +102,8 @@ int main(int argc, const char *argv[], const char *envp[]) atexit(ExitHandler); - giTerminal_Width = ioctl(1, 5, NULL); // getset_width - giTerminal_Height = ioctl(1, 6, NULL); // getset_height + giTerminal_Width = _SysIOCtl(1, 5, NULL); // getset_width + giTerminal_Height = _SysIOCtl(1, 6, NULL); // getset_height printf("\x1B[?1047h"); printf("\x1B[%i;%ir", 0, giTerminal_Height-1); @@ -194,7 +194,7 @@ int main(int argc, const char *argv[], const char *envp[]) { tServer *srv; for( srv = gpServers; srv; srv = srv->Next ) - close(srv->FD); + _SysClose(srv->FD); } return 0; } @@ -659,11 +659,11 @@ int ProcessIncoming(tServer *Server) // ioctl#8 on a TCP client gets the number of bytes in the recieve buffer // - Used to avoid blocking #if NON_BLOCK_READ - while( (len = ioctl(Server->FD, 8, NULL)) > 0 ) + while( (len = _SysIOCtl(Server->FD, 8, NULL)) > 0 ) { #endif // Read data - len = read(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos); + len = _SysRead(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos); if( len == -1 ) { return -1; } @@ -717,7 +717,7 @@ int writef(int FD, const char *Format, ...) vsnprintf(buf, len+1, Format, args); va_end(args); - return write(FD, buf, len); + return _SysWrite(FD, buf, len); } } @@ -747,12 +747,12 @@ int OpenTCP(const char *AddressString, short PortNumber) // Set remote port and address // printf("Setting port and remote address\n"); - ioctl(fd, 5, &PortNumber); - ioctl(fd, 6, addrBuffer); + _SysIOCtl(fd, 5, &PortNumber); + _SysIOCtl(fd, 6, addrBuffer); // Connect // printf("Initiating connection\n"); - if( ioctl(fd, 7, NULL) == 0 ) { + if( _SysIOCtl(fd, 7, NULL) == 0 ) { // Shouldn't happen :( fprintf(stderr, "Unable to start connection\n"); return -1; @@ -797,7 +797,7 @@ int SetCursorPos(int Row, int Col) Row = Col / giTerminal_Width; Col = Col % giTerminal_Width; } - rv = ioctl(1, 9, NULL); // Ugh, constants + rv = _SysIOCtl(1, 9, NULL); // Ugh, constants printf("\x1B[%i;%iH", Col, Row); return rv; } diff --git a/Usermode/Applications/ls_src/main.c b/Usermode/Applications/ls_src/main.c index 2394af61..973013b0 100644 --- a/Usermode/Applications/ls_src/main.c +++ b/Usermode/Applications/ls_src/main.c @@ -51,17 +51,17 @@ int main(int argc, char *argv[]) ParseArguments(argc, argv); // Open Directory - fd = open(gsDirectory, OPENFLAG_READ|OPENFLAG_EXEC); + fd = _SysOpen(gsDirectory, OPENFLAG_READ|OPENFLAG_EXEC); if(fd == -1) { printf("Unable to open '%s' for reading\n", gsDirectory); return EXIT_FAILURE; } // Check that it is a directory - finfo(fd, &info, 0); + _SysFInfo(fd, &info, 0); if( !(info.flags & FILEFLAG_DIRECTORY) ) { fprintf(stderr, "'%s' is not a directory\n", gsDirectory); - close(fd); + _SysClose(fd); return EXIT_FAILURE; } @@ -75,11 +75,11 @@ int main(int argc, char *argv[]) } // Traverse Directory - while( (tmp = SysReadDir(fd, buf)) > 0 ) + while( (tmp = _SysReadDir(fd, buf)) > 0 ) { // Error check if(tmp < 0) { - close(fd); + _SysClose(fd); return EXIT_FAILURE; } @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) space += 16; gFileList = realloc(gFileList, space*sizeof(char*)); if(gFileList == NULL) { - close(fd); + _SysClose(fd); return EXIT_FAILURE; } } @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) DisplayFile( gFileList[i] ); } - close(fd); + _SysClose(fd); printf("\n"); return EXIT_SUCCESS; @@ -218,13 +218,13 @@ void DisplayFile(char *Filename) strcpy(&path[dirLen+1], Filename); // Get file type - fd = open(path, 0); + fd = _SysOpen(path, 0); if(fd == -1) { fprintf(stderr, "Unable to open '%s'\n", path); } else { // Get Info - finfo(fd, &info, 0); + _SysFInfo(fd, &info, 0); // Get Type if(info.flags & FILEFLAG_DIRECTORY) { type = FTYPE_DIR; @@ -262,7 +262,7 @@ void DisplayFile(char *Filename) if(acl.perms & 8) perms |= 0001; // X // Close file - close(fd); + _SysClose(fd); } free(path); // We're finished with it diff --git a/Usermode/Applications/lspci_src/main.c b/Usermode/Applications/lspci_src/main.c index c24fde9d..44dc61ab 100644 --- a/Usermode/Applications/lspci_src/main.c +++ b/Usermode/Applications/lspci_src/main.c @@ -6,7 +6,6 @@ */ #include #include -#include #include #define PCI_BASE "/Devices/pci" @@ -17,17 +16,19 @@ void show_device(int PFD, const char *File, int bVerbose); // === CODE === int main(int argc, char *argv[]) { - int fd = open(PCI_BASE, OPENFLAG_READ); + int fd = _SysOpen(PCI_BASE, OPENFLAG_READ); char name[256]; - while( SysReadDir(fd, name) ) + while( _SysReadDir(fd, name) ) { if(name[0] == '.') continue ; show_device(fd, name, 0); } + _SysClose(fd); + return 0; } @@ -48,10 +49,10 @@ void show_device(int PFD, const char *File, int bVerbose) printf("%s - ERR (open failure)\n", File); return ; } - rv = read(fd, &pciinfo, sizeof(pciinfo)); + rv = _SysRead(fd, &pciinfo, sizeof(pciinfo)); if( rv != sizeof(pciinfo) ) { printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo)); - close(fd); + _SysClose(fd); return ; } uint32_t class_if = pciinfo.revclass >> 8; @@ -67,6 +68,6 @@ void show_device(int PFD, const char *File, int bVerbose) printf("\n"); } - close(fd); + _SysClose(fd); } diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index 7c401bd2..1a1fc7be 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -142,20 +142,20 @@ int main(int argc, char *argv[]) } // Check Device - fd = open(sDevice, OPENFLAG_READ); + fd = _SysOpen(sDevice, OPENFLAG_READ); if(fd == -1) { printf("Device '%s' cannot be opened for reading\n", sDevice); return EXIT_FAILURE; } - close(fd); + _SysClose(fd); // Check Mount Point - fd = open(sDir, OPENFLAG_EXEC); + fd = _SysOpen(sDir, OPENFLAG_EXEC); if(fd == -1) { printf("Directory '%s' does not exist\n", sDir); return EXIT_FAILURE; } - close(fd); + _SysClose(fd); // Replace sOptions with an empty string if it is still NULL if(sOptions == NULL) sOptions = ""; diff --git a/Usermode/Applications/ping_src/main.c b/Usermode/Applications/ping_src/main.c index 7686e5cc..7c10e57b 100644 --- a/Usermode/Applications/ping_src/main.c +++ b/Usermode/Applications/ping_src/main.c @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) free(iface); // TODO: Handle when this is not heap iface = _iface; printf("iface = '%s'\n", iface); - fd = open(iface, OPENFLAG_EXEC); + fd = _SysOpen(iface, OPENFLAG_EXEC); if(fd == -1) { fprintf(stderr, "ERROR: Unable to open interface '%s'\n", iface); return 1; @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) } } - call = ioctl(fd, 3, "ping"); + call = _SysIOCtl(fd, 3, "ping"); if(call == 0) { fprintf(stderr, "ERROR: '%s' does not have a 'ping' call\n", iface); return 1; @@ -114,11 +114,11 @@ int main(int argc, char *argv[]) for( i = 0; i < giNumberOfPings; i ++ ) { - ping = ioctl(fd, call, addr); + ping = _SysIOCtl(fd, call, addr); printf("ping = %i\n", ping); } - close(fd); + _SysClose(fd); return 0; } diff --git a/Usermode/Applications/telnet_src/main.c b/Usermode/Applications/telnet_src/main.c index 3fdbf006..708935d1 100644 --- a/Usermode/Applications/telnet_src/main.c +++ b/Usermode/Applications/telnet_src/main.c @@ -62,8 +62,8 @@ int main(int argc, char *argv[], char *envp[]) // Read from server, and write to stdout do { - len = read(server_fd, buffer, BUFSIZ); - write(1, buffer, len); + len = _SysRead(server_fd, buffer, BUFSIZ); + _SysWrite(1, buffer, len); } while( len == BUFSIZ ); } @@ -76,17 +76,17 @@ int main(int argc, char *argv[], char *envp[]) char *line = Readline_NonBlock(readline_info); if( line ) { - write(server_fd, line, strlen(line)); - write(server_fd, "\n", 1); + _SysWrite(server_fd, line, strlen(line)); + _SysWrite(server_fd, "\n", 1); } } else { do { - len = read(0, buffer, BUFSIZ); - write(server_fd, buffer, len); - write(1, buffer, len); + len = _SysRead(0, buffer, BUFSIZ); + _SysWrite(server_fd, buffer, len); + _SysWrite(1, buffer, len); } while( len == BUFSIZ ); } } @@ -99,7 +99,7 @@ int main(int argc, char *argv[], char *envp[]) } } - close(server_fd); + _SysClose(server_fd); return 0; } @@ -127,11 +127,11 @@ int OpenTCP(const char *AddressString, short PortNumber) } // Set remote port and address - ioctl(fd, 5, &PortNumber); - ioctl(fd, 6, addrBuffer); + _SysIOCtl(fd, 5, &PortNumber); + _SysIOCtl(fd, 6, addrBuffer); // Connect - if( ioctl(fd, 7, NULL) == 0 ) { + if( _SysIOCtl(fd, 7, NULL) == 0 ) { fprintf(stderr, "Unable to start connection\n"); return -1; } diff --git a/Usermode/Applications/telnetd_src/main.c b/Usermode/Applications/telnetd_src/main.c index a62d0dd3..a4f5e0da 100644 --- a/Usermode/Applications/telnetd_src/main.c +++ b/Usermode/Applications/telnetd_src/main.c @@ -1,9 +1,14 @@ /* + * Acess2 Telnet Server (TCP server test case) + * - By John Hodge (thePowersGang) + * + * main.c + * - All */ #include #include -#include #include +#include // === TYPES === typedef struct sClient @@ -41,7 +46,7 @@ int main(int argc, char *argv[]) int addrtype = Net_ParseAddress("10.0.2.10", data); int port = 23; giServerFD = Net_OpenSocket(addrtype, data, "tcps"); - ioctl(giServerFD, 4, &port); // Set port and start listening + _SysIOCtl(giServerFD, 4, &port); // Set port and start listening } // Event loop @@ -77,7 +82,7 @@ void EventLoop(void) } // Select! - select( maxfd+1, &fds, NULL, NULL, NULL ); + _SysSelect( maxfd+1, &fds, NULL, NULL, NULL, 0 ); // Check events if( FD_ISSET(giServerFD, &fds) ) @@ -108,7 +113,7 @@ void Server_NewClient(int FD) if( giNumClients == giConfig_MaxClients ) { // Open, reject - close( _SysOpenChild(FD, "", O_RDWR) ); + _SysClose( _SysOpenChild(FD, "", OPENFLAG_READ) ); return ; } @@ -121,12 +126,12 @@ void Server_NewClient(int FD) } } // Accept the connection - clt->Socket = _SysOpenChild(FD, "", O_RDWR); + clt->Socket = _SysOpenChild(FD, "", OPENFLAG_READ|OPENFLAG_WRITE); giNumClients ++; // Create stdin/stdout - clt->stdin = open("/Devices/fifo/anon", O_RDWR); - clt->stdout = open("/Devices/fifo/anon", O_RDWR); + clt->stdin = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + clt->stdout = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); // TODO: Arguments and envp { @@ -141,9 +146,9 @@ void HandleServerBoundData(tClient *Client) char buf[BUFSIZ]; int len; - len = read(Client->Socket, buf, BUFSIZ); + len = _SysRead(Client->Socket, buf, BUFSIZ); if( len <= 0 ) return ; - write(Client->stdin, buf, len); + _SysWrite(Client->stdin, buf, len); } void HandleClientBoundData(tClient *Client) @@ -151,8 +156,8 @@ void HandleClientBoundData(tClient *Client) char buf[BUFSIZ]; int len; - len = read(Client->stdout, buf, BUFSIZ); + len = _SysRead(Client->stdout, buf, BUFSIZ); if( len <= 0 ) return ; - write(Client->Socket, buf, len); + _SysWrite(Client->Socket, buf, len); } diff --git a/Usermode/Applications/wget_src/main.c b/Usermode/Applications/wget_src/main.c index 34108407..9b5391f1 100644 --- a/Usermode/Applications/wget_src/main.c +++ b/Usermode/Applications/wget_src/main.c @@ -11,6 +11,7 @@ #include #include #include +#include // _SysDebug enum eProcols { @@ -164,7 +165,7 @@ int main(int argc, char *argv[]) if( state == 2 ) { _SysDebug("RXing %i bytes to '%s'", bytes_wanted, outfile); - int outfd = open(outfile, O_WR|O_CREAT, 0666); + int outfd = open(outfile, O_WRONLY|O_CREAT, 0666); if( outfd == -1 ) { fprintf(stderr, "Unable to open '%s' for writing\n", outfile); } 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 a59e8571..77d88cef 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -5,8 +5,8 @@ SYSCALL1(_exit, SYS_EXIT) SYSCALL2(clone, SYS_CLONE) SYSCALL2(kill, SYS_KILL) -SYSCALL0(yield, SYS_YIELD) -SYSCALL0(sleep, SYS_SLEEP) +//SYSCALL0(yield, SYS_YIELD) +//SYSCALL0(sleep, SYS_SLEEP) SYSCALL1(_SysWaitEvent, SYS_WAITEVENT) SYSCALL2(waittid, SYS_WAITTID) @@ -39,20 +39,20 @@ 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) // VFS System calls -SYSCALL2(open, SYS_OPEN) // char*, int -SYSCALL3(reopen, SYS_REOPEN) // int, char*, int -SYSCALL1(close, SYS_CLOSE) // int -SYSCALL3(read, SYS_READ) // int, uint, void* -SYSCALL3(write, SYS_WRITE) // int, uint, void* -SYSCALL4(seek, SYS_SEEK) // int, uint64_t, int -SYSCALL1(tell, SYS_TELL) // int -SYSCALL3(finfo, SYS_FINFO) // int, void*, int -SYSCALL2(SysReadDir, SYS_READDIR) // int, char* +SYSCALL2(_SysOpen, SYS_OPEN) // char*, int +SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int +SYSCALL3(_SysReopen, SYS_REOPEN) // int, char*, int +SYSCALL1(_SysClose, SYS_CLOSE) // int +SYSCALL3(_SysRead, SYS_READ) // int, uint, void* +SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void* +SYSCALL4(_SysSeek, SYS_SEEK) // int, uint64_t, int +SYSCALL1(_SysTell, SYS_TELL) // int +SYSCALL3(_SysFInfo, SYS_FINFO) // int, void*, int +SYSCALL2(_SysReadDir, SYS_READDIR) // int, char* SYSCALL2(_SysGetACL,SYS_GETACL) // int, void* -SYSCALL1(chdir, SYS_CHDIR) // char* -SYSCALL3(ioctl, SYS_IOCTL) // int, int, void* +SYSCALL1(_SysChdir, SYS_CHDIR) // char* +SYSCALL3(_SysIOCtl, SYS_IOCTL) // int, int, void* SYSCALL4(_SysMount, SYS_MOUNT) // char*, char*, char*, char* SYSCALL6(_SysSelect, SYS_SELECT) // int, fd_set*, fd_set*, fd_set*, tTime*, uint32_t -SYSCALL1(unlink, SYS_UNLINK) // const char* +SYSCALL1(_SysUnlink, SYS_UNLINK) // const char* -SYSCALL3(_SysOpenChild, SYS_OPENCHILD) diff --git a/Usermode/Libraries/ld-acess.so_src/common.h b/Usermode/Libraries/ld-acess.so_src/common.h index eb9b83b9..fa1957f6 100644 --- a/Usermode/Libraries/ld-acess.so_src/common.h +++ b/Usermode/Libraries/ld-acess.so_src/common.h @@ -10,6 +10,7 @@ #include #include #include +#include typedef uintptr_t Uint; typedef uint8_t Uint8; @@ -51,14 +52,11 @@ extern int file_exists(const char *filename); extern void *memcpy(void *dest, const void *src, size_t len); // === System Calls === -extern void _exit(int retval); 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)); -extern int open(const char *filename, int flags, ...); -extern int close(int fd); // === ELF Loader === extern void *ElfRelocate(void *Base, char **envp, const char *Filename); diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h new file mode 100644 index 00000000..07939010 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h @@ -0,0 +1,29 @@ +/* + * Acess2 Dynamic Linker + * - By John Hodge (thePowersGang) + * + * acess/fd_set.h + * - fd_set structure used by select() + */ +#ifndef _ACESS__FD_SET_H_ +#define _ACESS__FD_SET_H_ + +#define FD_SETSIZE 128 + +typedef unsigned short fd_set_ent_t; + +/** + * \brief fd_set for select() + */ +typedef struct +{ + fd_set_ent_t flags[FD_SETSIZE/16]; +} fd_set; + + +extern void FD_ZERO(fd_set *fdsetp); +extern void FD_CLR(int fd, fd_set *fdsetp); +extern void FD_SET(int fd, fd_set *fdsetp); +extern int FD_ISSET(int fd, fd_set *fdsetp); + +#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 b5d0f0cf..0f9a5f99 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 @@ -5,7 +5,8 @@ #define _ACESS_SYS_H_ #include -#include "../sys/types.h" +#include // size_t +#include "syscall_types.h" // === CONSTANTS === #ifndef NULL @@ -19,6 +20,7 @@ #define OPENFLAG_EXEC 0x01 #define OPENFLAG_READ 0x02 #define OPENFLAG_WRITE 0x04 +#define OPENFLAG_RDWR (OPENFLAG_READ|OPENFLAG_WRITE) #define OPENFLAG_TRUNCATE 0x10 #define OPENFLAG_APPEND 0x20 #define OPENFLAG_NOLINK 0x40 @@ -41,8 +43,8 @@ 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 void sleep(void); +//extern void yield(void); extern int kill(int pid, int sig); //extern void wait(int miliseconds); extern int _SysWaitEvent(int EventMask); @@ -65,31 +67,35 @@ extern void setuid(int id); extern void setgid(int id); // --- VFS --- -extern int chdir(const char *dir); -extern int open(const char *path, int flags, ...); -extern int reopen(int fd, const char *path, int flags); -extern int close(int fd); -extern uint read(int fd, void *buffer, uint length); -extern uint write(int fd, const void *buffer, uint length); -extern int seek(int fd, int64_t offset, int whence); -extern uint64_t tell(int fd); -extern int ioctl(int fd, int id, void *data); -extern int finfo(int fd, t_sysFInfo *info, int maxacls); -extern int SysReadDir(int fd, char *dest); +extern int _SysChdir(const char *dir); +extern int _SysRoot(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 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); +extern int _SysIOCtl(int fd, int id, void *data); +extern int _SysFInfo(int fd, t_sysFInfo *info, int maxacls); +extern int _SysReadDir(int fd, char *dest); extern int _SysGetACL(int fd, t_sysACL *dest); extern int _SysMount(const char *Device, const char *Directory, const char *Type, const char *Options); extern int _SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *err, int64_t *timeout, unsigned int extraevents); #define select(nfs, rdfds, wrfds, erfds, timeout) _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0) -extern int unlink(const char *pathname); +extern int _SysUnlink(const char *pathname); // --- IPC --- -extern int SysSendMessage(pid_t dest, uint length, const void *Data); -extern int SysGetMessage(pid_t *src, uint 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(uint vaddr); -uint64_t _SysAllocate(uint vaddr); -uint32_t SysSetMemFlags(uint vaddr, uint32_t flags, uint32_t mask); +uint64_t _SysGetPhys(uintptr_t vaddr); +uint64_t _SysAllocate(uintptr_t vaddr); +uint32_t SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask); #endif diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h index 2da73331..c1f25c67 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h @@ -5,10 +5,11 @@ * acess/syscall_types.h * - Structures used for syscalls */ - #ifndef _ACESS__SYSCALL_TYPES_H_ #define _ACESS__SYSCALL_TYPES_H_ +#include "fd_set.h" + struct s_sysACL { unsigned long object; /*!< Group or user (bit 31 determines) */ unsigned long perms; /*!< Inverted by bit 31 */ @@ -20,9 +21,9 @@ struct s_sysFInfo { unsigned int gid; unsigned int flags; unsigned long long size; - time_t atime; - time_t mtime; - time_t ctime; + int64_t atime; + int64_t mtime; + int64_t ctime; int numacls; struct s_sysACL acls[]; } __attribute__((packed)); diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h deleted file mode 100644 index 36d2dba6..00000000 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - */ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H - -#include "../acess/intdefs.h" - -typedef signed int ssize_t; -//#ifdef __USE_BSD -typedef unsigned int u_int; -//#endif - -typedef struct stat t_fstat; - -#define FD_SETSIZE 128 - - -#define CLONE_VM 0x10 - -typedef unsigned int id_t; -typedef unsigned long pid_t; -typedef unsigned long tid_t; -typedef signed long long int time_t; -typedef long long int off_t; - -typedef unsigned int uint; - -typedef unsigned short fd_set_ent_t; - -/** - * \brief fd_set for select() - */ -typedef struct -{ - fd_set_ent_t flags[FD_SETSIZE/16]; -} fd_set; - -#include "../acess/syscall_types.h" - -extern void FD_ZERO(fd_set *fdsetp); -extern void FD_CLR(int fd, fd_set *fdsetp); -extern void FD_SET(int fd, fd_set *fdsetp); -extern int FD_ISSET(int fd, fd_set *fdsetp); - -#include "../sys/stat.h" - -#endif diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h b/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h deleted file mode 100644 index 54a68476..00000000 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _UNISTD_H_ -#define _UNISTD_H_ - -#define O_RDWR (OPENFLAG_READ|OPENFLAG_WRITE) -#define O_WR (OPENFLAG_WRITE) -#define O_RD (OPENFLAG_READ) -#define O_CREAT (OPENFLAG_CREATE) -#define O_RDONLY OPENFLAG_READ -#define O_WRONLY OPENFLAG_WRITE -#define O_TRUNC OPENFLAG_TRUNCATE -#define O_APPEND OPENFLAG_APPEND -#define O_NONBLOCK 0 // TODO: - -#include "acess/sys.h" - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -static inline int fork(void) { return clone(CLONE_VM, 0); } -static inline int execv(const char *b,char *v[]) { return execve(b,v,NULL); } - -#endif - diff --git a/Usermode/Libraries/ld-acess.so_src/lib.c b/Usermode/Libraries/ld-acess.so_src/lib.c index 06721026..9b8f86a8 100644 --- a/Usermode/Libraries/ld-acess.so_src/lib.c +++ b/Usermode/Libraries/ld-acess.so_src/lib.c @@ -73,10 +73,9 @@ void *memcpy(void *dest, const void *src, size_t len) int file_exists(const char *filename) { int fd; - //fd = open(filename, OPENFLAG_READ); - fd = open(filename, 0); + fd = _SysOpen(filename, 0); if(fd == -1) return 0; - close(fd); + _SysClose(fd); return 1; } diff --git a/Usermode/Libraries/libc.so_src/stdio.c b/Usermode/Libraries/libc.so_src/stdio.c index af8f0072..1dde9ade 100644 --- a/Usermode/Libraries/libc.so_src/stdio.c +++ b/Usermode/Libraries/libc.so_src/stdio.c @@ -109,16 +109,16 @@ EXPORT FILE *freopen(const char *file, const char *mode, FILE *fp) //Open File if(fp->FD != -1) - fp->FD = reopen(fp->FD, file, openFlags); + fp->FD = _SysReopen(fp->FD, file, openFlags); else - fp->FD = open(file, openFlags); + fp->FD = _SysOpen(file, openFlags); if(fp->FD == -1) { fp->Flags = 0; return NULL; } if( (fp->Flags & FILE_FLAG_MODE_MASK) == FILE_FLAG_MODE_APPEND ) { - seek(fp->FD, 0, SEEK_END); //SEEK_END + _SysSeek(fp->FD, 0, SEEK_END); //SEEK_END } return fp; @@ -168,7 +168,7 @@ EXPORT int fclose(FILE *fp) { fflush(fp); if( fp->FD != -1 ) { - close(fp->FD); + _SysClose(fp->FD); } fp->Flags = 0; fp->FD = -1; @@ -221,7 +221,7 @@ EXPORT off_t ftell(FILE *fp) if( fp->FD == -2 ) return fp->Pos; else - return tell(fp->FD); + return _SysTell(fp->FD); } EXPORT int fseek(FILE *fp, long int amt, int whence) @@ -251,7 +251,7 @@ EXPORT int fseek(FILE *fp, long int amt, int whence) return 0; } else - return seek(fp->FD, amt, whence); + return _SysSeek(fp->FD, amt, whence); } @@ -318,7 +318,7 @@ EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp) ret = num; } else { - ret = write(fp->FD, ptr, size*num); + ret = _SysWrite(fp->FD, ptr, size*num); ret /= size; } @@ -347,7 +347,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) ret = num; } else { - ret = read(fp->FD, ptr, size*num); + ret = _SysRead(fp->FD, ptr, size*num); ret /= size; } @@ -366,7 +366,7 @@ EXPORT int fputc(int c, FILE *fp) EXPORT int putchar(int c) { c &= 0xFF; - return write(_stdout, &c, 1); + return _SysWrite(_stdout, &c, 1); } /** @@ -384,7 +384,7 @@ EXPORT int fgetc(FILE *fp) EXPORT int getchar(void) { char ret = 0; - if(read(_stdin, &ret, 1) != 1) return -1; + if(_SysRead(_stdin, &ret, 1) != 1) return -1; return ret; } @@ -415,8 +415,8 @@ EXPORT int puts(const char *str) if(!str) return 0; len = strlen(str); - len = write(_stdout, str, len); - write(_stdout, "\n", 1); + len = _SysWrite(_stdout, str, len); + _SysWrite(_stdout, "\n", 1); return len; } @@ -681,7 +681,7 @@ EXPORT int printf(const char *format, ...) va_end(args); // Send to stdout - write(_stdout, buf, size+1); + _SysWrite(_stdout, buf, size+1); // Free buffer free(buf); diff --git a/Usermode/Libraries/libnet.so_src/main.c b/Usermode/Libraries/libnet.so_src/main.c index 2adaf1b8..2b3ff76c 100644 --- a/Usermode/Libraries/libnet.so_src/main.c +++ b/Usermode/Libraries/libnet.so_src/main.c @@ -47,7 +47,7 @@ char *Net_GetInterface(int AddressType, void *Address) uint32_t *type = (void*)buf; // Open - fd = open("/Devices/ip/routes", 0); + fd = _SysOpen("/Devices/ip/routes", 0); if( !fd ) { fprintf(stderr, "ERROR: Unable to open '/Devices/ip/routes'\n"); return NULL; @@ -56,10 +56,10 @@ char *Net_GetInterface(int AddressType, void *Address) // Make structure and ask *type = AddressType; memcpy(type+1, Address, size); - routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf); + routeNum = _SysIOCtl(fd, _SysIOCtl(fd, 3, "locate_route"), buf); // Close - close(fd); + _SysClose(fd); } // Check answer validity @@ -71,24 +71,24 @@ char *Net_GetInterface(int AddressType, void *Address) sprintf(buf, "/Devices/ip/routes/#%i", routeNum); // Open route - fd = open(buf, 0); + fd = _SysOpen(buf, 0); if( fd == -1 ) { fprintf(stderr, "Net_GetInterface - ERROR: Unable to open %s\n", buf); return NULL; // Shouldn't happen :/ } // Allocate space for name - ret = malloc( ioctl(fd, ioctl(fd, 3, "get_interface"), NULL) + 1 ); + ret = malloc( _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), NULL) + 1 ); if( !ret ) { fprintf(stderr, "malloc() failure - Allocating space for interface name\n"); return NULL; } // Get name - ioctl(fd, ioctl(fd, 3, "get_interface"), ret); + _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), ret); // Close and return - close(fd); + _SysClose(fd); return ret; } diff --git a/Usermode/Libraries/libnet.so_src/socket.c b/Usermode/Libraries/libnet.so_src/socket.c index 0b540793..f5933f22 100644 --- a/Usermode/Libraries/libnet.so_src/socket.c +++ b/Usermode/Libraries/libnet.so_src/socket.c @@ -26,14 +26,14 @@ int Net_OpenSocket(int AddrType, void *Addr, const char *Filename) char path[len+1]; snprintf(path, 100, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename); _SysDebug("%s", path); - return open(path, OPENFLAG_READ|OPENFLAG_WRITE); + return _SysOpen(path, OPENFLAG_READ|OPENFLAG_WRITE); } else { int len = snprintf(NULL, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr); char path[len+1]; snprintf(path, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr); - return open(path, OPENFLAG_READ); + return _SysOpen(path, OPENFLAG_READ); } } @@ -42,9 +42,9 @@ int Net_OpenSocket_TCPC(int AddrType, void *Addr, int Port) int fd = Net_OpenSocket(AddrType, Addr, "tcpc"); if( fd == -1 ) return -1; - ioctl(fd, 5, &Port); // Remote Port - ioctl(fd, 6, Addr); // Remote address - ioctl(fd, 7, NULL); // connect + _SysIOCtl(fd, 5, &Port); // Remote Port + _SysIOCtl(fd, 6, Addr); // Remote address + _SysIOCtl(fd, 7, NULL); // connect return fd; } diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile new file mode 100644 index 00000000..2f472fc7 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -0,0 +1,16 @@ +# Acess2 POSIX Emulation +# Makefile + +-include ../Makefile.cfg + +CPPFLAGS += +CFLAGS += -Werror -Wextra +ASFLAGS += +LDFLAGS += -soname libposix.so -Map map.txt + +OBJ = main.o unistd.o +DEPFILES := $(OBJ:%.o=%.d) +BIN = libposix.so + +include ../Makefile.tpl + diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h new file mode 100644 index 00000000..c33ccb13 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h @@ -0,0 +1,17 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * sys/select.h + * - select(2) + */ +#ifndef _SYS__SELECT_H_ +#define _SYS__SELECT_H_ + +#include + +extern int select(int nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout); +// TODO: pselect? + +#endif + diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h similarity index 98% rename from Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h rename to Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h index 4a1c107b..99c526b2 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h @@ -8,6 +8,7 @@ //#include "../acess/intdefs.h" /* Evil */ //#include "../stddef.h" #include +#include "sys/types.h" // off_t typedef void *dev_t; /* TODO: How to identify a device with Acess */ typedef uint64_t ino_t; diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h new file mode 100644 index 00000000..db78b5a4 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h @@ -0,0 +1,29 @@ +/* + */ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +#include + +//typedef signed int ssize_t; +//#ifdef __USE_BSD +typedef unsigned int u_int; +//#endif + +typedef struct stat t_fstat; + + +#define CLONE_VM 0x10 + +typedef unsigned int id_t; +typedef unsigned long pid_t; +typedef unsigned long tid_t; +typedef signed long long int time_t; +typedef long long int off_t; + +typedef unsigned int uint; + +#include "stat.h" +#include + +#endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h new file mode 100644 index 00000000..a2f397cc --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -0,0 +1,47 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * unistd.h + * - + */ +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include + +//! \brief flags for open(2) +#define O_WRONLY 0x01 +#define O_RDONLY 0x02 +#define O_RDWR 0x03 +#define O_APPEND 0x04 +#define O_CREAT 0x08 +#define O_DIRECTORY 0x10 +#define O_ASYNC 0x20 +#define O_TRUNC 0x40 +#define O_NOFOLLOW 0x80 // don't follow symlinks +#define O_EXCL 0x100 +#define O_NOCTTY 0 // unsupported +#define O_NONBLOCK 0x200 +#define O_SYNC 0 // not supported + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +typedef signed long ssize_t; + +#include "sys/stat.h" // mode_t + +extern int open(const char *path, int flags, ...); +extern int creat(const char *path, mode_t mode); +extern int close(int fd); + +extern ssize_t write(int fd, const void *buf, size_t count); +extern ssize_t read(int fd, void *buf, size_t count); + +extern int fork(void); +extern int execv(const char *b, char *v[]); + +#endif + diff --git a/Usermode/Libraries/libposix.so_src/main.c b/Usermode/Libraries/libposix.so_src/main.c new file mode 100644 index 00000000..72989a5a --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/main.c @@ -0,0 +1,14 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * main.c + * - Stub Main + */ + +// === CODE === +int SoMain(void) +{ + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c new file mode 100644 index 00000000..1a5b7beb --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -0,0 +1,71 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * unistd.c + * - POSIX->Acess VFS call translation + */ +#include +#include +#include + +// === CODE === +int open(const char *path, int openmode, ...) +{ + mode_t create_mode = 0; + int openflags = 0; + + switch( openmode & O_RDWR ) + { + case 0: // Special + break; + case O_RDONLY: openflags |= OPENFLAG_READ; break; + case O_WRONLY: openflags |= OPENFLAG_WRITE; break; + case O_RDWR: openflags |= OPENFLAG_READ|OPENFLAG_WRITE; break; + } + + if( openmode & O_CREAT ) { + openflags |= OPENFLAG_CREATE; + va_list args; + va_start(args, openmode); + create_mode = va_arg(args, mode_t); + va_end(args); + } + + return _SysOpen(path, openflags, create_mode); +} + +int creat(const char *path, mode_t mode) +{ + // TODO: Make native call to do this cheaper + int fd = _SysOpen(path, OPENFLAG_CREATE, mode); + if( fd == -1 ) return -1; + _SysClose(fd); + return 0; +} + +int close(int fd) +{ + _SysClose(fd); + return 0; +} + +ssize_t write(int fd, const void *buf, size_t count) +{ + return _SysWrite(fd, buf, count); +} + +ssize_t read(int fd, void *buf, size_t count) +{ + return _SysRead(fd, buf, count); +} + +int fork(void) +{ + return clone(CLONE_VM, 0); +} + +int execv(const char *b, char *v[]) +{ + return execve(b, v, NULL); +} diff --git a/Usermode/Libraries/libpsocket.so_src/common.h b/Usermode/Libraries/libpsocket.so_src/common.h new file mode 100644 index 00000000..27e88e49 --- /dev/null +++ b/Usermode/Libraries/libpsocket.so_src/common.h @@ -0,0 +1,2 @@ + +extern char *mkstr(const char *format, ...); diff --git a/Usermode/Libraries/libpsocket.so_src/main.c b/Usermode/Libraries/libpsocket.so_src/main.c index 99fbe2ae..9c1e5a15 100644 --- a/Usermode/Libraries/libpsocket.so_src/main.c +++ b/Usermode/Libraries/libpsocket.so_src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include "common.h" int SoMain(void) { diff --git a/Usermode/Libraries/libpsocket.so_src/socket.c b/Usermode/Libraries/libpsocket.so_src/socket.c index 913f72f7..613e82b7 100644 --- a/Usermode/Libraries/libpsocket.so_src/socket.c +++ b/Usermode/Libraries/libpsocket.so_src/socket.c @@ -6,10 +6,11 @@ * - sys/socket.h calls */ #include -#include +#include #include // malloc/free #include #include +#include "common.h" #define MAXFD 32 @@ -55,7 +56,7 @@ int socket(int domain, int type, int protocol) si = _GetInfo(0); if( !si ) return -1; - int fd = open("/Devices/null", O_RDWR); + int fd = _SysOpen("/Devices/null", OPENFLAG_RDWR); if( fd == -1 ) return -1; giNumPreinit ++; @@ -167,7 +168,7 @@ void _CommitServer(int sockfd) else path = mkstr("/Devices/ip/*%i/%s", si->local->sa_family, file); - reopen(si->fd, path, O_RDWR); + _SysReopen(si->fd, path, OPENFLAG_RDWR); // TODO: Error-check free(path); @@ -191,10 +192,11 @@ int accept(int sockfd, struct sockaddr *clientaddr, socklen_t addrlen) int child; - child = _SysOpenChild(sockfd, "", O_RDWR); + child = _SysOpenChild(sockfd, "", OPENFLAG_RDWR); if( child == -1 ) return -1; - ioctl(child, 8, clientaddr); + _SysIOCtl(child, 8, clientaddr); + return child; } @@ -203,25 +205,25 @@ int recvfrom(int sockfd, void *buffer, size_t length, int flags, struct sockaddr { _CommitClient(sockfd); // TODO: Determine socket type (TCP/UDP) and use a bounce-buffer for UDP - return read(sockfd, buffer, length); + return _SysRead(sockfd, buffer, length); } int recv(int sockfd, void *buffer, size_t length, int flags) { _CommitClient(sockfd); - return read(sockfd, buffer, length); + return _SysRead(sockfd, buffer, length); } int sendto(int sockfd, const void *buffer, size_t length, int flags, const struct sockaddr *clientaddr, socklen_t addrlen) { _CommitClient(sockfd); // TODO: Determine socket type (TCP/UDP) and use a bounce-buffer for UDP - return write(sockfd, buffer, length); + return _SysWrite(sockfd, buffer, length); } int send(int sockfd, void *buffer, size_t length, int flags) { _CommitClient(sockfd); - return write(sockfd, buffer, length); + return _SysWrite(sockfd, buffer, length); } diff --git a/Usermode/Libraries/libreadline.so_src/main.c b/Usermode/Libraries/libreadline.so_src/main.c index 719667d7..58db03a5 100644 --- a/Usermode/Libraries/libreadline.so_src/main.c +++ b/Usermode/Libraries/libreadline.so_src/main.c @@ -80,7 +80,7 @@ char *Readline_NonBlock(tReadline *Info) int len, i; // Read as much as possible (appending to remaining data) - len = read(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen); + len = _SysRead(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen); if( len <= 0 ) return NULL; Info->ReadBuffer[Info->ReadBufferLen + len] = '\0'; @@ -204,21 +204,21 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) // Move to the beginning of the line pos = oldLen; - while(pos--) write(STDOUT_FD, "\x1B[D", 3); + while(pos--) _SysWrite(STDOUT_FD, "\x1B[D", 3); // Update state Info->CurBuffer = Info->History[--Info->HistoryPos]; Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer); - write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed); + _SysWrite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed); Info->BufferWritePos = Info->BufferUsed; // Clear old characters (if needed) if( oldLen > Info->BufferWritePos ) { pos = oldLen - Info->BufferWritePos; - while(pos--) write(STDOUT_FD, " ", 1); + while(pos--) _SysWrite(STDOUT_FD, " ", 1); pos = oldLen - Info->BufferWritePos; - while(pos--) write(STDOUT_FD, "\x1B[D", 3); + while(pos--) _SysWrite(STDOUT_FD, "\x1B[D", 3); } } break; @@ -230,34 +230,34 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) // Move to the beginning of the line pos = oldLen; - while(pos--) write(STDOUT_FD, "\x1B[D", 3); + while(pos--) _SysWrite(STDOUT_FD, "\x1B[D", 3); // Update state Info->CurBuffer = Info->History[Info->HistoryPos++]; Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer); // Write new line - write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed); + _SysWrite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed); Info->BufferWritePos = Info->BufferUsed; // Clear old characters (if needed) if( oldLen > Info->BufferWritePos ) { pos = oldLen - Info->BufferWritePos; - while(pos--) write(STDOUT_FD, " ", 1); + while(pos--) _SysWrite(STDOUT_FD, " ", 1); pos = oldLen - Info->BufferWritePos; - while(pos--) write(STDOUT_FD, "\x1B[D", 3); + while(pos--) _SysWrite(STDOUT_FD, "\x1B[D", 3); } } break; case 'D': // Left if(Info->BufferWritePos == 0) break; Info->BufferWritePos --; - write(STDOUT_FD, "\x1B[D", 3); + _SysWrite(STDOUT_FD, "\x1B[D", 3); break; case 'C': // Right if(Info->BufferWritePos == Info->BufferUsed) break; Info->BufferWritePos ++; - write(STDOUT_FD, "\x1B[C", 3); + _SysWrite(STDOUT_FD, "\x1B[C", 3); break; } break; @@ -271,7 +271,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) case '\b': if(Info->BufferWritePos <= 0) break; // Protect against underflows // Write the backsapce - write(STDOUT_FD, &ch, 1); + _SysWrite(STDOUT_FD, &ch, 1); if(Info->BufferWritePos == Info->BufferUsed) // Simple case: End of string { Info->BufferUsed --; @@ -286,12 +286,12 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) buf[3] += (delta/10) % 10; buf[4] += (delta) % 10; // Write everything save for the deleted character - write(STDOUT_FD, + _SysWrite(STDOUT_FD, &Info->CurBuffer[Info->BufferWritePos], Info->BufferUsed - Info->BufferWritePos ); - ch = ' '; write(STDOUT_FD, &ch, 1); ch = '\b'; // Clear old last character - write(STDOUT_FD, buf, 7); // Update Cursor + ch = ' '; _SysWrite(STDOUT_FD, &ch, 1); ch = '\b'; // Clear old last character + _SysWrite(STDOUT_FD, buf, 7); // Update Cursor // Alter Buffer memmove(&Info->CurBuffer[Info->BufferWritePos-1], &Info->CurBuffer[Info->BufferWritePos], @@ -325,12 +325,12 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) buf[2] += (delta/100) % 10; buf[3] += (delta/10) % 10; buf[4] += (delta) % 10; - write(STDOUT_FD, &ch, 1); // Print new character - write(STDOUT_FD, + _SysWrite(STDOUT_FD, &ch, 1); // Print new character + _SysWrite(STDOUT_FD, &Info->CurBuffer[Info->BufferWritePos], Info->BufferUsed - Info->BufferWritePos ); - write(STDOUT_FD, buf, 7); // Update Cursor + _SysWrite(STDOUT_FD, buf, 7); // Update Cursor // Move buffer right memmove( &Info->CurBuffer[Info->BufferWritePos+1], @@ -340,7 +340,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) } // Simple append else { - write(STDOUT_FD, &ch, 1); + _SysWrite(STDOUT_FD, &ch, 1); } Info->CurBuffer[ Info->BufferWritePos ++ ] = ch; Info->BufferUsed ++; diff --git a/Usermode/Libraries/liburi.so_src/main.c b/Usermode/Libraries/liburi.so_src/main.c index bf88b98d..e8f8dea0 100644 --- a/Usermode/Libraries/liburi.so_src/main.c +++ b/Usermode/Libraries/liburi.so_src/main.c @@ -32,7 +32,7 @@ void URI_Close(tURIFile *File); size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer); size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer); void URI_file_Close(int Handle); -size_t URI_file_GetSize(int Handle); +off_t URI_file_GetSize(int Handle); // === CONSTANTS === // Builtin URI protocol handlers @@ -319,7 +319,7 @@ int URI_file_Open(char *Host, int Port, char *Path, int Mode) // printf("URI_file_Open: open('%s', 0x%x)\n", Path, smode); { int ret; - ret = open(Path, smode); + ret = _SysOpen(Path, smode); return ret; } } @@ -327,22 +327,22 @@ size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer) { // printf("URI_file_Read: (Handle=%i, Buffer=%p, Bytes=%i)\n", // Handle, Buffer, (int)Bytes); - return read(Handle, Buffer, Bytes); + return _SysRead(Handle, Buffer, Bytes); } size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer) { - return write(Handle, Buffer, Bytes); + return _SysWrite(Handle, Buffer, Bytes); } void URI_file_Close(int Handle) { - close(Handle); + _SysClose(Handle); } -size_t URI_file_GetSize(int Handle) +off_t URI_file_GetSize(int Handle) { - uint64_t curpos = tell(Handle); - size_t ret; - seek(Handle, 0, SEEK_END); - ret = tell(Handle); - seek(Handle, curpos, SEEK_SET); + uint64_t curpos = _SysTell(Handle); + off_t ret; + _SysSeek(Handle, 0, SEEK_END); + ret = _SysTell(Handle); + _SysSeek(Handle, curpos, SEEK_SET); return ret; } -- 2.20.1