From 28f540f45bbacd939bfd07f213bcad2bf730b1bf Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 18 Feb 1995 01:27:10 +0000 Subject: initial import --- mach/.cvsignore | 4 + mach/Machrules | 212 +++++++++++++++++++++++++++ mach/Makefile | 195 +++++++++++++++++++++++++ mach/bootprivport.c | 64 +++++++++ mach/devstream.c | 264 ++++++++++++++++++++++++++++++++++ mach/err_boot.sub | 63 ++++++++ mach/err_ipc.sub | 109 ++++++++++++++ mach/err_kern.sub | 188 ++++++++++++++++++++++++ mach/err_mach.sub | 130 +++++++++++++++++ mach/err_server.sub | 374 ++++++++++++++++++++++++++++++++++++++++++++++++ mach/err_us.sub | 56 ++++++++ mach/error_compat.c | 70 +++++++++ mach/errorlib.h | 87 +++++++++++ mach/errstring.c | 100 +++++++++++++ mach/errsystems.awk | 21 +++ mach/errsystems.c | 27 ++++ mach/hello.c | 48 +++++++ mach/lock-intern.h | 89 ++++++++++++ mach/mach.h | 95 ++++++++++++ mach/mach/error.h | 140 ++++++++++++++++++ mach/mach/mach.h | 3 + mach/mach/mach_traps.h | 76 ++++++++++ mach/mach/mig_support.h | 68 +++++++++ mach/mach_error.c | 85 +++++++++++ mach/mach_error.h | 80 +++++++++++ mach/mach_init.c | 39 +++++ mach/mach_init.h | 48 +++++++ mach/mach_shortcuts.c | 13 ++ mach/mach_syscalls.c | 10 ++ mach/mach_syscalls.h | 31 ++++ mach/mach_traps.S | 15 ++ mach/mig-alloc.c | 28 ++++ mach/mig-dealloc.c | 28 ++++ mach/mig_strncpy.c | 11 ++ mach/msg-destroy.c | 160 +++++++++++++++++++++ mach/msg.c | 82 +++++++++++ mach/msg_destroy.c | 4 + mach/msgserver.c | 194 +++++++++++++++++++++++++ mach/mutex-solid.c | 50 +++++++ mach/setup-thread.c | 99 +++++++++++++ mach/shortcut.awk | 45 ++++++ mach/spin-lock.c | 8 ++ mach/spin-lock.h | 34 +++++ mach/spin-solid.c | 28 ++++ mach/syscalls.awk | 9 ++ mach/vm_page_size.c | 3 + 46 files changed, 3587 insertions(+) create mode 100644 mach/.cvsignore create mode 100644 mach/Machrules create mode 100644 mach/Makefile create mode 100644 mach/bootprivport.c create mode 100644 mach/devstream.c create mode 100644 mach/err_boot.sub create mode 100644 mach/err_ipc.sub create mode 100644 mach/err_kern.sub create mode 100644 mach/err_mach.sub create mode 100644 mach/err_server.sub create mode 100644 mach/err_us.sub create mode 100644 mach/error_compat.c create mode 100644 mach/errorlib.h create mode 100644 mach/errstring.c create mode 100644 mach/errsystems.awk create mode 100644 mach/errsystems.c create mode 100644 mach/hello.c create mode 100644 mach/lock-intern.h create mode 100644 mach/mach.h create mode 100644 mach/mach/error.h create mode 100644 mach/mach/mach.h create mode 100644 mach/mach/mach_traps.h create mode 100644 mach/mach/mig_support.h create mode 100644 mach/mach_error.c create mode 100644 mach/mach_error.h create mode 100644 mach/mach_init.c create mode 100644 mach/mach_init.h create mode 100644 mach/mach_shortcuts.c create mode 100644 mach/mach_syscalls.c create mode 100644 mach/mach_syscalls.h create mode 100644 mach/mach_traps.S create mode 100644 mach/mig-alloc.c create mode 100644 mach/mig-dealloc.c create mode 100644 mach/mig_strncpy.c create mode 100644 mach/msg-destroy.c create mode 100644 mach/msg.c create mode 100644 mach/msg_destroy.c create mode 100644 mach/msgserver.c create mode 100644 mach/mutex-solid.c create mode 100644 mach/setup-thread.c create mode 100644 mach/shortcut.awk create mode 100644 mach/spin-lock.c create mode 100644 mach/spin-lock.h create mode 100644 mach/spin-solid.c create mode 100644 mach/syscalls.awk create mode 100644 mach/vm_page_size.c (limited to 'mach') 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 as . +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 '; \ + 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 + +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 +#include +#include +#include +#include + +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 +#include +#include + + +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 + +#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 +#include +#include +#include + +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[co