summaryrefslogtreecommitdiff
path: root/mach
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
committerRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
commit28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch)
tree15f07c4c43d635959c6afee96bde71fb1b3614ee /mach
downloadglibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.gz
initial import
Diffstat (limited to 'mach')
-rw-r--r--mach/.cvsignore4
-rw-r--r--mach/Machrules212
-rw-r--r--mach/Makefile195
-rw-r--r--mach/bootprivport.c64
-rw-r--r--mach/devstream.c264
-rw-r--r--mach/err_boot.sub63
-rw-r--r--mach/err_ipc.sub109
-rw-r--r--mach/err_kern.sub188
-rw-r--r--mach/err_mach.sub130
-rw-r--r--mach/err_server.sub374
-rw-r--r--mach/err_us.sub56
-rw-r--r--mach/error_compat.c70
-rw-r--r--mach/errorlib.h87
-rw-r--r--mach/errstring.c100
-rw-r--r--mach/errsystems.awk21
-rw-r--r--mach/errsystems.c27
-rw-r--r--mach/hello.c48
-rw-r--r--mach/lock-intern.h89
-rw-r--r--mach/mach.h95
-rw-r--r--mach/mach/error.h140
-rw-r--r--mach/mach/mach.h3
-rw-r--r--mach/mach/mach_traps.h76
-rw-r--r--mach/mach/mig_support.h68
-rw-r--r--mach/mach_error.c85
-rw-r--r--mach/mach_error.h80
-rw-r--r--mach/mach_init.c39
-rw-r--r--mach/mach_init.h48
-rw-r--r--mach/mach_shortcuts.c13
-rw-r--r--mach/mach_syscalls.c10
-rw-r--r--mach/mach_syscalls.h31
-rw-r--r--mach/mach_traps.S15
-rw-r--r--mach/mig-alloc.c28
-rw-r--r--mach/mig-dealloc.c28
-rw-r--r--mach/mig_strncpy.c11
-rw-r--r--mach/msg-destroy.c160
-rw-r--r--mach/msg.c82
-rw-r--r--mach/msg_destroy.c4
-rw-r--r--mach/msgserver.c194
-rw-r--r--mach/mutex-solid.c50
-rw-r--r--mach/setup-thread.c99
-rw-r--r--mach/shortcut.awk45
-rw-r--r--mach/spin-lock.c8
-rw-r--r--mach/spin-lock.h34
-rw-r--r--mach/spin-solid.c28
-rw-r--r--mach/syscalls.awk9
-rw-r--r--mach/vm_page_size.c3
46 files changed, 3587 insertions, 0 deletions
diff --git a/mach/.cvsignore b/mach/.cvsignore
new file mode 100644
index 0000000000..1f69fd919a
--- /dev/null
+++ b/mach/.cvsignore
@@ -0,0 +1,4 @@
+*.gz *.Z *.tar *.tgz
+=*
+TODO COPYING* AUTHORS copyr-* copying.*
+glibc-*
diff --git a/mach/Machrules b/mach/Machrules
new file mode 100644
index 0000000000..4f91d9bab7
--- /dev/null
+++ b/mach/Machrules
@@ -0,0 +1,212 @@
+# Rules for MiG interfaces that want to go into the C library.
+
+# Copyright (C) 1991, 1992, 1993, 1994, 1995 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 Library General Public License
+# as published by the Free Software Foundation; either version 2 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
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB. If
+# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+# Cambridge, MA 02139, USA.
+
+# 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
+
+ifndef MIG
+MIG = mig
+endif
+MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
+ $(+includes) $(migdefines) -subrprefix __
+
+.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 inhibit_interface_rules
+include $(*.ir)
+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.
+#
+# While we're at it, we figure out the imports used by %.defs and give them
+# as dependencies of the object files for the generated RPC_*.c files.
+#
+# 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 } \
+ /^#include/ { printf \"$*-imports += %s\\n\", \$$2 }" $< ;\
+ echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
+ echo '$$($*-calls:%=$$(objpfx)RPC_%.o): $$($*-imports:<%>=%)' ;\
+ ) > $@-new
+ mv $@-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
+
+# Not an implicit rule so the stamps are never removed as intermediates!
+$(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp: %.defs
+ $(MIG) $< $(MIGFLAGS) $(user-MIGFLAGS) \
+ -prefix __ -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 $@
+
+# 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: %.defs
+ $(MIG) $< $(MIGFLAGS) $(server-MIGFLAGS) \
+ -prefix _S_ \
+ -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.
+$(objpfx)%.uh: %.defs; $(mig.uh)
+define mig.uh
+$(make-target-directory)
+$(MIG) $< $(MIGFLAGS) \
+ -header $@ -server /dev/null -user /dev/null
+endef
+$(objpfx)%.__h: %.defs; $(mig.__h)
+define mig.__h
+$(make-target-directory)
+$(MIG) $< $(MIGFLAGS) -prefix __ \
+ -header $@ -server /dev/null -user /dev/null
+endef
+
+$(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 $@-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) \
+ $(foreach h,$(interface-headers:%.h=%),$h.h $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)
+
+# Specify the static dependencies of the generated files.
+$(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)RPC_%.o))): \
+ mach/boolean.h mach/kern_return.h mach/message.h mach/notify.h \
+ mach/mach_types.h mach/mig_errors.h mach/mig_support.h mach/msg_type.h \
+ $(..)libc-symbols.h $(objpfx)config.h
+$(server-interfaces:%=$(objpfx)%.o): \
+ mach/boolean.h mach/kern_return.h mach/message.h mach/mig_errors.h \
+ mach/mig_support.h mach/std_types.h
+# The MiG-generated sources also depend on the imports in their .defs files.
+# These dependencies are generated into the .ir files above.
+
+# If defined, $(interface-library) is `libNAME.a'. It is to be a library
+# containing all the MiG-generated functions for the specified interfaces.
+
+ifdef interface-library
+
+$(interface-library)-objs := $(interface-routines:%=%.o)
+
+install-lib += $(interface-library)
+extra-objs += $($(interface-library)-objs)
+
+$(objpfx)$(interface-library): $(addprefix $(objpfx),\
+ $($(interface-library)-objs))
+ifdef objdir
+ cd $(objdir); $(AR) cru$(verbose) $(@:$(objpfx)%=%) $(^:$(objpfx)%=%)
+else
+ $(AR) cru$(verbose) $@ $^
+endif
+ $(RANLIB) $@
+
+lib-noranlib: $(objpfx)$(interface-library)
+
+mostlyclean:
+ -rm -f $(objpfx)$(interface-library)
+
+endif
diff --git a/mach/Makefile b/mach/Makefile
new file mode 100644
index 0000000000..ce2670092e
--- /dev/null
+++ b/mach/Makefile
@@ -0,0 +1,195 @@
+# Copyright (C) 1991, 1992, 1993, 1994, 1995 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 Library General Public License
+# as published by the Free Software Foundation; either version 2 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
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB. If
+# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+# Cambridge, MA 02139, USA.
+
+subdir := mach
+
+all:
+
+# Some things below (but before including Rules) use configuration variables.
+include ../Makeconfig
+
+
+headers = mach_init.h mach.h mach_error.h mach-shortcuts.h \
+ $(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
+ $(lock-headers) machine-sp.h
+distribute = thread_state.h
+lock = spin-solid spin-lock 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 bootprivport setup-thread $(lock)
+# The RPC interfaces go in a separate library.
+interface-library := libmachuser.a
+user-interfaces := $(addprefix mach/,mach_interface mach_port mach_host \
+ memory_object_user \
+ memory_object_default \
+ exc mach4 \
+ )\
+ $(addprefix device/,device device_request)
+server-interfaces := device/device_reply mach/exc mach/notify
+tests := hello
+# It is important that we do not use the wildcard function to expand
+# `err_*.sub'. Leaving the wildcard allows Make-dist to find all matching
+# files in all sysdep directories.
+distribute += Machrules syscalls.awk shortcut.awk \
+ errorlib.h err_*.sub
+
+
+# Clear any environment value.
+generated =
+
+# Get the proper definition of `mach-srcdir'.
+include ../sysdeps/mach/Makefile
+
+# Use and install the Mach header files directly out of the Mach kernel source.
+
+# Find the MiG defs files in the kernel source.
+vpath %.defs $(mach-srcdir)
+
+# Install all .h and .defs files we find in some of the kernel's source
+# directories and their subdirectories (in MK82, max one level deep).
+mach-src-headers := $(wildcard $(foreach dir,mach device mach_debug \
+ $(config-machine),\
+ $(addprefix $(mach-srcdir)/$(dir)/,\
+ *.defs *.h \
+ */*.defs */*.h)))
+# Exclude mach/machine/*. A symlink will be installed for mach/machine.
+# Exclude $(headers) for Mach files we have our own versions of.
+mach-headers = $(filter-out mach/machine/% $(headers),\
+ $(mach-src-headers:$(mach-srcdir)/%=%))
+# Rename Mach's sys/version.h to mach/version.h.
+mach-headers := $(patsubst sys/version.h,mach/version.h,$(mach-headers))
+
+# Don't distribute the Mach headers; they are in the Mach distribution.
+dont_distribute = $(mach-headers)
+
+# DO NOT try to remake these in any way!!!
+$(addprefix $(mach-srcdir)/,$(mach-headers)) : ;
+install-others += $(addprefix $(includedir)/,$(mach-headers))
+$(includedir)/%: $(mach-srcdir)/%; $(do-install)
+
+# Make symlinks for machine and mach/machine in the include directory.
+install-others += $(includedir)/mach/machine $(includedir)/machine
+$(includedir)/mach/machine $(includedir)/machine: $(common-objpfx)config.make
+ -rm -f $@
+ cd $(@D); ln -s $(config-machine) $(@F)
+
+# Install Mach's <sys/version.h> as <mach/version.h>.
+install-others += $(includedir)/mach/version.h
+$(includedir)/mach/version.h: $(mach-srcdir)/sys/version.h; $(do-install)
+
+# Define mach-syscalls and sysno-*.
+ifndef inhibit_mach_syscalls
+include $(objpfx)mach-syscalls.mk
+endif
+$(objpfx)mach-syscalls.mk: mach/syscall_sw.h syscalls.awk
+# Go kludges!!!
+ sed -n -e '/Unix server implement them/,$$d' \
+ -e 's/^kernel_trap(\(.*\),\([-0-9]*\),\([0-9]*\))$$/\1 \2 \3/p'\
+ < $< | awk -f $(word 2,$^) > $@-new
+ mv $@-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 $@-new $@
+generated += $(mach-syscalls:=.S)
+endif # mach-syscalls
+
+# syscall_device_writev_request has no RPC equivalent.
+mach-shortcuts := $(filter-out device_writev_request,\
+ $(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/mach_interface \
+ mach/mach_port mach/mach_host mach/mach4 \
+ device/device_request,\
+ $(user-interfaces))
+endif
+
+# Make the MiG stubs for $(mach-shortcuts) be CALL_rpc.
+migdefines += $(foreach call,$(mach-shortcuts),-D$(call)=$(call)_rpc)
+mach/mach_interface.uh mach/mach_port.uh: $(objpfx)mach-syscalls.mk
+
+ifdef mach-shortcuts
+$(mach-shortcuts:%=$(objpfx)%.c): $(objpfx)%.c: shortcut.awk \
+ $(objpfx)RPC_%_rpc.c
+ gawk -v alias=$* -v call=__$* -v rpc=__$*_rpc -v syscall=__syscall_$* \
+ -f $^ > $@-new
+ mv $@-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: $(objpfx)mach/mach_interface.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 rerealifies the lines.
+ cat $^ | tr \\012 @ | sed s/@@/@%/g | tr % \\012 \
+ | grep '^/\* Routine [a-z0-9_]*_rpc \*/' \
+ | sed 's/_rpc//g' | tr @ \\012 > $@-new
+ mv $@-new $@
+generated += mach-shortcuts.h
+
+before-compile += $(objpfx)mach-shortcuts.h
+
+include Machrules
+include ../Rules
+
+
+# There is already a mach.h, so mach.defs generates mach_interface.h.
+$(objpfx)mach/mach_interface.defs: $(mach-srcdir)/mach/mach.defs
+ ln $< $@ || cp $< $@
+# There is already a memory_object.h,
+# so memory_object.defs generates memory_object_user.h.
+$(objpfx)mach/memory_object_user.defs: $(mach-srcdir)/mach/memory_object.defs
+ ln $< $@ || cp $< $@
+
+ifdef objdir
+vpath mach/mach_interface.defs $(objdir)
+vpath mach/memory_object_user.defs $(objdir)
+endif
+
+# Be sure not to make these with implicit rules from foo.defs.
+mach.h mach/memory_object.h: ;
+
+ifeq (,)
+# XXX we have an errsystems.c here because a gcc bug makes the generated
+# version lose.
+else
+generated += errsystems.c
+$(objpfx)errsystems.c: errsystems.awk err_*.sub \
+ $(wildcard $(addsuffix /err_*.sub,$(+sysdep_dirs)))
+ gawk -v subsys='$(filter-out $<,$^)' -f $^ > $@.n
+ mv $@.n $@
+endif
diff --git a/mach/bootprivport.c b/mach/bootprivport.c
new file mode 100644
index 0000000000..85c63309e7
--- /dev/null
+++ b/mach/bootprivport.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 1993 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <mach.h>
+
+kern_return_t
+__mach_get_priv_ports (mach_port_t *host_priv_ptr,
+ mach_port_t *device_master_ptr)
+{
+ kern_return_t err;
+ mach_port_t bootstrap, reply;
+
+ struct
+ {
+ mach_msg_header_t hdr;
+ mach_msg_type_t host_priv_type;
+ mach_port_t host_priv;
+ mach_msg_type_t dev_master_type;
+ mach_port_t dev_master;
+ } msg;
+
+ if (err = task_get_bootstrap_port (mach_task_self (), &bootstrap))
+ return err;
+
+ /* We cannot simply use a MiG-generated user stub to do this,
+ because the return message does not contain a return code datum. */
+ reply = __mach_reply_port ();
+ msg.hdr.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND,
+ MACH_MSG_TYPE_MAKE_SEND_ONCE);
+ msg.hdr.msgh_size = 0;
+ msg.hdr.msgh_remote_port = bootstrap;
+ msg.hdr.msgh_local_port = reply;
+ msg.hdr.msgh_kind = MACH_MSGH_KIND_NORMAL;
+ msg.hdr.msgh_id = 999999;
+ err = __mach_msg (&msg.hdr,
+ MACH_SEND_MSG|MACH_RCV_MSG|MACH_RCV_TIMEOUT,
+ sizeof (msg.hdr), sizeof (msg), reply,
+ 500, MACH_PORT_NULL); /* XXX timeout is arbitrary */
+ mach_port_deallocate (mach_task_self (), bootstrap);
+ mach_port_deallocate (mach_task_self (), reply);
+
+ if (err == KERN_SUCCESS)
+ {
+ *host_priv_ptr = msg.host_priv;
+ *device_master_ptr = msg.dev_master;
+ }
+
+ return err;
+}
diff --git a/mach/devstream.c b/mach/devstream.c
new file mode 100644
index 0000000000..a2162db98b
--- /dev/null
+++ b/mach/devstream.c
@@ -0,0 +1,264 @@
+/* stdio on a Mach device port.
+ Translates \n to \r\n on output, echos input.
+
+Copyright (C) 1992, 1993, 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <mach.h>
+#include <device/device.h>
+#include <errno.h>
+#include <string.h>
+
+static int
+input (FILE *f)
+{
+ kern_return_t err;
+ char *buffer;
+ size_t to_read;
+ mach_msg_type_number_t nread;
+ char c;
+
+ if (f->__buffer == NULL)
+ {
+ buffer = &c;
+ to_read = 1;
+ }
+ else
+ {
+ buffer = f->__buffer;
+ to_read = f->__bufsize;
+ }
+
+ f->__eof = 0;
+
+ nread = to_read;
+ err = device_read_inband ((device_t) f->__cookie, 0, f->__target,
+ to_read, buffer, &nread);
+
+ if (err)
+ {
+ f->__error = 1;
+ f->__bufp = f->__get_limit = f->__put_limit = f->__buffer;
+ errno = err;
+ return EOF;
+ }
+
+ /* Echo it back. */
+ err = device_write_inband ((device_t) f->__cookie, 0, f->__target,
+ buffer, nread, (int *) &to_read);
+
+ if (f->__buffer == NULL)
+ return (unsigned char) c;
+
+ f->__get_limit = f->__buffer + nread;
+ f->__bufp = f->__buffer;
+ f->__put_limit = f->__buffer + (f->__mode.__write ? f->__bufsize : 0);
+ return (unsigned char) *f->__bufp++;
+}
+
+
+#if 0
+static void
+output (FILE *f, int c)
+{
+ inline void write_some (const char *p, size_t to_write)
+ {
+ kern_return_t err;
+ int wrote;
+ while (to_write > 0)
+ {
+ if (err = device_write ((device_t) f->__cookie, 0,
+ f->__target, (char *)p,
+ to_write, &wrote))
+ {
+ errno = err;
+ f->__error = 1;
+ break;
+ }
+ p += wrote;
+ to_write -= wrote;
+ f->__target += wrote;
+ }
+ }
+
+ if (f->__buffer != NULL)
+ {
+ if (f->__put_limit == f->__buffer)
+ {
+ /* Prime the stream for writing. */
+ f->__put_limit = f->__buffer + f->__bufsize;
+ f->__bufp = f->__buffer;
+ if (c != EOF)
+ {
+ *f->__bufp++ = (unsigned char) c;
+ c = EOF;
+ }
+ }
+
+
+ /* Write out the buffer. */
+
+ write_some (f->__buffer, f->__bufp - f->__buffer);
+
+ f->__bufp = f->__buffer;
+ }
+
+ if (c != EOF && !ferror (f))
+ {
+ if (f->__linebuf && (unsigned char) c == '\n')
+ {
+ static const char nl = '\n';
+ write_some (&nl, 1);
+ }
+ else
+ *f->__bufp++ = (unsigned char) c;
+ }
+}
+#endif
+
+
+static void
+output (FILE *f, int c)
+{
+ void write_some (const char *p, size_t to_write)
+ {
+ kern_return_t err;
+ int wrote;
+ while (to_write > 0)
+ {
+ if (err = device_write_inband ((device_t) f->__cookie, 0,
+ f->__target, p, to_write, &wrote))
+ {
+ errno = err;
+ f->__error = 1;
+ break;
+ }
+ p += wrote;
+ to_write -= wrote;
+ f->__target += wrote;
+ }
+ }
+ void write_crlf (void)
+ {
+ static const char crlf[] = "\r\n";
+ write_some (crlf, 2);
+ }
+
+ if (f->__buffer == NULL)
+ {
+ /* The stream is unbuffered. */
+
+ if (c == '\n')
+ write_crlf ();
+ else if (c != EOF)
+ {
+ char cc = (unsigned char) c;
+ write_some (&cc, 1);
+ }
+
+ return;
+ }
+
+ if (f->__put_limit == f->__buffer)
+ {
+ /* Prime the stream for writing. */
+ f->__put_limit = f->__buffer + f->__bufsize;
+ f->__bufp = f->__buffer;
+ if (c != EOF)
+ {
+ *f->__bufp++ = (unsigned char) c;
+ c = EOF;
+ }
+ }
+
+ {
+ /* Search for newlines (LFs) in the buffer. */
+
+ char *start = f->__buffer, *p = start;
+
+ while (!ferror (f) && (p = memchr (p, '\n', f->__bufp - start)))
+ {
+ /* Found one. Replace it with a CR and write out through that CR. */
+
+ *p = '\r';
+ write_some (start, p + 1 - start);
+
+ /* Change it back to an LF; the next iteration will write it out
+ first thing. Start the next searching iteration one char later. */
+
+ start = p;
+ *p++ = '\n';
+ }
+
+ /* Write the remainder of the buffer. */
+
+ if (!ferror (f))
+ write_some (start, f->__bufp - start);
+ }
+
+ f->__bufp = f->__buffer;
+
+ if (c != EOF && !ferror (f))
+ {
+ if (f->__linebuf && (unsigned char) c == '\n')
+ write_crlf ();
+ else
+ *f->__bufp++ = (unsigned char) c;
+ }
+}
+
+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, __default_io_functions);
+ if (stream == NULL)
+ {
+ mach_port_deallocate (mach_task_self (), dev);
+ return NULL;
+ }
+
+ stream->__room_funcs.__input = input;
+ stream->__room_funcs.__output = output;
+ stream->__io_funcs.__close = dealloc_ref;
+ stream->__io_funcs.__seek = NULL; /* Cannot seek. */
+ stream->__io_funcs.__fileno = NULL; /* No corresponding POSIX.1 fd. */
+ stream->__seen = 1;
+
+ return stream;
+}
diff --git a/mach/err_boot.sub b/mach/err_boot.sub
new file mode 100644
index 0000000000..5393ab1335
--- /dev/null
+++ b/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/mach/err_ipc.sub b/mach/err_ipc.sub
new file mode 100644
index 0000000000..1de186e2e7
--- /dev/null
+++ b/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/mach/err_kern.sub b/mach/err_kern.sub
new file mode 100644
index 0000000000..d5290b4e9b
--- /dev/null
+++ b/mach/err_kern.sub
@@ -0,0 +1,188 @@
+/*
+ * 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.4 1993/12/17 06:14:52 mib
+ * entered into RCS
+ *
+ * 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 availaible",
+ "(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/mach/err_mach.sub b/mach/err_mach.sub
new file mode 100644
index 0000000000..b33522c344
--- /dev/null
+++ b/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/mach/err_server.sub b/mach/err_server.sub
new file mode 100644
index 0000000000..1594246462
--- /dev/null
+++ b/mach/err_server.sub
@@ -0,0 +1,374 @@
+/*
+ * 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:53 roland
+ * entered into RCS
+ *
+ * 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/mach/err_us.sub b/mach/err_us.sub
new file mode 100644
index 0000000000..7261165d8d
--- /dev/null
+++ b/mach/err_us.sub
@@ -0,0 +1,56 @@
+/*
+ * 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.2 1993/11/23 21:14:05 mib
+ * entered into RCS
+ *
+ * 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/mach/error_compat.c b/mach/error_compat.c
new file mode 100644
index 0000000000..0498f017ba
--- /dev/null
+++ b/mach/error_compat.c
@@ -0,0 +1,70 @@
+/*
+ * 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:
+ $Log$
+ Revision 1.1 1993/11/30 17:35:24 roland
+ entered into RCS
+
+ 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( org_err )
+ 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/mach/errorlib.h b/mach/errorlib.h
new file mode 100644
index 0000000000..b60fc5e5a4
--- /dev/null
+++ b/mach/errorlib.h
@@ -0,0 +1,87 @@
+/*
+ * 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.4 1993/12/17 21:56:16 roland
+ * entered into RCS
+ *
+ * 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 struct error_system errors[err_max_system+1];
+
+#define errlib_count(s) (sizeof(s)/sizeof(s[0]))
diff --git a/mach/errstring.c b/mach/errstring.c
new file mode 100644
index 0000000000..761a615e29
--- /dev/null
+++ b/mach/errstring.c
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1993/11/30 17:35:58 roland
+ * entered into RCS
+ *
+ * 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( err )
+ 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( err, diag )
+ 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( err )
+ mach_error_t err;
+{
+ boolean_t diag;
+
+ return mach_error_string_int( err, &diag );
+
+}
diff --git a/mach/errsystems.awk b/mach/errsystems.awk
new file mode 100644
index 0000000000..c5cc5302b4
--- /dev/null
+++ b/mach/errsystems.awk
@@ -0,0 +1,21 @@
+BEGIN {
+ print "#include <mach/error.h>\n#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 " };";
+ printf "\n\
+const int __mach_error_system_count = errlib_count (__mach_error_systems);";
+}
diff --git a/mach/errsystems.c b/mach/errsystems.c
new file mode 100644
index 0000000000..19909607f8
--- /dev/null
+++ b/mach/errsystems.c
@@ -0,0 +1,27 @@
+/* XXX temp kludge: this file should be generated, but a gcc bug screws it. */
+
+#include <mach/error.h>
+#include <errorlib.h>
+#define static static const
+#include "../sysdeps/mach/hurd/err_hurd.sub"
+#include "err_us.sub"
+#include "err_server.sub"
+#include "err_mach.sub"
+#include "err_kern.sub"
+#include "err_ipc.sub"
+#include "err_boot.sub"
+
+
+const struct error_system __mach_error_systems[err_max_system + 1] =
+ {
+ /* 0 [err_get_system (err_kern)] = */ { errlib_count (err_kern_sub),"(system kern) error with unknown subsystem", err_kern_sub },
+ /* 1 [err_get_system (err_us)] = */ { errlib_count (err_us_sub),"(system us) error with unknown subsystem", err_us_sub },
+ /* 2 [err_get_system (err_server)] = */ { errlib_count (err_server_sub),"(system server) error with unknown subsystem", err_server_sub },
+ /* 3 [err_get_system (err_ipc)] = */ { errlib_count (err_ipc_sub),"(system ipc) error with unknown subsystem", err_ipc_sub },
+ /* 4 [err_get_system (err_mach_ipc)] = */ { errlib_count (err_mach_ipc_sub),"(system mach_ipc) error with unknown subsystem", err_mach_ipc_sub },
+ /* 5 [err_get_system (err_bootstrap)] = */ { errlib_count (err_bootstrap_sub),"(system bootstrap) error with unknown subsystem", err_bootstrap_sub },
+ /* [6..15] */ {},{},{},{},{},{},{},{},{},{},
+ /* 16==0x10 [err_get_system (err_hurd)] = */ { errlib_count (err_hurd_sub),"(system hurd) error with unknown subsystem", err_hurd_sub },
+ };
+
+const int __mach_error_system_count = errlib_count (__mach_error_systems);
diff --git a/mach/hello.c b/mach/hello.c
new file mode 100644
index 0000000000..4712038e10
--- /dev/null
+++ b/mach/hello.c
@@ -0,0 +1,48 @@
+/* "Hello world" program for GNU C Library on bare Mach 3.0.
+
+Copyright (C) 1991, 1992, 1993 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <mach.h>
+#include <device/device.h>
+#include <errno.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+ kern_return_t err;
+ mach_port_t device, consdev;
+ FILE *consf;
+
+ err = get_privileged_ports (NULL, &device);
+ if (err)
+ _exit (err);
+ err = device_open (device, D_WRITE, "console", &consdev);
+ mach_port_deallocate (mach_task_self (), device);
+ if (err)
+ _exit (err);
+
+ consf = mach_open_devstream (consdev, "w");
+ if (consf == NULL)
+ exit (errno);
+
+ fputs ("Hello, world!\n", consf);
+
+ return 0;
+}
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
new file mode 100644
index 0000000000..9c6bab5ae2
--- /dev/null
+++ b/mach/lock-intern.h
@@ -0,0 +1,89 @@
+/* Copyright (C) 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifndef _LOCK_INTERN_H
+#define _LOCK_INTERN_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);
+}
+
+#endif /* lock-intern.h */
diff --git a/mach/mach.h b/mach/mach.h
new file mode 100644
index 0000000000..ea39fb45fe
--- /dev/null
+++ b/mach/mach.h
@@ -0,0 +1,95 @@
+/* Standard header for all Mach programs.
+Copyright (C) 1993, 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifndef _MACH_H
+
+#define _MACH_H 1
+
+/* 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);
+
+
+#define __need_FILE
+#include <stdio.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/mach/mach/error.h b/mach/mach/error.h
new file mode 100644
index 0000000000..e75ccf3f66
--- /dev/null
+++ b/mach/mach/error.h
@@ -0,0 +1,140 @@
+/* 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.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1993/12/17 21:40:28 roland
+ * entered into RCS
+ *
+ * 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.
+ * insigned 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/mach/mach/mach.h b/mach/mach/mach.h
new file mode 100644
index 0000000000..826e7172a7
--- /dev/null
+++ b/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/mach/mach/mach_traps.h b/mach/mach/mach_traps.h
new file mode 100644
index 0000000000..e741e16996
--- /dev/null
+++ b/mach/mach/mach_traps.h
@@ -0,0 +1,76 @@
+/* Copyright (C) 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+/* 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>
+
+
+/* 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. */
+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 of the rpocessor. 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, int time);
+kern_return_t __thread_switch (mach_port_t new_thread, int option, int 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);
+
+
+#endif /* mach/mach_traps.h */
diff --git a/mach/mach/mig_support.h b/mach/mach/mig_support.h
new file mode 100644
index 0000000000..0f8c983c87
--- /dev/null
+++ b/mach/mach/mig_support.h
@@ -0,0 +1,68 @@
+/* Copyright (C) 1993, 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+/* 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>
+
+/* 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 __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/mach/mach_error.c b/mach/mach_error.c
new file mode 100644
index 0000000000..6cac0a5a7c
--- /dev/null
+++ b/mach/mach_error.c
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.1 1992/10/06 18:29:54 roland
+ * entered into RCS
+ *
+ * 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();
+
+void
+mach_error( str, err )
+ 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/mach/mach_error.h b/mach/mach_error.h
new file mode 100644
index 0000000000..852ab4e622
--- /dev/null
+++ b/mach/mach_error.h
@@ -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
+ * 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.2 1993/11/23 20:39:08 mib
+ * entered into RCS
+ *
+ * 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
+ */
+#if c_plusplus
+ mach_error_t error_value
+#endif c_plusplus
+ );
+
+void mach_error(
+/*
+ * Prints an appropriate message on the standard error stream
+ */
+#if c_plusplus
+ char *str,
+ mach_error_t error_value
+#endif c_plusplus
+ );
+
+const char *mach_error_type(
+/*
+ * Returns a string with the error system, subsystem and code
+*/
+#if c_plusplus
+ mach_error_t error_value
+#endif c_plusplus
+ );
+
+#endif _MACH_ERROR_
diff --git a/mach/mach_init.c b/mach/mach_init.c
new file mode 100644
index 0000000000..42379feb85
--- /dev/null
+++ b/mach/mach_init.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 1992, 1993, 1995 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <mach_init.h>
+#include <mach/mach_interface.h>
+
+mach_port_t __mach_task_self_;
+vm_size_t __vm_page_size;
+weak_alias (__vm_page_size, vm_page_size)
+
+void
+__mach_init (void)
+{
+ kern_return_t err;
+ vm_statistics_data_t stats;
+
+ __mach_task_self_ = (__mach_task_self) ();
+ __mig_init (0);
+
+ if (err = __vm_statistics (__mach_task_self (), &stats))
+ _exit (err);
+ __vm_page_size = stats.pagesize;
+}
+weak_alias (__mach_init, mach_init)
diff --git a/mach/mach_init.h b/mach/mach_init.h
new file mode 100644
index 0000000000..904473dd3a
--- /dev/null
+++ b/mach/mach_init.h
@@ -0,0 +1,48 @@
+/* Declarations and macros for the basic Mach things set at startup.
+Copyright (C) 1993, 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#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 ())
+
+/* 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/mach/mach_shortcuts.c b/mach/mach_shortcuts.c
new file mode 100644
index 0000000000..ef1792b003
--- /dev/null
+++ b/mach/mach_shortcuts.c
@@ -0,0 +1,13 @@
+#include <mach/mach_types.h>
+#include <mach/mach_port.h>
+
+#define SHORTCUT(name, number, args, typed_args) \
+kern_return_t __##name typed_args \
+{ \
+ kern_return_t ret = __syscall_##name args; \
+ if (ret == MACH_SEND_INTERRUPTED) \
+ ret = __mig_##name args; \
+ return ret; \
+}
+
+#include "mach_shortcuts.h"
diff --git a/mach/mach_syscalls.c b/mach/mach_syscalls.c
new file mode 100644
index 0000000000..44930c33cf
--- /dev/null
+++ b/mach/mach_syscalls.c
@@ -0,0 +1,10 @@
+/* Aliases for basic Mach system calls:
+ mach_task_self -> __mach_task_self, etc. */
+
+#include <gnu-stabs.h>
+
+#define SYSCALL(name, number, type, args, typed_args) \
+ function_alias (name, __##name, type, args, \
+ name typed_args)
+
+#include "mach_syscalls.h"
diff --git a/mach/mach_syscalls.h b/mach/mach_syscalls.h
new file mode 100644
index 0000000000..8b33dc4e7e
--- /dev/null
+++ b/mach/mach_syscalls.h
@@ -0,0 +1,31 @@
+SYSCALL (mach_msg_trap, -25,
+ mach_msg_return_t,
+ (msg, option, send_size,
+ rcv_size, rcv_name, timeout, notify),
+ (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))
+
+SYSCALL (mach_reply_port, -26,
+ mach_port_t,
+ (),
+ (void))
+
+SYSCALL (mach_thread_self, -27,
+ mach_port_t,
+ (),
+ (void))
+
+SYSCALL (mach_task_self, -28,
+ mach_port_t,
+ (),
+ (void))
+
+SYSCALL (mach_host_self, -29,
+ mach_port_t,
+ (),
+ (void))
diff --git a/mach/mach_traps.S b/mach/mach_traps.S
new file mode 100644
index 0000000000..bd53646294
--- /dev/null
+++ b/mach/mach_traps.S
@@ -0,0 +1,15 @@
+/* Traps for Mach basic system calls and kernel RPC shortcuts. */
+
+#include <sysdep.h>
+
+#define SYSCALL(name, number, type, args, typed_args) \
+ SYSCALL_TRAP (__##name, number)
+
+/* Basic syscalls. */
+#include "mach_syscalls.h"
+
+/* RPC shortcuts. */
+#define SHORTCUT(name, number, args, typed_args) \
+ SYSCALL_TRAP (__syscall_##name, number)
+
+#include "mach_shortcuts.h"
diff --git a/mach/mig-alloc.c b/mach/mig-alloc.c
new file mode 100644
index 0000000000..6f05153acc
--- /dev/null
+++ b/mach/mig-alloc.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1992 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#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;
+}
diff --git a/mach/mig-dealloc.c b/mach/mig-dealloc.c
new file mode 100644
index 0000000000..3942acac58
--- /dev/null
+++ b/mach/mig-dealloc.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1992, 1995 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#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/mach/mig_strncpy.c b/mach/mig_strncpy.c
new file mode 100644
index 0000000000..b0c001d775
--- /dev/null
+++ b/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/mach/msg-destroy.c b/mach/msg-destroy.c
new file mode 100644
index 0000000000..c0841f1190
--- /dev/null
+++ b/mach/msg-destroy.c
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.3 1995/01/23 22:16:52 roland
+ * (mach_msg_destroy): Define as weak alias for __mach_msg_destroy.
+ *
+ * Revision 1.2 1993/08/03 06:13:18 roland
+ * entered into RCS
+ *
+ * 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();
+static void mach_msg_destroy_memory();
+
+/*
+ * Routine: mach_msg_destroy
+ * Purpose:
+ * Deallocates all port rights and out-of-line memory
+ * found in a received message.
+ */
+
+void
+__mach_msg_destroy(msg)
+ 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) {
+ 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) + 3) &~ 3;
+
+ 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);
+ }
+ }
+ }
+}
+
+weak_alias (__mach_msg_destroy, mach_msg_destroy)
+
+static void
+mach_msg_destroy_port(port, type)
+ mach_port_t port;
+ mach_msg_type_name_t type;
+{
+ if (MACH_PORT_VALID(port)) switch (type) {
+ case MACH_MSG_TYPE_PORT_SEND:
+ case MACH_MSG_TYPE_PORT_SEND_ONCE:
+ (void) __mach_port_deallocate(__mach_task_self(), port);
+ break;
+
+ case MACH_MSG_TYPE_PORT_RECEIVE:
+ (void) __mach_port_mod_refs(__mach_task_self(), port,
+ MACH_PORT_RIGHT_RECEIVE, -1);
+ break;
+ }
+}
+
+static void
+mach_msg_destroy_memory(addr, size)
+ vm_offset_t addr;
+ vm_size_t size;
+{
+ if (size > 0)
+ (void) __vm_deallocate(__mach_task_self(), addr, size);
+}
diff --git a/mach/msg.c b/mach/msg.c
new file mode 100644
index 0000000000..ece110868d
--- /dev/null
+++ b/mach/msg.c
@@ -0,0 +1,82 @@
+/*
+ * 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>
+
+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/mach/msg_destroy.c b/mach/msg_destroy.c
new file mode 100644
index 0000000000..9461e3d1a2
--- /dev/null
+++ b/mach/msg_destroy.c
@@ -0,0 +1,4 @@
+#include <gnu-stabs.h>
+
+#undef mach_msg_destroy
+symbol_alias (__mach_msg_destroy, mach_msg_destroy);
diff --git a/mach/msgserver.c b/mach/msgserver.c
new file mode 100644
index 0000000000..e0dc29b754
--- /dev/null
+++ b/mach/msgserver.c
@@ -0,0 +1,194 @@
+/* Copyright (C) 1993, 1994, 1995 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+/* 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.
+ */
+/*
+ * HISTORY
+ * $Log$
+ * Revision 1.3 1995/01/21 15:00:57 roland
+ * Converted to use weak aliases with macros from libc-symbols.h.
+ *
+ * Revision 1.2 1994/10/10 07:20:14 roland
+ * Increase default MAX_SIZE to two pages.
+ *
+ * Revision 1.1 1993/12/06 23:25:25 roland
+ * entered into RCS
+ *
+ * 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. */
+
+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)
+{
+ register mig_reply_header_t *request, *reply;
+ register mach_msg_return_t mr;
+
+ if (max_size == 0)
+ {
+ option |= MACH_RCV_LARGE;
+ max_size = 2 * __vm_page_size; /* Generic. Good? XXX */
+ }
+
+ 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);
+
+ 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:
+ /* The request message is larger than MAX_SIZE, and has not
+ been dequued. 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);
+
+ case MACH_SEND_INVALID_DEST:
+ /* The reply can't be delivered, so destroy it. This error
+ indicates only that the requestor 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 (demux, max_size, rcv_name)
+ boolean_t (*demux) ();
+ 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/mach/mutex-solid.c b/mach/mutex-solid.c
new file mode 100644
index 0000000000..aeaa269c6b
--- /dev/null
+++ b/mach/mutex-solid.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <lock-intern.h>
+#include <cthreads.h>
+
+/* If cthreads is linked in, it will define these variables with values
+ that point to its mutex functions. */
+void (*_cthread_mutex_lock_routine) (struct mutex *);
+void (*_cthread_mutex_unlock_routine) (struct mutex *);
+
+void
+__mutex_lock_solid (void *lock)
+{
+ if (_cthread_mutex_lock_routine)
+ (*_cthread_mutex_lock_routine) (lock);
+ else
+ __spin_lock_solid (lock);
+}
+
+void
+__mutex_unlock_solid (void *lock)
+{
+ if (_cthread_mutex_unlock_routine)
+ (*_cthread_mutex_unlock_routine) (lock);
+}
+
+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/mach/setup-thread.c b/mach/setup-thread.c
new file mode 100644
index 0000000000..a00edacdfd
--- /dev/null
+++ b/mach/setup-thread.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 1991, 1994, 1995 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#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 = 0;
+
+ size = stack_size ? *stack_size ? : STACK_SIZE : STACK_SIZE;
+
+ if (stack_base && *stack_base)
+ stack = *stack_base;
+ else if (size == STACK_SIZE)
+ {
+ /* Cthreads has a bug that makes its stack-probing code fail if
+ the stack is too low in memory. It's bad to try and fix it there
+ until cthreads is integrated into libc, so we'll just do it here
+ by requesting a high address. When the cthreads bug is fixed,
+ this assignment to STACK should be changed to 0, and the ANYWHERE
+ argument to vm_allocate should be changed to 0. This comment should
+ be left, however, in order to confuse people who wonder why its
+ here. (Though perhaps that last sentence (and this one) should
+ be deleted to maximize the effect.) */
+#ifdef STACK_GROWTH_DOWN
+ stack = VM_MAX_ADDRESS - size - __vm_page_size;
+#else
+ stack = VM_MIN_ADDRESS;
+#endif
+ }
+ else
+ anywhere = 1;
+
+ if (error = __vm_allocate (task, &stack, size + __vm_page_size, anywhere))
+ 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,
+ (int *) &ts, tssize);
+}
+
+weak_alias (__mach_setup_thread, mach_setup_thread)
diff --git a/mach/shortcut.awk b/mach/shortcut.awk
new file mode 100644
index 0000000000..d6090d7bf7
--- /dev/null
+++ b/mach/shortcut.awk
@@ -0,0 +1,45 @@
+# 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 }
+
+# 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; }
+
+/^}$/ \
+ {
+ print "{";
+ print " kern_return_t err;";
+ print " extern kern_return_t " syscall " (" proto ");";
+ print " err = " syscall " (" arglist ");";
+ print " if (err == MACH_SEND_INTERRUPTED)";
+ print " err = " rpc " (" arglist ");";
+ print " return err;"
+ print "}";
+ print "weak_alias (" call ", " alias ")"
+ echo = 1;
+ }
diff --git a/mach/spin-lock.c b/mach/spin-lock.c
new file mode 100644
index 0000000000..aaebc55cf4
--- /dev/null
+++ b/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/mach/spin-lock.h b/mach/spin-lock.h
new file mode 100644
index 0000000000..13b5e245b6
--- /dev/null
+++ b/mach/spin-lock.h
@@ -0,0 +1,34 @@
+/* Definitions of user-visible names for spin locks.
+Copyright (C) 1994 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#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/mach/spin-solid.c b/mach/spin-solid.c
new file mode 100644
index 0000000000..265df0632e
--- /dev/null
+++ b/mach/spin-solid.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1994, 1995 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <spin-lock.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 ();
+}
+weak_alias (__spin_lock_solid, spin_lock_solid);
diff --git a/mach/syscalls.awk b/mach/syscalls.awk
new file mode 100644
index 0000000000..dec8a3b537
--- /dev/null
+++ b/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 }
diff --git a/mach/vm_page_size.c b/mach/vm_page_size.c
new file mode 100644
index 0000000000..767e709f5c
--- /dev/null
+++ b/mach/vm_page_size.c
@@ -0,0 +1,3 @@
+#include <gnu-stabs.h>
+
+symbol_alias (__vm_page_size, vm_page_size);