newlib: bugfixes

git-svn-id: svn://kolibrios.org@2827 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2012-06-27 12:31:46 +00:00
parent 21140b30f2
commit b3ffd0487f
6 changed files with 48 additions and 6 deletions

View File

@ -1,11 +1,14 @@
.global ___chkstk .global ___chkstk
.global ___chkstk_ms
.global __alloca .global __alloca
.section .text .section .text
#.def ___chkstk; .scl 2; .type 32; .endef #.def ___chkstk; .scl 2; .type 32; .endef
#.def __alloca; .scl 2; .type 32; .endef #.def ___chkstk_ms; .scl 2; .type 32; .endef
#.def __alloca; .scl 2; .type 32; .endef
___chkstk: ___chkstk:
__alloca: __alloca:
pushl %ecx /* save temp */ pushl %ecx /* save temp */
@ -29,3 +32,30 @@ __alloca:
.ascii "Stack overflow" .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"

View File

@ -25,7 +25,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <stdlib.h> #include <stdlib.h>
#include <memory.h>
#include <malloc.h> #include <malloc.h>
#include <errno.h> #include <errno.h>
#include <gthr.h> #include <gthr.h>

View File

@ -35,6 +35,7 @@ extern "C" {
#define __have_long64 1 #define __have_long64 1
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
#define __have_long32 1 #define __have_long32 1
#define __have_long64 0
#endif #endif
#if __STDINT_EXP(SCHAR_MAX) == 0x7f #if __STDINT_EXP(SCHAR_MAX) == 0x7f
@ -177,6 +178,8 @@ typedef uint64_t uint_least32_t;
typedef signed int int_fast64_t; typedef signed int int_fast64_t;
typedef unsigned int uint_fast64_t; typedef unsigned int uint_fast64_t;
#define __int_fast64_t_defined 1 #define __int_fast64_t_defined 1
#else
#define __int_fast64_t_defined 0
#endif #endif
/* /*
@ -212,6 +215,7 @@ typedef uint64_t uint_least32_t;
#if __int_least64_t_defined #if __int_least64_t_defined
typedef int_least64_t int_fast64_t; typedef int_least64_t int_fast64_t;
typedef uint_least64_t uint_fast64_t; typedef uint_least64_t uint_fast64_t;
#undef __int_fast64_t_defined
#define __int_fast64_t_defined 1 #define __int_fast64_t_defined 1
#endif #endif
#endif #endif

View File

@ -42,6 +42,15 @@ extern "C" {
/* O_NDELAY _FNBIO set in include/fcntl.h */ /* O_NDELAY _FNBIO set in include/fcntl.h */
#define O_NONBLOCK _FNONBLOCK #define O_NONBLOCK _FNONBLOCK
#define O_NOCTTY _FNOCTTY #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 - */ /* For machines which care - */
#if defined (_WIN32) || defined (__CYGWIN__) #if defined (_WIN32) || defined (__CYGWIN__)
#define _FBINARY 0x10000 #define _FBINARY 0x10000

View File

@ -73,7 +73,7 @@ static inline int user_free(void *mem)
int val; int val;
__asm__ __volatile__( __asm__ __volatile__(
"int $0x40" "int $0x40"
:"=eax"(val) :"=a"(val)
:"a"(68),"b"(12),"c"(mem)); :"a"(68),"b"(12),"c"(mem));
return val; return val;
} }

View File

@ -68,7 +68,7 @@ void *user_alloc(size_t size)
__asm__ __volatile__( __asm__ __volatile__(
"int $0x40" "int $0x40"
:"=eax"(val) :"=a"(val)
:"a"(68),"b"(12),"c"(size)); :"a"(68),"b"(12),"c"(size));
return val; return val;
} }
@ -82,7 +82,7 @@ int user_free(void *mem)
__asm__ __volatile__( __asm__ __volatile__(
"int $0x40" "int $0x40"
:"=eax"(val) :"=a"(val)
:"a"(68),"b"(13),"c"(mem)); :"a"(68),"b"(13),"c"(mem));
return val; return val;
} }