From: John Hodge Date: Tue, 14 May 2013 07:26:26 +0000 (+0800) Subject: Merge branch 'master' of git://localhost/acess2 X-Git-Tag: rel0.15~484 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=4c78a1bdd506cda6cda27ee342165c7dfa7ecdc2;hp=55eda6fd3dfc5c46e204cfc2056195e0d0761258 Merge branch 'master' of git://localhost/acess2 --- diff --git a/KernelLand/Kernel/Makefile b/KernelLand/Kernel/Makefile index d6b936fa..f955068e 100644 --- a/KernelLand/Kernel/Makefile +++ b/KernelLand/Kernel/Makefile @@ -25,7 +25,7 @@ ASFLAGS += -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1 CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\" CPPFLAGS += -D ARCH=$(ARCH) -D ARCHDIR=$(ARCHDIR) -D PLATFORM=\"$(PLATFORM)\" -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1 CPPFLAGS += -D KERNEL_VERSION=$(KERNEL_VERSION) -ffreestanding -CFLAGS += -Wall -fno-stack-protector -Wstrict-prototypes -std=gnu99 -g +CFLAGS += -Wall -fno-stack-protector -Wstrict-prototypes -std=gnu99 -g -fno-omit-frame-pointer CFLAGS += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized CFLAGS += -O3 LDFLAGS += -T arch/$(ARCHDIR)/link.ld -g diff --git a/KernelLand/Kernel/drv/dgram_pipe.c b/KernelLand/Kernel/drv/dgram_pipe.c index 2ae22974..0acae3ad 100644 --- a/KernelLand/Kernel/drv/dgram_pipe.c +++ b/KernelLand/Kernel/drv/dgram_pipe.c @@ -5,7 +5,7 @@ * drv/dgram_pipe.c * - Connection+Datagram based local IPC */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include diff --git a/KernelLand/Kernel/drv/vterm.c b/KernelLand/Kernel/drv/vterm.c index aed92582..cf12ff96 100644 --- a/KernelLand/Kernel/drv/vterm.c +++ b/KernelLand/Kernel/drv/vterm.c @@ -737,11 +737,10 @@ void VT_SetTerminal(int ID) gpVT_CurTerm->Buffer = malloc( gpVT_CurTerm->Width*gpVT_CurTerm->Height*4 ); if( gpVT_CurTerm->Width < giVT_RealWidth ) { - int line; Uint ofs = 0; Uint32 *dest = gpVT_CurTerm->Buffer; // Slower scanline copy - for( line = 0; line < gpVT_CurTerm->Height; line ++ ) + for( int line = 0; line < gpVT_CurTerm->Height; line ++ ) { VFS_ReadAt(giVT_OutputDevHandle, ofs, gpVT_CurTerm->Width*4, dest); ofs += giVT_RealWidth * 4; @@ -755,6 +754,7 @@ void VT_SetTerminal(int ID) gpVT_CurTerm->Buffer ); } + LOG("Cached screen contents"); } // Update current terminal ID diff --git a/KernelLand/Kernel/include/syscalls.h b/KernelLand/Kernel/include/syscalls.h index 8a935119..03542e1b 100644 --- a/KernelLand/Kernel/include/syscalls.h +++ b/KernelLand/Kernel/include/syscalls.h @@ -48,7 +48,7 @@ #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_FDCTL 70 // Modify flags of a file descriptor #define SYS_READ 71 // Read from an open file #define SYS_WRITE 72 // Write to an open file #define SYS_IOCTL 73 // Perform an IOCtl Call diff --git a/KernelLand/Kernel/include/syscalls.inc.asm b/KernelLand/Kernel/include/syscalls.inc.asm index 55f8fee8..eec7edcd 100644 --- a/KernelLand/Kernel/include/syscalls.inc.asm +++ b/KernelLand/Kernel/include/syscalls.inc.asm @@ -40,7 +40,7 @@ %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_FDCTL 70 ;Modify flags of a file descriptor %define SYS_READ 71 ;Read from an open file %define SYS_WRITE 72 ;Write to an open file %define SYS_IOCTL 73 ;Perform an IOCtl Call diff --git a/KernelLand/Kernel/syscalls.lst b/KernelLand/Kernel/syscalls.lst index b1392171..6a82de27 100644 --- a/KernelLand/Kernel/syscalls.lst +++ b/KernelLand/Kernel/syscalls.lst @@ -47,7 +47,7 @@ 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_FDCTL Modify flags of a file descriptor SYS_READ Read from an open file SYS_WRITE Write to an open file SYS_IOCTL Perform an IOCtl Call diff --git a/KernelLand/Modules/IPStack/interface.c b/KernelLand/Modules/IPStack/interface.c index 9a47ba70..c6ec2b3d 100644 --- a/KernelLand/Modules/IPStack/interface.c +++ b/KernelLand/Modules/IPStack/interface.c @@ -304,7 +304,7 @@ tInterface *IPStack_AddInterface(const char *Device, int Type, const char *Name) */ int IPStack_AddFile(tSocketFile *File) { - Log_Log("IPStack", "Added file '%s'", File->Name); +// Log_Log("IPStack", "Added file '%s'", File->Name); File->Next = gIP_FileTemplates; gIP_FileTemplates = File; return 0; diff --git a/KernelLand/Modules/Network/E1000/e1000.c b/KernelLand/Modules/Network/E1000/e1000.c index 68c020da..bc60593e 100644 --- a/KernelLand/Modules/Network/E1000/e1000.c +++ b/KernelLand/Modules/Network/E1000/e1000.c @@ -118,8 +118,11 @@ void E1000_int_ReleaseRXD(void *Arg, size_t HeadLen, size_t FootLen, const void { tCard **cardptr = Arg; tCard *Card = *cardptr; - int rxd = (Arg - (void*)Card->RXDescs) / sizeof(tRXDesc); - + int rxd = (Arg - (void*)Card->RXBackHandles) / sizeof(void*); + + LOG("RXD %p %i being released", Card, rxd); + ASSERT(rxd >= 0 && rxd < NUM_RX_DESC); + Card->RXDescs[rxd].Status = 0; Mutex_Acquire(&Card->lRXDescs); if( rxd == REG32(Card, REG_RDT) ) { diff --git a/Notes/20130511-ptys.txt b/Notes/20130511-ptys.txt new file mode 100644 index 00000000..a83711c1 --- /dev/null +++ b/Notes/20130511-ptys.txt @@ -0,0 +1,9 @@ +PTYs + +Need support for toggling echo and line buffering +- This needs to be communicated to pty owner somehow + > Second FD? Nominated data structure? Out of band data? +- API for the pty control? + > "_SysSetFileFlag"/"_SysGetFileFlag"? + Provides arbitary flags for each node + E.g. Terminal graphics mode, echo and buffering diff --git a/RunQemu b/RunQemu index c34d963a..68f6efc8 100755 --- a/RunQemu +++ b/RunQemu @@ -9,9 +9,10 @@ QEMU_PARAMS="" QEMU_PARAMS=$QEMU_PARAMS" -hda AcessHDD.img" QEMU_PARAMS=$QEMU_PARAMS" -vga std" QEMU_PARAMS=$QEMU_PARAMS" -smp 2" -QEMU_PARAMS=$QEMU_PARAMS" -net nic" +QEMU_PARAMS=$QEMU_PARAMS" -net nic,model=e1000" +#QEMU_PARAMS=$QEMU_PARAMS" -net nic,model=rtl8139" -_NETTYPE="user" +_NETTYPE="user,hostfwd=tcp::5555-:23" _EVAL=eval diff --git a/Tools/GCCProxy/gccproxy.sh b/Tools/GCCProxy/gccproxy.sh index 0dd68644..1624fe0e 100755 --- a/Tools/GCCProxy/gccproxy.sh +++ b/Tools/GCCProxy/gccproxy.sh @@ -73,7 +73,9 @@ while [[ $# -gt 0 ]]; do done run() { - #echo --- $* + if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then + echo --- $* + fi $* return $? } @@ -101,11 +103,11 @@ elif [[ $_compile -eq 1 ]]; then elif echo " $_miscargs" | grep '\.c' >/dev/null; then tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir` run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout - run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $LIBGCC_PATH $_libs + run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH _rv=$? rm $tmpout exit $_rv else - run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $LIBGCC_PATH $_libs + run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH fi diff --git a/Usermode/Applications/Makefile.cfg b/Usermode/Applications/Makefile.cfg index d0a07d1c..02283245 100644 --- a/Usermode/Applications/Makefile.cfg +++ b/Usermode/Applications/Makefile.cfg @@ -21,6 +21,7 @@ endif CPPFLAGS += $(addprefix -I,$(wildcard $(ACESSUSERDIR)Libraries/*/include_exp/)) CPPFLAGS += -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR) +CFLAGS += -std=c99 LDFLAGS += -rpath-link $(OUTPUTDIR)Libs # Extra-verbose errors! diff --git a/Usermode/Applications/axwin3_src/Interface/main.c b/Usermode/Applications/axwin3_src/Interface/main.c index 5f323e46..82cedc23 100644 --- a/Usermode/Applications/axwin3_src/Interface/main.c +++ b/Usermode/Applications/axwin3_src/Interface/main.c @@ -157,6 +157,10 @@ int run_dorun(tAxWin3_Widget *unused) _SysDebug("DoRun pressed"); char *cmd = AxWin3_Widget_GetText(gRunInput); _SysDebug("Command string '%s'", cmd); + + // TODO: Parse the command string into components + // TODO: Call _SysSpawn + AxWin3_ShowWindow(gRunDialog, 0); return 0; } diff --git a/Usermode/Applications/axwin3_src/WM/include/common.h b/Usermode/Applications/axwin3_src/WM/include/common.h index 1be86ffe..e074450d 100644 --- a/Usermode/Applications/axwin3_src/WM/include/common.h +++ b/Usermode/Applications/axwin3_src/WM/include/common.h @@ -18,6 +18,9 @@ #define AXWIN_VERSION 0x300 +static inline int MIN(int a, int b) { return (a < b) ? a : b; } +static inline int MAX(int a, int b) { return (a > b) ? a : b; } + // === GLOBALS === extern int giTerminalFD; extern const char *gsTerminalDevice; diff --git a/Usermode/Applications/axwin3_src/WM/include/wm.h b/Usermode/Applications/axwin3_src/WM/include/wm.h index a4275c9f..914058ff 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm.h @@ -26,6 +26,8 @@ #define WINFLAG_MAXIMIZED 0x00000004 //! Window is contained within the parent #define WINFLAG_RELATIVE 0x00000008 +//! Window needs to be reblitted (child moved or contents changed) +#define WINFLAG_NEEDREBLIT 0x00000020 //! Window contents are valid #define WINFLAG_CLEAN 0x00000040 //! All child windows are un-changed @@ -49,7 +51,7 @@ typedef struct sIPC_Client tIPC_Client; extern tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int Flags, const char *Renderer); extern void WM_DestroyWindow(tWindow *Window); extern tWindow *WM_GetWindowByID(tWindow *Requester, uint32_t ID); -extern void WM_Invalidate(tWindow *Window); +extern void WM_Invalidate(tWindow *Window, int bClearClean); extern void WM_SetWindowTitle(tWindow *Window, const char *Title); extern void WM_FocusWindow(tWindow *Destination); extern void WM_RaiseWindow(tWindow *Window); diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index 44601841..79e0956f 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -57,6 +57,7 @@ void IPC_Type_Sys_Send(const void *Ident, size_t Length, const void *Data); int IPC_Type_IPCPipe_Compare(const void *Ident1, const void *Ident2); void IPC_Type_IPCPipe_Send(const void *Ident, size_t Length, const void *Data); tIPC_Client *IPC_int_GetClient(const tIPC_Type *IPCType, const void *Ident); +void IPC_int_DropClient(tIPC_Client *Client); void IPC_Handle(tIPC_Client *Client, size_t MsgLen, tAxWin_IPCMessage *Msg); // === GLOBALS === @@ -138,7 +139,7 @@ void IPC_HandleSelect(fd_set *set) if( giIPCPipeHandle != -1 && FD_ISSET(giIPCPipeHandle, set) ) { int newfd = _SysOpenChild(giIPCPipeHandle, "newclient", OPENFLAG_READ|OPENFLAG_WRITE); - _SysDebug("newfd = %i"); + _SysDebug("newfd = %i", newfd); IPC_int_GetClient(&gIPC_Type_IPCPipe, &newfd); } @@ -152,6 +153,11 @@ void IPC_HandleSelect(fd_set *set) char staticBuf[STATICBUF_SIZE]; size_t len; len = _SysRead(fd, staticBuf, sizeof(staticBuf)); + if( len == (size_t)-1 ) { + // TODO: Check errno for EINTR + IPC_int_DropClient(gIPC_Clients[i]); + break; + } IPC_Handle( gIPC_Clients[i], len, (void*)staticBuf ); } } @@ -238,6 +244,38 @@ int _CompareClientPtrs(const void *_a, const void *_b) return a->IPCType->CompareIdent(a->Ident, b->Ident); } +int IPC_int_BSearchClients(const tIPC_Client *TargetClient, int *Pos) +{ + int div; + int cmp = -1; + int pos = 0; + + div = giIPC_ClientCount; + pos = div/2; + while(div > 0) + { + div /= 2; + cmp = _CompareClientPtrs(&TargetClient, &gIPC_Clients[pos]); +// _SysDebug("Checking against %i gives %i", pos, cmp); + if(cmp == 0) break; + if(cmp < 0) + pos -= div; + else + pos += div; + } + + // - Return if found + if(cmp == 0) { + *Pos = pos; + return 1; + } + + // Adjust pos to be the index where the new client will be placed + if(cmp > 0) pos ++; + *Pos = pos; + return 0; +} + tIPC_Client *IPC_int_GetClient(const tIPC_Type *IPCType, const void *Ident) { int pos = 0; // Position where the new client will be inserted @@ -248,33 +286,10 @@ tIPC_Client *IPC_int_GetClient(const tIPC_Type *IPCType, const void *Ident) if(giIPC_ClientCount > 0) { tIPC_Client target; - int div; - int cmp = -1; - target.IPCType = IPCType; target.Ident = Ident; - ret = ⌖ // Abuse ret to get a pointer - - div = giIPC_ClientCount; - pos = div/2; - while(div > 0) - { - div /= 2; - cmp = _CompareClientPtrs(&ret, &gIPC_Clients[pos]); -// _SysDebug("Checking against %i gives %i", pos, cmp); - if(cmp == 0) break; - if(cmp < 0) - pos -= div; - else - pos += div; - } - - // - Return if found - if(cmp == 0) + if( IPC_int_BSearchClients(&target, &pos) ) return gIPC_Clients[pos]; - - // Adjust pos to be the index where the new client will be placed - if(cmp > 0) pos ++; } @@ -302,6 +317,40 @@ tIPC_Client *IPC_int_GetClient(const tIPC_Type *IPCType, const void *Ident) return ret; } +void IPC_int_DropClient(tIPC_Client *Client) +{ + // Remove from client list + int pos; + if( !IPC_int_BSearchClients(Client, &pos) ) { + _SysDebug("IPC_int_DropClient: Can't find client %p", Client); + return ; + } + + giIPC_ClientCount --; + memmove(&gIPC_Clients[pos], &gIPC_Clients[pos+1], (giIPC_ClientCount-pos)*sizeof(tIPC_Client*)); + + // Terminate client's windows + // - If there were active windows, show an error? + int nWindowsDestroyed = 0; + for(int i = 0; i < Client->nWindows; i ++) + { + if( Client->Windows[i] ) + { + _SysDebug("Window %p:%i %p still exists", Client, i, Client->Windows[i]); + WM_DestroyWindow(Client->Windows[i]); + nWindowsDestroyed ++; + } + } + if( nWindowsDestroyed ) + { + _SysDebug("TODO: Show notice that application exited without destroying windows"); + } + + // Free client structure + free(Client); + _SysDebug("Dropped client %p", Client); +} + tWindow *IPC_int_GetWindow(tIPC_Client *Client, uint32_t WindowID) { if( WindowID == -1 ) @@ -480,6 +529,7 @@ int IPC_Msg_DestroyWin(tIPC_Client *Client, tAxWin_IPCMessage *Msg) return 0; WM_DestroyWindow(win); + IPC_int_SetWindow(Client, Msg->Window, NULL); return 0; } @@ -628,7 +678,7 @@ void IPC_Handle(tIPC_Client *Client, size_t MsgLen, tAxWin_IPCMessage *Msg) { tWindow *win = IPC_int_GetWindow(Client, Msg->Window); if( !win ) { - _SysDebug("WARNING: NULL window in message %i", Msg->ID); + _SysDebug("WARNING: NULL window in message %i (%x)", Msg->ID, Msg->Window); return ; } tWMRenderer *renderer = win->Renderer; diff --git a/Usermode/Applications/axwin3_src/WM/renderers/menu.c b/Usermode/Applications/axwin3_src/WM/renderers/menu.c index d3534423..e17d9542 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/menu.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/menu.c @@ -422,7 +422,7 @@ int Renderer_Menu_HandleMessage(tWindow *Window, int Msg, int Length, const void { info->HilightedItem = new_hilight; // TODO: Change sub-menu - WM_Invalidate(Window); + WM_Invalidate(Window, 1); } return 0; } diff --git a/Usermode/Applications/axwin3_src/WM/renderers/richtext.c b/Usermode/Applications/axwin3_src/WM/renderers/richtext.c index 8f69c9ca..5f31057a 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/richtext.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/richtext.c @@ -20,6 +20,7 @@ typedef struct sRichText_Line struct sRichText_Line *Next; struct sRichText_Line *Prev; int Num; + char bIsClean; // TODO: Pre-rendered cache? short ByteLength; short Space; @@ -36,6 +37,7 @@ typedef struct sRichText_Window tColour DefaultFG; tColour DefaultBG; tFont *Font; + char bNeedsFullRedraw; short LineHeight; } tRichText_Window; @@ -201,7 +203,6 @@ void Renderer_RichText_RenderText(tWindow *Window, int Line, const char *Text) void Renderer_RichText_Redraw(tWindow *Window) { tRichText_Window *info = Window->RendererInfo; - int i; tRichText_Line *line = info->FirstVisLine; if( !line ) { @@ -213,41 +214,66 @@ void Renderer_RichText_Redraw(tWindow *Window) while( line && line->Prev && line->Prev->Num > info->FirstVisRow ) line = line->Prev; + int i; for( i = 0; i < info->DispLines && line; i ++ ) { if( i >= info->nLines - info->FirstVisRow ) break; - // TODO: Dirty rectangles? + // Empty line is noted by a discontinuity + if( line->Num > info->FirstVisRow + i ) { + // Clear line if window needs full redraw + if( info->bNeedsFullRedraw ) { + WM_Render_FillRect(Window, + 0, i*info->LineHeight, + Window->W, info->LineHeight, + info->DefaultBG + ); + } + else { + // Hack to clear cursor on NULL lines + WM_Render_FillRect(Window, + 0, i*info->LineHeight, + 1, info->LineHeight, + info->DefaultBG + ); + } + continue ; + } + + if( info->bNeedsFullRedraw || !line->bIsClean ) + { + WM_Render_FillRect(Window, + 0, i*info->LineHeight, + Window->W, info->LineHeight, + info->DefaultBG + ); + + // Formatted text out + Renderer_RichText_RenderText(Window, i, line->Data); + _SysDebug("RichText: %p - Render %i '%.*s'", Window, + line->Num, line->ByteLength, line->Data); + line->bIsClean = 1; + } + + line = line->Next; + } + // Clear out lines i to info->DispLines-1 + if( info->bNeedsFullRedraw ) + { + _SysDebug("RichText: %p - Clear %i px lines with %06x starting at %i", + Window, (info->DispLines-i)*info->LineHeight, info->DefaultBG, i*info->LineHeight); WM_Render_FillRect(Window, 0, i*info->LineHeight, - Window->W, info->LineHeight, + Window->W, (info->DispLines-i)*info->LineHeight, info->DefaultBG ); - if( line->Num > info->FirstVisRow + i ) - continue ; - // TODO: Horizontal scrolling? - // TODO: Formatting - - // Formatted text out - Renderer_RichText_RenderText(Window, i, line->Data); - _SysDebug("RichText: %p - Render %i '%.*s'", Window, - line->Num, line->ByteLength, line->Data); - - line = line->Next; } - // Clear out i -- info->DispLines - _SysDebug("RichText: %p - Clear %i px lines with %06x starting at %i", - Window, (info->DispLines-i)*info->LineHeight, info->DefaultBG, i*info->LineHeight); - WM_Render_FillRect(Window, - 0, i*info->LineHeight, - Window->W, (info->DispLines-i)*info->LineHeight, - info->DefaultBG - ); + info->bNeedsFullRedraw = 0; - // HACK! + // HACK: Hardcoded text width of 8 info->DispCols = Window->W / 8; - // TODO: Text cursor + // Text cursor _SysDebug("Cursor at %i,%i", info->CursorCol, info->CursorRow); _SysDebug(" Range [%i+%i],[%i+%i]", info->FirstVisRow, info->DispLines, info->FirstVisCol, info->DispCols); if( info->CursorRow >= info->FirstVisRow && info->CursorRow < info->FirstVisRow + info->DispLines ) @@ -266,6 +292,22 @@ void Renderer_RichText_Redraw(tWindow *Window) } } +tRichText_Line *Renderer_RichText_int_GetLine(tWindow *Window, int LineNum, tRichText_Line **Prev) +{ + tRichText_Window *info = Window->RendererInfo; + tRichText_Line *line = info->FirstLine; + tRichText_Line *prev = NULL; + while(line && line->Num < LineNum) + prev = line, line = line->Next; + + if( Prev ) + *Prev = prev; + + if( !line || line->Num > LineNum ) + return NULL; + return line; +} + int Renderer_RichText_HandleIPC_SetAttr(tWindow *Window, size_t Len, const void *Data) { tRichText_Window *info = Window->RendererInfo; @@ -281,10 +323,22 @@ int Renderer_RichText_HandleIPC_SetAttr(tWindow *Window, size_t Len, const void case _ATTR_DEFFG: info->DefaultFG = msg->Value; break; - case _ATTR_CURSORPOS: - info->CursorRow = msg->Value >> 12; - info->CursorCol = msg->Value & 0xFFF; - break; + case _ATTR_CURSORPOS: { + int newRow = msg->Value >> 12; + int newCol = msg->Value & 0xFFF; + // Force redraw of old and new row + tRichText_Line *line = Renderer_RichText_int_GetLine(Window, info->CursorRow, NULL); + if( line ) + line->bIsClean = 0; + if( newRow != info->CursorRow ) { + line = Renderer_RichText_int_GetLine(Window, newRow, NULL); + if(line) + line->bIsClean = 0; + } + info->CursorRow = newRow; + info->CursorCol = newCol; + WM_Invalidate(Window, 1); + break; } case _ATTR_SCROLL: // TODO: Set scroll flag break; @@ -303,18 +357,16 @@ int Renderer_RichText_HandleIPC_WriteLine(tWindow *Window, size_t Len, const voi if( Len < sizeof(*msg) ) return -1; if( msg->Line >= info->nLines ) return 1; // Bad count - tRichText_Line *line = info->FirstLine; tRichText_Line *prev = NULL; - while(line && line->Num < msg->Line) - prev = line, line = line->Next; - if( !line || line->Num > msg->Line ) + tRichText_Line *line = Renderer_RichText_int_GetLine(Window, msg->Line, &prev); + if( !line ) { // New line! // Round up to 32 int space = ((Len - sizeof(*msg)) + 32-1) & ~(32-1); tRichText_Line *new = malloc(sizeof(*line) + space); // TODO: Bookkeeping on how much memory each window uses - new->Next = line; + new->Next = (prev ? prev->Next : NULL); new->Prev = prev; new->Num = msg->Line; new->Space = space; @@ -342,10 +394,11 @@ int Renderer_RichText_HandleIPC_WriteLine(tWindow *Window, size_t Len, const voi } line->ByteLength = Len - sizeof(*msg); memcpy(line->Data, msg->LineData, Len - sizeof(*msg)); + line->bIsClean = 0; - WM_Invalidate( Window ); +// WM_Invalidate(Window, 1); - return 0; + return 0; } int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data) @@ -357,6 +410,7 @@ int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const voi const struct sWndMsg_Resize *msg = Data; if(Len < sizeof(*msg)) return -1; info->DispLines = msg->H / info->LineHeight; + info->bNeedsFullRedraw = 1; // force full rerender return 1; } case WNDMSG_KEYDOWN: case WNDMSG_KEYUP: diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c index fc7e1077..831565b3 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c @@ -213,7 +213,7 @@ int Widget_TextInput_KeyFire(tElement *Element, int KeySym, int Character) } // TODO: Have a Widget_ function to do this instead - WM_Invalidate(Element->Window); + WM_Invalidate(Element->Window, 1); return 0; } diff --git a/Usermode/Applications/axwin3_src/WM/video.c b/Usermode/Applications/axwin3_src/WM/video.c index a30dd377..dfdd2e50 100644 --- a/Usermode/Applications/axwin3_src/WM/video.c +++ b/Usermode/Applications/axwin3_src/WM/video.c @@ -92,7 +92,7 @@ void Video_Update(void) _SysDebug("Video_Update - Sending FD %i %p 0x%x", giTerminalFD, gpScreenBuffer+ofs, size*4); _SysWrite(giTerminalFD, gpScreenBuffer+ofs, size*4); _SysDebug("Video_Update - Done"); - giVideo_FirstDirtyLine = 0; + giVideo_FirstDirtyLine = giScreenHeight; giVideo_LastDirtyLine = 0; } @@ -159,10 +159,8 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H) if( W <= 0 || H <= 0 ) return; - if( DstY < giVideo_FirstDirtyLine ) - giVideo_FirstDirtyLine = DstY; - if( DstY + H > giVideo_LastDirtyLine ) - giVideo_LastDirtyLine = DstY + H; + giVideo_FirstDirtyLine = MIN(DstY, giVideo_FirstDirtyLine); + giVideo_LastDirtyLine = MAX(DstY+H, giVideo_LastDirtyLine); buf = gpScreenBuffer + DstY*giScreenWidth + DstX; if(drawW != giScreenWidth || W != giScreenWidth) diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index cc9d81d0..4b28d11d 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -112,7 +112,8 @@ void WM_DestroyWindow(tWindow *Window) else Window->Parent->LastChild = prev; } - WM_Invalidate(Window->Parent); + // - Full invalidate + WM_Invalidate(Window, 1); // - Remove from inheritance tree? @@ -134,7 +135,7 @@ void WM_DestroyWindow(tWindow *Window) if( Window->Renderer->DestroyWindow ) Window->Renderer->DestroyWindow(Window); else - _SysDebug("WARN: Renderer %s does not have a destroy function", Window->Renderer->Name); + _SysDebug("WARN: Renderer '%s' does not have a destroy function", Window->Renderer->Name); // - Tell client to clean up WM_SendMessage(NULL, Window, WNDMSG_DESTROY, 0, NULL); @@ -241,9 +242,10 @@ void WM_FocusWindow(tWindow *Destination) _msg.Val = 1; WM_SendMessage(NULL, Destination, WNDMSG_FOCUS, sizeof(_msg), &_msg); } - - WM_Invalidate(gpWM_FocusedWindow); - WM_Invalidate(Destination); + + // TODO: Leave it up to the renderer to decide to invalidate + WM_Invalidate(gpWM_FocusedWindow, 1); + WM_Invalidate(Destination, 1); gpWM_FocusedWindow = Destination; } @@ -255,6 +257,10 @@ void WM_ShowWindow(tWindow *Window, int bShow) if( !!(Window->Flags & WINFLAG_SHOW) == bShow ) return ; + + // Window is being hidden, invalidate parents + if( !bShow ) + WM_Invalidate(Window, 0); // Message window _msg.Val = !!bShow; @@ -280,7 +286,9 @@ void WM_ShowWindow(tWindow *Window, int bShow) _SysDebug("Window %p hidden", Window); } - WM_Invalidate(Window); + // Window has been shown, invalidate everything + if( bShow ) + WM_Invalidate(Window, 1); } void WM_DecorateWindow(tWindow *Window, int bDecorate) @@ -299,7 +307,7 @@ void WM_DecorateWindow(tWindow *Window, int bDecorate) Window->RenderBuffer = NULL; } - WM_Invalidate(Window); + WM_Invalidate(Window, 1); } void WM_SetRelative(tWindow *Window, int bRelativeToParent) @@ -342,12 +350,19 @@ int WM_MoveWindow(tWindow *Window, int X, int Y) } // TODO: Re-sanitise + if( Window->X == X && Window->Y == Y ) { + _SysDebug("WM_MoveWindow: Equal (%i,%i)", X, Y); + return 0; + } + + if( Window->Parent ) + Window->Parent->Flags |= WINFLAG_NEEDREBLIT; + _SysDebug("WM_MoveWindow: (%i,%i)", X, Y); Window->X = X; Window->Y = Y; // Mark up the tree that a child window has changed - while( (Window = Window->Parent) ) - Window->Flags &= ~WINFLAG_CHILDCLEAN; + WM_Invalidate(Window, 0); return 0; } @@ -360,15 +375,19 @@ int WM_ResizeWindow(tWindow *Window, int W, int H) if( Window->W == W && Window->H == H ) return 0; + + // If the window size has decreased, force the parent to reblit + if( Window->Parent && (Window->W > W || Window->H > H) ) + Window->Parent->Flags |= WINFLAG_NEEDREBLIT; - _SysDebug("WM_ResizeWindow: %ix%i", W, H); + _SysDebug("WM_ResizeWindow: %p:%i %ix%i", Window->Client, Window->ID, W, H); Window->W = W; Window->H = H; if(Window->RenderBuffer) { free(Window->RenderBuffer); Window->RenderBuffer = NULL; } - WM_Invalidate(Window); + WM_Invalidate(Window, 1); { struct sWndMsg_Resize msg; @@ -437,18 +456,20 @@ int WM_SendIPCReply(tWindow *Window, int Message, size_t Length, const void *Dat return 0; } -void WM_Invalidate(tWindow *Window) +void WM_Invalidate(tWindow *Window, int bClearClean) { if(!Window) return ; -// _SysDebug("Invalidating %p", Window); - // Don't invalidate twice (speedup) -// if( !(Window->Flags & WINFLAG_CLEAN) ) return; - + + // Don't bother invalidating if the window isn't shown + if( !(Window->Flags & WINFLAG_SHOW) ) + return ; + // Mark for re-render - Window->Flags &= ~WINFLAG_CLEAN; + if( bClearClean ) + Window->Flags &= ~WINFLAG_CLEAN; // Mark up the tree that a child window has changed - while( (Window = Window->Parent) ) + while( (Window = Window->Parent) && (Window->Flags & WINFLAG_SHOW) ) Window->Flags &= ~WINFLAG_CHILDCLEAN; } @@ -495,7 +516,7 @@ void WM_int_UpdateWindow(tWindow *Window) } Window->Renderer->Redraw(Window); - Window->Flags |= WINFLAG_CLEAN; + Window->Flags |= WINFLAG_CLEAN|WINFLAG_NEEDREBLIT; } // Process children @@ -513,7 +534,7 @@ void WM_int_UpdateWindow(tWindow *Window) Decorator_Redraw(Window); } -void WM_int_BlitWindow(tWindow *Window) +void WM_int_BlitWindow(tWindow *Window, int bForceReblit) { tWindow *child; @@ -535,7 +556,15 @@ void WM_int_BlitWindow(tWindow *Window) // _SysDebug("Blit %p (%p) to (%i,%i) %ix%i", Window, Window->RenderBuffer, // Window->RealX, Window->RealY, Window->RealW, Window->RealH); - Video_Blit(Window->RenderBuffer, Window->RealX, Window->RealY, Window->RealW, Window->RealH); + // TODO Don't blit unless: + // a) A parent has been reblitted (thus clobbering the existing content) + // b) A child has moved (exposing a previously hidden area) + if( bForceReblit || (Window->Flags & WINFLAG_NEEDREBLIT) ) + { + Video_Blit(Window->RenderBuffer, Window->RealX, Window->RealY, Window->RealW, Window->RealH); + Window->Flags &= ~WINFLAG_NEEDREBLIT; + bForceReblit = 1; + } if( Window == gpWM_FocusedWindow && Window->CursorW ) { @@ -549,7 +578,7 @@ void WM_int_BlitWindow(tWindow *Window) for( child = Window->FirstChild; child; child = child->NextSibling ) { - WM_int_BlitWindow(child); + WM_int_BlitWindow(child, bForceReblit); } } @@ -563,7 +592,7 @@ void WM_Update(void) WM_int_UpdateWindow(gpWM_RootWindow); // - Draw windows from back to front to the render buffer - WM_int_BlitWindow(gpWM_RootWindow); + WM_int_BlitWindow(gpWM_RootWindow, 0); Video_Update(); } diff --git a/Usermode/Applications/axwin3_src/include/wm_messages.h b/Usermode/Applications/axwin3_src/include/wm_messages.h index a0c49198..1cc7697a 100644 --- a/Usermode/Applications/axwin3_src/include/wm_messages.h +++ b/Usermode/Applications/axwin3_src/include/wm_messages.h @@ -13,21 +13,21 @@ */ enum eWM_WindowMessages { - WNDMSG_NULL, + WNDMSG_NULL, // 0 - WNDMSG_CREATE, - WNDMSG_DESTROY, - WNDMSG_CLOSE, - WNDMSG_FOCUS, // Called on change - WNDMSG_SHOW, // Called on change + WNDMSG_CREATE, // 1 + WNDMSG_DESTROY, // 2 + WNDMSG_CLOSE, // 3 + WNDMSG_FOCUS, // 4 Called on change + WNDMSG_SHOW, // 5 Called on change - WNDMSG_RESIZE, + WNDMSG_RESIZE, // 6 - WNDMSG_MOUSEMOVE, - WNDMSG_MOUSEBTN, - WNDMSG_KEYDOWN, - WNDMSG_KEYFIRE, - WNDMSG_KEYUP, + WNDMSG_MOUSEMOVE, // 7 + WNDMSG_MOUSEBTN, // 8 + WNDMSG_KEYDOWN, // 9 + WNDMSG_KEYFIRE, // 10 + WNDMSG_KEYUP, // 11 WNDMSG_HOTKEY, diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c index 9fed5449..1ac98fe5 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c @@ -26,13 +26,20 @@ int AxWin3_RichText_MessageHandler(tHWND Window, int MessageID, int Size, void * { tRichText_Window *info = AxWin3_int_GetDataPtr(Window); struct sWndMsg_KeyAction *keyaction = Data; - _SysDebug("MessageID = %i", MessageID); switch(MessageID) { case WNDMSG_KEYFIRE: if(Size < sizeof(*keyaction)) return -1; info->KeyCallback(Window, 2, keyaction->KeySym, keyaction->UCS32); return 1; + case WNDMSG_KEYDOWN: + if(Size < sizeof(*keyaction)) return -1; + info->KeyCallback(Window, 1, keyaction->KeySym, keyaction->UCS32); + return 1; + case WNDMSG_KEYUP: + if(Size < sizeof(*keyaction)) return -1; + info->KeyCallback(Window, 0, keyaction->KeySym, 0); + return 1; } return 0; } diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c index 62e42779..22a934bb 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c @@ -12,6 +12,9 @@ #include #include +//static const int ciBaseElementCount = 16; +static const int ciStepElementCount = 16; + // === STRUCTURES === struct sAxWin3_Widget { @@ -58,11 +61,10 @@ uint32_t AxWin3_Widget_int_AllocateID(tWidgetWindowInfo *Info) } if( newID == Info->nElements ) { - const int size_step = 4; - Info->nElements += 4; + Info->nElements += ciStepElementCount; Info->Elements = realloc(Info->Elements, sizeof(*Info->Elements)*Info->nElements); - newID = Info->nElements - 4; - memset( &Info->Elements[newID+1], 0, (size_step-1)*sizeof(Info->Elements)); + newID = Info->nElements - ciStepElementCount; + memset( &Info->Elements[newID+1], 0, (ciStepElementCount-1)*sizeof(Info->Elements)); _SysDebug("Widget: Expanded to %i and allocated %i", Info->nElements, newID); } else @@ -79,12 +81,19 @@ int AxWin3_Widget_MessageHandler(tHWND Window, int MessageID, int Size, void *Da switch(MessageID) { +// case WNDMSG_DESTROY: { +// return 0; } case MSG_WIDGET_FIRE: { tWidgetMsg_Fire *msg = Data; if(Size < sizeof(*msg)) return -1; widget = AxWin3_Widget_int_GetElementByID(Window, msg->WidgetID); if(widget->Fire) widget->Fire(widget); + return 1; } + case MSG_WIDGET_KEYPRESS: { + return 0; } + case MSG_WIDGET_MOUSEBTN: { + // TODO: Do something return 1; } default: return 0; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c index 99b9a1b6..f1ffd3b2 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c @@ -54,6 +54,20 @@ tWindow *AxWin3_int_GetWindowFromID(uint32_t ServerID) return block->Windows[ServerID]; } +void AxWin3_int_DelWindowByID(uint32_t ServerID) +{ + int orig_id = ServerID; + tWindowBlock *block = &gAxWin3_WindowList; + while(block && ServerID > WINDOWS_PER_ALLOC) { + block = block->Next; + ServerID -= WINDOWS_PER_ALLOC; + } + if( !block || !block->Windows[ServerID] ) + _SysDebug("AxWin3_int_DelWindowByID - Id %i out of range", orig_id); + else + block->Windows[ServerID] = NULL; +} + tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID) { int idx, newWinID; @@ -208,6 +222,7 @@ int AxWin3_int_DefaultMessageHandler(tWindow *Win, int ID, size_t Len, const voi case WNDMSG_DESTROY: _SysDebug("TODO: Check that WNDMSG_DESTROY was from us calling _DestroyWindow"); // TODO: Finalise cleanup of window, this will be the last message sent to this window + AxWin3_int_DelWindowByID(Win->ServerID); return 1; default: return 0; diff --git a/Usermode/Applications/gui_shell_src/display.c b/Usermode/Applications/gui_shell_src/display.c index 1665e448..bb07e39f 100644 --- a/Usermode/Applications/gui_shell_src/display.c +++ b/Usermode/Applications/gui_shell_src/display.c @@ -88,7 +88,6 @@ void Display_AddText(int Length, const char *UTF8Text) Display_int_PushString(bytes, UTF8Text); UTF8Text += bytes; - _SysDebug("Length(%i) -= bytes(%i)", Length, bytes); Length -= bytes; if( Length != 0 ) { @@ -102,7 +101,7 @@ void Display_AddText(int Length, const char *UTF8Text) void Display_Newline(int bCarriageReturn) { - Display_Flush(); +// Display_Flush(); // Going down! giCurrentLine ++; @@ -238,8 +237,6 @@ void Display_Flush(void) AxWin3_RichText_SendLine(gMainWindow, giFirstLine + i, gasDisplayLines[line] ); gabDisplayLinesDirty[line] = 0; } - - // force redraw? AxWin3_RichText_SetCursorPos(gMainWindow, giCurrentLine, giCurrentCol); } diff --git a/Usermode/Applications/gui_shell_src/main.c b/Usermode/Applications/gui_shell_src/main.c index 4b82d0e0..ec88bf32 100644 --- a/Usermode/Applications/gui_shell_src/main.c +++ b/Usermode/Applications/gui_shell_src/main.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[], const char **envp) { _SysDebug("Activity on child stdout"); // Read and update screen - char buf[32]; + char buf[128]; int len = _SysRead(giChildStdout, buf, sizeof(buf)); if( len <= 0 ) break; @@ -112,7 +112,7 @@ int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translat static int ctrl_state = 0; // Handle modifiers - #define _bitset(var,bit,set) do{if(set)var|=1<<(bit);else var&=1<<(bit);}while(0) + #define _bitset(var,bit,set) do{if(set)var|=1<<(bit);else var&=~(1<<(bit));}while(0) switch(KeySym) { case KEYSYM_LEFTCTRL: @@ -129,6 +129,7 @@ int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translat if( ctrl_state && KeySym >= KEYSYM_a && KeySym <= KEYSYM_z ) { Translated = KeySym - KEYSYM_a + 1; + _SysDebug("Ctrl-%c: KS %x => Trans %x", 'A'+(KeySym-KEYSYM_a), KeySym, Translated); } // == 2 :: FIRE @@ -142,7 +143,7 @@ int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translat // Encode and send len = WriteUTF8(buf, Translated); - _SysDebug("Keystroke translated to '%.*s'", len, buf); + _SysDebug("Keystroke %x:%x translated to '%.*s'", KeySym, Translated, len, buf); _SysWrite(giChildStdin, buf, len); return 0; @@ -184,7 +185,7 @@ void Term_HandleOutput(int Len, const char *Buf) esc_len = -esc_len; } ofs += esc_len; - _SysDebug("Len = %i, ofs = %i", Len, ofs); + //_SysDebug("Len = %i, ofs = %i", Len, ofs); } Display_Flush(); diff --git a/Usermode/Applications/irc_src/main.c b/Usermode/Applications/irc_src/main.c index 4ca24155..b96fcc9e 100644 --- a/Usermode/Applications/irc_src/main.c +++ b/Usermode/Applications/irc_src/main.c @@ -207,6 +207,79 @@ int ParseArguments(int argc, const char *argv[]) return 0; } + +void Cmd_join(char *ArgString) +{ + int pos=0; + char *channel_name = GetValue(ArgString, &pos); + + if( gpCurrentWindow->Server ) + { + writef(gpCurrentWindow->Server->FD, "JOIN :%s\n", channel_name); + } +} + +void Cmd_quit(char *ArgString) +{ + const char *quit_message = ArgString; + if( quit_message == NULL || quit_message[0] == '\0' ) + quit_message = "/quit - Acess2 IRC Client"; + + for( tServer *srv = gpServers; srv; srv = srv->Next ) + { + writef(srv->FD, "QUIT :%s\n", quit_message); + } + + exit(0); +} + +void Cmd_window(char *ArgString) +{ + int pos = 0; + char *window_id = GetValue(ArgString, &pos); + int window_num = atoi(window_id); + + if( window_num > 0 ) + { + tWindow *win; + window_num --; // Move to base 0 + // Get `window_num`th window + for( win = gpWindows; win && window_num--; win = win->Next ); + if( win ) { + gpCurrentWindow = win; + Redraw_Screen(); + } + // Otherwise, silently ignore + } + else + { + window_num = 1; + for( tWindow *win = gpWindows; win; win = win->Next, window_num ++ ) + { + if( win->Name[0] ) { + Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", + "%i: %s/%s", window_num, win->Server->Name, win->Name); + } + else { + Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", + "%i: (status)", window_num); + } + } + } +} + +const struct { + const char *Name; + void (*Fcn)(char *ArgString); +} caCommands[] = { + {"join", Cmd_join}, + {"quit", Cmd_quit}, + {"window", Cmd_window}, + {"win", Cmd_window}, + {"w", Cmd_window}, +}; +const int ciNumCommands = sizeof(caCommands)/sizeof(caCommands[0]); + /** * \brief Handle a line from the prompt */ @@ -217,65 +290,19 @@ int ParseUserCommand(char *String) char *command; int pos = 0; - command = GetValue(String, &pos); - - if( strcmp(command, "/join") == 0 ) - { - char *channel_name = GetValue(String, &pos); - - if( gpCurrentWindow->Server ) - { - writef(gpCurrentWindow->Server->FD, "JOIN :%s\n", channel_name); - } - } - else if( strcmp(command, "/quit") == 0 ) + command = GetValue(String, &pos)+1; + + // TODO: Prefix matches + int cmdIdx = -1; + for( int i = 0; i < ciNumCommands; i ++ ) { - char *quit_message = String + pos; - tServer *srv; - - if( quit_message == NULL || quit_message[0] == '\0' ) - quit_message = "/quit - Acess2 IRC Client"; - - for( srv = gpServers; srv; srv = srv->Next ) - { - writef(srv->FD, "QUIT :%s\n", quit_message); + if( strcmp(command, caCommands[i].Name) == 0 ) { + cmdIdx = i; + break; } - - exit(0); } - else if( strcmp(command, "/window") == 0 || strcmp(command, "/win") == 0 || strcmp(command, "/w") == 0 ) - { - char *window_id = GetValue(String, &pos); - int window_num = atoi(window_id); - - if( window_num > 0 ) - { - tWindow *win; - window_num --; // Move to base 0 - // Get `window_num`th window - for( win = gpWindows; win && window_num--; win = win->Next ); - if( win ) { - gpCurrentWindow = win; - Redraw_Screen(); - } - // Otherwise, silently ignore - } - else - { - tWindow *win; - window_num = 1; - for( win = gpWindows; win; win = win->Next, window_num ++ ) - { - if( win->Name[0] ) { - Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", - "%i: %s/%s", window_num, win->Server->Name, win->Name); - } - else { - Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", - "%i: (status)", window_num); - } - } - } + if( cmdIdx != -1 ) { + caCommands[cmdIdx].Fcn(String+pos); } else { diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 81bd4ee3..bc9013d4 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -27,10 +27,13 @@ int main(int argc, char *argv[]) for(;;) { sUsername = GetUsername(); + if(!sUsername) continue; sPassword = GetPassword(); + if(!sPassword) continue; if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) { printf("\nInvalid username or password\n"); + _SysDebug("Auth failure: '%s':'%s'", sUsername, sPassword); free(sUsername); free(sPassword); } @@ -61,38 +64,42 @@ int main(int argc, char *argv[]) return 0; } -/** - * \fn char *GetUsername() - */ -char *GetUsername() +char *_GetString(int bEcho) { - char ret[BUFLEN] = {0}; + char ret[BUFLEN]; int pos = 0; char ch; - // Prompt the user - printf("Username: "); - fflush(stdout); - // Read in text while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { + // Handle backspace if(ch == '\b') { if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; } + // Ctrl-C : Cancel + else if( ch == 'c'-'a'+1) + pos = 0; + // Ctrl-U : Clear + else if( ch == 'u'-'a'+1) + pos = 0; + // Ignore \r + else if( ch == '\r' ) + continue; else ret[pos++] = ch; - // Echo out to the screen - fputc(ch, stdout); - fflush(stdout); + // Don't echo out to the screen + if( bEcho ) { + fputc(ch, stdout); + fflush(stdout); + } if(pos == BUFLEN-1) break; } - // Finish String ret[pos] = '\0'; printf("\n"); @@ -100,37 +107,29 @@ char *GetUsername() } /** - * \fn char *GetPassword() + * \fn char *GetUsername() */ -char *GetPassword() +char *GetUsername() { - char ret[BUFLEN]; + char ret[BUFLEN] = {0}; int pos = 0; char ch; // Prompt the user - printf("Password: "); + printf("Username: "); fflush(stdout); - // Read in text - while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) - { - if(ch == '\b') { - if( pos <= 0 ) continue; - pos --; - ret[pos] = '\0'; - } - else - ret[pos++] = ch; - - // Don't echo out to the screen - //fputc(stdout, ch); - - if(pos == BUFLEN-1) break; - } - - ret[pos] = '\0'; + return _GetString(1); +} + +/** + * \fn char *GetPassword() + */ +char *GetPassword() +{ + // Prompt the user + printf("Password: "); + fflush(stdout); - printf("\n"); - return strdup(ret); + return _GetString(0); } diff --git a/Usermode/Applications/mount_src/main.c b/Usermode/Applications/mount_src/main.c index 1a1fc7be..ced39440 100644 --- a/Usermode/Applications/mount_src/main.c +++ b/Usermode/Applications/mount_src/main.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) // If no directory was passed (we want to use the mount list) // or we are not root (we need to use the mount list) // Check the mount list - if(sDir == NULL || getuid() != 0) + if(sDir == NULL || _SysGetUID() != 0) { // Check if it is defined in the mounts file // - At this point sDevice could be a device name or a mount point diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index a4346eb9..c3cb7b14 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -6,9 +6,9 @@ MAKEDEP = $(CC) -M ifeq ($(ARCHDIR),native) -ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 -LDFLAGS := -lacess-native -#CPPFLAGS := -D SoMain="__attribute__ ((constructor(101))) libacessnative_init" + ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 + LDFLAGS := -lacess-native + #CPPFLAGS := -D SoMain="__attribute__ ((constructor(101))) libacessnative_init" ifeq ($(PLATFORM),windows) else LDFLAGS += -Wl,-init,SoMain 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 c7a7215c..8ed66842 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -11,9 +11,9 @@ SYSCALL1(_SysWaitEvent, SYS_WAITEVENT) SYSCALL2(_SysWaitTID, SYS_WAITTID) SYSCALL0(gettid, SYS_GETTID) -SYSCALL0(getpid, SYS_GETPID) -SYSCALL0(getuid, SYS_GETUID) -SYSCALL0(getgid, SYS_GETGID) +SYSCALL0(_SysGetPID, SYS_GETPID) +SYSCALL0(_SysGetUID, SYS_GETUID) +SYSCALL0(_SysGetGID, SYS_GETGID) SYSCALL1(setuid, SYS_SETUID) SYSCALL1(setgid, SYS_SETGID) @@ -43,6 +43,7 @@ SYSCALL2(_SysOpen, SYS_OPEN) // char*, int SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int SYSCALL3(_SysReopen, SYS_REOPEN) // int, char*, int SYSCALL2(_SysCopyFD, SYS_COPYFD) // int, int +SYSCALL3(_SysFDFlags, SYS_FDCTL) // int, int, int SYSCALL1(_SysClose, SYS_CLOSE) // int SYSCALL3(_SysRead, SYS_READ) // int, uint, void* SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void* 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 21e40ae0..d45ffb64 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 @@ -55,7 +55,7 @@ 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 _SysGetPID(void); extern int _SysSetFaultHandler(int (*Handler)(int)); extern void _SysSetName(const char *Name); extern int _SysGetName(char *NameDest); @@ -64,8 +64,8 @@ extern int _SysSetPri(int Priority); extern int64_t _SysTimestamp(void); // --- Permissions --- -extern int getuid(void); -extern int getgid(void); +extern int _SysGetUID(void); +extern int _SysGetGID(void); extern void setuid(int id); extern void setgid(int id); @@ -78,6 +78,7 @@ 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 _SysFDFlags(int fd, int mask, int newflags); extern size_t _SysRead(int fd, void *buffer, size_t length); extern int _SysClose(int fd); extern int _SysFDCtl(int fd, int option, ...); @@ -90,7 +91,7 @@ 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) +//#define select(nfs, rdfds, wrfds, erfds, timeout) _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0) extern int _SysUnlink(const char *pathname); // --- IPC --- diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index be6e08aa..60b86cd2 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -12,7 +12,7 @@ INCFILES := stdio.h stdlib.h OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o rand.o OBJ += perror.o scanf.o signals.o strtoi.o strtof.o -OBJ += printf.o +OBJ += printf.o time.o OBJ += arch/$(ARCHDIR).ao # signals.o DEPFILES := $(OBJ:%.o=%.d) diff --git a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h index 67ca3519..1aeb879b 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h +++ b/Usermode/Libraries/libc.so_src/include_exp/errno.enum.h @@ -20,6 +20,7 @@ enum { ENODEV, // ??? EADDRNOTAVAIL, // ? EINPROGRESS, // ? + EROFS, EAGAIN, // Try again diff --git a/Usermode/Libraries/libc.so_src/include_exp/signal.h b/Usermode/Libraries/libc.so_src/include_exp/signal.h index da6d78fd..03816f32 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/signal.h +++ b/Usermode/Libraries/libc.so_src/include_exp/signal.h @@ -10,6 +10,7 @@ typedef void (*sighandler_t)(int); +#define SIG_IGN ((void*)1) #define SIG_DFL ((void*)0) #define SIG_ERR ((void*)-1) diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdio.h b/Usermode/Libraries/libc.so_src/include_exp/stdio.h index 70e71388..fed2e97a 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdio.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdio.h @@ -69,6 +69,7 @@ extern int fileno(FILE *stream); extern size_t fread(void *buf, size_t size, size_t n, FILE *fp); extern size_t fwrite(const void *buf, size_t size, size_t n, FILE *fp); extern int fgetc(FILE *fp); +#define getc(fp) fgetc(fp) extern char *fgets(char *s, int size, FILE *fp); extern int fputc(int ch, FILE *fp); extern int fputs(const char *s, FILE *fp); diff --git a/Usermode/Libraries/libc.so_src/include_exp/time.h b/Usermode/Libraries/libc.so_src/include_exp/time.h index 5d728cea..ce693267 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/time.h +++ b/Usermode/Libraries/libc.so_src/include_exp/time.h @@ -28,7 +28,9 @@ struct tm typedef signed long long clock_t; -extern clock_t clock(); +extern clock_t clock(void); + +extern time_t time(time_t *t); #endif diff --git a/Usermode/Libraries/libc.so_src/strtoi.c b/Usermode/Libraries/libc.so_src/strtoi.c index 9326fb8a..81af4601 100644 --- a/Usermode/Libraries/libc.so_src/strtoi.c +++ b/Usermode/Libraries/libc.so_src/strtoi.c @@ -132,3 +132,19 @@ int atoi(const char *str) } return tmp; } + +long atol(const char *str) +{ + long long tmp = strtoll(str, NULL, 0); + if( tmp > LONG_MAX || tmp < LONG_MIN ) { + errno = ERANGE; + return (tmp > LONG_MAX) ? LONG_MAX : LONG_MIN; + } + return tmp; +} + +long atoll(const char *str) +{ + long long tmp = strtoll(str, NULL, 0); + return tmp; +} diff --git a/Usermode/Libraries/libc.so_src/time.c b/Usermode/Libraries/libc.so_src/time.c new file mode 100644 index 00000000..aa4b2de8 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/time.c @@ -0,0 +1,22 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * time.c + * - POSIX/stdc time functions + */ +#include +#include + +clock_t clock(void) +{ + return _SysTimestamp(); +} + +time_t time(time_t *t) +{ + time_t ret = _SysTimestamp() / 1000; + if(t) + *t = ret; + return ret; +} diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index 628999c3..20b5fec4 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -8,7 +8,8 @@ CFLAGS += -Werror -Wextra ASFLAGS += LDFLAGS += -soname libposix.so -Map map.txt -lc -OBJ = main.o unistd.o dirent.o stat.o +OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o +OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h index daababb4..bdb54226 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h @@ -9,22 +9,27 @@ #ifndef _FCNTL_H_ #define _FCNTL_H_ -//#include - -// Hacks to handle different behaviors in Acess - -// Open doesn't take a chmod -//#define open(_1,_2,...) open(_1, _2) - -// Close returns void -//#define close(_1) (close(_1),0) - -// Acess doesn't implement lseek -#define lseek(_1,_2,_3) (seek(_1,_2,_3),tell(_1)) +struct flock +{ + short l_type; + short l_whece; + off_t l_start; + off_t l_len; + pid_t l_pid; +}; enum e_fcntl_cmds { - F_SETFL + F_DUPFD, // (long) + //F_DUPFD_CLOEXEC, // (long) - Non POSIX + F_GETFD, // (void) + F_SETFD, // (long) + F_GETFL, // (void) + F_SETFL, // (long) + + F_SETLK, // (struct flock *) + F_SETLKW, // (struct flock *) + F_GETLK, // (struct flock *) }; static inline int fcntl(int fd __attribute__((unused)), int cmd __attribute__((unused)), ...) { return -1; } diff --git a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h index ae4bf077..9d2e2990 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/pwd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/pwd.h @@ -8,6 +8,7 @@ #ifndef _LIBPOSIX__PWD_H_ #define _LIBPOSIX__PWD_H_ +#include // size_t #include // gid_t/uid_t struct passwd diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h index 16cdd40a..e4807ec8 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h @@ -8,7 +8,7 @@ #ifndef _LIBPOSIX__IOCTL_H_ #define _LIBPOSIX__IOCTL_H_ - +extern int ioctl(int d, int request, ...); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h index 90308f23..9aa2c23b 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h @@ -29,6 +29,7 @@ struct rlimit rlim_t rlim_max; }; +// (get|set)r(limit|usage) resource values enum { RLIMIT_AS, // Address space size @@ -45,10 +46,10 @@ struct rusage }; extern int getpriority(int, id_t); -extern int getrlimit(int, struct rlimit *); -extern int getrusage(int, struct rusage *); +extern int getrlimit(int resource, struct rlimit *rlim); +extern int getrusage(int resource, struct rusage *rusage); extern int setpriority(int, id_t, int); -extern int setrlimit(int, const struct rlimit *); +extern int setrlimit(int resource, const struct rlimit *rlim); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h index cf2f1aaf..f31e583e 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h @@ -11,7 +11,7 @@ #include #include -extern int select(int nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout); +extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *execptfds, struct timeval *timeout); // TODO: pselect? #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h index c5749281..be5ceb34 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h @@ -55,5 +55,6 @@ struct stat extern int stat(const char *path, struct stat *buf); extern int lstat(const char *path, struct stat *buf); extern int fstat(int fd, struct stat *buf); +extern int mkdir(const char *pathname, mode_t mode); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h index 5cd28762..79e40138 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h @@ -8,6 +8,8 @@ #ifndef _LIBPOSIX__SYS__TIME_H_ #define _LIBPOSIX__SYS__TIME_H_ +#include + typedef unsigned long suseconds_t; struct timeval @@ -16,6 +18,28 @@ struct timeval suseconds_t tv_usec; }; +// struct timezone . tz_dsttime +enum +{ + DST_NONE, // No DST + DST_USA, // USA style DST + DST_AUST, // Australian style DST + DST_WET, // Western European DST + DST_MET, // Middle European DST + DST_EET, // Eastern European DST + DST_CAN, // Canada + DST_GB, // Great Britain and Eire + DST_RUM, // Rumania + DST_TUR, // Turkey + DST_AUSTALT, // Australia with 1986 shift +}; + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; + struct itimerval { struct timeval it_interval; @@ -24,9 +48,10 @@ struct itimerval // TODO: This should also define fd_set and select() -extern int getitimer(int, struct itimerval *); -extern int setitimer(int, const struct itimerval *, struct itimerval *); -extern int gettimeofday(struct timeval *, void *); +extern int getitimer(int which, struct itimerval *current_value); +extern int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value); +extern int gettimeofday(struct timeval *tv, struct timezone *tz); +// extern int settimeofday(const struct timeval *tv, const struct timezone *tz); //ifdef _BSD_SOURCE // select extern int utimes(const char *, const struct timeval [2]); diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h index 03e24ddc..c6cdc020 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h @@ -11,6 +11,8 @@ typedef unsigned int u_int; typedef struct stat t_fstat; +typedef unsigned long uid_t; +typedef unsigned long gid_t; typedef unsigned int id_t; typedef unsigned long pid_t; typedef unsigned long tid_t; diff --git a/Usermode/Libraries/libposix.so_src/include_exp/syslog.h b/Usermode/Libraries/libposix.so_src/include_exp/syslog.h index ae891b7f..d74e994d 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/syslog.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/syslog.h @@ -3,7 +3,7 @@ * - By John Hodge (thePowersGang) * * syslog.h - * - Centra Loggin + * - Central Logging */ #ifndef _LIBPOSIX__SYSLOG_H_ #define _LIBPOSIX__SYSLOG_H_ diff --git a/Usermode/Libraries/libposix.so_src/include_exp/termios.h b/Usermode/Libraries/libposix.so_src/include_exp/termios.h index a200f2c4..bb3cf884 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/termios.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/termios.h @@ -131,5 +131,27 @@ struct termios cc_t c_cc[NCCS]; }; +extern int tcgetattr(int fd, struct termios *termios_p); + +#define TCSANOW 0x01 +#define TCSADRAIN 0x02 +#define TCSAFLUSH 0x04 +extern int tcsetattr(int fd, int optional_actions, const struct termios *termios_p); + +// ioctl() calls for terminals +enum +{ + TIOCGWINSZ, + TIOCSWINSZ +}; + +struct winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; /* unused */ + unsigned short ws_ypixel; /* unused */ +}; + + #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h index ea107a9d..98623b6e 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -45,5 +45,41 @@ extern int execv(const char *b, char *v[]); extern int dup2(int oldfd, int newfd); +extern int chown(const char *path, uid_t owner, gid_t group); + +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00300 +#define S_IXUSR 00100 +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 +#define S_IRWXO 0007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 +extern int chmod(const char *path, mode_t mode); + +extern pid_t setsid(void); + +extern uid_t getuid(void); +extern uid_t geteuid(void); +extern pid_t getpid(void); + +// signal.h / sys/types.h +#define SIGWINCH 101 +#define SIGTSTP 102 +extern int kill(pid_t pid, int sig); + +extern int chdir(const char *dir); + +// Deprecated POSIX.1-2001 +#define PASS_MAX 63 +extern char *getpass(void); + #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h b/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h new file mode 100644 index 00000000..8593a994 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/utmpx.h @@ -0,0 +1,49 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * utmpx.h + * - User login records + */ +#ifndef _LIBPOSIX__UTMPX_H_ +#define _LIBPOSIX__UTMPX_H_ + +#include // struct timeval + +#define UTMPX_FILE "/Acess/var/utmpx" + +enum e_utmpx_type_vals +{ + EMPTY, //!< No information + BOOT_TIME, //!< Identifies time of system boot + OLD_TIME, //!< Old time when system time was changed + NEW_TIME, //!< New time when system time was changed + USER_PROCESS, //!< Any process + INIT_PROCESS, //!< Process spawned by init + LOGIN_PROCESS, //!< Session leader for a logged-in user + DEAD_PROCESS //!< Exited session leader +}; + +#define UT_USER_MAX 32 +#define UT_ID_MAX 8 +#define UT_LINE_MAX 32 + +struct utmpx +{ + char ut_user[UT_USER_MAX]; + char ut_id[UT_ID_MAX]; + char ut_line[UT_LINE_MAX]; + pid_t ut_pid; + short ut_type; + struct timeval ut_tv; +}; + +extern void endutxent(void); +extern struct utmpx *getutxent(void); +extern struct utmpx *getutxid(const struct utmpx *); +extern struct utmpx *getutxline(const struct utmpx *); +extern struct utmpx *pututxline(const struct utmpx *); +extern void setutxent(void); + +#endif + diff --git a/Usermode/Libraries/libposix.so_src/pwd.c b/Usermode/Libraries/libposix.so_src/pwd.c new file mode 100644 index 00000000..99c4f5d1 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/pwd.c @@ -0,0 +1,96 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * pwd.c + * - Password Structure + */ +#include +#include +#include + +// TODO: Parse something like '/Acess/Conf/Users' + +// === GLOBALS === +static const struct passwd gPwd_RootInfo = { + .pw_name = "root", + .pw_uid = 0, + .pw_gid = 0, + .pw_dir = "/Acess/Root", + .pw_shell = "/Acess/Bin/CLIShell", + .pw_passwd = "", +}; + +// === CODE === +struct passwd *getpwnam(const char *name) +{ + static struct passwd ret_struct; + static char ret_buf[64]; + struct passwd *ret_ptr; + errno = getpwnam_r(name, &ret_struct, ret_buf, sizeof(ret_buf), &ret_ptr); + return ret_ptr; +} + +struct passwd *getpwuid(uid_t uid) +{ + static struct passwd ret_struct; + static char ret_buf[64]; + struct passwd *ret_ptr; + errno = getpwuid_r(uid, &ret_struct, ret_buf, sizeof(ret_buf), &ret_ptr); + return ret_ptr; +} + +static int fill_pwd(const struct passwd *tpl, struct passwd *pwd, char *buf, size_t buflen) +{ + size_t ofs = 0; + #define _setstr(field) do { \ + if( ofs + strlen(tpl->field)+1 > buflen ) \ + return ERANGE; \ + pwd->field = buf + ofs; \ + strcpy(pwd->field, tpl->field); \ + } while(0) + _setstr(pw_name); + pwd->pw_uid = tpl->pw_uid; + pwd->pw_gid = tpl->pw_gid; + _setstr(pw_dir); + _setstr(pw_shell); + _setstr(pw_passwd); + return 0; +} + +int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) +{ + *result = NULL; + if( strcmp(name, "root") == 0 ) { + int ret = fill_pwd(&gPwd_RootInfo, pwd, buf, buflen); + if(ret) return ret; + *result = pwd; + } + return 0; +} + +int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) +{ + *result = NULL; + if( uid == 0 ) { + int ret = fill_pwd(&gPwd_RootInfo, pwd, buf, buflen); + if(ret) return ret; + *result = pwd; + } + return 0; +} + +void endpwent(void) +{ +} + +struct passwd *getpwent(void) +{ + return NULL; +} + +void setpwent(void) +{ + +} + diff --git a/Usermode/Libraries/libposix.so_src/sys_ioctl.c b/Usermode/Libraries/libposix.so_src/sys_ioctl.c new file mode 100644 index 00000000..56871bc1 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_ioctl.c @@ -0,0 +1,45 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys_ioctl.c + * - IOCtl hacks + */ +#include +#include +#include + +// === CODE === +int ioctl(int fd, int request, ...) +{ + if( fd < 0 ) { + errno = EBADF; + return -1; + } + + if( request < 0 ) { + errno = EINVAL; + return -1; + } + + // #1. Get device type (IOCtl 0) + int devtype = _SysIOCtl(fd, 0, NULL); + + switch(devtype) + { + // 0: Normal file (no ioctls we care about) + case 0: + // 1: Has the ident set of ioctls, nothing else + case 1: + return -1; + // TODO: Terminals + + // NFI + default: + return -1; + } + + return 0; +} + + diff --git a/Usermode/Libraries/libposix.so_src/sys_resource.c b/Usermode/Libraries/libposix.so_src/sys_resource.c new file mode 100644 index 00000000..caeddd79 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_resource.c @@ -0,0 +1,25 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys_resource.c + * - (XSI) Resource Operations + */ +#include +#include + +// === CODE === +int getrlimit(int resource, struct rlimit *rlim) +{ + _SysDebug("TODO: getrlimit(%i)", resource); + rlim->rlim_cur = 0; + rlim->rlim_max = 0; + return 0; +} + +int setrlimit(int resource, const struct rlimit *rlim) +{ + _SysDebug("TODO: setrlimit(%i,{%i,%i})", resource, rlim->rlim_cur, rlim->rlim_max); + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/sys_time.c b/Usermode/Libraries/libposix.so_src/sys_time.c new file mode 100644 index 00000000..3edde789 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_time.c @@ -0,0 +1,43 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys/time.h + * - Timing calls + */ +#include +#include + +// === CODE === +#if 0 +int getitimer(int which, struct itimerval *current_value) +{ + +} + +int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) +{ + +} +#endif + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + const int correction_2k_to_unix = 30*365*24*3600; + long long int ts = _SysTimestamp(); + if( tv ) + { + tv->tv_sec = ts / 1000 + correction_2k_to_unix; + tv->tv_usec = (ts % 1000) * 1000; + } + if( tz ) + { + // TODO: Determine timezone? + tz->tz_minuteswest = 0; + tz->tz_dsttime = 0; + } + return 0; +} + +// ifdef _BSD_SOURCE +//int settimeofday(const struct timeval *tv, const struct timezone *tz); diff --git a/Usermode/Libraries/libposix.so_src/syslog.c b/Usermode/Libraries/libposix.so_src/syslog.c new file mode 100644 index 00000000..4412340c --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/syslog.c @@ -0,0 +1,63 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * syslog.h + * - Central Logging + */ +#include +#include // vsnprintf +#include // free +#include // strdup +#include +#include + +// === GLOBALS === +char *gsSyslogPrefix = NULL; + int gSyslogOptions; + int gSyslogFacility; + int gSyslogMask = -1; + +// === CODE === +/* + * Close global logging handle + */ +void closelog(void) +{ +} + +void openlog(const char *name, int option, int facility) +{ + if( gsSyslogPrefix ) + free(gsSyslogPrefix); + gsSyslogPrefix = strdup(name); + gSyslogOptions = option; + gSyslogFacility = facility; + + if( option & LOG_NOWAIT ) + { + // Open the logging handle! + } +} + +extern int setlogmask(int mask) +{ + int ret = gSyslogMask; + gSyslogMask = mask; + return ret; +} + +extern void syslog(int priority, const char *str, ...) +{ + char staticbuf[512]; + va_list args; + va_start(args, str); + vsnprintf(staticbuf, sizeof(staticbuf), str, args); + va_end(args); + if( gSyslogOptions & (1 << priority) ) + { + // TODO: Proper syslog + _SysDebug("syslog(%i: %s) - %s", priority, gsSyslogPrefix, staticbuf); + } +} + diff --git a/Usermode/Libraries/libposix.so_src/termios.c b/Usermode/Libraries/libposix.so_src/termios.c new file mode 100644 index 00000000..0e8e3564 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/termios.c @@ -0,0 +1,43 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * termios.c + * - Terminal Control + */ +#include +#include +#include + +// === CODE === +int tcgetattr(int fd, struct termios *termios_p) +{ + if( fd == -1 ) { + errno = EBADF; + return -1; + } + // Double-check `fd` describes a terminal + + // Fill defaults + memset(termios_p, 0, sizeof(struct termios)); + + // Query kernel for other params + + return 0; +} + +int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) +{ + if( fd == -1 ) { + errno = EBADF; + return -1; + } + + if( !termios_p || (optional_actions & ~(7)) ) { + errno = EINVAL; + return -1; + } + + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 68c4e522..d8cbbf65 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include // === CODE === int unlink(const char *pathname) @@ -85,9 +87,92 @@ int execv(const char *b, char *v[]) return _SysExecVE(b, v, NULL); } +int dup(int oldfd) +{ + // NOTE: Acess's CopyFD doesn't cause offset sharing + // TODO: Check that -1 does cause a new allocation + return _SysCopyFD(oldfd, -1); +} + int dup2(int oldfd, int newfd) { // NOTE: Acess's CopyFD doesn't cause offset sharing return _SysCopyFD(oldfd, newfd); } + +/* + * Set session ID to PID + */ +pid_t setsid(void) +{ + // TODO: actual syscall for this + return _SysGetPID(); +} + +pid_t getpid(void) +{ + return _SysGetPID(); +} + +uid_t getuid(void) +{ + return _SysGetUID(); +} + +uid_t geteuid(void) +{ + // TODO: Impliment EUIDs in-kernel? + return _SysGetUID(); +} + +int kill(pid_t pid, int signal) +{ + // TODO: Need special handling? + return _SysKill(pid, signal); +} + +int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout) +{ + + if( timeout ) + { + long long int ltimeout = 0; + ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000; + int ret = _SysSelect(nfd, rfd, wfd, efd, <imeout, 0); + return ret; + } + else + { + return _SysSelect(nfd, rfd, wfd, efd, NULL, 0); + } +} + +int pipe(int pipefd[2]) +{ + pipefd[0] = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + pipefd[1] = _SysCopyFD(pipefd[0], -1); + _SysFDFlags(pipefd[1], OPENFLAG_READ|OPENFLAG_WRITE, OPENFLAG_WRITE); + return 0; +} + +int chdir(const char *dir) +{ + return _SysChdir(dir); +} + +int mkdir(const char *pathname, mode_t mode) +{ + _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode); + return -1; +} + +char *getpass(void) +{ + static char passbuf[PASS_MAX+1]; + fprintf(stderr, "Password: "); + fgets(passbuf, PASS_MAX+1, stdin); + fprintf(stderr, "\n"); + return passbuf; +} + diff --git a/Usermode/Libraries/libposix.so_src/utmpx.c b/Usermode/Libraries/libposix.so_src/utmpx.c new file mode 100644 index 00000000..ef63c921 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/utmpx.c @@ -0,0 +1,52 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * utmpx.c + * - User login records + */ +#include +#include + +/* + * Rewind UTMPX file pointer + */ +void setutxent(void) +{ +} + +/* + * Close UTMPX file + */ +void endutxent(void) +{ +} + +/* + * Read from current position in UTMPX file + */ +struct utmpx *getutxent(void) +{ + return NULL; +} + +/* + * Locate an entry in the UTMPX file for a given id + */ +struct utmpx *getutxid(const struct utmpx *utmpx __attribute__((unused))) +{ + return NULL; +} + +struct utmpx *getutxline(const struct utmpx *utmpx __attribute__((unused))) +{ + utmpx = NULL; + return NULL; +} + +struct utmpx *pututxline(const struct utmpx *utmpx __attribute__((unused))) +{ + utmpx = NULL; + return NULL; +} + diff --git a/Usermode/Libraries/libpsocket.so_src/socket.c b/Usermode/Libraries/libpsocket.so_src/socket.c index 613e82b7..a03a2bd7 100644 --- a/Usermode/Libraries/libpsocket.so_src/socket.c +++ b/Usermode/Libraries/libpsocket.so_src/socket.c @@ -227,3 +227,29 @@ int send(int sockfd, void *buffer, size_t length, int flags) return _SysWrite(sockfd, buffer, length); } + +int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len) +{ + return 0; +} + +int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len) +{ + return 0; +} + +int getsockname(int socket, struct sockaddr *addr, socklen_t *addrlen) +{ + return 0; +} + +int getpeername(int socket, struct sockaddr *addr, socklen_t *addrlen) +{ + return 0; +} + +int shutdown(int socket, int how) +{ + return 0; +} +