From: John Hodge Date: Wed, 30 Sep 2009 12:39:55 +0000 (+0800) Subject: Immense cleanup of libc, implemening login program. Slight changes to ACL handling... X-Git-Tag: rel0.06~406 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=91dd38c34820c03311738439125675d59bf9e3f1;p=tpg%2Facess2.git Immense cleanup of libc, implemening login program. Slight changes to ACL handling and FAT driver --- diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index d2d4e4bf..3d3fee17 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -119,7 +119,7 @@ void MM_PageFault(Uint Addr, Uint ErrorCode, tRegs *Regs) gaPageTable[Addr>>12] &= PF_USER; gaPageTable[Addr>>12] |= paddr|PF_PRESENT|PF_WRITE; } - //LOG("Duplicated page at %p to 0x%x", Addr&~0xFFF, gaPageTable[Addr>>12]); + INVLPG( Addr & ~0xFFF ); //LEAVE('-') return; diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index 32caf1be..4ba3f452 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -97,6 +97,7 @@ extern tVFS_ACL gVFS_ACL_EveryoneRO; // === FUNCTIONS === extern int VFS_AddDriver(tVFS_Driver *Info); extern tVFS_Driver *VFS_GetFSByName(char *Name); +extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group); // --- Node Cache -- extern int Inode_GetHandle(); diff --git a/Kernel/system.c b/Kernel/system.c index a736c46c..b3134836 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -19,7 +19,7 @@ void System_ExecuteScript(); // === GLOBALS === char *gsInitPath = "/Acess/Bin/init"; -char *gsConfigScript = "/Acess/BootConf.cfg"; +char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; // === CODE === void System_Init(char *ArgString) diff --git a/Kernel/vfs/acls.c b/Kernel/vfs/acls.c index 9c81c387..e512b361 100644 --- a/Kernel/vfs/acls.c +++ b/Kernel/vfs/acls.c @@ -99,3 +99,39 @@ int VFS_GetACL(int FD, tVFS_ACL *Dest) Dest->Perms = 0; return 0; } + +/** + * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group) + * \brief Converts UNIX permissions to three Acess ACL entries + */ +tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group) +{ + tVFS_ACL *ret = malloc(sizeof(tVFS_ACL)*3); + + // Error Check + if(!ret) return NULL; + + // Owner + ret[0].Group = 0; ret[0].ID = Owner; + ret[0].Inv = 0; ret[0].Perms = 0; + if(Mode & 0400) ret[0].Perms |= VFS_PERM_READ; + if(Mode & 0200) ret[0].Perms |= VFS_PERM_WRITE; + if(Mode & 0100) ret[0].Perms |= VFS_PERM_EXECUTE; + + // Group + ret[1].Group = 1; ret[1].ID = Group; + ret[1].Inv = 0; ret[1].Perms = 0; + if(Mode & 0040) ret[1].Perms |= VFS_PERM_READ; + if(Mode & 0020) ret[1].Perms |= VFS_PERM_WRITE; + if(Mode & 0010) ret[1].Perms |= VFS_PERM_EXECUTE; + + // Global + ret[2].Group = 1; ret[2].ID = Group; + ret[2].Inv = 0; ret[2].Perms = 0; + if(Mode & 0004) ret[2].Perms |= VFS_PERM_READ; + if(Mode & 0002) ret[2].Perms |= VFS_PERM_WRITE; + if(Mode & 0001) ret[2].Perms |= VFS_PERM_EXECUTE; + + // Return buffer + return ret; +} diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index bfae4058..01c90c24 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -1,28 +1,15 @@ /* - * Acess2 + * Acess 2 * FAT12/16/32 Driver Version (Incl LFN) */ -//INCLUDES +#define DEBUG 0 #include #include #include #include "fs_fat.h" -#define DEBUG 0 #define VERBOSE 1 -#if DEBUG -# define DEBUGS(v...) Log(v) -#else -# define DEBUGS(v...) -# undef ENTER -# undef LOG -# undef LEAVE -# define ENTER(...) -# define LOG(...) -# define LEAVE(...) -#endif - #define CACHE_FAT 1 //!< Caches the FAT in memory #define USE_LFN 1 //!< Enables the use of Long File Names @@ -213,16 +200,13 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) fat_cache[giFAT_PartCount][i] = buf[i&127]; } } - DEBUGS(" FAT_InitDisk: FAT Fully Cached\n"); + LOG("FAT Fully Cached"); } #endif /*CACHE_FAT*/ //Initalise inode cache for FAT gFAT_Disks[giFAT_PartCount].inodeHandle = Inode_GetHandle(); - - #if DEBUG - Log(" FAT_InitDisk: Inode Cache handle is %i\n", gFAT_Disks[giFAT_PartCount].inodeHandle); - #endif + LOG("Inode Cache handle is %i", gFAT_Disks[giFAT_PartCount].inodeHandle); // == VFS Interface node = &gFAT_Disks[giFAT_PartCount].rootNode; @@ -292,9 +276,7 @@ static Uint32 FAT_int_GetFatValue(int handle, Uint32 cluster) */ static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Buffer) { - #if DEBUG ENTER("iHandle xCluster iLength pBuffer", Handle, Cluster, Length, Buffer); - #endif VFS_ReadAt( gFAT_Disks[Handle].fileHandle, (gFAT_Disks[Handle].firstDataSect + (Cluster-2)*gFAT_Disks[Handle].bootsect.spc ) @@ -302,9 +284,7 @@ static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Bu Length, Buffer ); - #if DEBUG LEAVE('-'); - #endif } /** diff --git a/Usermode/Applications/init_src/main.c b/Usermode/Applications/init_src/main.c index 2a4d6680..8787f39c 100644 --- a/Usermode/Applications/init_src/main.c +++ b/Usermode/Applications/init_src/main.c @@ -6,7 +6,7 @@ // === CONSTANTS === #define NULL ((void*)0) #define DEFAULT_TERMINAL "/Devices/VTerm/0" -#define DEFAULT_SHELL "/Acess/CLIShell" +#define DEFAULT_SHELL "/Acess/SBin/login" // === CODE === /** diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 293f783c..fd186a9d 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -13,7 +13,7 @@ CFLAGS = -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS) ASFLAGS = -felf LDFLAGS = -x -shared -soname libc.so.1 -Map map.txt -e SoMain -L$(ACESSDIR)/Usermode/Libraries -lacess -OBJ_LIBC = heap.o stdlib.o stub.o env.o fileIO.o signals.o +OBJ_LIBC = heap.o stdlib.o stub.o env.o fileIO.o signals.o string.o BIN = ../libc.so.1 .PHONY: all clean diff --git a/Usermode/Libraries/libc.so_src/fileIO.c b/Usermode/Libraries/libc.so_src/fileIO.c index be6f80b2..c1a47fff 100644 --- a/Usermode/Libraries/libc.so_src/fileIO.c +++ b/Usermode/Libraries/libc.so_src/fileIO.c @@ -5,23 +5,31 @@ AcessOS Basic C Library #include #include #include +#include +#include "lib.h" #include "stdio_int.h" #define DEBUG_BUILD 0 // === CONSTANTS === +#define _stdin 0 +#define _stdout 1 // === PROTOTYPES === +EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad); struct sFILE *get_file_struct(); // === GLOBALS === struct sFILE _iob[STDIO_MAX_STREAMS]; // IO Buffer +struct sFILE *stdin = &_iob[0]; // Standard Input +struct sFILE *stdout = &_iob[1]; // Standard Output +struct sFILE *stderr = &_iob[2]; // Standard Error // === CODE === /** * \fn FILE *freopen(FILE *fp, char *file, char *mode) */ -FILE *freopen(FILE *fp, char *file, char *mode) +EXPORT FILE *freopen(FILE *fp, char *file, char *mode) { int openFlags = 0; int i; @@ -90,7 +98,7 @@ FILE *freopen(FILE *fp, char *file, char *mode) \param file String - Filename to open \param mode Mode to open in */ -FILE *fopen(char *file, char *mode) +EXPORT FILE *fopen(char *file, char *mode) { FILE *retFile; @@ -103,42 +111,36 @@ FILE *fopen(char *file, char *mode) return freopen(retFile, file, mode); } -void fclose(FILE *fp) +EXPORT void fclose(FILE *fp) { close(fp->FD); free(fp); } -void fflush(FILE *fp) +EXPORT void fflush(FILE *fp) { ///\todo Implement } /** - * \fn int fprintf(FILE *fp, const char *format, ...) - * \brief Print a formatted string to a stream + * \fn int fprintfv(FILE *fp, const char *format, va_list args) + * \brief Print to a file from a variable argument list */ -int fprintf(FILE *fp, const char *format, ...) +EXPORT int fprintfv(FILE *fp, const char *format, va_list args) { + va_list tmpList = args; int size; char *buf; - va_list args; - + if(!fp || !format) return -1; - // Get Size - va_start(args, format); - size = ssprintfv((char*)format, args); - va_end(args); + size = ssprintfv((char*)format, tmpList); - // Allocate buffer buf = (char*)malloc(size+1); buf[size] = '\0'; // Print - va_start(args, format); sprintfv(buf, (char*)format, args); - va_end(args); // Write to stream write(fp->FD, size+1, buf); @@ -150,6 +152,57 @@ int fprintf(FILE *fp, const char *format, ...) return size; } +/** + * \fn int fprintf(FILE *fp, const char *format, ...) + * \brief Print a formatted string to a stream + */ +EXPORT int fprintf(FILE *fp, const char *format, ...) +{ + va_list args; + int ret; + + // Get Size + va_start(args, format); + ret = fprintfv(fp, (char*)format, args); + va_end(args); + + return ret; +} + +/** + */ +EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp) +{ + int ret; + if(!fp || !fp->FD) return -1; + + ret = write(fp->FD, size*num, ptr); + + return ret; +} + +/** + * \fn EXPORT int fputc(int c, FILE *fp) + * \brief Write a single character to the stream + */ +EXPORT int fputc(int c, FILE *fp) +{ + if(!fp || !fp->FD) return -1; + return write(fp->FD, 1, &c); +} + +/** + * \fn EXPORT int fgetc(FILE *fp) + * \brief Read a character from the stream + */ +EXPORT int fgetc(FILE *fp) +{ + int ret = 0; + if(!fp) return -1; + if(read(fp->FD, 1, &ret) == -1) return -1; + return ret; +} + // --- INTERNAL --- /** * \fn FILE *get_file_struct() @@ -164,3 +217,287 @@ FILE *get_file_struct() } return NULL; } + +EXPORT int putchar(int ch) +{ + return write(_stdout, 1, (char*)&ch); +} + +EXPORT int puts(const char *str) +{ + int len; + + if(!str) return 0; + len = strlen(str); + + len = write(_stdout, len, (char*)str); + write(_stdout, 1, "\n"); + return len; +} + +//sprintfv +/** + \fn EXPORT void sprintfv(char *buf, const char *format, va_list args) + \brief Prints a formatted string to a buffer + \param buf Pointer - Destination Buffer + \param format String - Format String + \param args VarArgs List - Arguments +*/ +EXPORT void sprintfv(char *buf, const char *format, va_list args) +{ + char tmp[33]; + int c, arg, minSize; + int pos = 0; + char *p; + char pad; + + tmp[32] = '\0'; + + while((c = *format++) != 0) + { + //SysDebug("c = '%c'\n", c); + if (c != '%') { + buf[pos++] = c; + continue; + } + + c = *format++; + if(c == '%') { + buf[pos++] = '%'; + continue; + } + + // Padding + if(c == '0') { + pad = '0'; + c = *format++; + } else + pad = ' '; + minSize = 0; + if('1' <= c && c <= '9') + { + while('0' <= c && c <= '9') + { + minSize *= 10; + minSize += c - '0'; + c = *format++; + } + } + + p = tmp; + + // Get Argument + arg = va_arg(args, int); + // Get Type + switch (c) { + case 'd': + case 'i': + if(arg < 0) { + buf[pos++] = '-'; + arg = -arg; + } + itoa(tmp, arg, 10, minSize, pad); + goto sprintf_puts; + // break; + case 'u': + itoa(tmp, arg, 10, minSize, pad); + goto sprintf_puts; + // break; + case 'x': + itoa(tmp, arg, 16, minSize, pad); + goto sprintf_puts; + // break; + case 'o': + itoa(tmp, arg, 8, minSize, pad); + goto sprintf_puts; + // break; + case 'b': + itoa(tmp, arg, 2, minSize, pad); + goto sprintf_puts; + // break; + + case 's': + p = (void*)arg; + sprintf_puts: + if(!p) p = "(null)"; + while(*p) buf[pos++] = *p++; + break; + + default: + buf[pos++] = arg; + break; + } + } + buf[pos++] = '\0'; +} +/* +ssprintfv +- Size, Stream, Print Formated, Variable Argument List +*/ +/** + \fn EXPORT int ssprintfv(char *format, va_list args) + \brief Gets the total character count from a formatted string + \param format String - Format String + \param args VarArgs - Argument List +*/ +EXPORT int ssprintfv(char *format, va_list args) +{ + char tmp[33]; + int c, arg, minSize; + int len = 0; + char *p; + char pad; + + tmp[32] = '\0'; + + while((c = *format++) != 0) + { + if (c != '%') { + len++; + continue; + } + + c = *format++; + + // Literal '%' + if(c == '%') { + len++; + continue; + } + + // Padding + if(c == '0') { + pad = '0'; + c = *format++; + } else + pad = ' '; + minSize = 0; + if('1' <= c && c <= '9') + { + while('0' <= c && c <= '9') + { + minSize *= 10; + minSize += c - '0'; + c = *format++; + } + } + + p = tmp; + arg = va_arg(args, int); + switch (c) { + case 'd': + case 'i': + if(arg < 0) { + len ++; + arg = -arg; + } + itoa(tmp, arg, 10, minSize, pad); + goto sprintf_puts; + case 'u': + itoa(tmp, arg, 10, minSize, pad); + goto sprintf_puts; + case 'x': + itoa(tmp, arg, 16, minSize, pad); + goto sprintf_puts; + case 'o': + itoa(tmp, arg, 8, minSize, pad); + p = tmp; + goto sprintf_puts; + case 'b': + itoa(tmp, arg, 2, minSize, pad); + goto sprintf_puts; + + case 's': + p = (char*)arg; + sprintf_puts: + if(!p) p = "(null)"; + while(*p) len++, p++; + break; + + default: + len ++; + break; + } + } + return len; +} + +const char cUCDIGITS[] = "0123456789ABCDEF"; +/** + * \fn static void itoa(char *buf, unsigned long num, int base, int minLength, char pad) + * \brief Convert an integer into a character string + */ +EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad) +{ + char tmpBuf[32]; + int pos=0, i; + + if(!buf) return; + if(base > 16) { + buf[0] = 0; + return; + } + + while(num > base-1) { + tmpBuf[pos] = cUCDIGITS[ num % base ]; + num = (long) num / base; //Shift {number} right 1 digit + pos++; + } + + tmpBuf[pos++] = cUCDIGITS[ num % base ]; //Last digit of {number} + i = 0; + minLength -= pos; + while(minLength-- > 0) buf[i++] = pad; + while(pos-- > 0) buf[i++] = tmpBuf[pos]; //Reverse the order of characters + buf[i] = 0; +} + +/** + * \fn EXPORT int printf(const char *format, ...) + * \brief Print a string to stdout + */ +EXPORT int printf(const char *format, ...) +{ + #if 0 + int size; + char *buf; + va_list args; + + va_start(args, format); + size = ssprintfv((char*)format, args); + va_end(args); + + buf = (char*)malloc(size+1); + buf[size] = '\0'; + + va_start(args, format); + sprintfv(buf, (char*)format, args); + va_end(args); + + + write(_stdout, size+1, buf); + + free(buf); + return size; + #endif + + int ret; + va_list args; + va_start(args, format); + ret = fprintfv(stdout, (char*)format, args); + va_end(args); + return ret; +} + +/** + * \fn EXPORT int sprintf(const char *buf, char *format, ...) + * \brief Print a formatted string to a buffer + */ +EXPORT int sprintf(char *buf, const char *format, ...) +{ + va_list args; + va_start(args, format); + sprintfv((char*)buf, (char*)format, args); + va_end(args); + return 1; +} diff --git a/Usermode/Libraries/libc.so_src/stdlib.c b/Usermode/Libraries/libc.so_src/stdlib.c index 44dc55fa..f5acadbd 100644 --- a/Usermode/Libraries/libc.so_src/stdlib.c +++ b/Usermode/Libraries/libc.so_src/stdlib.c @@ -1,260 +1,33 @@ /* -AcessOS Basic C Library - -stdlib.c -*/ + * AcessOS Basic C Library + * stdlib.c + */ +/** + * \todo Move half of these to stdio + */ #include #include +#include #include "lib.h" -int _stdout = 1; -int _stdin = 2; +#define _stdout 1 +#define _stdin 0 + +// === IMPORTS === +extern int fprintfv(FILE *fp, const char *format, va_list args); -EXPORT int puts(const char *str); -EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad); +// === PROTOTYPES === EXPORT int atoi(const char *str); -EXPORT int puts(const char *str); -EXPORT int ssprintfv(char *format, va_list args); -EXPORT void sprintfv(char *buf, char *format, va_list args); -EXPORT int printf(const char *format, ...); -EXPORT int strlen(const char *str); -EXPORT int strcmp(char *str1, char *str2); -EXPORT int strncmp(char *str1, char *str2, size_t len); -EXPORT char *strcpy(char *dst, const char *src); +EXPORT void exit(int status); // === CODE === -EXPORT int putchar(int ch) -{ - return write(_stdout, 1, (char*)&ch); -} - -EXPORT int puts(const char *str) -{ - int len; - - if(!str) return 0; - len = strlen(str); - - len = write(_stdout, len, (char*)str); - write(_stdout, 1, "\n"); - return len; -} - -//sprintfv /** - \fn EXPORT void sprintfv(char *buf, char *format, va_list args) - \brief Prints a formatted string to a buffer - \param buf Pointer - Destination Buffer - \param format String - Format String - \param args VarArgs List - Arguments -*/ -EXPORT void sprintfv(char *buf, char *format, va_list args) -{ - char tmp[33]; - int c, arg, minSize; - int pos = 0; - char *p; - char pad; - - tmp[32] = '\0'; - - while((c = *format++) != 0) - { - //SysDebug("c = '%c'\n", c); - if (c != '%') { - buf[pos++] = c; - continue; - } - - c = *format++; - if(c == '%') { - buf[pos++] = '%'; - continue; - } - - // Padding - if(c == '0') { - pad = '0'; - c = *format++; - } else - pad = ' '; - minSize = 0; - if('1' <= c && c <= '9') - { - while('0' <= c && c <= '9') - { - minSize *= 10; - minSize += c - '0'; - c = *format++; - } - } - - p = tmp; - - // Get Argument - arg = va_arg(args, int); - // Get Type - switch (c) { - case 'd': - case 'i': - if(arg < 0) { - buf[pos++] = '-'; - arg = -arg; - } - itoa(tmp, arg, 10, minSize, pad); - goto sprintf_puts; - // break; - case 'u': - itoa(tmp, arg, 10, minSize, pad); - goto sprintf_puts; - // break; - case 'x': - itoa(tmp, arg, 16, minSize, pad); - goto sprintf_puts; - // break; - case 'o': - itoa(tmp, arg, 8, minSize, pad); - goto sprintf_puts; - // break; - case 'b': - itoa(tmp, arg, 2, minSize, pad); - goto sprintf_puts; - // break; - - case 's': - p = (void*)arg; - sprintf_puts: - if(!p) p = "(null)"; - while(*p) buf[pos++] = *p++; - break; - - default: - buf[pos++] = arg; - break; - } - } - buf[pos++] = '\0'; -} -/* -ssprintfv -- Size, Stream, Print Formated, Variable Argument List -*/ -/** - \fn EXPORT int ssprintfv(char *format, va_list args) - \brief Gets the total character count from a formatted string - \param format String - Format String - \param args VarArgs - Argument List -*/ -EXPORT int ssprintfv(char *format, va_list args) -{ - char tmp[33]; - int c, arg, minSize; - int len = 0; - char *p; - char pad; - - tmp[32] = '\0'; - - while((c = *format++) != 0) - { - if (c != '%') { - len++; - continue; - } - - c = *format++; - - // Literal '%' - if(c == '%') { - len++; - continue; - } - - // Padding - if(c == '0') { - pad = '0'; - c = *format++; - } else - pad = ' '; - minSize = 0; - if('1' <= c && c <= '9') - { - while('0' <= c && c <= '9') - { - minSize *= 10; - minSize += c - '0'; - c = *format++; - } - } - - p = tmp; - arg = va_arg(args, int); - switch (c) { - case 'd': - case 'i': - if(arg < 0) { - len ++; - arg = -arg; - } - itoa(tmp, arg, 10, minSize, pad); - goto sprintf_puts; - case 'u': - itoa(tmp, arg, 10, minSize, pad); - goto sprintf_puts; - case 'x': - itoa(tmp, arg, 16, minSize, pad); - goto sprintf_puts; - case 'o': - itoa(tmp, arg, 8, minSize, pad); - p = tmp; - goto sprintf_puts; - case 'b': - itoa(tmp, arg, 2, minSize, pad); - goto sprintf_puts; - - case 's': - p = (char*)arg; - sprintf_puts: - if(!p) p = "(null)"; - while(*p) len++, p++; - break; - - default: - len ++; - break; - } - } - return len; -} - -const char cUCDIGITS[] = "0123456789ABCDEF"; -/** - * \fn static void itoa(char *buf, unsigned long num, int base, int minLength, char pad) - * \brief Convert an integer into a character string + * \fn EXPORT void exit(int status) + * \brief Exit */ -EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad) +EXPORT void exit(int status) { - char tmpBuf[32]; - int pos=0, i; - - if(!buf) return; - if(base > 16) { - buf[0] = 0; - return; - } - - while(num > base-1) { - tmpBuf[pos] = cUCDIGITS[ num % base ]; - num = (long) num / base; //Shift {number} right 1 digit - pos++; - } - - tmpBuf[pos++] = cUCDIGITS[ num % base ]; //Last digit of {number} - i = 0; - minLength -= pos; - while(minLength-- > 0) buf[i++] = pad; - while(pos-- > 0) buf[i++] = tmpBuf[pos]; //Reverse the order of characters - buf[i] = 0; + _exit(status); } /** @@ -318,92 +91,3 @@ EXPORT int atoi(const char *str) if(neg) ret = -ret; return ret; } - -//printf -EXPORT int printf(const char *format, ...) -{ - int size; - char *buf; - va_list args; - - va_start(args, format); - size = ssprintfv((char*)format, args); - va_end(args); - - buf = (char*)malloc(size+1); - buf[size] = '\0'; - - va_start(args, format); - sprintfv(buf, (char*)format, args); - va_end(args); - - - write(_stdout, size+1, buf); - - free(buf); - return size; -} - -EXPORT int sprintf(const char *buf, char *format, ...) -{ - va_list args; - va_start(args, format); - sprintfv((char*)buf, (char*)format, args); - va_end(args); - return 1; -} - - -//MEMORY -EXPORT int strcmp(char *s1, char *s2) -{ - while(*s1 == *s2 && *s1 != '\0' && *s2 != '\0') { - s1++; s2++; - } - return (int)*s1 - (int)*s2; -} -EXPORT char *strcpy(char *dst, const char *src) -{ - char *_dst = dst; - while(*src) { - *dst = *src; - src++; dst++; - } - *dst = '\0'; - return _dst; -} -EXPORT int strlen(const char *str) -{ - int retval; - for(retval = 0; *str != '\0'; str++) - retval++; - return retval; -} - -EXPORT int strncmp(char *s1, char *s2, size_t len) -{ - while(--len && *s1 == *s2 && *s1 != '\0' && *s2 != '\0') { - s1++; s2++; - } - return (int)*s1 - (int)*s2; -} - -EXPORT void *memcpy(void *dest, void *src, unsigned int count) -{ - char *sp = (char *)src; - char *dp = (char *)dest; - for(;count--;) *dp++ = *sp++; - return dest; -} - -EXPORT void *memmove(void *dest, void *src, unsigned int count) -{ - char *sp = (char *)src; - char *dp = (char *)dest; - // Check if corruption will happen - if( (unsigned int)dest > (unsigned int)src && (unsigned int)dest < (unsigned int)src+count ) - for(;count--;) dp[count] = sp[count]; - else - for(;count--;) *dp++ = *sp++; - return dest; -} diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index 05adb8eb..acb36539 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -1,8 +1,10 @@ /* -AcessOS Basic C Library -*/ + * AcessOS Basic C Library + */ +#include "stdio_int.h" extern char **_envp; +extern struct sFILE _iob[]; /** * \fn int SoMain() @@ -17,5 +19,10 @@ int SoMain(unsigned int BaseAddress, int argc, char **argv, char **envp) // Init for env.c _envp = envp; + // Init FileIO Pointers + _iob[0].FD = 0; _iob[0].Flags = FILE_FLAG_MODE_READ; + _iob[1].FD = 1; _iob[1].Flags = FILE_FLAG_MODE_WRITE; + _iob[2].FD = 2; _iob[2].Flags = FILE_FLAG_MODE_WRITE; + return 1; } diff --git a/Usermode/include/acess/sys.h b/Usermode/include/acess/sys.h index 7fec475f..707e5bb4 100644 --- a/Usermode/include/acess/sys.h +++ b/Usermode/include/acess/sys.h @@ -11,9 +11,11 @@ #define OPENFLAG_READ 0x02 #define OPENFLAG_WRITE 0x04 #define OPENFLAG_NOLINK 0x40 -#define SEEK_SET 1 -#define SEEK_CUR 0 -#define SEEK_END -1 +#ifndef SEEK_CUR +# define SEEK_SET 1 +# define SEEK_CUR 0 +# define SEEK_END -1 +#endif #define CLONE_VM 0x10 #define FILEFLAG_DIRECTORY 0x10 #define FILEFLAG_SYMLINK 0x20 @@ -51,11 +53,14 @@ typedef struct s_sysACL t_sysACL; // === FUNCTIONS === void _SysDebug(char *str, ...); // --- Proc --- +void _exit(int status) __attribute__((noreturn)); void sleep(); void wait(int miliseconds); int waittid(int id, int *status); int clone(int flags, void *stack); int execve(char *path, char **argv, char **envp); +void setuid(int id); +void setgid(int id); // --- VFS --- int chdir(char *dir); int open(char *path, int flags); diff --git a/Usermode/include/stdio.h b/Usermode/include/stdio.h index b8e70f95..2d7f31eb 100644 --- a/Usermode/include/stdio.h +++ b/Usermode/include/stdio.h @@ -8,16 +8,25 @@ typedef struct sFILE FILE; extern int printf(const char *format, ...); -extern void sprintfv(char *buf, char *format, va_list args); +extern void sprintfv(char *buf, const char *format, va_list args); extern int ssprintfv(char *format, va_list args); -extern int sprintf(char *buf, char *format, ...); +extern int sprintf(char *buf, const char *format, ...); extern FILE *fopen(char *file, char *mode); extern FILE *freopen(FILE *fp, char *file, char *mode); extern void fclose(FILE *fp); extern void fflush(FILE *fp); -extern int fprintf(FILE *fp, const char *format, ...); +extern size_t fread(void *buf, size_t size, size_t n, FILE *fp); +extern size_t fwrite(void *buf, size_t size, size_t n, FILE *fp); +extern int fgetc(FILE *fp); +extern int fputc(int ch, FILE *fp); + +extern int fprintf(FILE *fp, const char *format, ...); + +extern FILE *stdin; +extern FILE *stdout; +extern FILE *stderr; #endif diff --git a/Usermode/include/stdlib.h b/Usermode/include/stdlib.h index 87744271..6f745f16 100644 --- a/Usermode/include/stdlib.h +++ b/Usermode/include/stdlib.h @@ -23,9 +23,7 @@ typedef unsigned int size_t; // --- StdLib --- extern int atoi(const char *ptr); - -extern void *memcpy(void *dest, void *src, size_t count); -extern void *memmove(void *dest, void *src, size_t count); +extern void exit(int status) __attribute__((noreturn)); // --- Environment --- extern char *getenv(const char *name); @@ -36,12 +34,6 @@ extern void *malloc(unsigned int bytes); extern void *realloc(void *oldPos, unsigned int bytes); extern int IsHeap(void *ptr); -// --- Strings --- -extern int strlen(const char *string); -extern int strcmp(char *str1, char *str2); -extern int strncmp(char *str1, char *str2, size_t len); -extern char *strcpy(char *dst, const char *src); - #ifndef SEEK_CUR # define SEEK_CUR 0 # define SEEK_SET 1