summaryrefslogtreecommitdiff
path: root/libhurd-mm/anonymous.c
diff options
context:
space:
mode:
authorneal <neal>2005-04-06 16:30:37 +0000
committerneal <neal>2005-04-06 16:30:37 +0000
commitbf11bbd527b36cca883715231a19d2ece20f17d2 (patch)
treefb856d0133fb53243d469f09d2aabfca8e602a71 /libhurd-mm/anonymous.c
parent60099e7c8556f17f88262bbf783178a0c4147799 (diff)
2005-04-06 Neal H. Walfield <neal@gnu.org>
* vm.h (hurd_vm_allocate): Remove declaration. (hurd_vm_release): Rename from hurd_vm_deallocate. Update callers. (VM_HERE): Remove. (VM_ZEROFILL): Remove. * vm.c (hurd_vm_allocate): Remove function. (hurd_vm_release): Rename from hurd_vm_deallocate. * mm.h: Include <stdint.h>, <sys/types.h>, <l4/types.h> and <hurd/physmem.h>. (hurd_store_t): New typedef. (hurd_memory_t): Likewise. (hurd_memory_use): New declaration. (hurd_memory_transfer): Likewise. (hurd_store_fault_t): New typedef. (hurd_store_init): New declaration. (hurd_store_size): New declaration. (HURD_VM_HERE): New definition. (hurd_store_bind_to_vm): New declaration. (hurd_store_flush): New declaration. * priv.h: Include "vm.h" and "mm.h". (here): New debugging macro. (struct region): Move to... * mm.h: ...here. (struct hurd_memory): Rename from struct frame. Rename field dc_start to cont_start. Add field cont. Remove field refs. Update users. (memory_slab): Rename from frame_slab. Update users. (memory_alloc_into): Rename from frame_alloc_into. Update users. (frame_alloc): Move to... * priv.h (frame_insert): Move to... * mm.h (hurd_store_cache): ...here. * priv.h (frame_find_first): Move to... * mm.h (hurd_store_find_cached): ...here. * priv.h (frame_map): Move to... * mm.h (hurd_memory_map): ...here. * priv.h (frame_dealloc): Move to... * mm.h (hurd_memory_dealloc): ...here. * priv.h (struct hurd_store): Rename from struct store. Remove fields server and handle. Add fields hook and fault. Rename field frames to memory. Update users. (store_find_free): Remove declaration. (struct map): Add field store_offset. (default_container): Likewise. (map_init): Likewise. (map_free): Rename from map_dealloc. Update callers. (map_init): New declaration. (map_find_first): Rename from map_find. Update callers. (as_find_free): Rename from map_find_free. Update callers. (container_find_free): Remove declaration. (core_slab_allocate_buffer): Rename from mem_slab_allocate_buffer. Update users. (core_slab_deallocate_buffer): Rename from mem_slab_deallocate_buffer. Update users. (frame_spare): Rename to memory_spare. Update users. (core_store): New declaration. * map.c (VIRTUAL_MEMORY_START): Move from here... * priv.h: ...to here. * map.c (as): Move from here... * as.c: ...to here. (map_system_init): Rename from map_init. Reserve the UTCB and the KIP. (memory_spare): Rename from frame_spare. (core_slab_allocate_buffer): Rename from mem_slab_allocate_buffer. (core_slab_deallocate_buffer): Rename from mem_slab_deallocate_buffer. (map_init): New function. (map_free): Rename from map_dealloc. (map_find): Rename from map_find_first. Avoid gratuitous hurd_btree_map_prev. (map_find_free): Remove function. (store_find_free): Move from here... * as.c (as_find_free): ...to here. * frame.c: Move from here... * memory.c: ...to here. Include <hurd/startup.h>. (swap_store): Remove definition. (memory_slab): Rename from frame_slab. (default_container): New static global. (dc_offset): New function. (memory_system_init): Likewise. (memory_alloc_into): Rename from frame_alloc_into. (hurd_memory_new): New function. Refactored from frame_alloc. (hurd_memory_delete): New function. (hurd_memory_alloc): Rename from frame_alloc. Rewritten to use hurd_memory_new. (frame_insert): Move from here... * store.c (hurd_store_cache): ...to here. * memory.c (hurd_memory_use): New function. (hurd_memory_transfer): New function. (hurd_memory_dealloc): Rename from frame_dealloc. Don't deallocate too eagerly: split memory which is only partially deallocated. (frame_find_first): Move from here... * store.c (hurd_store_find_cached): ...to here. * memory.c (hurd_memory_map): Rename from frame_map. Loop mapping all of the requested if a single RPC is insufficient. * mm-init.c (default_container): Remove definition. (hurd_mm_init): Don't initialize DEFAULT_CONTAINER. Don't initialize the store data structures. Call memory_system_init, core_system_init, hurd_anonymous_init, and map_system_init. Use core_allocate rather than hurd_vm_allocate to allocate a stack for the pager thread. * pager.c (pager): Don't round ADDR. Call MAP->STORE->FAULT if the physical memory is not cached. * physmem-user.h: Include <hurd/physmem.h>. Improve documentation. (hurd_pm_control_t): Remove redundant typedef. (hurd_pm_container_t): Likewise. (hurd_pm_container_access_t): Remove typedef. (HURD_PM_CONT_ALLOC_PARTIAL): Remove redundant define. (HURD_PM_CONT_ALLOC_SQUASH): Likewise. (HURD_PM_CONT_ALLOC_EXTRA): Likewise. (HURD_PM_CONT_ALLOC_DMA): Likewise. (hurd_pm_container_share): Change ACCESSS from a hurd_pm_container_access_t * to a hurd_pm_container_t *. (hurd_pm_container_map): Rename parameter rights to flags. Add new parameter AMOUNT. Update callers. * physmem-user.c (container_ops): Remove redundant enumeration. (hurd_pm_container_create): Use hurd_pm_container_create_id as the RPC identifier. (hurd_pm_container_share): Use hurd_pm_container_share_id as the RPC identifier. (hurd_pm_container_allocate): Use hurd_pm_container_allocate_id as the RPC identifier. (hurd_pm_container_deallocate): Use hurd_pm_container_deallocate_id as the RPC identifier. (hurd_pm_container_map): Use hurd_pm_container_map_id as the RPC identifier. If AMOUNTP is non-NULL, return the number of bytes mapped in *AMOUNTP. Remove debugging code. (hurd_pm_container_copy): Use hurd_pm_container_copy_id as the RPC identifier. * anonymous.h: New file. * anonymous.c: New file. * as.c: New file. * core.c: New file. * frame.c: Remove file. * store.c: New file. * Makefile.am (libhurd_mm_a_SOURCES): Add as.c, store.c, memory.c, core.c, anonymous.c and anonymous.h. Remove frame.c. * headers.m4: Install anonymous.h as <hurd/anonymous.h>.
Diffstat (limited to 'libhurd-mm/anonymous.c')
-rw-r--r--libhurd-mm/anonymous.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/libhurd-mm/anonymous.c b/libhurd-mm/anonymous.c
new file mode 100644
index 0000000..62a831e
--- /dev/null
+++ b/libhurd-mm/anonymous.c
@@ -0,0 +1,80 @@
+/* anonymous.c - Anonymous memory management.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd 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 2, or (at
+ your option) any later version.
+
+ The GNU Hurd 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.
+
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd; see the file COPYING. If not, write to
+ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
+ USA. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+#include "priv.h"
+
+static struct hurd_store anonymous_store;
+
+error_t
+hurd_anonymous_allocate (uintptr_t *address, size_t size,
+ uintptr_t flags, int map_now)
+{
+ /* This is a bit frustrating. The store cache is indexed by the
+ store offset thus even though anonymous memory does not initially
+ have a location on backing store, we need to fabricate one.
+ Right now we just use a static variable. The 64-bits should give
+ us a fair amount of time before we need to come up with a better
+ solution. */
+ static off64_t offset;
+ error_t err;
+
+ err = hurd_store_bind_to_vm (&anonymous_store, offset,
+ address ? *address : 0, size,
+ flags, 1, address);
+ if (err)
+ return err;
+
+ offset += size;
+ return 0;
+}
+
+static void
+handle_fault (hurd_store_t *store, void *hook, l4_thread_id_t thread,
+ struct region vm_region, off64_t store_offset,
+ uintptr_t addr, l4_word_t access)
+{
+ /* XXX: Until we have a real swap server we (correctly) assume that
+ if there is no memory then memory has just not yet been allocated
+ (i.e. it is not just paged out). */
+ struct hurd_memory *memory = hurd_memory_alloc (vm_region.size);
+ if (! memory)
+ panic ("hurd_memory_alloc failed.");
+
+ store_offset -= addr - vm_region.start;
+
+ hurd_store_cache (store, store_offset, memory);
+}
+
+void
+hurd_anonymous_system_init (void)
+{
+ static bool init_done;
+
+ assert (! init_done);
+ init_done = true;
+
+ hurd_store_init (&anonymous_store, NULL, handle_fault);
+}