libgcc: Added check stack overflow
Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* stuff needed for libgcc on win32.
|
||||
/* stuff needed for libgcc on win32 and KolibriOS.
|
||||
*
|
||||
* Copyright (C) 1996-2023 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2026 KolibriOS team.
|
||||
* Written By Steve Chamberlain
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify it
|
||||
@@ -25,6 +26,10 @@
|
||||
|
||||
#include "i386-asm.h"
|
||||
|
||||
#ifdef __KOLIBRIOS__
|
||||
#include <kolibrios/tls.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AS_CFI_SECTIONS
|
||||
.cfi_sections .debug_frame
|
||||
#endif
|
||||
@@ -85,12 +90,16 @@ __alloca:
|
||||
jb 2f
|
||||
|
||||
1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
|
||||
#ifdef __KOLIBRIOS__
|
||||
cmpl %fs:KOS_TLS_OFF_LOW_STACK, %ecx /* check low stack limit */
|
||||
jb fail
|
||||
#endif
|
||||
orl $0x0, (%ecx) /* probe there */
|
||||
subl $0x1000, %eax /* decrement count */
|
||||
cmpl $0x1000, %eax
|
||||
ja 1b /* and do it again */
|
||||
|
||||
2: subl %eax, %ecx
|
||||
2: subl %eax, %ecx
|
||||
orl $0x0, (%ecx) /* less than 4k, just peek here */
|
||||
movl %esp, %eax /* save current stack pointer */
|
||||
cfi_def_cfa_register(%eax)
|
||||
@@ -149,6 +158,10 @@ ___chkstk_ms:
|
||||
jb 2f
|
||||
|
||||
1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
|
||||
#ifdef __KOLIBRIOS__
|
||||
cmpl %fs:KOS_TLS_OFF_LOW_STACK, %ecx /* check low stack limit */
|
||||
jb fail
|
||||
#endif
|
||||
orl $0x0, (%ecx) /* probe there */
|
||||
subl $0x1000, %eax /* decrement count */
|
||||
cmpl $0x1000, %eax
|
||||
@@ -163,5 +176,12 @@ ___chkstk_ms:
|
||||
cfi_pop(%ecx)
|
||||
ret
|
||||
cfi_endproc()
|
||||
|
||||
#ifdef __KOLIBRIOS__
|
||||
fail:
|
||||
int3 /* trap to debugger */
|
||||
.asciz "Stack overflow"
|
||||
#endif
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
#endif /* L_chkstk_ms */
|
||||
|
||||
Reference in New Issue
Block a user