aboutsummaryrefslogtreecommitdiff
path: root/libmudflap/mf-hooks3.c
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@gcc.gnu.org>2004-06-04 20:12:01 +0000
committerFrank Ch. Eigler <fche@gcc.gnu.org>2004-06-04 20:12:01 +0000
commit7954e85c0016deceecd4dafc8622292ad1363967 (patch)
treed248b4bcf141c1cec13d21a71e4945815f2ccb44 /libmudflap/mf-hooks3.c
parent28af2467e40311bbddd132788d0dcd7fe02f72d4 (diff)
downloadgcc-7954e85c0016deceecd4dafc8622292ad1363967.zip
gcc-7954e85c0016deceecd4dafc8622292ad1363967.tar.gz
gcc-7954e85c0016deceecd4dafc8622292ad1363967.tar.bz2
Portability improvements, e.g., libmudflap/15293.
2004-06-04 Frank Ch. Eigler <fche@redhat.com> Portability improvements, e.g., libmudflap/15293. * configure.in: Look for glibc extension functions. Look for support of -f{function,data}-sections. Look for more headers. Create testsuite/mfconfig.exp. Correct more "test x.." thinkos. * Makefile.am: Use $(SECTION_FLAGS). Collapse piecemeal-compiled mf-hooks* into usual single object per source. * mf-hooks*.c: Remove all #if WRAP_foo conditionals. * mf-hooks2.c: #include a bunch more system headers. Define strnlen if system doesn't provide one. * mf-hooks3.c (struct pthread_info): Add stack_*_alloc fields. (pthread_create): Use it to properly GC dead thread stacks. * mf-runtime.c (__mf_violation): Correct snprintf type warning. * testsuite/Makefile.am: Stop generating site.exp. * testsuite/mfconfig.exp.in: New file. * testsuite/config/default.exp: Load new mfconfig.exp. * testsuite/lib/libmudflap.exp (libmudflap-init): Add extra libraries. (prune_gcc_output): Add glibc static linking warnings. * testsuite/libmudflap.*/*frags.exp: Enumerate needed -lmudflap* libs. * testsuite/libmudflap.c/pass46-frag.c: Ditto. * configure, Makefile, aclocal.m4, config.h.in, testsuite/Makefile.in: Regenerated with autoconf 2.57 and automake 1.7. From-SVN: r82632
Diffstat (limited to 'libmudflap/mf-hooks3.c')
-rw-r--r--libmudflap/mf-hooks3.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/libmudflap/mf-hooks3.c b/libmudflap/mf-hooks3.c
index 838f381..6a14cb2 100644
--- a/libmudflap/mf-hooks3.c
+++ b/libmudflap/mf-hooks3.c
@@ -1,5 +1,5 @@
/* Mudflap: narrow-pointer bounds-checking by tree rewriting.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Frank Ch. Eigler <fche@redhat.com>
and Graydon Hoare <graydon@redhat.com>
@@ -59,6 +59,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <errno.h>
#include <limits.h>
#include <sched.h>
+#include <fcntl.h>
#include "mf-runtime.h"
#include "mf-impl.h"
@@ -71,8 +72,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
/* Multithreading support hooks. */
-#ifdef WRAP_pthreadstuff
-
#ifndef LIBMUDFLAPTH
#error "pthreadstuff is to be included only in libmudflapth"
@@ -87,9 +86,12 @@ struct pthread_info
short dead_p; /* Is this thread dead? */
pthread_t self; /* The thread id. */
- /* If libmudflapth allocated the stack, store its base/size. */
+ /* If libmudflapth allocated the stack, store its adjusted base/size. */
void *stack;
size_t stack_size;
+ /* The _alloc fields store unadjusted values from the moment of allocation. */
+ void *stack_alloc;
+ size_t stack_size_alloc;
int *thread_errno;
enum __mf_state_enum state;
@@ -357,6 +359,8 @@ WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
pthread_attr_t override_attr;
void *override_stack;
size_t override_stacksize;
+ void *override_stack_alloc = (void *) 0;
+ size_t override_stacksize_alloc = 0;
unsigned i;
TRACE ("pthread_create\n");
@@ -381,9 +385,9 @@ WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
if (pi->dead_p >= 10 /* XXX */)
{
if (pi->stack)
- CALL_REAL (munmap, pi->stack, pi->stack_size);
+ CALL_REAL (munmap, pi->stack_alloc, pi->stack_size_alloc);
- VERBOSE_TRACE ("slot %u freed, stack %p\n", i, pi->stack);
+ VERBOSE_TRACE ("slot %u freed, stack %p\n", i, pi->stack_alloc);
memset (pi, 0, sizeof (*pi));
/* One round of garbage collection is enough. */
@@ -435,14 +439,32 @@ WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
#define MF_MAP_ANON MAP_ANONYMOUS
#elif defined(MAP_ANON)
#define MF_MAP_ANON MAP_ANON
-#else
-#error "Cannot mmap anonymous memory."
#endif
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *) -1)
+#endif
+
+#ifdef MF_MAP_ANON
override_stack = CALL_REAL (mmap, NULL, override_stacksize,
PROT_READ|PROT_WRITE,
MAP_PRIVATE|MF_MAP_ANON,
0, 0);
+#else
+ /* Try mapping /dev/zero instead. */
+ {
+ static int zerofd = -1;
+ if (zerofd == -1)
+ zerofd = open ("/dev/zero", O_RDWR);
+ if (zerofd == -1)
+ override_stack = MAP_FAILED;
+ else
+ override_stack = CALL_REAL (mmap, NULL, override_stacksize,
+ PROT_READ|PROT_WRITE,
+ MAP_PRIVATE, zerofd, 0);
+ }
+#endif
+
if (override_stack == 0 || override_stack == MAP_FAILED)
{
errno = EAGAIN;
@@ -452,10 +474,15 @@ WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
VERBOSE_TRACE ("thread stack alloc %p size %lu\n",
override_stack, (unsigned long) override_stacksize);
+ /* Save the original allocated values for later deallocation. */
+ override_stack_alloc = override_stack;
+ override_stacksize_alloc = override_stacksize;
+
/* The stackaddr pthreads attribute is a candidate stack pointer.
It must point near the top or the bottom of this buffer, depending
on whether stack grows downward or upward, and suitably aligned.
On the x86, it grows down, so we set stackaddr near the top. */
+ /* XXX: port logic */
override_stack = (void *)
(((uintptr_t) override_stack + override_stacksize - alignment - perturb)
& (~(uintptr_t)(alignment-1)));
@@ -504,6 +531,8 @@ WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
/* Fill in remaining fields in pthread_info. */
pi->stack = override_stack;
pi->stack_size = override_stacksize;
+ pi->stack_alloc = override_stack_alloc;
+ pi->stack_size_alloc = override_stacksize_alloc;
/* XXX: this might be too late for future heuristics that attempt
to use thread stack bounds. We may need to put the new thread
to sleep. */
@@ -563,11 +592,3 @@ WRAPPER(void, pthread_exit, void *rc)
CALL_REAL (pthread_exit, rc);
/* NOTREACHED */
}
-
-
-
-
-
-
-
-#endif /* pthreadstuff */