diff options
author | bryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-05-07 00:43:49 +0000 |
---|---|---|
committer | bryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-05-07 00:43:49 +0000 |
commit | ff457641f1961586e13e4b95b4f000c8b2615f99 (patch) | |
tree | 0d22c55f1ff05d1e504f0d4e95fc271a3ca6203f /boehm-gc/os_dep.c | |
parent | 9fd99fa7fb2136182a2f4d6c4184807febd5d6a4 (diff) | |
download | gcc-ff457641f1961586e13e4b95b4f000c8b2615f99.tar.gz |
2000-05-07 Bryce McKinlay <bryce@albatross.co.nz>
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
Diffstat (limited to 'boehm-gc/os_dep.c')
-rw-r--r-- | boehm-gc/os_dep.c | 35 |
1 files changed, 26 insertions, 9 deletions
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 <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + # 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; } |