From ff457641f1961586e13e4b95b4f000c8b2615f99 Mon Sep 17 00:00:00 2001 From: bryce Date: Sun, 7 May 2000 00:43:49 +0000 Subject: 2000-05-07 Bryce McKinlay Imported version 5.0alpha7. * acinclude.m4: Update version to 5.0a7. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@33750 138bc75d-0d04-0410-961f-82ee72b054a4 --- boehm-gc/os_dep.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'boehm-gc/os_dep.c') diff --git a/boehm-gc/os_dep.c b/boehm-gc/os_dep.c index 76e909f7971..636495ed039 100644 --- a/boehm-gc/os_dep.c +++ b/boehm-gc/os_dep.c @@ -642,31 +642,48 @@ ptr_t GC_get_stack_base() #ifdef LINUX_STACKBOTTOM +#include +#include +#include + # define STAT_SKIP 27 /* Number of fields preceding startstack */ /* field in /proc/self/stat */ ptr_t GC_linux_stack_base(void) { - FILE *f; + /* We read the stack base value from /proc/self/stat. We do this */ + /* using direct I/O system calls in order to avoid calling malloc */ + /* in case REDIRECT_MALLOC is defined. */ +# define STAT_BUF_SIZE 4096 +# ifdef USE_LD_WRAP +# define STAT_READ __real_read +# else +# define STAT_READ read +# endif + char stat_buf[STAT_BUF_SIZE]; + int f; char c; word result = 0; - int i; + size_t i, buf_offset = 0; - f = fopen("/proc/self/stat", "r"); - if (NULL == f) ABORT("Couldn't open /proc/self/stat"); - c = getc(f); + f = open("/proc/self/stat", O_RDONLY); + if (f < 0 || read(f, stat_buf, STAT_BUF_SIZE) < 2 * STAT_SKIP) { + ABORT("Couldn't read /proc/self/stat"); + } + c = stat_buf[buf_offset++]; /* Skip the required number of fields. This number is hopefully */ /* constant across all Linux implementations. */ for (i = 0; i < STAT_SKIP; ++i) { - while (isspace(c)) c = getc(f); - while (!isspace(c)) c = getc(f); + while (isspace(c)) c = stat_buf[buf_offset++]; + while (!isspace(c)) c = stat_buf[buf_offset++]; } - while (isspace(c)) c = getc(f); + while (isspace(c)) c = stat_buf[buf_offset++]; while (isdigit(c)) { result *= 10; result += c - '0'; - c = getc(f); + c = stat_buf[buf_offset++]; } + close(f); if (result < 0x10000000) ABORT("Absurd stack bottom value"); return (ptr_t)result; } -- cgit v1.2.1