diff options
-rw-r--r-- | libmom/Makefile | 40 | ||||
-rw-r--r-- | libmom/allocate-address.c | 50 | ||||
-rw-r--r-- | libmom/allocate-memory.c | 51 | ||||
-rw-r--r-- | libmom/copy-ref.c | 43 | ||||
-rw-r--r-- | libmom/deallocate-memory.c | 35 | ||||
-rw-r--r-- | libmom/fetch-mach-port.c | 33 | ||||
-rw-r--r-- | libmom/hash-ref.c | 28 | ||||
-rw-r--r-- | libmom/mach-port-set.c | 32 | ||||
-rw-r--r-- | libmom/make-memory-readonly.c | 36 | ||||
-rw-r--r-- | libmom/make-memory-readwrite.c | 36 | ||||
-rw-r--r-- | libmom/memory-init.c | 32 | ||||
-rw-r--r-- | libmom/mom-kerndep.h | 43 | ||||
-rw-r--r-- | libmom/mom.h | 138 | ||||
-rw-r--r-- | libmom/priv.h | 27 | ||||
-rw-r--r-- | libmom/ref-destroy.c | 33 | ||||
-rw-r--r-- | libmom/refs-identical.c | 43 | ||||
-rw-r--r-- | libmom/reserve-memory-anywhere.c | 40 | ||||
-rw-r--r-- | libmom/reserve-memory.c | 42 | ||||
-rw-r--r-- | libmom/unreserve-memory.c | 27 | ||||
-rw-r--r-- | libmom/unuse-memory.c | 43 | ||||
-rw-r--r-- | libmom/wire-memory.c | 28 |
21 files changed, 880 insertions, 0 deletions
diff --git a/libmom/Makefile b/libmom/Makefile new file mode 100644 index 00000000..61796585 --- /dev/null +++ b/libmom/Makefile @@ -0,0 +1,40 @@ +# +# Copyright (C) 1996 Free Software Foundation, Inc. +# Written by Michael I. Bushnell, p/BSG. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + +dir := libmom +makemode := library + +libname = libmom + +SRCS = add-ref.c allocate-address.c allocate-memory.c copy-ref.c \ + deallocate-memory.c drop-ref.c fetch-mach-port.c hash-ref.c \ + mach-port-set.c make-memory-readonly.c make-memory-readwrite.c \ + memory-init.c ref-destroy.c refs-identical.c reserve-memory.c \ + reserve-memory-anywhere.c unreserve-memory.c unuse-memory.c \ + wire-memory.c + +LCLHDRS = mom.h mom-kernep.h priv.h +installhdrs = mom.h mom-kerndep.h + +OBJS = $(SRCS:.c=.o) + +include ../Makeconf + + diff --git a/libmom/allocate-address.c b/libmom/allocate-address.c new file mode 100644 index 00000000..fa017bac --- /dev/null +++ b/libmom/allocate-address.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_allocate_address (void *start, size_t len, int readonly, + struct mom_port_ref *obj, size_t offset, + int copy) +{ + error_t err; + mach_port_t port; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + if (obj) + { + port = mom_fetch_mach_port (obj); + assert (offset % vm_page_size == 0); + } + else + port = MACH_PORT_NULL; + + mutex_lock (&_mom_memory_lock); + err = vm_map (mach_task_self (), (vm_address_t *)&start, len, 0, 0, + port, (obj ? offset : 0), (obj ? copy : 0), + (VM_PROT_READ | VM_PROT_EXECUTE + | (!readonly ? VM_PROT_WRITE : 0)), + VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_WRITE, + VM_INHERIT_COPY); + mutex_unlock (&_mom_memory_lock); + return err; +} diff --git a/libmom/allocate-memory.c b/libmom/allocate-memory.c new file mode 100644 index 00000000..d98632bc --- /dev/null +++ b/libmom/allocate-memory.c @@ -0,0 +1,51 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_allocate_memory (void **start, size_t len, int readonly, + struct mom_port_ref *obj, size_t offset, + int copy) +{ + error_t err; + mach_port_t port; + + assert (len % vm_page_size == 0); + if (obj) + { + port = mom_fetch_mach_port (obj); + assert (offset % vm_page_size == 0); + } + else + port = MACH_PORT_NULL; + + *start = 0; + + mutex_lock (&_mom_memory_lock); + err = vm_map (mach_task_self (), (vm_address_t *)start, len, 0, 0, + port, (obj ? offset : 0), (obj ? copy : 0), + (VM_PROT_READ | VM_PROT_EXECUTE + | (!readonly ? VM_PROT_WRITE : 0)), + VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_WRITE, + VM_INHERIT_COPY); + mutex_unlock (&_mom_memory_lock); + return err; +} diff --git a/libmom/copy-ref.c b/libmom/copy-ref.c new file mode 100644 index 00000000..f0d37954 --- /dev/null +++ b/libmom/copy-ref.c @@ -0,0 +1,43 @@ +/* Copy a mom port reference + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_copy_ref (struct mom_port_ref *new, + struct mom_port_ref *obj) +{ + error_t err; + + new->lock = SPIN_LOCK_INITIALIZER; + + spin_lock (&obj->lock); + assert (obj->refcnt); + err = mach_port_mod_refs (mach_task_self (), + obj->port, MACH_PORT_RIGHT_SEND, 1); + new->port = obj->port; + spin_unlock (&obj->lock); + + if (err) + return err; + + new->refcnt = 1; + return 0; +} diff --git a/libmom/deallocate-memory.c b/libmom/deallocate-memory.c new file mode 100644 index 00000000..bf7acfdb --- /dev/null +++ b/libmom/deallocate-memory.c @@ -0,0 +1,35 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_deallocate_memory (void *start, size_t len) +{ + error_t err; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + + mutex_lock (&_mom_memory_lock); + err = vm_deallocate (mach_task_self (), (vm_address_t) start, len); + mutex_unlock (&_mom_memory_lock); + return err; +} diff --git a/libmom/fetch-mach-port.c b/libmom/fetch-mach-port.c new file mode 100644 index 00000000..b747485e --- /dev/null +++ b/libmom/fetch-mach-port.c @@ -0,0 +1,33 @@ +/* Return the Mach port corresponding to a mom port reference + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +mach_port_t +mom_fetch_mach_port (struct mom_port_ref *obj) +{ + mach_port_t ret; + + spin_lock (&obj->lock); + assert (obj->refcnt); + ret = obj->port; + spin_unlock (&obj->lock); + return ret; +} diff --git a/libmom/hash-ref.c b/libmom/hash-ref.c new file mode 100644 index 00000000..6c160b1b --- /dev/null +++ b/libmom/hash-ref.c @@ -0,0 +1,28 @@ +/* Return a hash key for a mom port + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +int +mom_hash_port (struct mom_port_ref *obj) +{ + return mom_fetch_mach_port (obj); +} + diff --git a/libmom/mach-port-set.c b/libmom/mach-port-set.c new file mode 100644 index 00000000..11619900 --- /dev/null +++ b/libmom/mach-port-set.c @@ -0,0 +1,32 @@ +/* Initialize a mom port reference from a Mach port + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_mach_port_set (struct mom_port_ref *obj, + mach_port_t port) +{ + obj->lock = SPIN_LOCK_INITIALIZER; + obj->port = port; + obj->refcnt = 1; + return 0; +} + diff --git a/libmom/make-memory-readonly.c b/libmom/make-memory-readonly.c new file mode 100644 index 00000000..e7ca4c87 --- /dev/null +++ b/libmom/make-memory-readonly.c @@ -0,0 +1,36 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_make_memory_readonly (void *start, size_t len) +{ + error_t err; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + + mutex_lock (&_mom_memory_lock); + err = vm_protect (mach_task_self (), (vm_address_t) start, len, 0, + VM_PROT_READ | VM_PROT_EXECUTE); + mutex_unlock (&_mom_memory_lock); + return err; +} diff --git a/libmom/make-memory-readwrite.c b/libmom/make-memory-readwrite.c new file mode 100644 index 00000000..f35e6bfd --- /dev/null +++ b/libmom/make-memory-readwrite.c @@ -0,0 +1,36 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_make_memory_readwrite (void *start, size_t len) +{ + error_t err; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + + mutex_lock (&_mom_memory_lock); + err = vm_protect (mach_task_self (), (vm_address_t) start, len, 0, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); + mutex_unlock (&_mom_memory_lock); + return err; +} diff --git a/libmom/memory-init.c b/libmom/memory-init.c new file mode 100644 index 00000000..38972018 --- /dev/null +++ b/libmom/memory-init.c @@ -0,0 +1,32 @@ +/* Initialization and static data for mom memory management. + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +struct mutex _mom_memory_lock = MUTEX_INITIALIZER; +size_t mom_page_size; + +static void init_memory (void) __attribute__ ((constructor)); + +static void +init_memory (void) +{ + mom_page_size = vm_page_size; +} diff --git a/libmom/mom-kerndep.h b/libmom/mom-kerndep.h new file mode 100644 index 00000000..3534fdc7 --- /dev/null +++ b/libmom/mom-kerndep.h @@ -0,0 +1,43 @@ +/* Mach-specific type definitions for MOM + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include <mach/mach.h> +#include <spin-lock.h> + +struct mom_port_ref +{ + spin_lock_t lock; + mach_port_t port; + int refcnt; +}; + +/* Mach-specific functions */ + +/* Initialize OBJ with a reference to Mach port PORT. One Mach user + reference is consumed. OBJ should not currently be used, and will + have one reference upon return. */ +error_t mom_mach_port_set (struct mom_port_ref *obj, mach_port_t port); + +/* Return the Mach port corresponding to OBJ. No new Mach user + references are created, so this Mach port should only be used as + long as the user has a reference to OBJ. */ +mach_port_t mom_fetch_mach_port (struct mom_port_ref *obj); + + diff --git a/libmom/mom.h b/libmom/mom.h new file mode 100644 index 00000000..8a2c1667 --- /dev/null +++ b/libmom/mom.h @@ -0,0 +1,138 @@ +/* Microkernel object module + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + + + +#include <stdlib.h> +#include <errno.h> + +/* This header file defines structure layouts for the use of functions + below; it is specific to the particular microkernel in use. */ +#include <mom-kerndep.h> + + + + + +/* User RPC endpoints */ + +/* A communications end-point suitable for sending RPC's to servers. */ +struct mom_port_ref; /* layout defined in mom-kerndep.h */ + +/* Add a reference to to port reference OBJ. */ +error_t mom_add_ref (struct mom_port_ref *obj); + +/* Drop a reference from port reference OBJ. If this is the last reference, + then OBJ should no longer be used for further mom operations. */ +error_t mom_drop_ref (struct mom_port_ref *obj); + +/* Create a new port reference that refers to the same underlying channel + as OBJ. Fill *NEW with the new reference. NEW should be otherwise + unused memory. The new reference will have a refcount of one (as if + mom_add_ref had been called on it already). */ +error_t mom_copy_ref (struct mom_port_ref *new, struct mom_port_ref *obj); + +/* Tell if two mom ports refer to the same underlying server RPC channel */ +int mom_refs_identical (struct mom_port_ref *obj1, struct mom_port_ref *obj2); + +/* Return a hash key for a port. Different ports may have the same + hash key, but no port's hash key will ever change as long as that + port is known to this task. Two identical ports (as by + mom_ports_identical) will always have the same hash key. */ +int mom_hash_ref (struct mom_port_ref *obj); + +/* Destroy mom port reference OBJ. All existing references go away, + and the underlying kernel object is deallocated. After this call, + the memory in *OBJ may be used by the user for any purpose. It + is an error to call this routine if any other thread might be calling + any other mom port reference function on OBJ concurrently. */ +void mom_ref_destroy (struct mom_port_ref *obj); + + + +/* Memory management */ + +/* Size of a physical page; mom memory management calls must be in + aligned multiples of this value. */ +extern size_t mom_page_size; + +/* Reserve a region of memory from START and continuing for LEN bytes + so that it won't be used by anyone, but don't make it directly + usable. */ +error_t mom_reserve_memory (void *start, size_t len); + +/* Reserve a region of memory anywhere of size LEN bytes and return + its address in ADDR. */ +error_t mom_reserve_memory_anywhere (void **addr, size_t len); + +/* Make a reserved region of memory usable, as specified by START and + LEN. If READONLY is set then only make it available for read + access; otherwise permit both read and write. If OBJ is null, then + use zero-filled anonymous storage. If OBJ is non-null, then it + specifies a mom port reference referring to a memory server, and + OFFSET is the offset within that server. If COPY is set, then the + data is copied from the memory object, otherwise it shares with + other users of the same object. */ +error_t mom_use_memory (void *start, size_t len, int readonly, + struct mom_port_ref *obj, size_t offset, + int copy); + +/* Ask the kernel to wire the region of memory specified to physical + memory. The exact semantics of this are kernel dependent; it is + also usually privileged in some fashion and will fail for + non-privileged users. */ +error_t mom_wire_memory (void *start, size_t len); + +/* Convert a region of usable memory to read-only */ +error_t mom_make_memory_readonly (void *start, size_t len); + +/* Convert a region of usable memory to read/write */ +error_t mom_make_memory_readwrite (void *start, size_t len); + +/* Convert a region of usable memory to reserved but unusable status. */ +error_t mom_unuse_memory (void *start, size_t len); + +/* Convert a region of reserved unusable memory to unreserved status. */ +error_t mom_unreserve_memory (void *start, size_t len); + + + +/* Optimized combination versions of memory functions; these are very + likely to be faster than using the two call sequences they are + equivalent to. */ + +/* Combined version of mom_unuse_memory followed by mom_unreserve_memory. */ +error_t mom_deallocate_memory (void *start, size_t len); + +/* Combined version of mom_reserve_memory and mom_use_memory. */ +error_t mom_allocate_address (void *start, size_t len, int readonly, + struct mom_port_ref *obj, size_t offset, + int copy); + +/* Combined version of mom_reserve_memory_anywhere and mom_use_memory. */ +error_t mom_allocate_memory (void **start, size_t len, int readonly, + struct mom_port_ref *obj, size_t offset, + int copy); + +/* Shorthand for the most common sort of allocation--like mom_allocate_memory, + but READONLY, and OBJ are both null. */ +#define mom_allocate(start,len) \ + (mom_allocate_memory ((start), (len), 0, 0, 0, 0)) + diff --git a/libmom/priv.h b/libmom/priv.h new file mode 100644 index 00000000..88d2d9ed --- /dev/null +++ b/libmom/priv.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "mom.h" +#include <assert.h> +#include <cthreads.h> + +extern struct mutex _mom_memory_lock; + + diff --git a/libmom/ref-destroy.c b/libmom/ref-destroy.c new file mode 100644 index 00000000..3e9266ec --- /dev/null +++ b/libmom/ref-destroy.c @@ -0,0 +1,33 @@ +/* Completely destroy a MOM port + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +void +mom_ref_destroy (struct mom_port_ref *obj) +{ + spin_lock (&obj->lock); + assert (obj->refcnt); + mach_port_deallocate (mach_task_self (), obj->port); + obj->refcnt = 0; + spin_unlock (&obj->lock); +} + + diff --git a/libmom/refs-identical.c b/libmom/refs-identical.c new file mode 100644 index 00000000..74dad9b8 --- /dev/null +++ b/libmom/refs-identical.c @@ -0,0 +1,43 @@ +/* Tell if two mom port references refer to the same channel + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +int +mom_ports_identical (struct mom_port_ref *obj1, + struct mom_port_ref *obj2) +{ + int ret; + + tryagain: + spin_lock (&obj1->lock); + if (!spin_try_lock (&obj2->lock)) + { + spin_unlock (&obj1->lock); + goto tryagain; + } + assert (obj1->refcnt); + assert (obj2->refcnt); + + ret = (obj1->port == obj2->port); + spin_unlock (&obj1->lock); + spin_unlock (&obj2->lock); + return ret; +} diff --git a/libmom/reserve-memory-anywhere.c b/libmom/reserve-memory-anywhere.c new file mode 100644 index 00000000..40f9ec00 --- /dev/null +++ b/libmom/reserve-memory-anywhere.c @@ -0,0 +1,40 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_reserve_memory_anywhere (void **start, size_t len) +{ + error_t err; + + assert (len % vm_page_size == 0); + + *start = 0; + + mutex_lock (&_mom_memory_lock); + err = vm_map (mach_task_self (), (vm_address_t *)&start, len, 0, 1, + MACH_PORT_NULL, 0, 0, 0, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, + VM_INHERIT_COPY); + mutex_unlock (&_mom_memory_lock); + + return err; +} diff --git a/libmom/reserve-memory.c b/libmom/reserve-memory.c new file mode 100644 index 00000000..ada9ef02 --- /dev/null +++ b/libmom/reserve-memory.c @@ -0,0 +1,42 @@ +/* Reserve memory + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + + +#include "priv.h" + +error_t +mom_reserve_memory (void *start, size_t len) +{ + error_t err; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + + mutex_lock (&_mom_memory_lock); + err = vm_map (mach_task_self (), (vm_address_t *)&start, len, 0, 0, + MACH_PORT_NULL, 0, 0, 0, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, + VM_INHERIT_COPY); + mutex_unlock (&_mom_memory_lock); + + return err; +} + + diff --git a/libmom/unreserve-memory.c b/libmom/unreserve-memory.c new file mode 100644 index 00000000..88e8eb94 --- /dev/null +++ b/libmom/unreserve-memory.c @@ -0,0 +1,27 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_unreserve_memory (void *start, size_t len) +{ + return mom_deallocate_memory (start, len); +} diff --git a/libmom/unuse-memory.c b/libmom/unuse-memory.c new file mode 100644 index 00000000..363f2a45 --- /dev/null +++ b/libmom/unuse-memory.c @@ -0,0 +1,43 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + +error_t +mom_unuse_memory (void *start, size_t len) +{ + error_t err; + + assert ((vm_address_t) start % vm_page_size == 0); + assert (len % vm_page_size == 0); + + mutex_lock (&_mom_memory_lock); + /* Deallocate and reallocate so that we drop any mapping around. */ + err = vm_deallocate (mach_task_self (), (vm_address_t) start, len); + if (!err) + err = vm_map (mach_task_self (), (vm_address_t *)&start, len, 0, 0, + MACH_PORT_NULL, 0, 0, 0, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, + VM_INHERIT_COPY); + mutex_unlock (&_mom_memory_lock); + return err; +} + + diff --git a/libmom/wire-memory.c b/libmom/wire-memory.c new file mode 100644 index 00000000..b3832154 --- /dev/null +++ b/libmom/wire-memory.c @@ -0,0 +1,28 @@ +/* + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "priv.h" + + +error_t +mom_wire_memory (void *start, size_t len) +{ + return EOPNOTSUPP; +} |