summaryrefslogtreecommitdiff
path: root/sysdeps/l4/hurd/pt-thread-alloc.c
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2008-05-29 20:45:48 +0000
committerThomas Schwinge <tschwinge@gnu.org>2009-04-07 23:16:14 +0200
commitba1501075d81ce42c88707021eb8c2befa0fe4a4 (patch)
tree9e96100971636a5604027cc28be766389558e35d /sysdeps/l4/hurd/pt-thread-alloc.c
parent9acc87073cfc18eaa2ea5b46fa81f239d6b32b31 (diff)
libhurd-mm/
2008-05-29 Neal H. Walfield <neal@gnu.org> * exceptions.c (exception_handler_activated): Assume the fault is on the stack if it is one page above or three pages below the stack pointer. (exception_handler_init): Allocate an area of address space EXCEPTION_STACK_SIZE bytes larges. Fill it with pages. Set the first page as the thread's exception page and the top of the area minus one word as the stack pointer. Set the last word to the location of the exception page. * ia32-exception-entry.S: Include <hurd/exceptions.h>. (PAGESIZE): Don't define. (_exception_handler_entry): Rewrite to not assume that the exception page is at the start of the page in which the stack pointer is, but at the location stored in the word after the bottom of the stack. * Makefile.am (libhurd_mm_a_CCASFLAGS): New variable. * pager.c (ensure_stack): Change SPACE to be EXCEPTION_STACK_SIZE - PAGESIZE bytes large. Write to each page. libpthread/ 2008-05-29 Neal H. Walfield <neal@gnu.org> * sysdeps/l4/hurd/pt-sysdep.h Include <hurd/exceptions.h>. (EXCEPTION_AREA_SIZE): Define. (EXCEPTION_AREA_SIZE_LOG2): Likewise. (EXCEPTION_PAGE): Likewise. (PTHREAD_SYSDEP_MEMBERS): Change object's type to an addr_t. Update users. Remove field exception_page, replace with exception_area. Add field exception_area_va. * sysdeps/l4/hurd/pt-thread-alloc.c: Include <hurd/as.h> and <hurd/addr.h>. (__pthread_thread_alloc): Allocate EXCEPTION_AREA_SIZE bytes of address space. Save it in THREAD->EXCEPTION_AREA_VA. Allocate a page for each page in that area. Save them in THREAD->EXCEPTION_AREA. * sysdeps/l4/hurd/ia32/pt-setup.c (__pthread_setup): Set EXCEPTION_PAGE->EXCEPTION_HANDLER_SP to the end of EXCEPTION_PAGE->EXCEPTION_HANDLER_SP minus one word, in which we save the address of the exception page. * sysdeps/l4/hurd/pt-thread-start.c (__pthread_thread_start): Set IN.EXCEPTION_PAGE to the first page in THREAD->EXCEPTION_AREA_VA. * sysdeps/l4/hurd/pt-thread-halt.c: Include <hurd/mutex.h>, <hurd/as.h> and <hurd/addr.h>. (saved_object_lock): New variable. (__pthread_thread_halt): Lock SAVED_OBJECT_LOCK when accessing SAVED_OBJECT. Free the address space used by the exception area (THREAD->EXCEPTION_AREA_VA) and its associated storage (THREAD->EXCEPTION_AREA). hurd/ 2008-05-29 Neal H. Walfield <neal@gnu.org> * exceptions.h: Include <hurd/stddef.h>. [ASM]: Only define relevant macros. (EXCEPTION_STACK_SIZE_LOG2): Define. (EXCEPTION_STACK_SIZE): Define. * stddef.h [ASM]: Only define relevant macros. (PAGESIZE): Don't append C type specifier. (PAGESIZE_LOG2): Likewise. viengoos/ 2008-05-29 Neal H. Walfield <neal@gnu.org> * as.c: Include <hurd/exceptions.h>. (ensure_stack): Change SPACE to be EXCEPTION_STACK_SIZE - PAGESIZE bytes large. Write to each page. * cap-lookup.c: Include <hurd/exceptions.h>. (ensure_stack): Change SPACE to be EXCEPTION_STACK_SIZE - PAGESIZE bytes large. Write to each page. * zalloc.c (ZONE_SIZE): Add suffix the 1 with a U type qualifier. (ZONES): Include one less zone.
Diffstat (limited to 'sysdeps/l4/hurd/pt-thread-alloc.c')
-rw-r--r--sysdeps/l4/hurd/pt-thread-alloc.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/sysdeps/l4/hurd/pt-thread-alloc.c b/sysdeps/l4/hurd/pt-thread-alloc.c
index daa13dba..6941e10e 100644
--- a/sysdeps/l4/hurd/pt-thread-alloc.c
+++ b/sysdeps/l4/hurd/pt-thread-alloc.c
@@ -1,4 +1,4 @@
-/* Allocate kernel thread. Hurd/L4 version.
+/* Allocate kernel thread. Viengoos version.
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -23,6 +23,8 @@
#include <hurd/startup.h>
#include <hurd/storage.h>
+#include <hurd/as.h>
+#include <hurd/addr.h>
#include <pt-internal.h>
@@ -36,40 +38,57 @@ __pthread_thread_alloc (struct __pthread *thread)
/* The main thread is already running of course. */
if (__pthread_num_threads == 1)
{
- thread->object.addr = __hurd_startup_data->thread;
- /* If the main thread exits, then we wait. Thus, we don't need
- the shadow cap. */
- thread->object.cap = NULL;
+ thread->object = __hurd_startup_data->thread;
thread->threadid = l4_myself ();
return 0;
}
else
{
- struct storage storage;
+ addr_t exception_area = as_alloc (EXCEPTION_AREA_SIZE_LOG2, 1, true);
- /* We can't don't use mmap as when the exception thread starts
- running and it accesses its stack, it will fault, which we
- naturally cannot handle. */
- storage = storage_alloc (ADDR_VOID, cap_page,
- STORAGE_UNKNOWN, OBJECT_POLICY_DEFAULT,
- ADDR_VOID);
- if (ADDR_IS_VOID (storage.addr))
- return EAGAIN;
+ thread->exception_area_va
+ = ADDR_TO_PTR (addr_extend (exception_area,
+ 0, EXCEPTION_AREA_SIZE_LOG2));
- thread->exception_page = storage;
+ int i;
+ for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++)
+ {
+ addr_t slot = addr_chop (PTR_TO_ADDR (thread->exception_area_va
+ + i * PAGESIZE),
+ PAGESIZE_LOG2);
+ as_slot_ensure (slot);
+ struct storage storage = storage_alloc (ADDR_VOID, cap_page,
+ STORAGE_LONG_LIVED,
+ OBJECT_POLICY_DEFAULT,
+ slot);
+ if (ADDR_IS_VOID (storage.addr))
+ {
+ int j;
+ for (j = 0; j < i; j ++)
+ storage_free (thread->exception_area[j], false);
+ as_free (exception_area, false);
+ return EAGAIN;
+ }
+ thread->exception_area[i] = storage.addr;
+ }
+
+ struct storage storage;
storage = storage_alloc (meta_data_activity, cap_thread,
/* Threads are rarely shortly lived. */
STORAGE_MEDIUM_LIVED, OBJECT_POLICY_DEFAULT,
ADDR_VOID);
if (ADDR_IS_VOID (storage.addr))
{
- storage_free (thread->exception_page.addr, false);
+ int j;
+ for (j = 0; j < EXCEPTION_AREA_SIZE / PAGESIZE; j ++)
+ storage_free (thread->exception_area[j], false);
+ as_free (exception_area, false);
return EAGAIN;
}
- thread->object = storage;
+ thread->object = storage.addr;
}
return 0;