aboutsummaryrefslogtreecommitdiff
path: root/REORG.TODO/mach
diff options
context:
space:
mode:
Diffstat (limited to 'REORG.TODO/mach')
-rw-r--r--REORG.TODO/mach/Machrules235
-rw-r--r--REORG.TODO/mach/Makefile167
-rw-r--r--REORG.TODO/mach/Versions67
-rw-r--r--REORG.TODO/mach/devstream.c144
-rw-r--r--REORG.TODO/mach/err_boot.sub63
-rw-r--r--REORG.TODO/mach/err_ipc.sub109
-rw-r--r--REORG.TODO/mach/err_kern.sub185
-rw-r--r--REORG.TODO/mach/err_mach.sub130
-rw-r--r--REORG.TODO/mach/err_server.sub370
-rw-r--r--REORG.TODO/mach/err_us.sub48
-rw-r--r--REORG.TODO/mach/error_compat.c67
-rw-r--r--REORG.TODO/mach/errorlib.h84
-rw-r--r--REORG.TODO/mach/errstring.c94
-rw-r--r--REORG.TODO/mach/errsystems.awk23
-rw-r--r--REORG.TODO/mach/lock-intern.h96
-rw-r--r--REORG.TODO/mach/mach.h100
-rw-r--r--REORG.TODO/mach/mach/error.h137
-rw-r--r--REORG.TODO/mach/mach/mach.h3
-rw-r--r--REORG.TODO/mach/mach/mach_traps.h84
-rw-r--r--REORG.TODO/mach/mach/mig_support.h82
-rw-r--r--REORG.TODO/mach/mach_error.c80
-rw-r--r--REORG.TODO/mach/mach_error.h71
-rw-r--r--REORG.TODO/mach/mach_init.c53
-rw-r--r--REORG.TODO/mach/mach_init.h52
-rw-r--r--REORG.TODO/mach/mig-alloc.c29
-rw-r--r--REORG.TODO/mach/mig-dealloc.c27
-rw-r--r--REORG.TODO/mach/mig-reply.c52
-rw-r--r--REORG.TODO/mach/mig_strncpy.c11
-rw-r--r--REORG.TODO/mach/msg-destroy.c231
-rw-r--r--REORG.TODO/mach/msg.c145
-rw-r--r--REORG.TODO/mach/msgserver.c199
-rw-r--r--REORG.TODO/mach/mutex-init.c29
-rw-r--r--REORG.TODO/mach/mutex-solid.c36
-rw-r--r--REORG.TODO/mach/setup-thread.c79
-rw-r--r--REORG.TODO/mach/shortcut.awk50
-rw-r--r--REORG.TODO/mach/spin-lock.c8
-rw-r--r--REORG.TODO/mach/spin-lock.h33
-rw-r--r--REORG.TODO/mach/spin-solid.c28
-rw-r--r--REORG.TODO/mach/syscalls.awk9
39 files changed, 3510 insertions, 0 deletions
diff --git a/REORG.TODO/mach/Machrules b/REORG.TODO/mach/Machrules
new file mode 100644
index 0000000000..36adfc7681
--- /dev/null
+++ b/REORG.TODO/mach/Machrules
@@ -0,0 +1,235 @@
+# Rules for MiG interfaces that want to go into the C library.
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+# Makefiles may define these variable before including this file:
+# user-interfaces Names of interfaces to put user stubs in for.
+# server-interfaces Names of interfaces to put server stubs in for.
+# interface-library Name of interface library to build and install.
+# This file sets:
+# interface-headers Names of generated interface header files.
+# interface-routines Names of generated interface routines.
+# All user stubs are put in individual files, prefixed with RPC_; header
+# for both __ and non-__ names is put in foo.h. Server interfaces are
+# written to foo_server.c and foo_server.h; the server functions are called
+# _S_rpcname.
+
+# Includers can also add to or modify `migdefines' to set MiG flags.
+
+all:
+
+# Make sure no value comes from the environment, since we append to it.
+# This is done also in ../Rules, but we append to the value before
+# including Rules, which changes the origin.
+ifneq "$(findstring env,$(origin generated))" ""
+generated :=
+endif
+
+
+include ../Makeconfig
+
+# This makefile contains a lot of implicit rules that get optimized
+# away if the target directory does not exist.
+ifndef no_deps
+-include $(objpfx)dummy.mk
+endif
+$(objpfx)dummy.mk:
+ $(make-target-directory)
+ echo '# Empty' > $@
+
+MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
+ $(+includes) $(migdefines) -subrprefix __
+# Putting CC in the enivronment makes the mig wrapper script
+# use the same compiler setup we are using to run cpp.
+MIG := CC='${CC}' CPP='${CPP} -x c' $(MIG)
+
+.SUFFIXES: .defs # Just to set specified_rule_matched.
+
+define nl # This is needed by *.ir.
+
+
+endef
+ifdef user-interfaces
+*.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
+ifndef no_deps
+ifndef inhibit_interface_rules
+-include $(*.ir)
+endif
+endif
+ifneq "$(*.ir)" "$(wildcard $(*.ir))"
+# If any .ir file is missing, we will be unable to make all the deps.
+no_deps=t
+endif
+generated += $(*.ir:$(objpfx)%=%)
+endif
+
+
+# %.ir defines a variable `%-calls', which lists the RPCs defined by
+# %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
+# %.defs, where $(%-userprefix) is the user prefix given in %.defs. We use
+# the kludgificacious method of defining a pattern rule to build files
+# matching patterns we are pretty damn sure will only match the particular
+# files we have in mind. To be so damn sure, we use the silly names
+# RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
+# other useful pattern) causes the rule for `host_info' to also match
+# `xxx_host_info', and analogous lossage.
+#
+# Depend on %.h just so they will be built from %.uh in the
+# makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
+# intermediate in order to make %.ir and then removed before re-exec, when
+# %.uh is built all over again to build %.h.
+$(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
+ ($(AWK) "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
+ { printf \"$*-calls += %s\\n\", \$$3 }" $< ;\
+ echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
+ ) > $@-new
+ mv -f $@-new $@
+vpath Machrules ../mach # Find ourselves.
+
+ifndef transform-user-stub-output
+transform-user-stub-output = tmp
+define transform-user-stub
+echo "weak_alias (__$$call, $$call)" >> $(objpfx)tmp_$${call}.c;
+endef
+endif
+
+
+# Generate `#include <NAME.defs>', taking $* for NAME.
+# If $(NAME.defs) is defined use its value in place of `NAME.defs'.
+define include-%.defs
+echo '#include <$(firstword $($*.defs) $*.defs)>'
+endef
+
+ifndef no_deps
+# Not an implicit rule so the stamps are never removed as intermediates!
+$(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp:
+ rm -f $@
+ $(include-%.defs) | \
+ $(MIG) - /dev/null -prefix __ \
+ $(MIGFLAGS) $(user-MIGFLAGS) $(MIGFLAGS-$*) \
+ -i $(objpfx)tmp_ \
+ -server /dev/null -user /dev/null -header /dev/null
+ for call in $($*-calls); do \
+ $(transform-user-stub) \
+ $(move-if-change) $(objpfx)$(transform-user-stub-output)_$${call}.c \
+ $(objpfx)RPC_$${call}.c; \
+ done
+ touch $@
+-include $(patsubst %,$(objpfx)%.udeps,$(user-interfaces))
+$(patsubst %,$(objpfx)%.udeps,$(user-interfaces)):
+ $(objpfx)%.udeps: $(..)mach/Machrules
+ $(make-target-directory)
+# We must use $(CFLAGS) to get -O flags that affect #if's in header files.
+ $(include-%.defs) | \
+ $(CC) $(CFLAGS) $(CPPFLAGS) -M -x c - | \
+ sed -e 's,- *:,$(.udeps-targets):,' \
+ $(sed-remove-objpfx) > $@.new
+ mv -f $@.new $@
+.udeps-targets = $@ $(@:.udeps=.ustamp) $(@:.udeps=.uh) $(@:.udeps=.__h) \
+ $(@:.udeps=_server.c) $(@:.udeps=_server.h)
+endif
+
+# Look for the server stub files where they will be written.
+vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
+
+# Build the server stubs in $(objdir).
+$(objpfx)%_server.c $(objpfx)%_server.h:
+ $(make-target-directory)
+ $(include-%.defs) | \
+ $(MIG) - /dev/null -prefix _S_ \
+ $(MIGFLAGS) $(server-MIGFLAGS) $(MIGFLAGS-$*) \
+ -user /dev/null -header /dev/null \
+ -server $(@:.h=.c) -sheader $(@:.c=.h)
+
+# To get header files that declare both the straight and __ functions,
+# we generate two files and paste them together.
+$(patsubst %,$(objpfx)%.uh,$(user-interfaces)): $(objpfx)%.uh:; $(mig.uh)
+define mig.uh
+$(make-target-directory)
+$(include-%.defs) | \
+$(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) \
+ -header $@ -server /dev/null -user /dev/null
+endef
+$(patsubst %,$(objpfx)%.__h,$(user-interfaces)): $(objpfx)%.__h:; $(mig.__h)
+define mig.__h
+$(make-target-directory)
+$(include-%.defs) | \
+$(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) -prefix __ \
+ -header $@ -server /dev/null -user /dev/null
+endef
+
+$(patsubst %,$(objpfx)%.h,$(user-interfaces)): $(objpfx)%.h: $(objpfx)%.__h \
+ $(objpfx)%.uh
+# The last line of foo.__h is "#endif _foo_user_".
+# The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
+ (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
+ mv -f $@-new $@
+
+interface-routines := $(foreach if,$(user-interfaces), \
+ $(addprefix RPC_,$($(if)-calls))) \
+ $(server-interfaces:%=%_server)
+interface-headers := $(user-interfaces:%=%.h) \
+ $(server-interfaces:%=%_server.h)
+
+# Remove the generated user stub source and header files,
+# and don't distribute them.
+mach-generated = $(interface-routines:%=%.c) $(interface-headers) \
+ $(foreach h,$(user-interfaces),$h.uh $h.__h)
+generated += $(mach-generated)
+
+# These are needed to generate the dependencies.
+before-compile += $(interface-headers:%=$(objpfx)%)
+
+# Don't let these be intermediate files and get removed.
+$(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
+$(interface-routines:%=$(objpfx)%.c) :
+
+# Convenient target to generate all the headers.
+.PHONY: interface-headers
+interface-headers: $(interface-headers)
+
+# Don't automatically generate dependencies for the sources we generate.
+# There are likely to be a whole lot of them, and we know their
+# dependencies ahead of time anyway because they're boilerplate.
+omit-deps += $(interface-routines)
+
+# Choose any single module generated by MiG. We will compute this module's
+# dependencies and then assume all other MiG-generated modules depend on the
+# same headers.
+some-if-rtn := $(firstword $(interface-routines))
+ifdef some-if-rtn
+$(foreach o,$(object-suffixes),$(interfaces-routines:%=%$o)): $(some-if-rtn).d
+generated += $(some-if-rtn).d
+endif
+
+# If defined, $(interface-library) is `libNAME'. It is to be a library
+# containing all the MiG-generated functions for the specified interfaces.
+
+ifdef interface-library
+
+$(interface-library)-routines = $(interface-routines)
+extra-libs += $(interface-library)
+extra-libs-others += $(interface-library)
+
+ifeq (yes,$(build-shared))
+interface.so = $(interface-library:=.so)
+
+# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
+$(objpfx)$(interface.so): $(common-objpfx)libc.so
+endif
+
+endif
diff --git a/REORG.TODO/mach/Makefile b/REORG.TODO/mach/Makefile
new file mode 100644
index 0000000000..127cad00ca
--- /dev/null
+++ b/REORG.TODO/mach/Makefile
@@ -0,0 +1,167 @@
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+subdir := mach
+
+include ../Makeconfig
+
+headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
+ $(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
+ $(lock-headers) machine-sp.h
+lock = spin-solid spin-lock mutex-init mutex-solid
+lock-headers = lock-intern.h machine-lock.h spin-lock.h
+routines = $(mach-syscalls) $(mach-shortcuts) \
+ mach_init mig_strncpy msg \
+ mig-alloc mig-dealloc mig-reply \
+ msg-destroy msgserver \
+ mach_error errstring error_compat errsystems \
+ devstream setup-thread $(lock)
+
+# The RPC interfaces go in a separate library.
+interface-library := libmachuser
+
+# We produce mach_interface.h from mach.defs because there is already a
+# <mach/mach.h> that is not the interface header (thanks CMU).
+mach-interface-list := $(patsubst mach,mach_interface,$(mach-interface-list))
+mach/mach_interface.defs = mach/mach.defs
+
+# Similarly for memory_object_user vs. memory_object
+mach-interface-list := $(patsubst memory_object,memory_object_user,\
+ $(mach-interface-list))
+mach/memory_object_user.defs = mach/memory_object.defs
+
+user-interfaces := $(addprefix mach/,$(mach-interface-list) \
+ mach_port mach_host exc \
+ )\
+ $(addprefix device/,device device_request)
+
+server-interfaces := mach/exc
+
+# Clear any environment value.
+generated =
+
+# Translate GNU names for CPUs into the names used in Mach header files.
+mach-machine = $(patsubst powerpc,ppc,$(base-machine))
+
+# Define mach-syscalls and sysno-*.
+ifndef inhibit_mach_syscalls
+-include $(objpfx)mach-syscalls.mk
+endif
+$(objpfx)mach-syscalls.mk: syscalls.awk Makefile libc-modules.h
+# Go kludges!!!
+ $(make-target-directory)
+# We must use $(CFLAGS) to get -O flags that affect #if's in header files.
+ echo '#include <mach/syscall_sw.h>' | \
+ $(CC) $(CFLAGS) $(CPPFLAGS) -E -MD -MP -MF $@-dep -MT $@ \
+ -x c-header - \
+ -D_MACH_`echo $(mach-machine) | tr a-z A-Z`_SYSCALL_SW_H_=1 | \
+ sed -n -e 's/^kernel_trap(\(.*\),\([-0-9]*\),\([0-9]*\))$$/\1 \2 \3/p'\
+ | $(AWK) -f $< > $@-new
+ifneq (,$(objpfx))
+ sed $(sed-remove-objpfx) $@-dep >> $@-new
+else
+ cat $@-dep >> $@-new
+endif
+ rm -f $@-dep
+ mv -f $@-new $@
+generated += mach-syscalls.mk
+
+ifndef mach-syscalls
+# We cannot make the deps properly until we know how to make the system
+# call functions, and for that we must know what they all are.
+no_deps=t
+else
+$(mach-syscalls:%=$(objpfx)%.S): $(objpfx)%.S: $(objpfx)mach-syscalls.mk
+ (echo '#include <sysdep.h>'; \
+ echo 'kernel_trap (__$*,$(sysno-$*),$(nargs-$*))'; \
+ echo 'weak_alias (__$*, $*)') > $@-new
+ mv -f $@-new $@
+generated += $(mach-syscalls:=.S)
+endif # mach-syscalls
+
+# These syscalls that look like RPCs actually have no RPC equivalents.
+mach-shortcuts := $(filter-out device_writev_request \
+ device_read_overwrite_request \
+ device_read_overwrite \
+ vm_read_overwrite \
+ thread_switch \
+ ,\
+ $(patsubst syscall_%,%,$(filter syscall_%,$(mach-syscalls))))
+
+ifndef mach-shortcuts
+# Forget about mach_interface.defs for this run. On the next run,
+# $(mach-shortcuts) will be set, and that will change how
+# mach_interface.defs is processed: it will get the -D flags below.
+user-interfaces := $(filter-out $(mach-interface-list:%=mach/%) \
+ mach/mach_port mach/mach_host mach/mach4 \
+ device/device_request,\
+ $(user-interfaces))
+endif
+
+# For some reason, the calls in this file are `protected' by an ifdef.
+MIGFLAGS-mach/mach4=-DMACH_PCSAMPLE
+
+# Make the MiG stubs for $(mach-shortcuts) be CALL_rpc.
+migdefines += $(foreach call,$(mach-shortcuts),-D$(call)=$(call)_rpc)
+$(mach-interface-list:%=mach/%.uh) \
+ mach/mach_host.uh mach/mach_port.uh: $(objpfx)mach-syscalls.mk
+
+ifdef mach-shortcuts
+$(mach-shortcuts:%=$(objpfx)%.c): $(objpfx)%.c: shortcut.awk \
+ $(objpfx)RPC_%_rpc.c
+ $(AWK) -v alias=$* -v call=__$* -v rpc=__$*_rpc \
+ -v syscall=__syscall_$* -f $^ > $@-new
+ mv -f $@-new $@
+generated += $(mach-shortcuts:%=%.c)
+endif # mach-shortcuts
+
+# Generate mach-shortcuts.h, which will contain the prototypes for the
+# shortcutted kernel RPC functions.
+$(objpfx)mach-shortcuts.h: $(mach-interface-list:%=$(objpfx)mach/%.h) \
+ $(objpfx)mach/mach_host.h \
+ $(objpfx)mach/mach_port.h
+# The first line gets us one paragraph per line, with @s separating real lines.
+# The second line selects paragraphs for the shortcutted functions.
+# The third line removes `_rpc' from the names and reconstitutes the lines.
+ cat $^ | tr \\012 @ | sed s/@@/@%/g | tr % \\012 \
+ | grep '^/\* Routine [a-z0-9_]*_rpc \*/' \
+ | sed 's/_rpc//g' | tr @ \\012 > $@-new
+ mv -f $@-new $@
+generated += mach-shortcuts.h
+
+before-compile += $(objpfx)mach-shortcuts.h
+
+include Machrules
+include ../Rules
+
+
+# A gcc bug prevents the generated file from working properly,
+# so we have one in the distribution for the time being.
+generated += errsystems.c
+$(objpfx)errsystems.c: errsystems.awk err_*.sub \
+ $(wildcard $(addsuffix /err_*.sub,$(+sysdep_dirs)))
+ $(AWK) -v subsys='$(filter-out $<,$^)' -f $^ > $@.n
+ mv -f $@.n $@
+
+
+# Convenient target to update all the generated source files.
+.PHONY: generated
+generated: $(addprefix $(common-objpfx),$(common-generated)) \
+ $(addprefix $(objpfx),$(generated))
+
+.PHONY: mach-before-compile
+mach-before-compile: $(mach-before-compile)
diff --git a/REORG.TODO/mach/Versions b/REORG.TODO/mach/Versions
new file mode 100644
index 0000000000..0097aad59b
--- /dev/null
+++ b/REORG.TODO/mach/Versions
@@ -0,0 +1,67 @@
+libc {
+ GLIBC_2.0 {
+ # variables used in Mach-specific macros
+ __mach_task_self_;
+ __vm_page_size;
+
+ # functions used in inline functions and macros
+ __mach_port_deallocate; __mach_thread_self;
+
+ # functions used by RPC stubs
+ __mach_msg; __mach_msg_overwrite;
+ __mig_allocate; __mig_deallocate; __mig_dealloc_reply_port;
+ __mig_get_reply_port; __mig_put_reply_port;
+ __mig_strncpy;
+
+ # variables in normal name space
+ vm_page_size;
+
+ # functions in normal name space
+
+ # e*
+ evc_wait;
+
+ # m*
+ mach_error; mach_error_string; mach_error_type;
+ mach_host_self;
+ mach_msg; mach_msg_overwrite;
+ mach_msg_destroy;
+ mach_msg_send; mach_msg_receive;
+ mach_msg_server; mach_msg_server_timeout;
+ mach_open_devstream;
+ mach_port_allocate; mach_port_allocate_name; mach_port_deallocate;
+ mach_port_insert_right; mach_reply_port;
+ mach_setup_thread;
+ mach_task_self;
+ mach_thread_self;
+ mig_allocate; mig_dealloc_reply_port; mig_deallocate;
+ mig_get_reply_port; mig_init; mig_put_reply_port;
+
+ # v*
+ vm_allocate; vm_deallocate; vm_map;
+
+ # s*
+ swtch; swtch_pri;
+
+ # t*
+ task_create; task_set_special_port; task_suspend; task_terminate;
+ thread_depress_abort; thread_switch;
+ }
+ GLIBC_2.2.5 {
+ # internal functions used by other libraries (e.g. librt)
+ __mach_msg_destroy; __mach_reply_port;
+
+ # This was always there, but not exported as it should have been.
+ mig_strncpy;
+ }
+ GLIBC_2.23 {
+ __mach_host_self_;
+ }
+
+ HURD_CTHREADS_0.3 {
+ __mutex_init; __mutex_lock; __mutex_lock_solid; __mutex_trylock;
+ __mutex_unlock; __mutex_unlock_solid;
+ __spin_lock; __spin_lock_init; __spin_lock_solid; __spin_try_lock;
+ __spin_unlock;
+ }
+}
diff --git a/REORG.TODO/mach/devstream.c b/REORG.TODO/mach/devstream.c
new file mode 100644
index 0000000000..1a9e207b47
--- /dev/null
+++ b/REORG.TODO/mach/devstream.c
@@ -0,0 +1,144 @@
+/* stdio on a Mach device port.
+ Translates \n to \r\n on output, echos and translates \r to \n on input.
+ Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <mach.h>
+#include <device/device.h>
+#include <errno.h>
+#include <string.h>
+
+
+static ssize_t
+devstream_write (void *cookie, const char *buffer, size_t n)
+{
+ const device_t dev = (device_t) cookie;
+
+ int write_some (const char *p, size_t to_write)
+ {
+ kern_return_t err;
+ int wrote;
+ int thiswrite;
+
+ while (to_write > 0)
+ {
+ thiswrite = to_write;
+ if (thiswrite > IO_INBAND_MAX)
+ thiswrite = IO_INBAND_MAX;
+
+ if (err = device_write_inband (dev, 0, 0, p, thiswrite, &wrote))
+ {
+ errno = err;
+ return 0;
+ }
+ p += wrote;
+ to_write -= wrote;
+ }
+ return 1;
+ }
+ int write_crlf (void)
+ {
+ static const char crlf[] = "\r\n";
+ return write_some (crlf, 2);
+ }
+
+ /* Search for newlines (LFs) in the buffer. */
+
+ const char *start = buffer, *p;
+ while ((p = memchr (start, '\n', n)) != NULL)
+ {
+ /* Found one. Write out through the preceding character,
+ and then write a CR/LF pair. */
+
+ if ((p > start && !write_some (start, p - start))
+ || !write_crlf ())
+ return (start - buffer) ?: -1;
+
+ n -= p + 1 - start;
+ start = p + 1;
+ }
+
+ /* Write the remainder of the buffer. */
+ if (write_some (start, n))
+ start += n;
+ return (start - buffer) ?: -1;
+}
+
+static ssize_t
+devstream_read (void *cookie, char *buffer, size_t to_read)
+{
+ const device_t dev = (device_t) cookie;
+
+ kern_return_t err;
+ mach_msg_type_number_t nread = to_read;
+
+ err = device_read_inband (dev, 0, 0, to_read, buffer, &nread);
+ if (err)
+ {
+ errno = err;
+ return -1;
+ }
+
+ /* Translate CR to LF. */
+ {
+ char *p;
+ for (p = memchr (buffer, '\r', nread); p;
+ p = memchr (p + 1, '\r', (buffer + nread) - (p + 1)))
+ *p = '\n';
+ }
+
+ /* Echo back what we read. */
+ (void) devstream_write (cookie, buffer, nread);
+
+ return nread;
+}
+
+static int
+dealloc_ref (void *cookie)
+{
+ if (mach_port_deallocate (mach_task_self (), (mach_port_t) cookie))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ return 0;
+}
+
+FILE *
+mach_open_devstream (mach_port_t dev, const char *mode)
+{
+ FILE *stream;
+
+ if (mach_port_mod_refs (mach_task_self (), dev, MACH_PORT_RIGHT_SEND, 1))
+ {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ stream = fopencookie ((void *) dev, mode,
+ (cookie_io_functions_t) { write: devstream_write,
+ read: devstream_read,
+ close: dealloc_ref });
+ if (stream == NULL)
+ {
+ mach_port_deallocate (mach_task_self (), dev);
+ return NULL;
+ }
+
+ return stream;
+}
diff --git a/REORG.TODO/mach/err_boot.sub b/REORG.TODO/mach/err_boot.sub
new file mode 100644
index 0000000000..feba8fcd6f
--- /dev/null
+++ b/REORG.TODO/mach/err_boot.sub
@@ -0,0 +1,63 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1992 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1992/10/06 18:29:52 roland
+ * entered into RCS
+ *
+ * Revision 2.2 92/04/01 19:37:59 rpd
+ * Created.
+ * [92/03/09 rpd]
+ *
+ */
+/*
+ * File: err_bootstrap.sub
+ * Author: Richard Draves, Carnegie Mellon University
+ * Date: March 9, 1992
+ *
+ * Error string definitions for bootstrap
+ */
+
+static char * err_codes_bootstrap_fs[] = {
+ /* 0 */ "(bootstrap/fs) not a directory",
+ /* 1 */ "(bootstrap/fs) name not found",
+ /* 2 */ "(bootstrap/fs) name too long",
+ /* 3 */ "(bootstrap/fs) symbolic link loop",
+ /* 4 */ "(bootstrap/fs) bad file system",
+ /* 5 */ "(bootstrap/fs) offset not in file",
+ /* 6 */ "(bootstrap/fs) invalid parameter",
+};
+
+/* err_bootstrap subsystems */
+static struct error_subsystem err_bootstrap_sub[] = {
+ /* bootstrap/0; */
+ {
+ "(bootstrap/fs)",
+ errlib_count(err_codes_bootstrap_fs),
+ err_codes_bootstrap_fs,
+ },
+};
diff --git a/REORG.TODO/mach/err_ipc.sub b/REORG.TODO/mach/err_ipc.sub
new file mode 100644
index 0000000000..3acabd847c
--- /dev/null
+++ b/REORG.TODO/mach/err_ipc.sub
@@ -0,0 +1,109 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1992/10/06 18:29:52 roland
+ * entered into RCS
+ *
+ * Revision 2.2 92/01/16 00:08:40 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.2 91/03/27 16:05:16 mrt
+ * First checkin
+ *
+ *
+ */
+/*
+ * File: err_ipc.sub
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar, 1988
+ *
+ * Definitions of error strings for original IPC
+ */
+
+static char * err_codes_send[] = {
+ "(ipc/send) unknown error", /* -100 */
+ "(ipc/send) invalid memory", /* -101 */
+ "(ipc/send) invalid port", /* -102 */
+ "(ipc/send) timed out", /* -103 */
+ "(ipc/send) unused error", /* -104 */
+ "(ipc/send) will notify", /* -105 */
+ "(ipc/send) notify in progress", /* -106 */
+ "(ipc/send) kernel refused message", /* -107 */
+ "(ipc/send) send interrupted", /* -108 */
+ "(ipc/send) send message too large", /* -109 */
+ "(ipc/send) send message too small", /* -110 */
+ "(ipc/send) message size changed while being copied", /* -111 */
+};
+
+static char * err_codes_rcv[] = {
+ "(ipc/rcv) unknown error", /* -200 */
+ "(ipc/rcv) invalid memory", /* -201 */
+ "(ipc/rcv) invalid port", /* -202 */
+ "(ipc/rcv) receive timed out", /* -203 */
+ "(ipc/rcv) message too large", /* -204 */
+ "(ipc/rcv) no space for message data", /* -205 */
+ "(ipc/rcv) only sender remaining", /* -206 */
+ "(ipc/rcv) receive interrupted", /* -207 */
+ "(ipc/rcv) port receiver changed or port became enabled", /* -208 */
+};
+
+static char * err_codes_mig[] = {
+ "(ipc/mig) type check failure in message interface", /* 0 (-300) */
+ "(ipc/mig) wrong return message ID", /* 1 */
+ "(ipc/mig) server detected error", /* 2 */
+ "(ipc/mig) bad message ID", /* 3 */
+ "(ipc/mig) server found wrong arguments", /* 4 */
+ "(ipc/mig) no reply should be sent", /* 5 */
+ "(ipc/mig) server raised exception", /* 6 */
+ "(ipc/mig) user specified array not large enough for return info", /* 7 */
+};
+
+/* err_ipc subsystems */
+static struct error_subsystem err_ipc_sub[] = {
+ /* ipc/0; */
+ {
+ "(ipc/send)",
+ errlib_count(err_codes_send),
+ err_codes_send,
+ },
+ /* ipc/1; */
+ {
+ "(ipc/rcv)",
+ errlib_count(err_codes_rcv),
+ err_codes_rcv,
+
+ },
+ /* ipc/2 */
+ {
+ "(ipc/mig)",
+ errlib_count(err_codes_mig),
+ err_codes_mig,
+ },
+
+};
+
diff --git a/REORG.TODO/mach/err_kern.sub b/REORG.TODO/mach/err_kern.sub
new file mode 100644
index 0000000000..ab00ae40f2
--- /dev/null
+++ b/REORG.TODO/mach/err_kern.sub
@@ -0,0 +1,185 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.3 92/04/01 19:38:02 rpd
+ * Added err_codes_device.
+ * [92/03/09 rpd]
+ *
+ * Revision 2.2 92/01/16 00:08:50 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.3 91/08/29 15:51:22 rpd
+ * Updated err_codes_kern.
+ * [91/08/15 rpd]
+ *
+ * Revision 2.2 91/03/27 16:05:27 mrt
+ * First checkin
+ *
+ */
+/*
+ * File: err_kern.sub
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar, 1988
+ *
+ * error codes for Mach and Unix kernels
+ */
+
+static char * err_codes_kern[] = {
+ "(os/kern) successful",
+ "(os/kern) invalid address",
+ "(os/kern) protection failure",
+ "(os/kern) no space available",
+ "(os/kern) invalid argument",
+ "(os/kern) failure",
+ "(os/kern) resource shortage",
+ "(os/kern) not receiver",
+ "(os/kern) no access",
+ "(os/kern) memory failure",
+ "(os/kern) memory error",
+ "(os/kern) already in set",
+ "(os/kern) not in set",
+ "(os/kern) name exists",
+ "(os/kern) aborted",
+ "(os/kern) invalid name",
+ "(os/kern) invalid task",
+ "(os/kern) invalid right",
+ "(os/kern) invalid value",
+ "(os/kern) urefs overflow",
+ "(os/kern) invalid capability",
+ "(os/kern) right exists",
+ "(os/kern) invalid host",
+ "(os/kern) memory present",
+};
+
+static char * err_codes_device[] = {
+ "(os/device) hardware IO error",
+ "(os/device) operation would block",
+ "(os/device) no such device",
+ "(os/device) device already open",
+ "(os/device) device is shut down",
+ "(os/device) invalid operation",
+ "(os/device) invalid record number",
+ "(os/device) invalid IO size",
+ "(os/device) memory allocation failure",
+ "(os/device) read only",
+};
+
+static char * err_codes_unix[] = {
+ NO_SUCH_ERROR,
+ "(os/unix) no rights to object",
+ "(os/unix) file or directory does not exist",
+ "(os/unix) no such process",
+ "(os/unix) interrupted system call",
+ "(os/unix) i/o error",
+ "(os/unix) device does not exist",
+ "(os/unix) argument list is too long",
+ "(os/unix) invalid executable object format",
+ "(os/unix) bad file descriptor number",
+ "(os/unix) no child processes are present",
+ "(os/unix) no more processes are available",
+ "(os/unix) insufficient memory",
+ "(os/unix) access denied",
+ "(os/unix) memory access fault",
+ "(os/unix) block device required for operation",
+ "(os/unix) mount device busy",
+ "(os/unix) file already exists",
+ "(os/unix) cross device link",
+ "(os/unix) device does not exist",
+ "(os/unix) object is not a directory",
+ "(os/unix) object is a directory",
+ "(os/unix) invalid argument",
+ "(os/unix) internal file table overflow",
+ "(os/unix) maximum number of open files reached",
+ "(os/unix) object is not a tty-like device",
+ "(os/unix) executable object is in use",
+ "(os/unix) file is too large",
+ "(os/unix) no space is left on device",
+ "(os/unix) illegal seek attempt",
+ "(os/unix) read-only file system",
+ "(os/unix) too many links",
+ "(os/unix) broken pipe",
+ "(os/unix) argument is too large",
+ "(os/unix) result is out of range",
+ "(os/unix) operation on device would block",
+ "(os/unix) operation is now in progress",
+ "(os/unix) operation is already in progress",
+ "(os/unix) socket operation attempted on non-socket object",
+ "(os/unix) destination address is required",
+ "(os/unix) message is too long",
+ "(os/unix) protocol type is incorrect for socket",
+ "(os/unix) protocol type is not available",
+ "(os/unix) protocol type is not supported",
+ "(os/unix) socket type is not supported",
+ "(os/unix) operation is not supported on sockets",
+ "(os/unix) protocol family is not supported",
+ "(os/unix) address family is not supported by protocol family",
+ "(os/unix) address is already in use",
+ "(os/unix) can't assign requested address",
+ "(os/unix) network is down",
+ "(os/unix) network is unreachable",
+ "(os/unix) network dropped connection on reset",
+ "(os/unix) software aborted connection",
+ "(os/unix) connection reset by peer",
+ "(os/unix) no buffer space is available",
+ "(os/unix) socket is already connected",
+ "(os/unix) socket is not connected",
+ "(os/unix) can't send after socket shutdown",
+ "(os/unix) too many references; can't splice",
+ "(os/unix) connection timed out",
+ "(os/unix) connection was refused",
+ "(os/unix) too many levels of symbolic links",
+ "(os/unix) file name exceeds system maximum limit",
+ "(os/unix) host is down",
+ "(os/unix) there is no route to host",
+ "(os/unix) directory is not empty",
+ "(os/unix) quota on number of processes exceeded",
+ "(os/unix) quota on number of users exceeded",
+ "(os/unix) quota on available disk space exceeded",
+};
+
+static struct error_subsystem err_kern_sub[] = {
+ {
+ "(os/kern)",
+ errlib_count(err_codes_kern),
+ err_codes_kern,
+ },
+ {
+ "(os/device)",
+ errlib_count(err_codes_device),
+ err_codes_device,
+ },
+ {
+ "(os/?)",
+ 0,
+ },
+ {
+ "(os/unix)",
+ errlib_count(err_codes_unix),
+ err_codes_unix,
+ },
+};
diff --git a/REORG.TODO/mach/err_mach.sub b/REORG.TODO/mach/err_mach.sub
new file mode 100644
index 0000000000..708047150e
--- /dev/null
+++ b/REORG.TODO/mach/err_mach.sub
@@ -0,0 +1,130 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1992/10/06 18:29:52 roland
+ * entered into RCS
+ *
+ * Revision 2.3 92/04/01 19:38:05 rpd
+ * Added MIG_DESTROY_REQUEST.
+ * [92/03/09 rpd]
+ *
+ * Revision 2.2 92/01/16 00:09:05 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.3 91/08/29 15:51:30 rpd
+ * Added MIG_SERVER_DIED.
+ * [91/08/21 rpd]
+ *
+ * Revision 2.2 91/03/27 16:05:37 mrt
+ * First checkin
+ *
+ * Revision 2.2 91/03/18 17:39:03 rpd
+ * Created.
+ * [91/03/18 rpd]
+ *
+ */
+/*
+ * File: err_mach_ipc.sub
+ * Author: Richard Draves, Carnegie Mellon University
+ * Date: Jan, 1990
+ *
+ * Error string definitions for the new Mach IPC
+ */
+
+static char * err_codes_mach_send[] = {
+ /* 0 */ "(ipc/send) no error",
+ /* 1 */ "(ipc/send) send in progress",
+ /* 2 */ "(ipc/send) invalid data",
+ /* 3 */ "(ipc/send) invalid destination port",
+ /* 4 */ "(ipc/send) timed out",
+ /* 5 */ "(ipc/send) will notify",
+ /* 6 */ "(ipc/send) notify in progress",
+ /* 7 */ "(ipc/send) interrupted",
+ /* 8 */ "(ipc/send) msg too small",
+ /* 9 */ "(ipc/send) invalid reply port",
+ /* 10 */ "(ipc/send) invalid port right",
+ /* 11 */ "(ipc/send) invalid notify port",
+ /* 12 */ "(ipc/send) invalid memory",
+ /* 13 */ "(ipc/send) no msg buffer",
+ /* 14 */ "(ipc/send) no notify possible",
+ /* 15 */ "(ipc/send) invalid msg-type",
+ /* 16 */ "(ipc/send) invalid msg-header",
+};
+
+static char * err_codes_mach_rcv[] = {
+ /* 0 */ "(ipc/rcv) no error",
+ /* 1 */ "(ipc/rcv) receive in progress",
+ /* 2 */ "(ipc/rcv) invalid name",
+ /* 3 */ "(ipc/rcv) timed out",
+ /* 4 */ "(ipc/rcv) msg too large",
+ /* 5 */ "(ipc/rcv) interrupted",
+ /* 6 */ "(ipc/rcv) port changed",
+ /* 7 */ "(ipc/rcv) invalid notify port",
+ /* 8 */ "(ipc/rcv) invalid data",
+ /* 9 */ "(ipc/rcv) port died",
+ /* 10 */ "(ipc/rcv) port in set",
+ /* 11 */ "(ipc/rcv) header error",
+ /* 12 */ "(ipc/rcv) body error",
+};
+
+static char * err_codes_mach_mig[] = {
+ /* 0 */ "(ipc/mig) client type check failure",
+ /* 1 */ "(ipc/mig) wrong reply message ID",
+ /* 2 */ "(ipc/mig) server detected error",
+ /* 3 */ "(ipc/mig) bad request message ID",
+ /* 4 */ "(ipc/mig) server type check failure",
+ /* 5 */ "(ipc/mig) no reply should be sent",
+ /* 6 */ "(ipc/mig) server raised exception",
+ /* 7 */ "(ipc/mig) array not large enough",
+ /* 8 */ "(ipc/mig) server died",
+ /* 9 */ "(ipc/mig) destroy request with no reply",
+};
+
+/* err_mach_ipc subsystems */
+static struct error_subsystem err_mach_ipc_sub[] = {
+ /* ipc/0; */
+ {
+ "(ipc/send)",
+ errlib_count(err_codes_mach_send),
+ err_codes_mach_send,
+ },
+ /* ipc/1; */
+ {
+ "(ipc/rcv)",
+ errlib_count(err_codes_mach_rcv),
+ err_codes_mach_rcv,
+
+ },
+ /* ipc/2 */
+ {
+ "(ipc/mig)",
+ errlib_count(err_codes_mach_mig),
+ err_codes_mach_mig,
+ },
+
+};
diff --git a/REORG.TODO/mach/err_server.sub b/REORG.TODO/mach/err_server.sub
new file mode 100644
index 0000000000..a2f806aa09
--- /dev/null
+++ b/REORG.TODO/mach/err_server.sub
@@ -0,0 +1,370 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * HISTORY
+ *
+ * Revision 2.2 92/01/16 00:10:29 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.3 91/08/29 15:51:39 rpd
+ * Fixed err_codes_netname.
+ * [91/08/22 rpd]
+ *
+ * Revision 2.2 91/03/27 16:05:51 mrt
+ * First checkin
+ *
+ * Revision 2.3 90/10/29 17:27:20 dpj
+ * Merged-up to U25
+ * [90/09/02 20:00:25 dpj]
+ *
+ */
+/*
+ * File: err_server.sub
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar, 1988
+ *
+ * Definitions of Servers error strings
+ */
+
+static char * err_codes_netname[] = { /* 0 */
+ "(server/netname) name is not yours",
+ "(server/netname) name not checked in",
+ "(server/netname) no such host",
+ "(server/netname) host not found",
+};
+static char * err_codes_env_mgr[] = { /* 1 */
+ NO_SUCH_ERROR,
+ "(server/env_mgr) variable not found",
+ "(server/env_mgr) wrong type of variable",
+ "(server/env_mgr) unknown port",
+ "(server/env_mgr) read only environment",
+ "(server/env_mgr) no more connections available",
+ "(server/env_mgr) port table full",
+ "(server/env_mgr) attempting to enter a null port ",
+};
+static char * err_codes_execd[] = { /* 2 */
+ NO_SUCH_ERROR,
+ "(server/execd) could not find file to run",
+ "(server/execd) userid or password incorrect",
+ "(server/execd) fork failed",
+};
+static char * err_codes_netmemory[] = { /* 3 */
+ "(server/netmemory) successful",
+ "(server/netmemory) invalid argument",
+ "(server/netmemory) resource shortage",
+};
+static char * err_codes_ufs[] = { /* 4 */
+ NO_SUCH_ERROR,
+/* XXX "(server/ufs) invalid port", */
+};
+
+static char * err_codes_task_master[] = { /* 5 */
+ "(server/task_master) GENERIC ERROR",
+ "(server/task_master) invalid tm_task port",
+ "(server/task_master) invalid task id",
+ "(server/task_master) invalid kernel port",
+ "(server/task_master) invalid job group",
+ "(server/task_master) invalid action",
+};
+
+static char * err_codes_ns[] = { /* 6 */
+ "(server/ns) GENERIC ERROR",
+ "(server/ns) invalid handle",
+ "(server/ns) name not found",
+ "(server/ns) name already exists",
+ "(server/ns) name too long",
+ "(server/ns) path too long",
+ "(server/ns) invalid name",
+ "(server/ns) not a directory",
+ "(server/ns) is a directory",
+ "(server/ns) directory not empty",
+ "(server/ns) infinite retry loop in resolver",
+ "(server/ns) infinite forwarding loop in resolver",
+ "(server/ns) invalid prefix",
+ "(server/ns) prefix table overflow",
+ "(server/ns) bad format for directory",
+ "(server/ns) unknown entry type",
+ "(server/ns) invalid generation",
+ "(server/ns) entry not reserved",
+};
+
+static char * err_codes_io[] = { /* 7 */
+ "(server/io) GENERIC ERROR",
+ "(server/io) invalid offset",
+ "(server/io) invalid size",
+ "(server/io) invalid mode",
+ "(server/io) invalid strategy",
+ "(server/io) operation rejected under current I/O strategy",
+};
+
+static char * err_codes_auth[] = { /* 8 */
+ "(server/auth) GENERIC ERROR",
+ "(server/auth) bad private port",
+ "(server/auth) bad name",
+ "(server/auth) not primary",
+ "(server/auth) bad pauthsword",
+ "(server/auth) bad group",
+ "(server/auth) duplicate id",
+ "(server/auth) duplicate name",
+ "(server/auth) not secondary",
+};
+
+static char * err_codes_us[] = { /* 9 */
+ "(server/us) GENERIC ERROR",
+ "(server/us) unknown error",
+ "(server/us) object not found",
+ "(server/us) object exists",
+ "(server/us) object busy",
+ "(server/us) object not started",
+ "(server/us) object dead",
+ "(server/us) invalid args",
+ "(server/us) invalid access",
+ "(server/us) invalid format",
+ "(server/us) invalid buffer size",
+ "(server/us) access denied",
+ "(server/us) resource exhausted",
+ "(server/us) quota exceeded",
+ "(server/us) limit exceeded",
+ "(server/us) not implemented",
+ "(server/us) not supported",
+ "(server/us) hardware error",
+ "(server/us) retry required",
+ "(server/us) not authenticated",
+ "(server/us) exclusive access",
+ "(server/us) timeout",
+ "(server/us) bad reference count",
+ "(server/us) internal error",
+};
+
+static char * err_codes_sunrpc[] = { /* 10 */
+ "(server/sunrpc) GENERIC ERROR",
+ "(server/sunrpc) cannot encode arguments",
+ "(server/sunrpc) cannot decode results",
+ "(server/sunrpc) failure in sending call",
+ "(server/sunrpc) failure in receiving result",
+ "(server/sunrpc) call timed out",
+ "(server/sunrpc) rpc versions not compatible",
+ "(server/sunrpc) authentication error",
+ "(server/sunrpc) program not available",
+ "(server/sunrpc) program version mismatched",
+ "(server/sunrpc) procedure unavailable",
+ "(server/sunrpc) decode arguments error",
+ "(server/sunrpc) generic other problem",
+ "(server/sunrpc) unknown host name",
+ "(server/sunrpc) portmapper failed",
+ "(server/sunrpc) remote program not registered",
+ "(server/sunrpc) unspecified error",
+ "(server/sunrpc) unknown protocol",
+};
+
+static char * err_codes_machobj[] = { /* 11 */
+ "(server/object system) GENERIC ERROR",
+ "(server/object system) object not found",
+ "(server/object system) no such operation",
+ "(server/object system) undefined ipc method arguments",
+ "(server/object system) too many arguments to method",
+ "(server/object system) bad ipc message format",
+};
+
+static char * err_codes_loader[] = { /* 12 */
+ "(server/loader) GENERIC ERROR",
+ "(server/loader) object file not relocated",
+ "(server/loader) unknown file type",
+ "(server/loader) symbol not found",
+ "(server/loader) symbol multiply defined",
+ "(server/loader) memory region overlap",
+};
+
+
+static char * err_codes_exception[] = { /* 13 */
+ "(server/exception) GENERIC ERROR",
+ "(server/exception) invalid access",
+ "(server/exception) invalid instruction",
+ "(server/exception) arithmetic exception",
+ "(server/exception) emulation exception",
+ "(server/exception) software exception",
+ "(server/exception) breakpoint exception",
+};
+
+static char * err_codes_ux_signal[] = { /* 14 */
+ "(server/unix-signal) GENERIC ERROR",
+ "(server/unix-signal) hangup",
+ "(server/unix-signal) interrupt",
+ "(server/unix-signal) quit",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) kill",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) undefined",
+ "(server/unix-signal) system error",
+ "(server/unix-signal) pipe signal",
+ "(server/unix-signal) alarm",
+ "(server/unix-signal) terminate",
+ "(server/unix-signal) urgent i/o",
+ "(server/unix-signal) stop",
+ "(server/unix-signal) terminal stop",
+ "(server/unix-signal) continue",
+ "(server/unix-signal) child death",
+ "(server/unix-signal) tty input",
+ "(server/unix-signal) tty output",
+ "(server/unix-signal) i/o signal",
+ "(server/unix-signal) cpu time limit exceeded",
+ "(server/unix-signal) file size exceeded",
+ "(server/unix-signal) virtual alarm",
+ "(server/unix-signal) profile signal",
+ "(server/unix-signal) window size change",
+ "(server/unix-signal) user-defined signal 1",
+ "(server/unix-signal) user-defined signal 2",
+};
+
+static char * err_codes_xkernel[] = { /* 15 */
+ "(server/xkernel) GENERIC ERROR",
+ "(server/xkernel) map full",
+ "(server/xkernel) inconsistent bind",
+ "(server/xkernel) cannot resolve",
+ "(server/xkernel) cannot unbind",
+ "(server/xkernel) invalid type",
+ "(server/xkernel) invalid opcode",
+ "(server/xkernel) buffer too small",
+ "(server/xkernel) invalid ev code",
+ "(server/xkernel) event not registered",
+ "(server/xkernel) invalid open",
+ "(server/xkernel) already open",
+ "(server/xkernel) bad addr",
+};
+
+
+/* err_server subsystems */
+static struct error_subsystem err_server_sub[] = {
+ /* server/0; */
+ {
+ "(server/netname)",
+ errlib_count(err_codes_netname),
+ err_codes_netname,
+ },
+ /* server/1; */
+ {
+ "(server/env_mgr)",
+ errlib_count(err_codes_env_mgr),
+ err_codes_env_mgr,
+ },
+ /* server/2; */
+ {
+ "(server/execd)",
+ errlib_count(err_codes_execd),
+ err_codes_execd,
+ },
+ /* server/3; */
+ {
+ "(server/netmemory)",
+ errlib_count(err_codes_netmemory),
+ err_codes_netmemory,
+ },
+ /* server/4; */
+ {
+ "(server/ufs)",
+ errlib_count(err_codes_ufs),
+ err_codes_ufs,
+ },
+ /* server/5; */
+ {
+ "(server/task_master)",
+ errlib_count(err_codes_task_master),
+ err_codes_task_master,
+ },
+ /* server/6; */
+ {
+ "(server/ns)",
+ errlib_count(err_codes_ns),
+ err_codes_ns,
+ },
+
+ /* server/7; i/o subsystem */
+ {
+ "(server/io)",
+ errlib_count(err_codes_io),
+ err_codes_io,
+ },
+
+ /* server/8; authentication server */
+ {
+ "(server/auth)",
+ errlib_count(err_codes_auth),
+ err_codes_auth,
+ },
+
+ /* server/9; generic US system */
+ {
+ "(server/us)",
+ errlib_count(err_codes_us),
+ err_codes_us,
+ },
+
+ /* server/10; SUN RPC package */
+ {
+ "(server/sunrpc)",
+ errlib_count(err_codes_sunrpc),
+ err_codes_sunrpc,
+ },
+
+ /* server/11; MachObject system */
+ {
+ "(server/object system)",
+ errlib_count(err_codes_machobj),
+ err_codes_machobj,
+ },
+
+ /* server/12; loader */
+ {
+ "(server/loader)",
+ errlib_count(err_codes_loader),
+ err_codes_loader,
+ },
+
+ /* server/13; mach exception */
+ {
+ "(server/exception)",
+ errlib_count(err_codes_exception),
+ err_codes_exception,
+ },
+
+ /* server/14; unix signal */
+ {
+ "(server/unix-signal)",
+ errlib_count(err_codes_ux_signal),
+ err_codes_ux_signal,
+ },
+
+ /* server/15; xkernel */
+ {
+ "(server/xkernel)",
+ errlib_count(err_codes_xkernel),
+ err_codes_xkernel,
+ },
+
+};
diff --git a/REORG.TODO/mach/err_us.sub b/REORG.TODO/mach/err_us.sub
new file mode 100644
index 0000000000..184f11d369
--- /dev/null
+++ b/REORG.TODO/mach/err_us.sub
@@ -0,0 +1,48 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * HISTORY
+ *
+ * Revision 2.2 92/01/16 00:10:45 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.2 91/03/27 16:06:06 mrt
+ * First checkin
+ *
+ */
+/*
+ * File: err_us.sub
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar, 1988
+ *
+ * A place to define User errors
+ */
+
+
+/* err_us subsystems */
+static struct error_subsystem err_us_sub[] = {
+ {0,0,0}
+};
diff --git a/REORG.TODO/mach/error_compat.c b/REORG.TODO/mach/error_compat.c
new file mode 100644
index 0000000000..8f7bd87c0f
--- /dev/null
+++ b/REORG.TODO/mach/error_compat.c
@@ -0,0 +1,67 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+
+/* This file was broken out from:
+
+ Revision 2.3 92/04/01 19:38:18 rpd
+
+ The static do_compat function is renamed to be globally accessible.
+ */
+
+#include <mach/error.h>
+#include <mach_error.h>
+#include <errorlib.h>
+
+
+void
+__mach_error_map_compat(mach_error_t *org_err)
+{
+ mach_error_t err = *org_err;
+
+ /*
+ * map old error numbers to
+ * to new error sys & subsystem
+ */
+
+ if ((-200 < err) && (err <= -100))
+ err = -(err + 100) | IPC_SEND_MOD;
+ else if ((-300 < err) && (err <= -200))
+ err = -(err + 200) | IPC_RCV_MOD;
+ else if ((-400 < err) && (err <= -300))
+ err = -(err + 300) | MACH_IPC_MIG_MOD;
+ else if ((1000 <= err) && (err < 1100))
+ err = (err - 1000) | SERV_NETNAME_MOD;
+ else if ((1600 <= err) && (err < 1700))
+ err = (err - 1600) | SERV_ENV_MOD;
+ else if ((27600 <= err) && (err < 27700))
+ err = (err - 27600) | SERV_EXECD_MOD;
+ else if ((2500 <= err) && (err < 2600))
+ err = (err - 2500) | KERN_DEVICE_MOD;
+ else if ((5000 <= err) && (err < 5100))
+ err = (err - 5000) | BOOTSTRAP_FS_MOD;
+
+ *org_err = err;
+}
diff --git a/REORG.TODO/mach/errorlib.h b/REORG.TODO/mach/errorlib.h
new file mode 100644
index 0000000000..ff0c55eb36
--- /dev/null
+++ b/REORG.TODO/mach/errorlib.h
@@ -0,0 +1,84 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.3 92/03/31 15:18:52 rpd
+ * Added KERN_DEVICE_MOD for device errors.
+ * [92/03/09 rpd]
+ *
+ * Revision 2.2 92/01/16 00:21:17 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.2 91/03/27 15:37:37 mrt
+ * First checkin
+ *
+ */
+/*
+ * File: errorlib.h
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar. 1988
+ *
+ * Error bases for subsytems errors.
+ */
+
+#include <mach/error.h>
+
+#define KERN_DEVICE_MOD (err_kern|err_sub(1))
+
+#define BOOTSTRAP_FS_MOD (err_bootstrap|err_sub(0))
+
+#define MACH_IPC_SEND_MOD (err_mach_ipc|err_sub(0))
+#define MACH_IPC_RCV_MOD (err_mach_ipc|err_sub(1))
+#define MACH_IPC_MIG_MOD (err_mach_ipc|err_sub(2))
+
+#define IPC_SEND_MOD (err_ipc|err_sub(0))
+#define IPC_RCV_MOD (err_ipc|err_sub(1))
+#define IPC_MIG_MOD (err_ipc|err_sub(2))
+
+#define SERV_NETNAME_MOD (err_server|err_sub(0))
+#define SERV_ENV_MOD (err_server|err_sub(1))
+#define SERV_EXECD_MOD (err_server|err_sub(2))
+
+
+#define NO_SUCH_ERROR "unknown error code"
+
+struct error_subsystem {
+ const char * subsys_name;
+ int max_code;
+ const char * const * codes;
+};
+
+struct error_system {
+ int max_sub;
+ const char * bad_sub;
+ const struct error_subsystem * subsystem;
+};
+
+#define errors __mach_error_systems
+extern const struct error_system errors[err_max_system+1];
+
+#define errlib_count(s) (sizeof(s)/sizeof(s[0]))
diff --git a/REORG.TODO/mach/errstring.c b/REORG.TODO/mach/errstring.c
new file mode 100644
index 0000000000..c00b02c2a6
--- /dev/null
+++ b/REORG.TODO/mach/errstring.c
@@ -0,0 +1,94 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.3 92/04/01 19:38:18 rpd
+ * Updated do_compat for kernel device errors,
+ * bootstrap file-system errors.
+ * [92/03/09 rpd]
+ *
+ * Revision 2.2 92/02/20 15:58:08 elf
+ * Created from mach_error.c.
+ * [92/02/11 rpd]
+ *
+ */
+
+#define EXPORT_BOOLEAN
+#include <mach/boolean.h>
+#include <mach/error.h>
+#include <mach_error.h>
+#include <errorlib.h>
+
+extern void __mach_error_map_compat (mach_error_t *);
+
+const char *
+mach_error_type(mach_error_t err)
+{
+ int sub, system;
+
+ __mach_error_map_compat( &err );
+
+ sub = err_get_sub(err);
+ system = err_get_system(err);
+
+ if (system > err_max_system
+ || sub >= errors[system].max_sub ) return( "(?/?)" );
+ return( errors[system].subsystem[sub].subsys_name );
+}
+
+boolean_t mach_error_full_diag = FALSE;
+
+const char *
+mach_error_string_int(mach_error_t err,
+ boolean_t * diag)
+{
+ int sub, system, code;
+
+ __mach_error_map_compat( &err );
+
+ sub = err_get_sub(err);
+ system = err_get_system(err);
+ code = err_get_code(err);
+
+ *diag = TRUE;
+
+ if (system > err_max_system) return( "(?/?) unknown error system" );
+ if (sub >= errors[system].max_sub) return( errors[system].bad_sub );
+ if (code >= errors[system].subsystem[sub].max_code) return ( NO_SUCH_ERROR );
+
+ *diag = mach_error_full_diag;
+ return( errors[system].subsystem[sub].codes[code] );
+}
+
+const char *
+mach_error_string(mach_error_t err)
+{
+ boolean_t diag;
+
+ return mach_error_string_int( err, &diag );
+
+}
diff --git a/REORG.TODO/mach/errsystems.awk b/REORG.TODO/mach/errsystems.awk
new file mode 100644
index 0000000000..a5e93604bc
--- /dev/null
+++ b/REORG.TODO/mach/errsystems.awk
@@ -0,0 +1,23 @@
+BEGIN {
+ print "#include <errno.h>";
+ print "#include <mach/error.h>";
+ print "#include <errorlib.h>";
+ print "#define static static const";
+ nsubs = split(subsys, subs);
+ while (nsubs > 0) printf "#include \"%s\"\n", subs[nsubs--];
+ print "\n\n\
+const struct error_system __mach_error_systems[err_max_system + 1] =";
+ print " {";
+}
+/^static.*err_[a-z0-9A-Z_]+_sub *\[/ {
+ s = $0; sub(/^.*err_/, "", s); sub(/_sub.*$/, "", s);
+ printf " [err_get_system (err_%s)] = { errlib_count (err_%s_sub),",
+ s, s;
+ printf "\"(system %s) error with unknown subsystem\", err_%s_sub },\n",
+ s, s;
+}
+END {
+ print " };";
+ print "\n\
+const int __mach_error_system_count = errlib_count (__mach_error_systems);";
+}
diff --git a/REORG.TODO/mach/lock-intern.h b/REORG.TODO/mach/lock-intern.h
new file mode 100644
index 0000000000..94f306d31a
--- /dev/null
+++ b/REORG.TODO/mach/lock-intern.h
@@ -0,0 +1,96 @@
+/* Copyright (C) 1994-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LOCK_INTERN_H
+#define _LOCK_INTERN_H
+
+#include <sys/cdefs.h>
+#include <machine-lock.h>
+
+#ifndef _EXTERN_INLINE
+#define _EXTERN_INLINE __extern_inline
+#endif
+
+
+/* Initialize LOCK. */
+
+_EXTERN_INLINE void
+__spin_lock_init (__spin_lock_t *__lock)
+{
+ *__lock = __SPIN_LOCK_INITIALIZER;
+}
+
+
+/* Lock LOCK, blocking if we can't get it. */
+extern void __spin_lock_solid (__spin_lock_t *__lock);
+
+/* Lock the spin lock LOCK. */
+
+_EXTERN_INLINE void
+__spin_lock (__spin_lock_t *__lock)
+{
+ if (! __spin_try_lock (__lock))
+ __spin_lock_solid (__lock);
+}
+
+/* Name space-clean internal interface to mutex locks.
+
+ Code internal to the C library uses these functions to lock and unlock
+ mutex locks. These locks are of type `struct mutex', defined in
+ <cthreads.h>. The functions here are name space-clean. If the program
+ is linked with the cthreads library, `__mutex_lock_solid' and
+ `__mutex_unlock_solid' will invoke the corresponding cthreads functions
+ to implement real mutex locks. If not, simple stub versions just use
+ spin locks. */
+
+
+/* Initialize the newly allocated mutex lock LOCK for further use. */
+extern void __mutex_init (void *__lock);
+
+/* Lock LOCK, blocking if we can't get it. */
+extern void __mutex_lock_solid (void *__lock);
+
+/* Finish unlocking LOCK, after the spin lock LOCK->held has already been
+ unlocked. This function will wake up any thread waiting on LOCK. */
+extern void __mutex_unlock_solid (void *__lock);
+
+/* Lock the mutex lock LOCK. */
+
+_EXTERN_INLINE void
+__mutex_lock (void *__lock)
+{
+ if (! __spin_try_lock ((__spin_lock_t *) __lock))
+ __mutex_lock_solid (__lock);
+}
+
+/* Unlock the mutex lock LOCK. */
+
+_EXTERN_INLINE void
+__mutex_unlock (void *__lock)
+{
+ __spin_unlock ((__spin_lock_t *) __lock);
+ __mutex_unlock_solid (__lock);
+}
+
+
+_EXTERN_INLINE int
+__mutex_trylock (void *__lock)
+{
+ return __spin_try_lock ((__spin_lock_t *) __lock);
+}
+
+#endif /* lock-intern.h */
diff --git a/REORG.TODO/mach/mach.h b/REORG.TODO/mach/mach.h
new file mode 100644
index 0000000000..42605af865
--- /dev/null
+++ b/REORG.TODO/mach/mach.h
@@ -0,0 +1,100 @@
+/* Standard header for all Mach programs.
+ Copyright (C) 1993-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _MACH_H
+
+#define _MACH_H 1
+
+#include <features.h>
+
+/* Get the basic types used by Mach. */
+#include <mach/mach_types.h>
+
+/* This declares the basic variables and macros everything needs. */
+#include <mach_init.h>
+
+/* This declares all the real system call functions. */
+#include <mach/mach_traps.h>
+
+/* These are MiG-generated headers for the kernel interfaces commonly used. */
+#include <mach/mach_interface.h> /* From <mach/mach.defs>. */
+#include <mach/mach_port.h>
+#include <mach/mach_host.h>
+
+/* For the kernel RPCs which have system call shortcut versions,
+ the MiG-generated header in fact declares `CALL_rpc' rather than `CALL'.
+ This file declares the simple `CALL' functions. */
+#include <mach-shortcuts.h>
+
+
+/* Receive RPC request messages on RCV_NAME and pass them to DEMUX, which
+ decodes them and produces reply messages. MAX_SIZE is the maximum size
+ (in bytes) of the request and reply buffers. */
+extern mach_msg_return_t
+__mach_msg_server (boolean_t (*__demux) (mach_msg_header_t *__request,
+ mach_msg_header_t *__reply),
+ mach_msg_size_t __max_size,
+ mach_port_t __rcv_name),
+mach_msg_server (boolean_t (*__demux) (mach_msg_header_t *__request,
+ mach_msg_header_t *__reply),
+ mach_msg_size_t __max_size,
+ mach_port_t __rcv_name);
+
+/* Just like `mach_msg_server', but the OPTION and TIMEOUT parameters are
+ passed on to `mach_msg'. */
+extern mach_msg_return_t
+__mach_msg_server_timeout (boolean_t (*__demux) (mach_msg_header_t *__request,
+ mach_msg_header_t *__reply),
+ mach_msg_size_t __max_size,
+ mach_port_t __rcv_name,
+ mach_msg_option_t __option,
+ mach_msg_timeout_t __timeout),
+mach_msg_server_timeout (boolean_t (*__demux) (mach_msg_header_t *__request,
+ mach_msg_header_t *__reply),
+ mach_msg_size_t __max_size,
+ mach_port_t __rcv_name,
+ mach_msg_option_t __option,
+ mach_msg_timeout_t __timeout);
+
+
+/* Deallocate all port rights and out-of-line memory in MSG. */
+extern void
+__mach_msg_destroy (mach_msg_header_t *msg),
+mach_msg_destroy (mach_msg_header_t *msg);
+
+#include <bits/types/FILE.h>
+
+/* Open a stream on a Mach device. */
+extern FILE *mach_open_devstream (mach_port_t device_port, const char *mode);
+
+/* Give THREAD a stack and set it to run at PC when resumed.
+ If *STACK_SIZE is nonzero, that size of stack is allocated.
+ If *STACK_BASE is nonzero, that stack location is used.
+ If STACK_BASE is not null it is filled in with the chosen stack base.
+ If STACK_SIZE is not null it is filled in with the chosen stack size.
+ Regardless, an extra page of red zone is allocated off the end; this
+ is not included in *STACK_SIZE. */
+kern_return_t __mach_setup_thread (task_t task, thread_t thread, void *pc,
+ vm_address_t *stack_base,
+ vm_size_t *stack_size);
+kern_return_t mach_setup_thread (task_t task, thread_t thread, void *pc,
+ vm_address_t *stack_base,
+ vm_size_t *stack_size);
+
+
+#endif /* mach.h */
diff --git a/REORG.TODO/mach/mach/error.h b/REORG.TODO/mach/mach/error.h
new file mode 100644
index 0000000000..084d8afd37
--- /dev/null
+++ b/REORG.TODO/mach/mach/error.h
@@ -0,0 +1,137 @@
+/* err_hurd added by roland@gnu.ai.mit.edu for GNU Hurd.
+ *
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.6 93/01/14 17:41:31 danner
+ * Standardized include symbol name.
+ * [92/06/10 pds]
+ *
+ * Revision 2.5 92/03/31 15:18:11 rpd
+ * Added err_bootstrap for bootstrap errors.
+ * [92/03/09 rpd]
+ *
+ * Revision 2.4 91/05/14 16:51:24 mrt
+ * Correcting copyright
+ *
+ * Revision 2.3 91/02/05 17:31:48 mrt
+ * Changed to new Mach copyright
+ * [91/02/01 17:16:50 mrt]
+ *
+ * Revision 2.2 90/06/02 14:57:47 rpd
+ * Added err_mach_ipc for new IPC.
+ * [90/03/26 22:28:42 rpd]
+ *
+ * Revision 2.1 89/08/03 16:02:07 rwd
+ * Created.
+ *
+ * Revision 2.4 89/02/25 18:13:18 gm0w
+ * Changes for cleanup.
+ *
+ * Revision 2.3 89/02/07 00:51:57 mwyoung
+ * Relocated from sys/error.h
+ *
+ * Revision 2.2 88/10/18 00:37:31 mwyoung
+ * Added {system,sub and code}_emask
+ * [88/10/17 17:06:58 mrt]
+ *
+ * Added {system,sub and code}_emask
+ *
+ * 12-May-88 Mary Thompson (mrt) at Carnegie Mellon
+ * Changed mach_error_t from unsigned int to kern_return_t
+ * which is a 32 bit integer regardless of machine type.
+ * unsigned int was incompatible with old usages of mach_error.
+ *
+ * 10-May-88 Douglas Orr (dorr) at Carnegie-Mellon University
+ * Missing endif replaced
+ *
+ * 5-May-88 Mary Thompson (mrt) at Carnegie Mellon
+ * Changed typedef of mach_error_t from long to unsigned int
+ * to keep our Camelot users happy. Also moved the nonkernel
+ * function declarations from here to mach_error.h.
+ *
+ * 10-Feb-88 Douglas Orr (dorr) at Carnegie-Mellon University
+ * Created.
+ *
+ */
+/*
+ * File: mach/error.h
+ * Purpose:
+ * error module definitions
+ *
+ */
+
+#ifndef _MACH_ERROR_H_
+#define _MACH_ERROR_H_
+#include <mach/kern_return.h>
+
+/*
+ * error number layout as follows:
+ *
+ * hi lo
+ * | system(6) | subsystem(12) | code(14) |
+ */
+
+
+#define err_none (mach_error_t)0
+#define ERR_SUCCESS (mach_error_t)0
+#define ERR_ROUTINE_NIL (mach_error_fn_t)0
+
+
+#define err_system(x) (((x)&0x3f)<<26)
+#define err_sub(x) (((x)&0xfff)<<14)
+
+#define err_get_system(err) (((err)>>26)&0x3f)
+#define err_get_sub(err) (((err)>>14)&0xfff)
+#define err_get_code(err) ((err)&0x3fff)
+
+#define system_emask (err_system(0x3f))
+#define sub_emask (err_sub(0xfff))
+#define code_emask (0x3fff)
+
+
+/* major error systems */
+#define err_kern err_system(0x0) /* kernel */
+#define err_us err_system(0x1) /* user space library */
+#define err_server err_system(0x2) /* user space servers */
+#define err_ipc err_system(0x3) /* old ipc errors */
+#define err_mach_ipc err_system(0x4) /* mach-ipc errors */
+#define err_bootstrap err_system(0x5) /* bootstrap errors */
+#define err_hurd err_system(0x10) /* GNU Hurd server errors */
+#define err_local err_system(0x3e) /* user defined errors */
+#define err_ipc_compat err_system(0x3f) /* (compatibility) mach-ipc errors */
+
+#define err_max_system 0x3f
+
+
+/* unix errors get lumped into one subsystem */
+#define unix_err(errno) (err_kern|err_sub(3)|errno)
+
+typedef kern_return_t mach_error_t;
+/* typedef mach_error_t (* mach_error_fn_t)(); */
+
+#endif /* _MACH_ERROR_H_ */
diff --git a/REORG.TODO/mach/mach/mach.h b/REORG.TODO/mach/mach/mach.h
new file mode 100644
index 0000000000..826e7172a7
--- /dev/null
+++ b/REORG.TODO/mach/mach/mach.h
@@ -0,0 +1,3 @@
+/* Some old programs may expect to find <mach.h> in <mach/mach.h>. */
+
+#include <mach.h>
diff --git a/REORG.TODO/mach/mach/mach_traps.h b/REORG.TODO/mach/mach/mach_traps.h
new file mode 100644
index 0000000000..cd3d7b8924
--- /dev/null
+++ b/REORG.TODO/mach/mach/mach_traps.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 1994-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Declare the few Mach system calls (except mach_msg, in <mach/message.h>).
+ This does not include the kernel RPC shortcut calls (in <mach-shortcuts.h>).
+
+ This file omits the MACH_IPC_COMPAT functions. */
+
+#ifndef _MACH_MACH_TRAPS_H
+
+#define _MACH_MACH_TRAPS_H_ 1
+
+#include <mach/port.h>
+#include <mach/message.h> /* mach_msg_timeout_t */
+#include <mach/kern_return.h>
+
+/* Create and return a new receive right. */
+extern mach_port_t mach_reply_port (void);
+extern mach_port_t __mach_reply_port (void);
+
+/* Return the thread control port for the calling thread. */
+extern mach_port_t mach_thread_self (void);
+extern mach_port_t __mach_thread_self (void);
+
+/* Return the task control port for the calling task.
+ The parens are needed to protect against the macro in <mach_init.h>. */
+extern mach_port_t (mach_task_self) (void);
+extern mach_port_t (__mach_task_self) (void);
+
+/* Return the host information port for the host of the calling task.
+ The parens are needed to protect against the macro in <mach_init.h>. */
+extern mach_port_t (mach_host_self) (void);
+extern mach_port_t (__mach_host_self) (void);
+
+/* Attempt to context switch the current thread off the processor. Returns
+ true if there are other threads that can be run and false if not. */
+extern boolean_t swtch (void);
+extern boolean_t __swtch (void);
+
+/* Attempt to context switch the current thread off the processor. Lower
+ the thread's priority as much as possible. The thread's priority will
+ be restored when it runs again. PRIORITY is currently unused. Return
+ true if there are other threads that can be run and false if not. */
+extern boolean_t swtch_pri (int priority);
+extern boolean_t __swtch_pri (int priority);
+
+/* Attempt to context switch the current thread off the processor. Try
+ to run NEW_THREAD next, ignoring normal scheduling policies. The
+ OPTION value comes from <mach/thread_switch.h>. If OPTION is
+ SWITCH_OPTION_WAIT, then block the current thread for TIME
+ milliseconds. If OPTION is SWITCH_OPTION_DEPRESS, then block for
+ TIME milliseconds and depress the thread's priority as done by
+ swtch_pri. If OPTION is SWITCH_OPTION_NONE, ignore TIME. */
+kern_return_t thread_switch (mach_port_t new_thread,
+ int option, mach_msg_timeout_t option_time);
+kern_return_t __thread_switch (mach_port_t new_thread,
+ int option, mach_msg_timeout_t option_time);
+
+/* Block the current thread until the kernel (or device) event
+ identified by EVENT occurs. */
+kern_return_t evc_wait (unsigned int event);
+kern_return_t __evc_wait (unsigned int event);
+
+/* Display a null-terminated character string on the Mach console. This
+ system call is meant as a debugging tool useful to circumvent messaging
+ altogether. */
+
+extern void mach_print(const char *s);
+
+#endif /* mach/mach_traps.h */
diff --git a/REORG.TODO/mach/mach/mig_support.h b/REORG.TODO/mach/mach/mig_support.h
new file mode 100644
index 0000000000..7300d7996b
--- /dev/null
+++ b/REORG.TODO/mach/mach/mig_support.h
@@ -0,0 +1,82 @@
+/* Copyright (C) 1993-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Useful declarations and support functions for MiG-generated stubs. */
+
+#ifndef _MACH_MIG_SUPPORT_H
+
+#define _MACH_MIG_SUPPORT_H 1
+
+#include <mach/std_types.h>
+#include <mach/message.h>
+#include <sys/types.h>
+#include <string.h>
+
+#ifndef __USE_GNU
+/* The only problem that has come up so far is __stpncpy being undeclared
+ below because <string.h> doesn't declare it without __USE_GNU. We could
+ work around that problem by just adding the declaration there, or by
+ eliding the inline functions in the absence of __USE_GNU. But either of
+ these would result in unoptimized calls (because no inline version of
+ __stpncpy will have been defined), and there may be other niggling
+ problems lurking. Instead we simply insist on _GNU_SOURCE for
+ compiling mig output; anyway, that better reflects the fact that mig
+ output requires nonstandard special support code not found elsewhere. */
+# error mig stubs must be compiled with -D_GNU_SOURCE
+#endif
+
+/* MiG initialization. */
+extern void __mig_init (void *__first);
+extern void mig_init (void *__first);
+
+/* Shorthand functions for vm_allocate and vm_deallocate on
+ mach_task_self () (and with ANYWHERE=1). */
+extern void __mig_allocate (vm_address_t *__addr_p, vm_size_t __size);
+extern void mig_allocate (vm_address_t *__addr_p, vm_size_t __size);
+extern void __mig_deallocate (vm_address_t __addr, vm_size_t __size);
+extern void mig_deallocate (vm_address_t __addr, vm_size_t __size);
+
+/* Reply-port management support functions. */
+extern void __mig_dealloc_reply_port (mach_port_t);
+extern void mig_dealloc_reply_port (mach_port_t);
+extern mach_port_t __mig_get_reply_port (void);
+extern mach_port_t mig_get_reply_port (void);
+extern void __mig_put_reply_port (mach_port_t);
+extern void mig_put_reply_port (mach_port_t);
+
+extern void __mig_reply_setup (const mach_msg_header_t *__request,
+ mach_msg_header_t *__reply);
+extern void mig_reply_setup (const mach_msg_header_t *__request,
+ mach_msg_header_t *__reply);
+
+/* Idiocy support function. */
+extern vm_size_t mig_strncpy (char *__dst, const char *__src, vm_size_t __len);
+extern vm_size_t __mig_strncpy (char *__dst, const char *__src, vm_size_t);
+__extern_inline vm_size_t
+__mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
+{
+ return __stpncpy (__dst, __src, __len) - __dst;
+}
+__extern_inline vm_size_t
+mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
+{
+ return __mig_strncpy (__dst, __src, __len);
+}
+
+
+
+#endif /* mach/mig_support.h */
diff --git a/REORG.TODO/mach/mach_error.c b/REORG.TODO/mach/mach_error.c
new file mode 100644
index 0000000000..0d3082d021
--- /dev/null
+++ b/REORG.TODO/mach/mach_error.c
@@ -0,0 +1,80 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.4 92/02/19 15:10:52 elf
+ * Moved mach_error_string and mach_error_type to mach_error_string.c.
+ * [92/02/11 rpd]
+ *
+ * Revision 2.3 92/01/23 15:22:06 rpd
+ * Changed <servers/errorlib.h> to <errorlib.h>.
+ * [92/01/16 rpd]
+ *
+ * Revision 2.2 92/01/16 00:08:03 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.3 91/08/29 15:51:50 rpd
+ * Changed IPC_MIG_MOD to MACH_IPC_MIG_MOD, to get the new error strings.
+ * [91/08/22 rpd]
+ *
+ * Revision 2.2 91/03/27 16:06:29 mrt
+ * Changed include of "errorlib.h" to <servers/errorlib.h>
+ * Added new copyright
+ * [91/03/20 mrt]
+ *
+ */
+/*
+ * File: mach_error.c
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar 1988
+ *
+ * interprets structured mach error codes and prints
+ * or returns a descriptive string.
+ */
+
+#include <stdio.h>
+#include <mach_error.h>
+#include <mach/boolean.h>
+
+extern char * mach_error_string_int(mach_error_t, boolean_t *);
+
+void
+mach_error(char *str, mach_error_t err)
+{
+ char * err_str;
+ char buf[1024];
+ boolean_t diag;
+
+ err_str=mach_error_string_int(err, &diag);
+
+ if ( diag ) {
+ sprintf( buf, "%s %s (%x)", mach_error_type(err), err_str, err );
+ err_str = buf;
+ }
+
+ fprintf(stderr, "%s %s\n", str, err_str);
+}
diff --git a/REORG.TODO/mach/mach_error.h b/REORG.TODO/mach/mach_error.h
new file mode 100644
index 0000000000..fc4a3fed7e
--- /dev/null
+++ b/REORG.TODO/mach/mach_error.h
@@ -0,0 +1,71 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.2 92/01/16 00:08:10 rpd
+ * Moved from user collection to mk collection.
+ *
+ * Revision 2.2 91/03/27 15:39:13 mrt
+ * First checkin
+ *
+ */
+/*
+ * File: mach_error.h
+ * Author: Douglas Orr, Carnegie Mellon University
+ * Date: Mar. 1988
+ *
+ * Definitions of routines in mach_error.c
+ */
+
+#ifndef _MACH_ERROR_
+#define _MACH_ERROR_ 1
+
+#include <mach/error.h>
+
+const char *mach_error_string(
+/*
+ * Returns a string appropriate to the error argument given
+ */
+ mach_error_t error_value
+ );
+
+void mach_error(
+/*
+ * Prints an appropriate message on the standard error stream
+ */
+ char *str,
+ mach_error_t error_value
+ );
+
+const char *mach_error_type(
+/*
+ * Returns a string with the error system, subsystem and code
+*/
+ mach_error_t error_value
+ );
+
+#endif /* _MACH_ERROR_ */
diff --git a/REORG.TODO/mach/mach_init.c b/REORG.TODO/mach/mach_init.c
new file mode 100644
index 0000000000..75eb218d01
--- /dev/null
+++ b/REORG.TODO/mach/mach_init.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <mach.h>
+#include <mach/mig_support.h>
+#include <unistd.h>
+
+mach_port_t __mach_task_self_;
+mach_port_t __mach_host_self_;
+vm_size_t __vm_page_size = 0; /* Must be data not bss for weak alias. */
+weak_alias (__vm_page_size, vm_page_size)
+
+#ifdef NDR_DEF_HEADER
+/* This defines NDR_record, which the MiG-generated stubs use. XXX namespace */
+# include NDR_DEF_HEADER
+#endif
+
+void
+__mach_init (void)
+{
+ kern_return_t err;
+
+ __mach_task_self_ = (__mach_task_self) ();
+ __mach_host_self_ = (__mach_host_self) ();
+ __mig_init (0);
+
+#ifdef HAVE_HOST_PAGE_SIZE
+ if (err = __host_page_size (__mach_host_self (), &__vm_page_size))
+ _exit (err);
+#else
+ {
+ vm_statistics_data_t stats;
+ if (err = __vm_statistics (__mach_task_self (), &stats))
+ _exit (err);
+ __vm_page_size = stats.pagesize;
+ }
+#endif
+}
+weak_alias (__mach_init, mach_init)
diff --git a/REORG.TODO/mach/mach_init.h b/REORG.TODO/mach/mach_init.h
new file mode 100644
index 0000000000..7e1bc42c68
--- /dev/null
+++ b/REORG.TODO/mach/mach_init.h
@@ -0,0 +1,52 @@
+/* Declarations and macros for the basic Mach things set at startup.
+ Copyright (C) 1993-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _MACH_INIT_H
+
+#define _MACH_INIT_H 1
+
+#include <mach/mach_types.h>
+
+/* Return the current task's task port. */
+extern mach_port_t __mach_task_self (void);
+extern mach_port_t mach_task_self (void);
+
+/* This cache is initialized at startup. */
+extern mach_port_t __mach_task_self_;
+#define __mach_task_self() (__mach_task_self_ + 0) /* Not an lvalue. */
+#define mach_task_self() (__mach_task_self ())
+
+/* This cache is initialized at startup. */
+extern mach_port_t __mach_host_self_;
+#define __mach_host_self() (__mach_host_self_ + 0) /* Not an lvalue. */
+#define mach_host_self() (__mach_host_self ())
+
+/* Kernel page size. */
+extern vm_size_t __vm_page_size;
+extern vm_size_t vm_page_size;
+
+/* Round the address X up to a page boundary. */
+#define round_page(x) \
+ ((((vm_offset_t) (x) + __vm_page_size - 1) / __vm_page_size) * \
+ __vm_page_size)
+
+/* Truncate the address X down to a page boundary. */
+#define trunc_page(x) \
+ ((((vm_offset_t) (x)) / __vm_page_size) * __vm_page_size)
+
+#endif /* mach_init.h */
diff --git a/REORG.TODO/mach/mig-alloc.c b/REORG.TODO/mach/mig-alloc.c
new file mode 100644
index 0000000000..73a23be3aa
--- /dev/null
+++ b/REORG.TODO/mach/mig-alloc.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <mach.h>
+
+/* Called by MiG to allocate space. */
+void
+__mig_allocate (vm_address_t *addr,
+ vm_size_t size)
+{
+ if (__vm_allocate (__mach_task_self (), addr, size, 1) != KERN_SUCCESS)
+ *addr = 0;
+}
+
+weak_alias (__mig_allocate, mig_allocate)
diff --git a/REORG.TODO/mach/mig-dealloc.c b/REORG.TODO/mach/mig-dealloc.c
new file mode 100644
index 0000000000..ba6452fea1
--- /dev/null
+++ b/REORG.TODO/mach/mig-dealloc.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <mach.h>
+
+/* Called by MiG to deallocate space. */
+void
+__mig_deallocate (vm_address_t addr,
+ vm_size_t size)
+{
+ (void) __vm_deallocate (__mach_task_self (), addr, size);
+}
+weak_alias (__mig_deallocate, mig_deallocate)
diff --git a/REORG.TODO/mach/mig-reply.c b/REORG.TODO/mach/mig-reply.c
new file mode 100644
index 0000000000..fa53216635
--- /dev/null
+++ b/REORG.TODO/mach/mig-reply.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <mach.h>
+
+/* These functions are called by MiG-generated code. */
+
+static mach_port_t reply_port;
+
+/* Called by MiG to get a reply port. */
+mach_port_t
+__mig_get_reply_port (void)
+{
+ if (reply_port == MACH_PORT_NULL)
+ reply_port = __mach_reply_port ();
+
+ return reply_port;
+}
+
+/* Called by MiG to deallocate the reply port. */
+void
+__mig_dealloc_reply_port (void)
+{
+ mach_port_t port = reply_port;
+ reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */
+ __mach_port_mod_refs (__mach_task_self (), port,
+ MACH_PORT_RIGHT_RECEIVE, -1);
+}
+
+
+/* Called at startup with CPROC == NULL. cthreads has a different version
+ of this function that is sometimes called with a `cproc_t' pointer. */
+void
+__mig_init (void *cproc)
+{
+ if (cproc == 0)
+ reply_port = MACH_PORT_NULL;
+}
diff --git a/REORG.TODO/mach/mig_strncpy.c b/REORG.TODO/mach/mig_strncpy.c
new file mode 100644
index 0000000000..b0c001d775
--- /dev/null
+++ b/REORG.TODO/mach/mig_strncpy.c
@@ -0,0 +1,11 @@
+/* Silly pointless function MiG needs. */
+
+#include <mach.h>
+#include <string.h>
+
+vm_size_t
+__mig_strncpy (char *dst, const char *src, vm_size_t len)
+{
+ return __stpncpy (dst, src, len) - dst;
+}
+weak_alias (__mig_strncpy, mig_strncpy)
diff --git a/REORG.TODO/mach/msg-destroy.c b/REORG.TODO/mach/msg-destroy.c
new file mode 100644
index 0000000000..bc7dd558e9
--- /dev/null
+++ b/REORG.TODO/mach/msg-destroy.c
@@ -0,0 +1,231 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.4 91/05/14 17:53:15 mrt
+ * Correcting copyright
+ *
+ * Revision 2.3 91/02/14 14:17:43 mrt
+ * Added new Mach copyright
+ * [91/02/13 12:44:15 mrt]
+ *
+ * Revision 2.2 90/08/06 17:24:22 rpd
+ * Created.
+ *
+ */
+
+#if 1
+#include <mach.h>
+#else
+/* This is what CMU did, but that fails to declare some used functions. */
+#include <mach/port.h>
+#include <mach/message.h>
+#include <mach_init.h>
+#endif
+
+static void mach_msg_destroy_port(mach_port_t, mach_msg_type_name_t);
+static void mach_msg_destroy_memory(vm_offset_t, vm_size_t);
+
+/*
+ * Routine: mach_msg_destroy
+ * Purpose:
+ * Deallocates all port rights and out-of-line memory
+ * found in a received message.
+ */
+
+void
+__mach_msg_destroy (mach_msg_header_t *msg)
+{
+ mach_msg_bits_t mbits = msg->msgh_bits;
+
+ /*
+ * The msgh_local_port field doesn't hold a port right.
+ * The receive operation consumes the destination port right.
+ */
+
+ mach_msg_destroy_port(msg->msgh_remote_port, MACH_MSGH_BITS_REMOTE(mbits));
+
+ if (mbits & MACH_MSGH_BITS_COMPLEX) {
+#ifdef MACH_MSG_PORT_DESCRIPTOR
+ mach_msg_body_t *body;
+ mach_msg_descriptor_t *saddr, *eaddr;
+
+ body = (mach_msg_body_t *) (msg + 1);
+ saddr = (mach_msg_descriptor_t *)
+ ((mach_msg_base_t *) msg + 1);
+ eaddr = saddr + body->msgh_descriptor_count;
+
+ for ( ; saddr < eaddr; saddr++) {
+ switch (saddr->type.type) {
+
+ case MACH_MSG_PORT_DESCRIPTOR: {
+ mach_msg_port_descriptor_t *dsc;
+
+ /*
+ * Destroy port rights carried in the message
+ */
+ dsc = &saddr->port;
+ mach_msg_destroy_port(dsc->name, dsc->disposition);
+ break;
+ }
+
+ case MACH_MSG_OOL_DESCRIPTOR : {
+ mach_msg_ool_descriptor_t *dsc;
+
+ /*
+ * Destroy memory carried in the message
+ */
+ dsc = &saddr->out_of_line;
+ if (dsc->deallocate) {
+ mach_msg_destroy_memory((vm_offset_t)dsc->address,
+ dsc->size);
+ }
+ break;
+ }
+
+ case MACH_MSG_OOL_PORTS_DESCRIPTOR : {
+ mach_port_t *ports;
+ mach_msg_ool_ports_descriptor_t *dsc;
+ mach_msg_type_number_t j;
+
+ /*
+ * Destroy port rights carried in the message
+ */
+ dsc = &saddr->ool_ports;
+ ports = (mach_port_t *) dsc->address;
+ for (j = 0; j < dsc->count; j++, ports++) {
+ mach_msg_destroy_port(*ports, dsc->disposition);
+ }
+
+ /*
+ * Destroy memory carried in the message
+ */
+ if (dsc->deallocate) {
+ mach_msg_destroy_memory((vm_offset_t)dsc->address,
+ dsc->count * sizeof(mach_port_t));
+ }
+ break;
+ }
+ }
+ }
+#else
+ vm_offset_t saddr;
+ vm_offset_t eaddr;
+
+ saddr = (vm_offset_t) (msg + 1);
+ eaddr = (vm_offset_t) msg + msg->msgh_size;
+
+ while (saddr < eaddr) {
+ mach_msg_type_long_t *type;
+ mach_msg_type_name_t name;
+ mach_msg_type_size_t size;
+ mach_msg_type_number_t number;
+ boolean_t is_inline;
+ vm_size_t length;
+ vm_offset_t addr;
+
+ type = (mach_msg_type_long_t *) saddr;
+ is_inline = type->msgtl_header.msgt_inline;
+ if (type->msgtl_header.msgt_longform) {
+ name = type->msgtl_name;
+ size = type->msgtl_size;
+ number = type->msgtl_number;
+ saddr += sizeof(mach_msg_type_long_t);
+ } else {
+ name = type->msgtl_header.msgt_name;
+ size = type->msgtl_header.msgt_size;
+ number = type->msgtl_header.msgt_number;
+ saddr += sizeof(mach_msg_type_t);
+ }
+
+ /* calculate length of data in bytes, rounding up */
+ length = (((((number * size) + 7) >> 3) + sizeof (int) - 1)
+ &~ (sizeof (int) - 1));
+
+ addr = is_inline ? saddr : * (vm_offset_t *) saddr;
+
+ if (MACH_MSG_TYPE_PORT_ANY(name)) {
+ mach_port_t *ports = (mach_port_t *) addr;
+ mach_msg_type_number_t i;
+
+ for (i = 0; i < number; i++)
+ mach_msg_destroy_port(*ports++, name);
+ }
+
+ if (is_inline) {
+ /* inline data sizes round up to int boundaries */
+ saddr += length;
+ } else {
+ mach_msg_destroy_memory(addr, length);
+ saddr += sizeof(vm_offset_t);
+ }
+ }
+#endif
+ }
+}
+
+weak_alias (__mach_msg_destroy, mach_msg_destroy)
+
+static void
+mach_msg_destroy_port (mach_port_t port, mach_msg_type_name_t type)
+{
+ if (MACH_PORT_VALID(port)) switch (type) {
+ case MACH_MSG_TYPE_MOVE_SEND:
+ case MACH_MSG_TYPE_MOVE_SEND_ONCE:
+ /* destroy the send/send-once right */
+ (void) __mach_port_deallocate(mach_task_self(), port);
+ break;
+
+ case MACH_MSG_TYPE_MOVE_RECEIVE:
+ /* destroy the receive right */
+ (void) __mach_port_mod_refs(mach_task_self(), port,
+ MACH_PORT_RIGHT_RECEIVE, -1);
+ break;
+
+ case MACH_MSG_TYPE_MAKE_SEND:
+ /* create a send right and then destroy it */
+ (void) __mach_port_insert_right(mach_task_self(), port,
+ port, MACH_MSG_TYPE_MAKE_SEND);
+ (void) __mach_port_deallocate(mach_task_self(), port);
+ break;
+
+ case MACH_MSG_TYPE_MAKE_SEND_ONCE:
+ /* create a send-once right and then destroy it */
+ (void) __mach_port_extract_right(mach_task_self(), port,
+ MACH_MSG_TYPE_MAKE_SEND_ONCE,
+ &port, &type);
+ (void) __mach_port_deallocate(mach_task_self(), port);
+ break;
+ }
+}
+
+static void
+mach_msg_destroy_memory (vm_offset_t addr, vm_size_t size)
+{
+ if (size > 0)
+ (void) __vm_deallocate(__mach_task_self(), addr, size);
+}
diff --git a/REORG.TODO/mach/msg.c b/REORG.TODO/mach/msg.c
new file mode 100644
index 0000000000..bccad7fd26
--- /dev/null
+++ b/REORG.TODO/mach/msg.c
@@ -0,0 +1,145 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+#include <mach/port.h>
+#include <mach/message.h>
+
+#ifdef MACH_MSG_OVERWRITE
+/* In variants with this feature, the actual system call is
+ __mach_msg_overwrite_trap. */
+mach_msg_return_t
+__mach_msg_trap (mach_msg_header_t *msg,
+ mach_msg_option_t option,
+ mach_msg_size_t send_size,
+ mach_msg_size_t rcv_size,
+ mach_port_t rcv_name,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify)
+{
+ return __mach_msg_overwrite_trap (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify,
+ MACH_MSG_NULL, 0);
+}
+weak_alias (__mach_msg_trap, mach_msg_trap)
+
+/* See comments below in __mach_msg. */
+mach_msg_return_t
+__mach_msg_overwrite (mach_msg_header_t *msg,
+ mach_msg_option_t option,
+ mach_msg_size_t send_size,
+ mach_msg_size_t rcv_size,
+ mach_port_t rcv_name,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify,
+ mach_msg_header_t *rcv_msg,
+ mach_msg_size_t rcv_msg_size)
+
+{
+ mach_msg_return_t ret;
+
+ /* Consider the following cases:
+ 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
+ plus special bits).
+ 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
+ 3. RPC calls with interruptions in one/both halves.
+ */
+
+ ret = __mach_msg_overwrite_trap (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify,
+ rcv_msg, rcv_msg_size);
+ if (ret == MACH_MSG_SUCCESS)
+ return MACH_MSG_SUCCESS;
+
+ if (!(option & MACH_SEND_INTERRUPT))
+ while (ret == MACH_SEND_INTERRUPTED)
+ ret = __mach_msg_overwrite_trap (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify,
+ rcv_msg, rcv_msg_size);
+
+ if (!(option & MACH_RCV_INTERRUPT))
+ while (ret == MACH_RCV_INTERRUPTED)
+ ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
+ 0, rcv_size, rcv_name, timeout, notify,
+ rcv_msg, rcv_msg_size);
+
+ return ret;
+}
+weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
+#endif
+
+mach_msg_return_t
+__mach_msg (mach_msg_header_t *msg,
+ mach_msg_option_t option,
+ mach_msg_size_t send_size,
+ mach_msg_size_t rcv_size,
+ mach_port_t rcv_name,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify)
+{
+ mach_msg_return_t ret;
+
+ /* Consider the following cases:
+ 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
+ plus special bits).
+ 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
+ 3. RPC calls with interruptions in one/both halves.
+ */
+
+ ret = __mach_msg_trap (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify);
+ if (ret == MACH_MSG_SUCCESS)
+ return MACH_MSG_SUCCESS;
+
+ if (!(option & MACH_SEND_INTERRUPT))
+ while (ret == MACH_SEND_INTERRUPTED)
+ ret = __mach_msg_trap (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify);
+
+ if (!(option & MACH_RCV_INTERRUPT))
+ while (ret == MACH_RCV_INTERRUPTED)
+ ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
+ 0, rcv_size, rcv_name, timeout, notify);
+
+ return ret;
+}
+weak_alias (__mach_msg, mach_msg)
+
+mach_msg_return_t
+__mach_msg_send (mach_msg_header_t *msg)
+{
+ return __mach_msg (msg, MACH_SEND_MSG,
+ msg->msgh_size, 0, MACH_PORT_NULL,
+ MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+}
+weak_alias (__mach_msg_send, mach_msg_send)
+
+mach_msg_return_t
+__mach_msg_receive (mach_msg_header_t *msg)
+{
+ return __mach_msg (msg, MACH_RCV_MSG,
+ 0, msg->msgh_size, msg->msgh_local_port,
+ MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+}
+weak_alias (__mach_msg_receive, mach_msg_receive)
diff --git a/REORG.TODO/mach/msgserver.c b/REORG.TODO/mach/msgserver.c
new file mode 100644
index 0000000000..d95e545985
--- /dev/null
+++ b/REORG.TODO/mach/msgserver.c
@@ -0,0 +1,199 @@
+/* Copyright (C) 1993-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Based on CMU's mach_msg_server.c revision 2.4 of 91/05/14, and thus
+ under the following copyright. Rewritten by Roland McGrath (FSF)
+ 93/12/06 to use stack space instead of malloc, and to handle
+ large messages with MACH_RCV_LARGE. */
+
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * (pre-GNU) HISTORY
+ *
+ * Revision 2.4 91/05/14 17:53:22 mrt
+ * Correcting copyright
+ *
+ * Revision 2.3 91/02/14 14:17:47 mrt
+ * Added new Mach copyright
+ * [91/02/13 12:44:20 mrt]
+ *
+ * Revision 2.2 90/08/06 17:23:58 rpd
+ * Created.
+ *
+ */
+
+
+#include <mach.h>
+#include <mach/mig_errors.h>
+#include <stdlib.h> /* For malloc and free. */
+#include <assert.h>
+
+#ifdef NDR_CHAR_ASCII /* OSF Mach flavors have different names. */
+# define mig_reply_header_t mig_reply_error_t
+#endif
+
+mach_msg_return_t
+__mach_msg_server_timeout (boolean_t (*demux) (mach_msg_header_t *request,
+ mach_msg_header_t *reply),
+ mach_msg_size_t max_size,
+ mach_port_t rcv_name,
+ mach_msg_option_t option,
+ mach_msg_timeout_t timeout)
+{
+ mig_reply_header_t *request, *reply;
+ mach_msg_return_t mr;
+
+ if (max_size == 0)
+ {
+#ifdef MACH_RCV_LARGE
+ option |= MACH_RCV_LARGE;
+ max_size = 2 * __vm_page_size; /* Generic. Good? XXX */
+#else
+ max_size = 4 * __vm_page_size; /* XXX */
+#endif
+ }
+
+ request = __alloca (max_size);
+ reply = __alloca (max_size);
+
+ while (1)
+ {
+ get_request:
+ mr = __mach_msg (&request->Head, MACH_RCV_MSG|option,
+ 0, max_size, rcv_name,
+ timeout, MACH_PORT_NULL);
+ while (mr == MACH_MSG_SUCCESS)
+ {
+ /* We have a request message.
+ Pass it to DEMUX for processing. */
+
+ (void) (*demux) (&request->Head, &reply->Head);
+ assert (reply->Head.msgh_size <= max_size);
+
+ switch (reply->RetCode)
+ {
+ case KERN_SUCCESS:
+ /* Hunky dory. */
+ break;
+
+ case MIG_NO_REPLY:
+ /* The server function wanted no reply sent.
+ Loop for another request. */
+ goto get_request;
+
+ default:
+ /* Some error; destroy the request message to release any
+ port rights or VM it holds. Don't destroy the reply port
+ right, so we can send an error message. */
+ request->Head.msgh_remote_port = MACH_PORT_NULL;
+ __mach_msg_destroy (&request->Head);
+ break;
+ }
+
+ if (reply->Head.msgh_remote_port == MACH_PORT_NULL)
+ {
+ /* No reply port, so destroy the reply. */
+ if (reply->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)
+ __mach_msg_destroy (&reply->Head);
+ goto get_request;
+ }
+
+ /* Send the reply and the get next request. */
+
+ {
+ /* Swap the request and reply buffers. mach_msg will read the
+ reply message from the buffer we pass and write the new
+ request message to the same buffer. */
+ void *tmp = request;
+ request = reply;
+ reply = tmp;
+ }
+
+ mr = __mach_msg (&request->Head,
+ MACH_SEND_MSG|MACH_RCV_MSG|option,
+ request->Head.msgh_size, max_size, rcv_name,
+ timeout, MACH_PORT_NULL);
+ }
+
+ /* A message error occurred. */
+
+ switch (mr)
+ {
+ case MACH_RCV_TOO_LARGE:
+#ifdef MACH_RCV_LARGE
+ /* The request message is larger than MAX_SIZE, and has not
+ been dequeued. The message header has the actual size of
+ the message. We recurse here in hopes that the compiler
+ will optimize the tail-call and allocate some more stack
+ space instead of way too much. */
+ return __mach_msg_server_timeout (demux, request->Head.msgh_size,
+ rcv_name, option, timeout);
+#else
+ /* XXX the kernel has destroyed the msg */
+ break;
+#endif
+
+ case MACH_SEND_INVALID_DEST:
+ /* The reply can't be delivered, so destroy it. This error
+ indicates only that the requester went away, so we
+ continue and get the next request. */
+ __mach_msg_destroy (&request->Head);
+ break;
+
+ default:
+ /* Some other form of lossage; return to caller. */
+ return mr;
+ }
+ }
+}
+weak_alias (__mach_msg_server_timeout, mach_msg_server_timeout)
+
+mach_msg_return_t
+__mach_msg_server (boolean_t (*demux) (mach_msg_header_t *in,
+ mach_msg_header_t *out),
+ mach_msg_size_t max_size,
+ mach_port_t rcv_name)
+{
+ return __mach_msg_server_timeout (demux, max_size, rcv_name,
+ MACH_MSG_OPTION_NONE,
+ MACH_MSG_TIMEOUT_NONE);
+}
+weak_alias (__mach_msg_server, mach_msg_server)
diff --git a/REORG.TODO/mach/mutex-init.c b/REORG.TODO/mach/mutex-init.c
new file mode 100644
index 0000000000..ff184b1b7e
--- /dev/null
+++ b/REORG.TODO/mach/mutex-init.c
@@ -0,0 +1,29 @@
+/* Initialize a cthreads mutex structure.
+ Copyright (C) 1995-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <lock-intern.h>
+#include <cthreads.h>
+
+void
+__mutex_init (void *lock)
+{
+ /* This happens to be name space-safe because it is a macro.
+ It invokes only spin_lock_init, which is a macro for __spin_lock_init;
+ and cthread_queue_init, which is a macro for some simple code. */
+ mutex_init ((struct mutex *) lock);
+}
diff --git a/REORG.TODO/mach/mutex-solid.c b/REORG.TODO/mach/mutex-solid.c
new file mode 100644
index 0000000000..b1d75b2551
--- /dev/null
+++ b/REORG.TODO/mach/mutex-solid.c
@@ -0,0 +1,36 @@
+/* Stub versions of mutex_lock_solid/mutex_unlock_solid for no -lthreads.
+ Copyright (C) 1995-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <lock-intern.h>
+#include <cthreads.h>
+
+/* If cthreads is linked in, it will define these functions itself to do
+ real cthreads mutex locks. This file will only be linked in when
+ cthreads is not used, and `mutexes' are in fact just spin locks (and
+ some unused storage). */
+
+void
+__mutex_lock_solid (void *lock)
+{
+ __spin_lock_solid (lock);
+}
+
+void
+__mutex_unlock_solid (void *lock)
+{
+}
diff --git a/REORG.TODO/mach/setup-thread.c b/REORG.TODO/mach/setup-thread.c
new file mode 100644
index 0000000000..090d9086ad
--- /dev/null
+++ b/REORG.TODO/mach/setup-thread.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <mach.h>
+#include <thread_state.h>
+#include <string.h>
+#include <mach/machine/vm_param.h>
+#include "sysdep.h" /* Defines stack direction. */
+
+#define STACK_SIZE (16 * 1024 * 1024) /* 16MB, arbitrary. */
+
+/* Give THREAD a stack and set it to run at PC when resumed.
+ If *STACK_SIZE is nonzero, that size of stack is allocated.
+ If *STACK_BASE is nonzero, that stack location is used.
+ If STACK_BASE is not null it is filled in with the chosen stack base.
+ If STACK_SIZE is not null it is filled in with the chosen stack size.
+ Regardless, an extra page of red zone is allocated off the end; this
+ is not included in *STACK_SIZE. */
+
+kern_return_t
+__mach_setup_thread (task_t task, thread_t thread, void *pc,
+ vm_address_t *stack_base, vm_size_t *stack_size)
+{
+ kern_return_t error;
+ struct machine_thread_state ts;
+ mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
+ vm_address_t stack;
+ vm_size_t size;
+ int anywhere;
+
+ size = stack_size ? *stack_size ? : STACK_SIZE : STACK_SIZE;
+ stack = stack_base ? *stack_base ? : 0 : 0;
+ anywhere = !stack_base || !*stack_base;
+
+ error = __vm_allocate (task, &stack, size + __vm_page_size, anywhere);
+ if (error)
+ return error;
+
+ if (stack_size)
+ *stack_size = size;
+
+ memset (&ts, 0, sizeof (ts));
+ MACHINE_THREAD_STATE_SET_PC (&ts, pc);
+#ifdef STACK_GROWTH_DOWN
+ if (stack_base)
+ *stack_base = stack + __vm_page_size;
+ ts.SP = stack + __vm_page_size + size;
+#elif defined (STACK_GROWTH_UP)
+ if (stack_base)
+ *stack_base = stack;
+ ts.SP = stack;
+ stack += size;
+#else
+ #error stack direction unknown
+#endif
+
+ /* Create the red zone. */
+ if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
+ return error;
+
+ return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ (natural_t *) &ts, tssize);
+}
+
+weak_alias (__mach_setup_thread, mach_setup_thread)
diff --git a/REORG.TODO/mach/shortcut.awk b/REORG.TODO/mach/shortcut.awk
new file mode 100644
index 0000000000..ea283d49ba
--- /dev/null
+++ b/REORG.TODO/mach/shortcut.awk
@@ -0,0 +1,50 @@
+# Icky intimate knowledge of MiG output.
+
+BEGIN { print "/* This file is generated by shortcut.awk. */";
+ echo=1;
+ inproto=0; proto=""; arglist="";
+ }
+
+$1 == "LINTLIBRARY" { print "#include <mach.h>"; next }
+
+$1 == "weak_alias" { next }
+
+# Copy the first line of the definition, but
+# replace the function name (RPC) with CALL.
+$NF == rpc \
+ {
+ for (i = 1; i < NF; ++i) printf "%s ", $i;
+ print call;
+ next;
+ }
+
+# Collect the lines of the prototype in PROTO, and extract the parameter
+# names into ARGLIST.
+NF == 1 && $1 == ")" { inproto=0 }
+inproto { proto = proto $0;
+ arg = $NF;
+ gsub(/[^a-zA-Z0-9_,]/, "", arg);
+ arglist = arglist arg;
+ }
+NF == 1 && $1 == "(" { inproto=1 }
+
+/^{$/ { echo=0; }
+
+echo == 1 { print $0; }
+
+/^}$/ && proto != "" \
+ {
+ print "{";
+ print " kern_return_t err;";
+ print " extern kern_return_t " syscall " (" proto ");";
+ print " extern kern_return_t " rpc " (" proto ");";
+ print " err = " syscall " (" arglist ");";
+ print " if (err == MACH_SEND_INTERRUPTED)";
+ print " err = " rpc " (" arglist ");";
+ print " return err;"
+ print "}";
+ print "weak_alias (" call ", " alias ")";
+ # Declare RPC so the weak_alias that follows will work.
+ print "extern __typeof (" call ") " rpc ";";
+ echo = 1;
+ }
diff --git a/REORG.TODO/mach/spin-lock.c b/REORG.TODO/mach/spin-lock.c
new file mode 100644
index 0000000000..aaebc55cf4
--- /dev/null
+++ b/REORG.TODO/mach/spin-lock.c
@@ -0,0 +1,8 @@
+#define _EXTERN_INLINE /* Empty to define the real functions. */
+#include "spin-lock.h"
+
+weak_alias (__spin_lock_init, spin_lock_init);
+weak_alias (__spin_lock_locked, spin_lock_locked);
+weak_alias (__spin_lock, spin_lock);
+weak_alias (__spin_unlock, spin_unlock);
+weak_alias (__spin_try_lock, spin_try_lock);
diff --git a/REORG.TODO/mach/spin-lock.h b/REORG.TODO/mach/spin-lock.h
new file mode 100644
index 0000000000..aa8b10983c
--- /dev/null
+++ b/REORG.TODO/mach/spin-lock.h
@@ -0,0 +1,33 @@
+/* Definitions of user-visible names for spin locks.
+ Copyright (C) 1994-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SPIN_LOCK_H
+#define _SPIN_LOCK_H
+
+#include <lock-intern.h> /* This does all the work. */
+
+typedef __spin_lock_t spin_lock_t;
+#define SPIN_LOCK_INITIALIZER __SPIN_LOCK_INITIALIZER
+
+#define spin_lock_init(lock) __spin_lock_init (lock)
+#define spin_lock(lock) __spin_lock (lock)
+#define spin_try_lock(lock) __spin_try_lock (lock)
+#define spin_unlock(lock) __spin_unlock (lock)
+#define spin_lock_locked(lock) __spin_lock_locked (lock)
+
+#endif /* spin-lock.h */
diff --git a/REORG.TODO/mach/spin-solid.c b/REORG.TODO/mach/spin-solid.c
new file mode 100644
index 0000000000..711fab8ada
--- /dev/null
+++ b/REORG.TODO/mach/spin-solid.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1994-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <spin-lock.h>
+#include <mach/mach_traps.h>
+
+void
+__spin_lock_solid (spin_lock_t *lock)
+{
+ while (__spin_lock_locked (lock) || ! __spin_try_lock (lock))
+ /* Yield to another thread (system call). */
+ __swtch_pri (0);
+}
+weak_alias (__spin_lock_solid, spin_lock_solid);
diff --git a/REORG.TODO/mach/syscalls.awk b/REORG.TODO/mach/syscalls.awk
new file mode 100644
index 0000000000..dec8a3b537
--- /dev/null
+++ b/REORG.TODO/mach/syscalls.awk
@@ -0,0 +1,9 @@
+BEGIN { calls="" }
+
+{
+ calls = calls " " $1;
+ print "sysno-" $1 " = " $2;
+ print "nargs-" $1 " = " $3;
+}
+
+END { print "mach-syscalls := " calls }