From: John Hodge Date: Sat, 23 Jan 2010 11:48:18 +0000 (+0800) Subject: Altered & Renamed LookupString, Added DrvUtil_SetIdent X-Git-Tag: rel0.06~312 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6ea2f6040da80c963882f6ccfe4bf21ff048eaff;p=tpg%2Facess2.git Altered & Renamed LookupString, Added DrvUtil_SetIdent - Both now check the user memory before using it --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 2c33bfce..3ef05eab 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1389 +BUILD_NUM = 1398 diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 0e66601a..76b7f1e8 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -318,7 +318,7 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) break; case TERM_MODE_FB: - case TERM_MODE_OPENGL: + //case TERM_MODE_: while(pos < Length) { while(term->InputRead == term->InputWrite) Threads_Yield(); @@ -922,8 +922,8 @@ void VT_int_ChangeMode(tVTerm *Term, int NewMode) free(Term->Text); Term->Buffer = calloc( Term->Width*Term->Height, sizeof(Uint32) ); break; - case TERM_MODE_OPENGL: - return; + //case TERM_MODE_OPENGL: + // return; } Term->Mode = NewMode; diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index d4df34bc..930e3238 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -293,6 +293,7 @@ extern Uint32 BigEndian32(Uint32 Val); * \name Strings * \{ */ +extern int sprintf(char *__s, const char *__format, ...); extern Uint strlen(const char *Str); extern char *strcpy(char *__dest, const char *__src); extern int strcmp(const char *__str1, const char *__str2); @@ -304,7 +305,8 @@ extern int strpos8(const char *str, Uint32 search); extern void itoa(char *buf, Uint num, int base, int minLength, char pad); extern int ReadUTF8(Uint8 *str, Uint32 *Val); extern int WriteUTF8(Uint8 *str, Uint32 Val); -extern int LookupString(char **Array, char *Needle); +extern int ModUtil_SetIdent(char *Dest, char *Value); +extern int ModUtil_LookupString(char **Array, char *Needle); extern Uint8 ByteSum(void *Ptr, int Size); /** * \} diff --git a/Kernel/include/tpl_drv_terminal.h b/Kernel/include/tpl_drv_terminal.h index fa90c865..907cc142 100644 --- a/Kernel/include/tpl_drv_terminal.h +++ b/Kernel/include/tpl_drv_terminal.h @@ -97,13 +97,15 @@ enum eTplTerminal_Modes { */ TERM_MODE_FB, + TERM_MODE_2DACCEL, + /** * \brief OpenGL 2D/3D * Writes to the terminal file will send 3D commands * Reads will return UTF-32 characters * \note May or may not stay in the spec */ - TERM_MODE_OPENGL, + TERM_MODE_3D, /** * \brief Number of terminal modes @@ -111,5 +113,17 @@ enum eTplTerminal_Modes { NUM_TERM_MODES }; +enum eTplTerminal_2D_Commands +{ + TERM_2DCMD_NOP, + + /** + * (Uint16 X, Y, W, H, Uint32 Data[]) + * \param X,Y Coordinates of Top-Left corner + * \param W,H Dimensions + * \param Data 32-bpp pixel data + */ + TERM_2DCMD_PUSH, +}; #endif diff --git a/Kernel/lib.c b/Kernel/lib.c index db014505..f99f58ac 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -55,6 +55,148 @@ void itoa(char *buf, Uint num, int base, int minLength, char pad) buf[i] = 0; } +#define PUTCH(c) do{if(pos==__maxlen)break;if(__s){__s[pos++]=(c);}else{pos++;}}while(0) +int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) +{ + char c, pad = ' '; + int minSize = 0; + char tmpBuf[34]; // For Integers + char *p = NULL; + int isLongLong = 0; + Uint64 val; + size_t pos = 0; + + while((c = *__format++) != 0) + { + // Non control character + if(c != '%') { PUTCH(c); continue; } + + c = *__format++; + + // Literal % + if(c == '%') { PUTCH('%'); continue; } + + // Pointer - Done first for debugging + if(c == 'p') { + Uint ptr = va_arg(args, Uint); + PUTCH('*'); PUTCH('0'); PUTCH('x'); + p = tmpBuf; + itoa(p, ptr, 16, BITS/4, '0'); + goto printString; + } + + // Get Argument + val = va_arg(args, Uint); + + // - Padding + if(c == '0') { + pad = '0'; + c = *__format++; + } + else + pad = ' '; + + // - Minimum length + minSize = 1; + if('1' <= c && c <= '9') + { + minSize = 0; + while('0' <= c && c <= '9') + { + minSize *= 10; + minSize += c - '0'; + c = *__format++; + } + } + + // - Default, Long or LongLong? + isLongLong = 0; + if(c == 'l') // Long is actually the default on x86 + { + c = *__format++; + if(c == 'l') { + #if BITS == 32 + val |= (Uint64)va_arg(args, Uint) << 32; + #endif + c = *__format++; + isLongLong = 1; + } + } + + // - Now get the format code + p = tmpBuf; + switch(c) + { + case 'd': + case 'i': + if( (isLongLong && val >> 63) || (!isLongLong && val >> 31) ) { + PUTCH('-'); + val = -val; + } + itoa(p, val, 10, minSize, pad); + goto printString; + case 'u': + itoa(p, val, 10, minSize, pad); + goto printString; + case 'x': + itoa(p, val, 16, minSize, pad); + goto printString; + case 'o': + itoa(p, val, 8, minSize, pad); + goto printString; + case 'b': + itoa(p, val, 2, minSize, pad); + goto printString; + + case 'B': //Boolean + if(val) p = "True"; + else p = "False"; + goto printString; + + // String - Null Terminated Array + case 's': + p = (char*)(Uint)val; + printString: + if(!p) p = "(null)"; + while(*p) PUTCH(*p++); + break; + + case 'C': // Non-Null Terminated Character Array + p = (char*)(Uint)val; + if(!p) goto printString; + while(minSize--) PUTCH(*p++); + break; + + // Single Character + case 'c': + default: + PUTCH( (Uint8)val ); + break; + } + } + + if(__s && pos != __maxlen) + __s[pos] = '\0'; + + + return pos; +} +#undef PUTCH + +/** + */ +int sprintf(char *__s, const char *__format, ...) +{ + va_list args; + int ret; + + va_start(args, __format); + ret = vsnprintf(__s, -1, __format, args); + va_end(args); + + return ret; +} + /** * \fn int tolower(int c) * \brief Converts a character to lower case @@ -125,6 +267,19 @@ char *strcpy(char *__str1, const char *__str2) return __str1; } +/** + * \fn char *strcpy(const char *__str1, const char *__str2) + * \brief Copy a string to a new location + */ +char *strncpy(char *__str1, const char *__str2, size_t max) +{ + while(*__str2 && max-- >= 1) + *__str1++ = *__str2++; + if(max) + *__str1 = '\0'; // Terminate String + return __str1; +} + /** * \fn int strcmp(const char *str1, const char *str2) * \brief Compare two strings return the difference between @@ -411,9 +566,10 @@ int CheckMem(void *Mem, int NumBytes) * \brief Search a string array for \a Needle * \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP */ -int LookupString(char **Array, char *Needle) +int ModUtil_LookupString(char **Array, char *Needle) { int i; + if( !CheckString(Needle) ) return -1; for( i = 0; Array[i]; i++ ) { if(strcmp(Array[i], Needle) == 0) return i; @@ -421,15 +577,23 @@ int LookupString(char **Array, char *Needle) return -1; } +int ModUtil_SetIdent(char *Dest, char *Value) +{ + if( !CheckMem(Dest, 32) ) return -1; + strncpy(Dest, Value, 32); + return 1; +} + EXPORT(strlen); EXPORT(strdup); EXPORT(strcmp); EXPORT(strncmp); EXPORT(strcpy); -//EXPORT(strncpy); +EXPORT(strncpy); EXPORT(timestamp); EXPORT(ReadUTF8); EXPORT(CheckMem); EXPORT(CheckString); -EXPORT(LookupString); +EXPORT(ModUtil_LookupString); +EXPORT(ModUtil_SetIdent); diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index c840bdde..3ebe89ad 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -116,6 +116,7 @@ tVFS_Node *FAT_InitDevice(char *Device, char **options) case FAT12: sFatType = "FAT12"; break; case FAT16: sFatType = "FAT16"; break; case FAT32: sFatType = "FAT32"; break; + default: sFatType = "UNKNOWN"; break; } if(iSize <= 2*1024) { sSize = "KiB"; diff --git a/Modules/ATA/mbr.c b/Modules/ATA/mbr.c index de02505c..45ade88a 100644 --- a/Modules/ATA/mbr.c +++ b/Modules/ATA/mbr.c @@ -34,8 +34,7 @@ void ATA_ParseMBR(int Disk) for( i = 0; i < 4; i ++ ) { if( mbr.Parts[i].SystemID == 0 ) continue; - if( - mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28 + if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28 || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48 ) { diff --git a/Modules/FDD/fdd.c b/Modules/FDD/fdd.c index 69d3a559..6b55f17b 100644 --- a/Modules/FDD/fdd.c +++ b/Modules/FDD/fdd.c @@ -277,23 +277,12 @@ int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data) { switch(ID) { - case DRV_IOCTL_TYPE: - return DRV_TYPE_DISK; + case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; + case DRV_IOCTL_IDENT: return ModUtil_SetIdent(Data, "FDD"); + case DRV_IOCTL_VERSION: return FDD_VERSION; + case DRV_IOCTL_LOOKUP: return ModUtil_LookupString((char**)casIOCTLS, Data); - case DRV_IOCTL_IDENT: - if(!CheckMem(Data, 4)) return -1; - memcpy(Data, "FDD\0", 4); - return 1; - - case DRV_IOCTL_VERSION: - return FDD_VERSION; - - case DRV_IOCTL_LOOKUP: - if(!CheckString(Data)) return -1; - return LookupString((char**)casIOCTLS, Data); - - case DISK_IOCTL_GETBLOCKSIZE: - return 512; + case DISK_IOCTL_GETBLOCKSIZE: return 512; default: return 0; diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 5f34d9a1..01e65f90 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -4,6 +4,7 @@ */ #define DEBUG 0 #define VERSION VER2(0,10) +#define IDENT IPStack #include "ipstack.h" #include "link.h" #include @@ -30,7 +31,7 @@ tVFS_Node *IPStack_FindDir(tVFS_Node *Node, char *Name); tAdapter *IPStack_GetAdapter(char *Path); // === GLOBALS === -MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL); +MODULE_DEFINE(0, VERSION, IDENT, IPStack_Install, NULL, NULL); tDevFS_Driver gIP_DriverInfo = { NULL, "ip", { @@ -180,8 +181,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) return DRV_TYPE_MISC; case DRV_IOCTL_IDENT: - if( !CheckMem( Data, 4 ) ) LEAVE_RET('i', -1); - memcpy(Data, "IP\0\0", 4); + tmp = ModUtil_SetIdent(Data, STR(IDENT)); LEAVE('i', 1); return 1; @@ -190,9 +190,7 @@ int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data) return VERSION; case DRV_IOCTL_LOOKUP: - if( !CheckString( Data ) ) LEAVE_RET('i', -1); - LOG("Lookup '%s'", Data); - tmp = LookupString( (char**)casIOCtls_Root, (char*)Data ); + tmp = ModUtil_LookupString( (char**)casIOCtls_Root, (char*)Data ); LEAVE('i', tmp); return tmp; @@ -236,8 +234,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data) return DRV_TYPE_MISC; case DRV_IOCTL_IDENT: - if( !CheckMem( Data, 4 ) ) LEAVE_RET('i', -1); - memcpy(Data, "IP\0\0", 4); + tmp = ModUtil_SetIdent(Data, STR(IDENT)); LEAVE('i', 1); return 1; @@ -246,9 +243,7 @@ int IPStack_IOCtl(tVFS_Node *Node, int ID, void *Data) return VERSION; case DRV_IOCTL_LOOKUP: - if( !CheckString( Data ) ) LEAVE_RET('i', -1); - LOG("Lookup '%s'", Data); - tmp = LookupString( (char**)casIOCtls_Iface, (char*)Data ); + tmp = ModUtil_LookupString( (char**)casIOCtls_Iface, (char*)Data ); LEAVE('i', tmp); return tmp; diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 06275590..ae6d5748 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -4,9 +4,13 @@ _CPPFLAGS := $(CPPFLAGS) --include ../../Makefile.cfg +CFGFILES = +CFGFILES += $(shell test -f ../../Makefile.cfg && echo ../../Makefile.cfg) +CFGFILES += $(shell test -f ../Makefile.cfg && echo ../Makefile.cfg) +CFGFILES += $(shell test -f Makefile.cfg && echo Makefile.cfg) +-include $(CFGFILES) -CPPFLAGS = -I../../Kernel/include -I../../Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS) +CPPFLAGS = -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS) CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) OBJ := $(addsuffix .$(ARCH),$(OBJ)) @@ -28,12 +32,12 @@ install: $(BIN) $(BIN): $(OBJ) @echo --- $(LD) -o $@ - @$(LD) -T ../link.ld -shared -nostdlib -o $@ $(OBJ) + @$(LD) -T $(ACESSDIR)/Modules/link.ld -shared -nostdlib -o $@ $(OBJ) @$(OBJDUMP) -d $(BIN) > $(BIN).dsm @echo --- $(LD) -o $(KOBJ) @$(CC) -Wl,-r -nostdlib -o $(KOBJ) $(OBJ) -%.o.$(ARCH): %.c Makefile ../Makefile.tpl ../../Makefile.cfg +%.o.$(ARCH): %.c Makefile ../Makefile.tpl $(CFGFILES) @echo --- $(CC) -o $@ @$(CC) $(CFLAGS) -o $@ -c $< @$(CC) -M $(CPPFLAGS) -MT $@ -o $*.d.$(ARCH) $< diff --git a/Modules/NE2000/ne2000.c b/Modules/NE2000/ne2000.c index 99abbb39..76e4379f 100644 --- a/Modules/NE2000/ne2000.c +++ b/Modules/NE2000/ne2000.c @@ -257,24 +257,16 @@ int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data) return DRV_TYPE_NETWORK; case DRV_IOCTL_IDENT: - if(!CheckMem(Data, 4)) { - LEAVE('i', -1); - return -1; - } - memcpy(Data, "NE2K", 4); - LEAVE('i', 1); - return 1; + tmp = ModUtil_SetIdent(Data, "Ne2k"); + LEAVE('i', tmp); + return tmp; case DRV_IOCTL_VERSION: LEAVE('x', VERSION); return VERSION; case DRV_IOCTL_LOOKUP: - if( !CheckString(Data) ) { - LEAVE('i', -1); - return -1; - } - tmp = LookupString( (char**)casIOCtls, Data ); + tmp = ModUtil_LookupString( (char**)casIOCtls, Data ); LEAVE('i', tmp); return tmp; }