From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libgcc/generic-morestack-thread.c | 162 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 libgcc/generic-morestack-thread.c (limited to 'libgcc/generic-morestack-thread.c') diff --git a/libgcc/generic-morestack-thread.c b/libgcc/generic-morestack-thread.c new file mode 100644 index 000000000..bc237957e --- /dev/null +++ b/libgcc/generic-morestack-thread.c @@ -0,0 +1,162 @@ +/* Thread library support for -fsplit-stack. */ +/* Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Contributed by Ian Lance Taylor . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "tconfig.h" +#include "tsystem.h" +#include "coretypes.h" +#include "tm.h" + +/* If inhibit_libc is defined, we can not compile this file. The + effect is that people will not be able to use -fsplit-stack. That + is much better than failing the build particularly since people + will want to define inhibit_libc while building a compiler which + can build glibc. */ + +#ifndef inhibit_libc + +#include + +#include "generic-morestack.h" + +/* We declare the pthread functions we need as weak, so that + libgcc_s.so does not need to be linked against -lpthread. */ + +extern int pthread_once (pthread_once_t *, void (*) (void)) + __attribute__ ((weak)); + +extern int pthread_key_create (pthread_key_t *, void (*) (void *)) + __attribute__ ((weak)); + +extern int pthread_setspecific (pthread_key_t, const void *) + __attribute__ ((weak)); + +/* The key for the list of stack segments to free when the thread + exits. This is created by pthread_key_create. */ + +static pthread_key_t segment_list_key; + +/* Used to only run create_key once. */ + +static pthread_once_t create_key_once = PTHREAD_ONCE_INIT; + +/* Release all the segments for a thread. This is the destructor + function used by pthread_key_create, and is called when a thread + exits. */ + +static void +free_segments (void* arg) +{ + __morestack_release_segments ((struct stack_segment **) arg, 1); +} + +/* Set up the key for the list of segments. This is called via + pthread_once. */ + +static void +create_key (void) +{ + int err; + + err = pthread_key_create (&segment_list_key, free_segments); + if (err != 0) + { + static const char msg[] = "pthread_key_create failed: errno "; + __morestack_fail (msg, sizeof msg - 1, err); + } +} + +/* Pass information from the pthread_create wrapper to + stack_split_initialize_thread. */ + +struct pthread_create_args +{ + void *(*start_routine) (void *); + void *arg; +}; + +/* Initialize a thread. This is called via pthread_create. It calls + a target dependent function to set up any required stack guard. */ + +static void* stack_split_initialize_thread (void *) + __attribute__ ((no_split_stack)); + +static void * +stack_split_initialize_thread (void *varg) +{ + struct pthread_create_args *args = (struct pthread_create_args *) varg; + int err; + void *(*start_routine) (void *); + void *arg; + + __stack_split_initialize (); + + err = pthread_setspecific (segment_list_key, (void *) &__morestack_segments); + if (err != 0) + { + static const char msg[] = "pthread_setspecific failed: errno "; + __morestack_fail (msg, sizeof msg - 1, err); + } + + start_routine = args->start_routine; + arg = args->arg; + free (args); + return (*start_routine) (arg); +} + +/* This function wraps calls to pthread_create to make sure that the + stack guard is initialized for new threads. FIXME: This hack will + not be necessary if glibc supports -fsplit-stack directly. */ + +int __wrap_pthread_create (pthread_t *, const pthread_attr_t *, + void *(*start_routine) (void *), void *) + __attribute__ ((visibility ("hidden"))); + +extern int __real_pthread_create (pthread_t *, const pthread_attr_t *, + void *(*start_routine) (void *), void *) + __attribute__ ((weak)); + +int +__wrap_pthread_create (pthread_t *tid, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) +{ + int err; + struct pthread_create_args* args; + + err = pthread_once (&create_key_once, create_key); + if (err != 0) + { + static const char msg[] = "pthread_once failed: errno "; + __morestack_fail (msg, sizeof msg - 1, err); + } + + args = malloc (sizeof (struct pthread_create_args)); + if (args == NULL) + return EAGAIN; + args->start_routine = start_routine; + args->arg = arg; + return __real_pthread_create (tid, attr, stack_split_initialize_thread, args); +} + +#endif /* !defined (inhibit_libc) */ -- cgit v1.2.3