diff --git a/.gitattributes b/.gitattributes index 65ac26a94939e0d71f48c2c2626e9a0718272836..7794d1625d0128a8b7850876e63d189fc634610e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -24,10 +24,12 @@ lib/tiny_linker_script -text libc/Makefile.in -text libc/include/assert.h -text libc/include/cgc.h -text +libc/include/close.h -text libc/include/itoa.h -text libc/include/itox.h -text libc/include/malloc.h -text libc/include/null.h -text +libc/include/open.h -text libc/include/read.h -text libc/include/stdint.h -text libc/include/stdlib.h -text @@ -36,9 +38,12 @@ libc/include/syscall.h -text libc/include/write.h -text libc/src/Makefile.in -text libc/src/cgc.s -text +libc/src/close.c -text libc/src/itoa.c -text libc/src/malloc.c -text +libc/src/open.c -text libc/src/read.c -text +libc/src/stdlib.c -text libc/src/strlen.c -text libc/src/syscall.s -text libc/src/write.c -text diff --git a/libc/include/close.h b/libc/include/close.h new file mode 100644 index 0000000000000000000000000000000000000000..45a7003b7070603d0cff27941850bd397d80ec59 --- /dev/null +++ b/libc/include/close.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 - Zephyr Software LLC + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from Zephyr + * Software. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: Zephyr Software + * e-mail: jwd@zephyr-software.com + * URL : http://www.zephyr-software.com/ + * + */ + +#ifndef close_h +#define close_h + +#include <stdint.h> + +int close(int fd); + +#endif + diff --git a/libc/include/open.h b/libc/include/open.h new file mode 100644 index 0000000000000000000000000000000000000000..459dfb434f968d6a77e8f4f990ba2c8b7e838fac --- /dev/null +++ b/libc/include/open.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 - Zephyr Software LLC + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from Zephyr + * Software. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: Zephyr Software + * e-mail: jwd@zephyr-software.com + * URL : http://www.zephyr-software.com/ + * + */ + +#ifndef open_h +#define open_h + +#include <stdint.h> + +int open(char *file, int mode); + +#endif + diff --git a/libc/include/stdint.h b/libc/include/stdint.h index d7f0f9d90d473c22bf39c2e5e6a689d02a332df6..f9cf7b831606cfec73ce41cddcd95ffed45591d6 100644 --- a/libc/include/stdint.h +++ b/libc/include/stdint.h @@ -21,10 +21,15 @@ #ifndef stdint_h #define stdint_h +#define NULL 0 + #ifdef LINUX64 typedef signed long long int ssize_t; typedef unsigned long long int size_t; typedef unsigned long long int uintptr_t; + typedef unsigned long long int uint64_t; + typedef unsigned short int uint16_t; + typedef unsigned int uint32_t; #else typedef signed long int ssize_t; typedef unsigned long int size_t; diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 5d0e8b1e8043e87544d357aea8789ef77c23da5e..8b39fa1ccd5aeb8be863d2e37d73026795d3ebcd 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -25,6 +25,8 @@ #define FALSE 0 #define NULL 0 +void __stack_chk_fail(void); + #include <malloc.h> #endif diff --git a/libc/include/syscall.h b/libc/include/syscall.h index 1fdd0a7a30ee34db62c86027ff31eea603aca032..115c35dd9617452e606ecc9d051cf0020551a166 100644 --- a/libc/include/syscall.h +++ b/libc/include/syscall.h @@ -21,7 +21,11 @@ #ifdef LINUX64 #define SYS_read 0 #define SYS_write 1 +#define SYS_open 2 +#define SYS_close 3 #else #define SYS_read 3 #define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 #endif diff --git a/libc/src/Makefile.in b/libc/src/Makefile.in index 02d6a60183e58b345ce017708dcbaf3e0446dd52..1560c20d7bfd88fa8a9da3d951a7c8c06dbbcef4 100644 --- a/libc/src/Makefile.in +++ b/libc/src/Makefile.in @@ -7,7 +7,7 @@ AR=@AR@ AS=@AS@ ASFLAGS=@ASFLAGS@ -OBJS=malloc.o read.o write.o itoa.o strlen.o cgc.o +OBJS=malloc.o read.o write.o itoa.o strlen.o cgc.o open.o close.o stdlib.o # note: cgc.s is empty when -DCGC is not in ASFLAGS, so it's an empty object file that's created.. diff --git a/libc/src/close.c b/libc/src/close.c new file mode 100644 index 0000000000000000000000000000000000000000..0512a6fa9fa8086619b36a793d8d29068cda0e01 --- /dev/null +++ b/libc/src/close.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014 - Zephyr Software LLC + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from Zephyr + * Software. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: Zephyr Software + * e-mail: jwd@zephyr-software.com + * URL : http://www.zephyr-software.com/ + * + */ + +#include <close.h> +#include <syscall.h> + +int close(int fd) +{ + syscall(SYS_close,fd); +} + diff --git a/libc/src/open.c b/libc/src/open.c new file mode 100644 index 0000000000000000000000000000000000000000..27ec96e43aee81c653fca3b1276c7c26121e4326 --- /dev/null +++ b/libc/src/open.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014 - Zephyr Software LLC + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from Zephyr + * Software. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: Zephyr Software + * e-mail: jwd@zephyr-software.com + * URL : http://www.zephyr-software.com/ + * + */ + +#include <open.h> +#include <syscall.h> + +int open(char *file, int mode) +{ + syscall(SYS_open,file,mode); +} + diff --git a/libc/src/stdlib.c b/libc/src/stdlib.c new file mode 100644 index 0000000000000000000000000000000000000000..282357560bb143764a5692b7b9c5446db4072f49 --- /dev/null +++ b/libc/src/stdlib.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 - Zephyr Software LLC + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from Zephyr + * Software. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: Zephyr Software + * e-mail: jwd@zephyr-software.com + * URL : http://www.zephyr-software.com/ + * + */ + +#include <stdlib.h> +#include <write.h> + +#define STOP_IMM() \ +do { \ + asm volatile ("mov $1, %%eax\n" \ + "int $0x80" \ + ::); \ +} while (0); + +void __stack_chk_fail(void) { + char *error = "Error: Stack check failed.\n"; + write(2, error, strlen(error)); + STOP_IMM(); +}