From b3ffd0487fdde26954471a8ee0e146a09643fc87 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Wed, 27 Jun 2012 12:31:46 +0000 Subject: [PATCH] newlib: bugfixes git-svn-id: svn://kolibrios.org@2827 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/libraries/newlib/crt/chkstk.S | 34 +++++++++++++++++-- .../develop/libraries/newlib/crt/emutls.c | 1 - .../develop/libraries/newlib/include/stdint.h | 4 +++ .../newlib/include/sys/_default_fcntl.h | 9 +++++ .../libraries/newlib/include/sys/kos_io.h | 2 +- .../develop/libraries/newlib/stdlib/mallocr.c | 4 +-- 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/programs/develop/libraries/newlib/crt/chkstk.S b/programs/develop/libraries/newlib/crt/chkstk.S index 405dfc6eb2..4df1b52786 100644 --- a/programs/develop/libraries/newlib/crt/chkstk.S +++ b/programs/develop/libraries/newlib/crt/chkstk.S @@ -1,11 +1,14 @@ .global ___chkstk +.global ___chkstk_ms .global __alloca .section .text -#.def ___chkstk; .scl 2; .type 32; .endef -#.def __alloca; .scl 2; .type 32; .endef +#.def ___chkstk; .scl 2; .type 32; .endef +#.def ___chkstk_ms; .scl 2; .type 32; .endef +#.def __alloca; .scl 2; .type 32; .endef + ___chkstk: __alloca: pushl %ecx /* save temp */ @@ -29,3 +32,30 @@ __alloca: .ascii "Stack overflow" +___chkstk_ms: + pushl %ecx /* save temp */ + pushl %eax + cmpl $0x1000, %eax /* > 4k ?*/ + leal 12(%esp), %ecx /* point past return addr */ + jb 2f + +1: + subl $0x1000, %ecx /* yes, move pointer down 4k*/ + cmpl %fs:4, %ecx /* check low stack limit */ + jb 3f + + orl $0x0, (%ecx) /* probe there */ + subl $0x1000, %eax /* decrement count */ + cmpl $0x1000, %eax + ja 1b /* and do it again */ + +2: + subl %eax, %ecx + orl $0x0, (%ecx) /* less than 4k, just peek here */ + + popl %eax + popl %ecx + ret +3: + int3 #trap to debugger + .ascii "Stack overflow" diff --git a/programs/develop/libraries/newlib/crt/emutls.c b/programs/develop/libraries/newlib/crt/emutls.c index c9a6907309..77485e1422 100644 --- a/programs/develop/libraries/newlib/crt/emutls.c +++ b/programs/develop/libraries/newlib/crt/emutls.c @@ -25,7 +25,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include -#include #include #include #include diff --git a/programs/develop/libraries/newlib/include/stdint.h b/programs/develop/libraries/newlib/include/stdint.h index ccf46b17a6..f15f735081 100644 --- a/programs/develop/libraries/newlib/include/stdint.h +++ b/programs/develop/libraries/newlib/include/stdint.h @@ -35,6 +35,7 @@ extern "C" { #define __have_long64 1 #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) #define __have_long32 1 +#define __have_long64 0 #endif #if __STDINT_EXP(SCHAR_MAX) == 0x7f @@ -177,6 +178,8 @@ typedef uint64_t uint_least32_t; typedef signed int int_fast64_t; typedef unsigned int uint_fast64_t; #define __int_fast64_t_defined 1 +#else +#define __int_fast64_t_defined 0 #endif /* @@ -212,6 +215,7 @@ typedef uint64_t uint_least32_t; #if __int_least64_t_defined typedef int_least64_t int_fast64_t; typedef uint_least64_t uint_fast64_t; +#undef __int_fast64_t_defined #define __int_fast64_t_defined 1 #endif #endif diff --git a/programs/develop/libraries/newlib/include/sys/_default_fcntl.h b/programs/develop/libraries/newlib/include/sys/_default_fcntl.h index 396208bbb0..cf9c9be479 100644 --- a/programs/develop/libraries/newlib/include/sys/_default_fcntl.h +++ b/programs/develop/libraries/newlib/include/sys/_default_fcntl.h @@ -42,6 +42,15 @@ extern "C" { /* O_NDELAY _FNBIO set in include/fcntl.h */ #define O_NONBLOCK _FNONBLOCK #define O_NOCTTY _FNOCTTY + +#define _FBINARY 0x10000 +#define _FTEXT 0x20000 +#define _FNOINHERIT 0x40000 + +#define O_BINARY _FBINARY +#define O_TEXT _FTEXT +#define O_NOINHERIT _FNOINHERIT + /* For machines which care - */ #if defined (_WIN32) || defined (__CYGWIN__) #define _FBINARY 0x10000 diff --git a/programs/develop/libraries/newlib/include/sys/kos_io.h b/programs/develop/libraries/newlib/include/sys/kos_io.h index 373d341a26..ff967c1eec 100644 --- a/programs/develop/libraries/newlib/include/sys/kos_io.h +++ b/programs/develop/libraries/newlib/include/sys/kos_io.h @@ -73,7 +73,7 @@ static inline int user_free(void *mem) int val; __asm__ __volatile__( "int $0x40" - :"=eax"(val) + :"=a"(val) :"a"(68),"b"(12),"c"(mem)); return val; } diff --git a/programs/develop/libraries/newlib/stdlib/mallocr.c b/programs/develop/libraries/newlib/stdlib/mallocr.c index 9e7aecba0f..cff67ed419 100644 --- a/programs/develop/libraries/newlib/stdlib/mallocr.c +++ b/programs/develop/libraries/newlib/stdlib/mallocr.c @@ -68,7 +68,7 @@ void *user_alloc(size_t size) __asm__ __volatile__( "int $0x40" - :"=eax"(val) + :"=a"(val) :"a"(68),"b"(12),"c"(size)); return val; } @@ -82,7 +82,7 @@ int user_free(void *mem) __asm__ __volatile__( "int $0x40" - :"=eax"(val) + :"=a"(val) :"a"(68),"b"(13),"c"(mem)); return val; }