diff options
Diffstat (limited to 'boot-proxy-exc')
34 files changed, 10716 insertions, 0 deletions
diff --git a/boot-proxy-exc/ChangeLog b/boot-proxy-exc/ChangeLog new file mode 100644 index 00000000..39dc9f7a --- /dev/null +++ b/boot-proxy-exc/ChangeLog @@ -0,0 +1,998 @@ +2009-04-19 Zheng Da <zhengda1936@gmail.com> + + * boot.c (init_kernel_task): Create a pseudo kernel task. + (main): Create the port bucket, initialize the kernel task and fork a + thread after the arguments of boot are parsed. + +2009-04-19 Zheng Da <zhengda1936@gmail.com> + + * boot.c (thread_portclass): Removed variable. + (is_user): Added variable. + (options): Add option 'u'. + (parse_opt): Handle option 'u'. + (logfile): Added variabled. + (main): Handle the cases differently when the user is root. + (do_bootstrap_privileged_ports): Likewise. + (bootstrap_compat): Likewise. + (do_mach_notify_no_senders): Likewise. + (ds_device_open): If the user is root, open the kernel device + directly. + + * userland-boot.c (boot_script_task_create): Create the pseudo task + port if it's the normal user. + (boot_script_free_task): Deallocate the task port if it's root. + +2009-04-05 Zheng Da <zhengda1936@gmail.com> + + * Makefile (SRCS): Add list.c, mach_proxy.c. + (COMMON-OBJS): Add ourmach_hostServer.o, ourmachServer.o, + ourmach_portServer.o, excServer.o. + (OBJS): Add mach_host_impl.o, mach_impl.o, mach_port_impl.o, + exc_impl.o, list.o, mach_proxy.o. + (LCLHDRS): Add util.h. + (HURDLIBS): Add ports. + + * boot.c: Include hurd/ports.h, util.h, mach_proxy.h. + (port_bucket): New variable. + (task_portclass): Likewise. + (thread_portclass): Likewise. + (privileged_host_port): Removed variable. + (master_device_port): Likewise. + (pseudo_privileged_host_port): New variable. + (request_server): Call mach_host_server() and mach_server(). + (mach_proxy_demuxer): New function. + (mach_proxy_thread): Likewise. + (options): Add option -p. + (pager_file): New variable. + (parse_opt): Handle option -p. + (init_kernel_task): New function. + (main): Create port bucket, port class, new thread; + get default memory manager; get the pseudo privileged host port; + set 'host-port' with the pseudo privileged host port. + (do_bootstrap_privileged_ports): Return the pseudo privileged host port. + (bootstrap_compat): Use the pseudo privileged host port. + (ds_device_open): Return D_NO_SUCH_DEVICE if the device isn't specified. + (do_mach_notify_no_senders): Call ports_do_mach_notify_no_senders(); + check the pseudo privileged host port. + + * boot_script.c (add_arg): Convert 'cmd->args' to 'void *' pointer first. + (sym_enter): Convert 'symtab' to 'void *' pointer first. + (boot_script_parse_line): Convert 'cmds' to to 'void *' pointer first; + Convert 'cmd->exec_funcs' to to 'void *' pointer first. + + * exc_impl.c: New file. Implement the server-side RPCs of exc. + + * list.c: New file. Implement a double linked list. + + * list.h: New file. Define a double linked list. + + * mach_host_impl.c: New file. Implement the server-side RPCs of mach_host. + + * mach_impl.c: New file. Implement the server-side RPCs of mach. + + * mach_port_impl.c: New file. Implement the server-side RPCs of mach_port. + + * mach_proxy.c: New file. + + * mach_proxy.h: New file. + + * ourmach.defs: New file. A modified mach/mach.defs. + + * ourmach_host.defs: New file. A modified mach/mach_host.defs. + + * ourmach_port.defs: New file. A modified mach/mach_port.defs. + + * userland-boot.c: Include mach_proxy.h and util.h. + (boot_script_task_create): Create a pseudo task port. + (boot_script_free_task): Don't deallocate the task port. + + * util.h: New file. + +2008-09-21 Zheng Da <zhengda1936@gmail.com> + + * boot.c (options): Change the long option and the description of + its argument. + +2008-08-28 Zheng Da <zhengda1936@gmail.com> + + * boot.c: Add '-m' option. + (dev_map): New structure. + (dev_map_head): New variable. + (add_dev_map): New function. + (lookup_dev): New function. + (parse_opt): Handle the '-m' option. + (ds_device_open): Open the device from the device file. + +2006-03-15 Thomas Schwinge <tschwinge@gnu.org> + + * boot.c (boot_script_exec_cmd): Fix invalid lvalues. + +2003-01-04 Roland McGrath <roland@frob.com> + + * boot_script.c (boot_script_parse_line): Copy the file name into + malloc'd storage. + (add_arg): New arg TEXTLEN. Store malloc'd copy of TEXT. + (boot_script_parse_line): Update callers. + +2002-06-13 Roland McGrath <roland@frob.com> + + * boot.c (ds_device_write): int -> size_t in store_write call. + (ds_device_write_inband): Likewise. + +2002-06-08 Roland McGrath <roland@frob.com> + + * boot.c (S_io_identity): Use ino_t for FILENO. + +2002-05-31 Roland McGrath <roland@frob.com> + + * boot.c: Don't include "exec_S.h". + + * boot.c (boot_script_exec_cmd): Fix typos: + {I386,ALPHA}_THREAD_STATE -> {i386,ALPHA}_THREAD_STATE_COUNT + +2002-05-28 Roland McGrath <roland@frob.com> + + * boot_script.c (boot_script_set_variable): Values int -> integer_t. + (boot_script_define_function): Likewise. + (boot_script_parse_line): Likewise. + (struct sym, struct arg): Likewise. + (boot_script_exec): Likewise. + (builtin_symbols): Likewise. + * boot.c (main): Likewise. + * boot_script.h: Update decls. + + * boot.c (boot_script_exec_cmd) + [I386_THREAD_STATE]: Conditionalize i386 thread setup code on this. + [ALPHA_THREAD_STATE]: Add Alpha thread setup code. + (set_mach_stack_args): Obsolete function removed. + + * boot.c (load_image): u_int -> vm_address_t + (ds_xxx_device_get_status, ds_xxx_device_set_status): u_int -> size_t + (S_io_restrict_auth, S_io_reauthenticate): Likewise. + (ds_device_write, ds_device_read_inband): Likewise. + (ds_device_get_status): Likewise. + (ds_device_set_status): Likewise. + (boot_script_exec_cmd): Likewise. + (ds_device_read, ds_device_write_inband): Likewise. + (ds_xxx_device_set_filter): Likewise. + (ds_device_set_filter): Likewise. + +2002-05-13 Marcus Brinkmann <marcus@gnu.org> + + * boot.c: Include <version.h> + (argp_program_version): New variable. + +2002-03-23 James A. Morrison <ja2morri@uwaterloo.ca> + + * boot.c (main): Use error, not perror and exit. + +2001-10-07 Neal H Walfield <neal@cs.uml.edu> + + * boot.c (main): Set the boot script variables based on + the KERNEL_COMMAND_LINE value. + +2001-08-23 Roland McGrath <roland@frob.com> + + * boot.c (kernel_command_line): New variable. + (options): Add --kernel-command-line/-K. + (parse_opt): Parse it, set kernel_command_line. + (main): If unset, default it to "argv[0] bootstrap_args bootdevice". + Set ${kernel-command-line} boot script variable to kernel_command_line. + +2001-08-17 Neal H Walfield <neal@cs.uml.edu> + + * userland-boot.c (boot_script_task_create): Suspend the newly + created task as the protocol requires. + (boot_script_insert_right): Fix the error message. + +2001-08-17 Roland McGrath <roland@frob.com> + + * userland-boot.c (boot_script_insert_right): Take new result + parameter for send right name in target task. + (boot_script_insert_task_port): New function. + + * boot_script.h: Update those two decls. + (VAL_TASK): New macro. + * boot_script.c (VAL_SYM, VAL_FUNC): Increase these constants. + (builtin_symbols): Use VAL_TASK for "task-create". + (boot_script_exec): Update caller of boot_script_insert_right. + Treat VAL_TASK like VAL_PORT, but call boot_script_insert_task_port. + + * boot_script.h: size_t -> unsigned int + * boot_script.c: Don't #include <string.h>. + +2001-08-16 Roland McGrath <roland@frob.com> + + * userland-boot.c (boot_script_insert_right): New function. + * boot_script.h: Declare it. + * boot_script.c (boot_script_exec): Use that instead of + mach_port_insert_right. + + * boot_script.h: Protect from multiple inclusion. + (safe_gets): Remove decl. + + * boot_script.h (boot_script_exec_cmd): Change TASK arg type to task_t. + * userland-boot.c: Likewise. + + * boot_script.h (struct cmd): Change `task' member type to `task_t'. + (boot_script_task_create, boot_script_task_resume, + boot_script_prompt_task_resume, boot_script_free_task): Declare new + functions that callers must define. + * userland-boot.c: Define those. + * boot_script.c (create_task, resume_task, prompt_resume_task): Use + those instead of direct Mach calls. + (free_cmd): Likewise. + (read_file): Function removed. + (builtin_symbols): Remove the "read-file" element. + + * boot_script.h (boot_script_malloc, boot_script_free): Declare new + functions that callers must define. + * boot_script.c: All uses of malloc/free changed to use those instead. + * userland-boot.c: New file. Defines them using malloc/free. + * Makefile (SRCS, OBJS): Add it. + * boot.c (boot_script_malloc, boot_script_free): Old cruft functions + removed. + + * boot_script.c (boot_script_parse_line): Take new first argument HOOK. + Store it in CMD->hook. + (main): Update caller. + (boot_script_exec): Pass CMD->hook as 1st arg to boot_script_exec_cmd. + (boot_script_exec_cmd): Take new first argument HOOK. + * boot.c (boot_script_exec_cmd): Likewise. + * boot_script.h (struct cmd): New member `void *hook'. + Update decls for HOOK arguments added. + +2001-02-25 Roland McGrath <roland@frob.com> + + * Makefile (ourdevice.defs): Loosen up regexp since some whitespace in + the file changed. + +2000-12-21 Marcus Brinkmann <marcus@gnu.org> + + * boot.c (main): If malloc or realloc fails, print diagnostic + message and exit. + (queue_read): Change return type from void to kern_return_t. + If malloc fails, return D_NO_MEMORY, otherwise D_SUCCESS (to simplify + code flow, malloc before acquiring the queuelock). + (ds_device_read): New variable err (local to the block in which it is + used). If queue_read fails, pass through error. + (ds_device_read_inband): Likewise. + (S_io_read): Likewise. + Reported by Igor Khavkine <i_khavki@alcor.concordia.ca>. + +2000-03-17 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (S_io_reauthenticate): Check mach_port_insert_right result + with assert_perror. + +2000-03-17 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (S_io_reauthenticate): Don't use MACH_MSG_TYPE_MAKE_SEND + in Hurd RPC. + +2000-02-28 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (ds_device_get_status): Accept *STATUSLEN greater than needed. + +1999-09-13 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c: Reverted changes related to io_map_segment. + +1999-09-07 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (S_io_map_segment): New function. + +1999-07-11 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (ds_device_read, S_io_read): Fix sloppy bugs in last change. + +1999-07-06 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (load_image): Use mmap instead of vm_allocate, when + allocating in mach_task_self (). + (boot_script_exec_cmd): Likewise. + (set_mach_stack_args): Likewise. + (read_reply): Likewise. + (S_io_read): Likewise. + +1999-07-10 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c: Add #include <sys/mman.h> for munmap decl. + +Mon Jul 5 20:04:06 1999 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (load_image): Fix typo in cast. Reported by Yamashita + TAKAO <jargon@lares.dti.ne.jp>. + +1999-07-03 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (load_image): Use munmap instead of vm_deallocate when + it's from our own task. + (boot_script_read_file): Likewise. + (boot_script_exec_cmd): Likewise. + (set_mach_stack_args): Likewise. + (ds_device_read_inband): Likewise. + +1999-03-20 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (S_term_get_peername): New function. + +1999-03-14 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c: Fix typo in last change. + +1999-03-10 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (main): Only use real device name if root_store is for an + enforced single run starting at the beginning of the device. + +1999-03-09 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (main): Add newline to error msg. + Patch by Marcus Brinkmann <Marcus.Brinkmann@ruhr-uni-bochum.de>. + +1999-02-16 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (S_io_revoke): Add reply, replyPoly args. + +Tue Feb 16 05:06:12 1999 Thomas Bushnell, BSG <tb@mit.edu> + + * boot.c (S_io_revoke): New (unsupported) routine. + +1998-12-26 Roland McGrath <roland@baalperazim.frob.com> + + * boot.c (isig): New variable. + (init_termstate): If it's set, set ISIG flag in c_lflag. + (options): New option -I/--isig. + (parse_opt): Make -I set `isig'. + (boot_script_exec_cmd): Print out args as well as file name. + +1998-09-04 Roland McGrath <roland@baalperazim.frob.com> + + * boot_script.c: Include <string.h> instead of declaring memset here. + Include <stdlib.h> instead of declaring malloc, free here. + +1997-07-08 Miles Bader <miles@gnu.ai.mit.edu> + + * boot_script.c (prompt_resume_task): Pass more than a single + character buffer to safe_gets. + +Mon Jul 7 16:25:49 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * boot.c: Include <fcntl.h> instead of <fcntlbits.h>. Suggested + by Marcus G. Daniels (marcus@cathcart.sysc.pdx.edu). + +1997-06-20 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (bootscript): Made global. + (parse_opt): New function. + (options, doc, args_doc): New variables. + (bootscript_args): Now an array. + (ds_device_open, ds_device_close, ds_device_write, + ds_device_write_inband, ds_device_read, ds_device_read_inband, + ds_device_get_status, ds_device_set_status, ds_device_map, + ds_xxx_device_set_filter, ds_xxx_device_get_status, + ds_xxx_device_set_status, ds_device_set_filter): + Handle "pseudo-root" device. + (pseudo_root, root_store): New variables. + (main): Use argp to parse args, and implement the pseudo-root device. + Include <argp.h> & <hurd/store.h> + * Makefile (HURDLIBS): Include libstore & libshouldbeinlibc. + +Thu Apr 10 11:53:57 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * boot.c: Don't include varargs.h. + (set_mach_stack_args): Use stdarg instead of vararg. + +Mon Mar 17 13:12:45 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * boot_script.c (boot_script_parse_line): Don't print gratuitous + output noise. + +Thu Sep 12 16:28:47 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (HURDLIBS): New variable. + (boot): Delete special depedencies. + +Tue Aug 13 16:57:22 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * Makefile (device.defs): Rule removed. + (ourdevice.defs): Fix rule to work with Makeconf-generated device.defs. + +Tue Aug 13 15:09:45 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (ourdevice.defs): Depend on local device.defs. + (device.defs): New rule. + +Mon Aug 12 11:11:08 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * Makefile (ourdevice.defs): Find device.defs under + install_includedir now. + + * Makefile (all): No longer build uxboot by default. + +Thu Aug 1 14:38:38 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * boot_script.h (safe_gets): Declare second parm as type `int'. + * boot.c (safe_gets): Likewise. + +Sun Jul 7 21:10:08 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * boot.c (S_io_reauthenticate): Don't use unsafe MOVE_SEND in + auth_server_authenticate. + +Fri May 10 16:11:49 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (S_io_identity): Typo. + +Fri May 10 09:18:53 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * boot.c (S_io_identity): New function. + +Thu May 9 18:57:34 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * boot.c (S_io_select): No longer has TAG parm. + + * boot.c (S_io_reauthenticate): Use new interface. + +Sun Apr 28 22:50:38 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (main): Use select instead of SIGIO. + +Mon Apr 15 12:57:29 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * Makefile (uxboot): Permit errors because people might not have + the a.out-mach3 target installed, and that's OK for many users. + + * Makefile (uxboot.0): Find frank1.ld in #(srcdir). + + * boot_script.h (safe_gets): Add decl. + * boot_script.c: Include <stdio.h>. + +Wed Apr 3 18:54:22 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * ux.c (printf): Add %d. + +Wed Mar 27 11:30:29 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c [notanymore] (S_tioctl_tiocgeta, S_tioctl_tiocseta, + S_tioctl_tiocsetaf, term_modes, term_ccs, term_speeds): + Functions & variables removed. + * Makefile (COMMON-OBJS): Remove tcattr.o. + (SRCS): Remove tcattr.c. + +Thu Mar 14 10:10:20 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu> + + * Makefile (boot): Depend on libthreads.so, nothing wrong with shared + libs. + (uxboot.0, uxboot.1): Use automatic vars in cmds instead of gratuitous + redundancy. + (LDFLAGS-uxboot.0): Remove useless indirection through variable. + +Wed Feb 14 16:50:05 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c [!UX] + (orig_tty_state): New variable. + (init_termstate, restore_termstate): New hurd versions of these funcs. + * ux.c (init_termstate, restore_termstate, term_sgb, localbits): + Moved here from boot.c + +Tue Feb 13 18:49:26 1996 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (load_image, boot_script_read_file, main): Use O_RDONLY, + not 0 (kind of ironic, this...). + (load_image): Give the filename with the error message (and a newline). + + * ux.h (O_RDONLY, O_WRONLY, O_RDWR): New macros. + + * ux.c, ux.h: New files. + * boot.c: Move all the ux-specific grot into ux.c & ux.h. + If UX is defined, include "ux.h", else define hurdish stuff. + (main): Use get_privileged_ports instead of task_by_pid. + (load_image, boot_script_read_file, main, do_mach_notify_no_senders, + do_mach_notify_dead_name): Use host_exit instead of uxexit. + (boot_script_read_file): Use host_stat instead of uxstat. + (init_termstate, S_tioctl_tiocseta): Use sg_flags fld in struct sgttyb. + + * Makefile (all): Depend on `boot' and `uxboot'. + (COMMON-OBJS, UX-OBJS): New macros. + (OBJS): Inherit most names from $(COMMON-OBJS). + (LCLHDRS): Add ux.h. + (LDFLAGS): Use target-specific value. + (uxboot.0-LDFLAGS): New macro (with contents from old LDFLAGS). + (uxboot.o, uxboot.0): New targets. + (uxboot): Target renamed from boot.a. + +Sun Dec 10 18:05:14 1995 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (read_reply): Don't call clear_should_read(), just do + things ourselves. + (should_read_lock): Variable deleted. + (service_sigio): Function deleted. + (main): Use read_reply to service SIGIO again, not service_sigio. + + * boot.c (service_sigio): New function, replacing set_should_read. + Calls read_reply() itself too. + (unlock_readlock): New function. + (ds_device_read, ds_device_read_inband, S_io_read): Call + unlock_readlock instead of directly unlocking READLOCK. + (request_server, main): Don't call read_reply() anymore. + + * boot.c (should_read): New variable. + (main): SIGIO uses set_should_read instead of read_reply. + Call read_reply() after sigpause() returns. + (read_reply): Call clear_should_read(), and don't do anything if + SHOULD_READ wasn't set. + (set_should_read): New function. + (clear_should_read): New function. + (request_server): Call read_reply() before returning. + +Sat Dec 9 19:01:10 1995 Miles Bader <miles@gnu.ai.mit.edu> + + * boot.c (S_io_read, ds_device_read_inband, ds_device_read): Don't + block SIGIO. + (main): Don't trap SIGMSG & SIGEMSG. + +Mon Dec 4 23:54:18 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (main): Request no-senders notification on + pseudo_master_device_port. + Deallocate our send right to it when we no longer need it. + (do_mach_notify_no_senders): Exit only when both pseudo_console and + pseudo_master_device_port have no senders. + (ds_device_read_inband): Unlock readlock properly. + +Thu Nov 30 15:58:47 1995 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> + + * boot.c (readlock): New variable. + (read_reply): Check FIONREAD before dequeueing QR so that we don't + abandon requests. Lock READLOCK around FIONREAD/read pair. + (ds_device_read): Lock READLOCK around FIONREAD/read pair. + (ds_device_read_inband): Likewise. + (S_io_read): Likewise. + +Nov 22 16:25:01 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (request_server): Don't call exec_server. + (S_exec_*): Functions removed. + (boot_script_task_port): Variable removed. + (boot_script_task_*, boot_script_port_*): Functions removed. + +Tue Nov 14 12:07:24 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * Makefile (OBJS): Remove execServer.o. + +Thu Sep 28 14:47:46 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot_script.c (read_file): Pass CMD->path for file name. + (CHECK_CMDLINE_LEN): Update ARGV pointers after reallocating the line + buffer. + +Wed Sep 27 14:01:03 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (struct uxstat): New type. + (uxfstat): Renamed from fstat; use struct uxstat * for arg. + (boot_script_read_file): Use those. + Return the memory object port, not zero. + + * boot.c (fstat): New syscall function. + + * boot_script.c (read_file): New function. + (builtin_symbols): Add $(read-file) builtin. + * boot_script.h (boot_script_read_file): Declare it. + * boot.c (close): New syscall function. + (defpager): New variable. + (main): Set it up. + (boot_script_read_file): New function. + (useropen_dir): New variable. + (useropen): New function. + (load_image): Call it instead of open. + (main): Grok -D arg to set useropen_dir. + +Sat Sep 23 00:53:51 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * syscall.S: Restore entry SP before return. + + * boot.c (main): Use static const for constant strings. + On boot script error, write script line with error msg. + + * boot_script.c (boot_script_parse_line): Ignore line beginning + with #. + + * boot.c (S_io_pathconf): New function. + + * Makefile (LDFLAGS): Add -static. + +Fri Sep 22 14:14:23 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * mach-crt0.c (__data_start): New variable. + +Tue Aug 29 10:41:29 1995 Michael I. Bushnell, p/BSG <mib@duality.gnu.ai.mit.edu> + + * boot.c (mig_dealloc_reply_port): Remove __ from call to + mach_port_mod_refs. + (main): Look for -d in bootstrap_args, not (nonexistent) + boot_args. Remove `const' keyword from decl of MSG. + + * boot.c (sigblock, sigsetmask): New functions. + (sigmask): New macro. + (ds_device_read): Block SIGIO around critical section. + (ds_device_read_inband): Likewise. + (S_io_read): Likewise. + +Mon Aug 28 17:16:48 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot_script.h, boot_script.c: Updated by Shantanu Goel, to + accept action keywords only inside $(...) and only variable values + inside ${...}. + * boot.c: Updated for changes in boot_script.h protocol by + Shantanu Goel. + (main): Use boot_script_set_variable instead of magic variables. + Under -d, pause between parsing bootscript and executing it. + +Wed Aug 23 16:08:04 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + New script-driven boot mechanism, mostly implemented by Shantanu Goel. + * Makefile (SRCS): Add boot_script.c. + (OBJS): Add boot_script.o. + (LCLHDRS): New variable. + (HURDLIBS): Variable removed. + (boot): Depend on ../libthreads/libthreads.a. + * boot_script.c, boot_script.h: New files. + * boot.c (boot_like_kernel, boot_like_cmudef, boot_like_hurd): + Variables removed. + (main): Don't interpret switches. Instead of servers, take + command line argument of boot script file name. Read the file and + use boot_script functions to parse and execute its directives. + (boot_script_*): New variables and functions for boot_script callbacks. + +Sun Jul 30 23:50:53 1995 Michael I. Bushnell, p/BSG <mib@geech.gnu.ai.mit.edu> + + * Makefile: DISTFILES -> DIST_FILES. + +Sat Jul 8 11:37:32 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> + + * boot.c (free_reply_ports, free_reply_ports_lock): New variables. + (__mig_get_reply_port, __mig_put_reply_port, __mig_dealloc_reply_port, + mig_get_reply_port, mig_put_reply_port, mig_dealloc_reply_port): + Provide better versions of these routines that won't leak reply ports. + +Fri Jul 7 15:55:18 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> + + * mach-crt0.c: New file, from mach4-i386/libmach/standalone. + * boot.c (mach_init_routine): New variable, wanted by mach-crt0.o. + (__mig_get_reply_port, __mig_dealloc_reply_port, __mig_put_reply_port): + New functions, to avoid using hurdish versions. + * Makefile (OBJS): Add mach-crt0.o. + (SRCS): Add mach-crt0.c. + (LDFLAGS): Add -nostartfiles (as we now use mach-crt0.o). + +Thu Jul 6 15:30:18 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> + + * Makefile (boot.1, boot.a): Use $(LD) and $(OBJCOPY) instead of + explicit names. + + * boot.c: Include <mach/mig_support.h>. + (S_io_reauthenticate): Cast first arg to mig_deallocate. + (load_image): Cast second arg to read. + * tcattr.c: Undo last change; add private decl of ioctl. + + * boot.c (bootdevice): Initialize to hard-coded `sd0a' instead of + DEFAULT_BOOTDEVICE. + + * Makefile (all): Depend on boot.a too. + + * Makefile: Removed dependencies that are now automatically + generated. + +Wed May 31 10:02:11 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * Makefile (DISTFILES): New variable; include frank1.ld and + frankemul.ld. + (CPPFLAGS): Variable removed. + (LDFLAGS): Append -T frank1.ld. + (boot.1, boot.a): New targets. + + * syscall.S: Omit .globl decl for errno; it caused some as + complaint. + +Mon May 22 11:48:58 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> + + * sigvec.S: Remove copyright notice. + +Wed May 17 13:10:27 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> + + * boot.c (load_image): Make sure we actually allocate enough + memory to read into, including the offset into the buffer at which + the segment is read. + + * sigvec.S (sigreturn, _sigreturn, sigvec): Remove the explicit + underscore prefixes from these names, now that we're using elf. + Instead we use the various macros from <i386/asm.h>. Also, return + errors correctly. [Also added a copyright notice] + +Sat May 13 03:37:24 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (load_image): Fixed alignment calculation in ELF segment + loading. + + * syscall.S: Include i386/asm.h and use ENTRY and EXT macros, + instead of explicit _s. + +Fri May 12 18:36:39 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (load_image): Grok ELF executables as well as a.out. + (main): Load multiple servers. Suspend all but the first. + The first gets an extra arg, its name for the task port of the + second. + +Wed Apr 12 09:18:50 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> + + * Makefile: Don't try and install boot in /usr/local/bin. + +Wed Apr 5 17:25:19 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c: Don't include <errno.h>. Define `errno' variable. + * Makefile (SRCS): Add syscall.S. + (OBJS): Add syscall.o. + * syscall.S: Check for errors. + +Thu Jan 19 01:21:24 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (S_io_select): Updated to new io_select protocol. + +Fri Dec 9 01:23:22 1994 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c: Use mach_msg_type_number_t in place of unsigned int and + int. + +Fri Nov 11 14:05:43 1994 Michael I Bushnell <mib@churchy.gnu.ai.mit.edu> + + * boot.c (main): Always set `f' flag (signifying "fake" because we + aren't a real native bootstrap). + +Thu Nov 3 17:26:37 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * Makefile (boot.o): Depend on bootstrap_S.h. + +Fri Oct 28 17:08:12 1994 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * boot.c (main): Create the thread before setting it up. + (bootstrap_compat): Make a send right for psuedo_master_device_port. + (main): Explicitly clear NEWTASK's bootstrap port for boot_like_kernel. + (main): Format strings for port names for boot_like_kernel. + +Fri Oct 28 15:26:48 1994 Michael I Bushnell <mib@churchy.gnu.ai.mit.edu> + + * boot.c (boot_like_kernel, boot_like_cmudef, boot_like_hurd): New + global vars. + (set_mach_stack_args): New function. + (main): If the -k flag is given, set BOOT_LIKE_KERNEL. + If the -p flag is given, set BOOT_LIKE_CMUDEF. If neither is + given, set BOOT_LIKE_HURD. + Only set a bootstrap port if BOOT_LIKE_CMUDEF or BOOT_LIKE_HURD. + If BOOT_LIKE_KERNEL or BOOT_LIKE_CMUDEF, set up the stack the + Mach way using set_mach_stack_args. + (request_server): Declare and call bootstrap_server. + (do_bootstrap_priveleged_ports, bootstrap_compat): New functions. + * Makefile (OBJS): Require bootstrapServer.o. + * bootstrap.defs: New file. + +Tue Aug 30 11:41:33 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * boot.c (S_io_reauthenticate): Use new authentication protocol. + +Mon Aug 22 13:43:32 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * boot.c: Include <cthreads.h>. + (main): Run msg_thread fork; don't call + mach_msg_server_timeout here. Use sigpause instead of getpid. + (msg_thread): New function. + (queuelock): New variable. + (queue_read): Acquire queuelock. + (read_reply): Acquire queuelock. + * Makefile (HURDLIBS): New var to get threads. + +Thu Aug 18 18:04:36 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * boot.c (restore_termstate): New function. + (do_mach_notify_no_senders): Call restore_termstate before exiting. + + * boot.c (main): New var `usagemsg'; print it if args are wrong. + Allow flags and disk device to be given on command line. + New var `bootfile'. + (bootdevice, bootstrap_args): New vars. + (load_image): Exit nicely if the startup file can't be found. + (S_exec_startup): Use `bootdevice' instead of hardcoded name. + Use `bootstrap_args' instead of hardcoded "-x". + (main): Only do `pausing' hack if -d was provided. + + * Makefile (CPPFLAGS): Define DEFAULT_BOOTDEVICE. + + * Makefile (/usr/local/bin/boot): Depend on boot. + + * boot.c (S_termctty_open_terminal): New "function". + (S_io_select): Added `rettype' arg. + +Sat Jul 23 02:58:05 1994 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * Makefile (io-MIGSFLAGS): Renamed from ioMIGSFLAGS. + +Fri Jul 22 15:10:45 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * boot.c (request_server): Remove S_ from io_server and + term_server. + +Thu Jul 21 19:00:36 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * Makefile: Rewritten to use new scheme. + * boot.c: Include io_reply_U.h and device_reply_U.h instead + of io_repl.h and device_reply.h. + +Wed Jul 20 13:19:45 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> + + * boot.c: Comment out bits relating to tioctl interface. + * Makefile: Likewise. + +Tue Jul 19 12:41:46 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * Makefile (boot): Don't use variable $(link) anymore. + +Tue Jul 5 14:19:36 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * Makefile (SRCS): New variable. + +Sun Jul 3 17:20:07 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) + + * tcattr.c: New file. + * boot.c (S_tioctl_tiocgeta): Call tcgetattr. + (S_tioctl_tiocseta): Call tcsetattr. + * Makefile (OBJS): Add tcattr.o. + (DIST_FILES): Add tcattr.c. + +Fri Jul 1 11:16:27 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * boot.c (init_termstate): Enter raw mode here. + +Fri Jun 24 14:27:56 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * boot.c (S_term_open_ctty): Renamed from term_become_ctty. + Deleted SIGPT arg. Add msg type arg for NEWTTY. + +Fri Jun 17 13:46:07 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) + + * boot.c (request_server): Remove S_ prefix from exec_server + and notify_server. + +Fri Jun 17 00:12:16 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * Makefile (boot.o): Depend on term_S.h. + +Tue Jun 14 01:28:10 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * boot.c (request_server): Add S_ prefix to demuxer functions. + +Wed Jun 8 18:02:19 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * boot.c (S_tioctl_tiocseta): Turn off ECHO. + (S_io_select): Implement. + +Tue Jun 7 04:33:42 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * Makefile (tioctlServer.o): Depend on ../hurd/ioctl_types.h. + +Mon Jun 6 20:33:39 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * boot.c (authserver): New variable. + (S_io_reauthenticate): Do auth_server_authenticate and throw away + the returned info. + (S_exec_init): Set authserver to the passed port. + +Sat Jun 4 02:32:03 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) + + * boot.c: Include term_S.h and tioctl_S.h. + (S_term_getctty): New function. + (S_term_*): Stub functions. + (request_server): Use S_term_server. + + * Makefile (termServer.c term_S.h): New rule. + (OBJS): Add termServer.o. + + * boot.c (S_exec_setexecdata, S_exec_exec): Fix prototypes. + +Tue May 17 18:44:29 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * boot.c (ds_device_write): DATA arg is char *; don't dereference + it in call to write. + +Mon May 16 14:34:15 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) + + * boot.c (fsname): New variable. + (main): Set fsname to argv[1]. + (S_exec_startup): Include fsname in child's argv[0]. + + * boot.c (init_termstate): Add forward declaration. + (struct sigvec): Make SV_HANDLER member void (*)(). + (sigvec): Add declaration to avoid warning. + +Tue May 10 18:14:39 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) + + * boot.c (tioctl_tiocseta, tioctl_tiocsetw, tioctl_tiocsetf, + tioctl_tiocgeta, init_termstate): New functions. + (term_modes, term_ccs, term_speeds, term_sgb, localbits): Nev + vars. + Also added new bits from ioctl.h. + (main): Call init_termstate. + (request_server): Call tioctl_server. + * Makefile (tioctlServer.c tioctl_S.h): New targets. + (OBJS): Include tioctlServer.o. + (boot.o): Depend on tioctl_S.h + +Fri May 6 13:56:58 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) + + * boot.c (main): Restore braindamage of yesterday relating to + signals; that is, restore declaration of VEC and calls to sigvec. + * Makefile (DIST_FILES): Add sigvec.S. + +Thu May 5 13:16:42 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) + + * Makefile (device_replyUser.c): Mention that this build + device_reply.h as well. + (boot.o): Add dependency on device_reply.h and io_repl.h. + + * boot.c: Include <stdlib.h> for malloc and free prototypes. + Include <string.h> for bcopy and bzero prototypes. + Include <stdio.h> for sprintf prototype. + Include "device_reply.h" for its prototypes. + Include "io_reply.h" for its prototypes. + Declare return type for all the server functions that were lacking + such. + (sigpause): Declare type of MASK. + (ioctl): Declare third arg to be generic pointer, not char *. + (request_server): Declare MiG functions we call. + (load_image): Delete unused variable STACKADDR. + (main): Comment out declaration of VEC. + Comment out calls to sigvec. + Cast STARTPC in call to __mach_setup_thread. + Delete unused variable TIMEOUT. + (read_reply): Cast BUF correctly in call to ds_device_read_reply. + (S_exec_startup): Delete unused variable DTABLE. + (ds_device_write): Double cast arg to write to avoid warning. + (S_io_read): Order args to vm_allocate properly; cast DATA arg. + Check *datalen properly for unsigned type. + + * boot.c: Renamed _exit to uxexit to avoid library name clash. + (do_mach_notify_dead_name, do_mach_notify_no_senders): + Call uxexit instead of _exit. + + * boot.c (S_io_async, S_io_get_icky_async_id, S_io_map_cntl): + Expect new type arg for returned port. + (S_io_prenotify, S_io_postnotify): START and END args are now + vm_offset_t. + + * boot.c: Change error_t to kern_return_t because error_t + is now unsigned and conflicts with MiG's use of kern_return_t. + + * Makefile (io_S.h, ioServer.c): Punt mungio hack; use + -DREPLY_PORTS. + * boot.c: Changed all io server stubs to expect reply ports. + + * mungio: removed file. + * Makefile (DIST_FILES): Removed mungio. + + * boot.c (load_image): Only read from the image file the actual + amount being read, not that amount rounded to the nearest page. + Otherwise, the first bit of the BSS will not be zero, but will be + whatever is in the front of the symbol section of the a.out. + +Thu May 5 07:43:06 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) + + * Makefile: Change uses of $(headers) to $(includedir). + +Mon May 2 16:47:49 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) + + * boot.c (S_io_readable): Implement io_readable fully. + +Fri Apr 1 17:55:38 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) + + * Makefile (OBJS): Remove boot_machdep.o. diff --git a/boot-proxy-exc/Makefile b/boot-proxy-exc/Makefile new file mode 100644 index 00000000..33c475fb --- /dev/null +++ b/boot-proxy-exc/Makefile @@ -0,0 +1,56 @@ +# Copyright (C) 1993,94,95,96,97,2001 Free Software Foundation, Inc. +# This file is part of the GNU Hurd. +# +# The GNU Hurd is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# The GNU Hurd is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with the GNU Hurd; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +dir := boot +makemode := utility + +SRCS = mach-crt0.c boot.c ux.c sigvec.S syscall.S \ + boot_script.c userland-boot.c list.c mach_proxy.c +COMMON-OBJS = notifyServer.o ourdeviceServer.o \ + ioServer.o io_replyUser.o device_replyUser.o \ + termServer.o bootstrapServer.o boot_script.o userland-boot.o \ + ourmach_hostServer.o ourmachServer.o ourmach_portServer.o excServer.o +OBJS = boot.o mach_host_impl.o mach_impl.o mach_port_impl.o \ + exc_impl.o list.o mach_proxy.o $(COMMON-OBJS) +UX-OBJS = mach-crt0.o uxboot.o sigvec.o syscall.o ux.o $(COMMON-OBJS) +LCLHDRS = boot_script.h ux.h util.h +target = boot +io-MIGSFLAGS=-DREPLY_PORTS +DIST_FILES=frank1.ld frankemul.ld +HURDLIBS=store shouldbeinlibc threads ports + +include ../Makeconf + +#install: /usr/local/bin/uxboot +# +#/usr/local/bin/uxboot: uxboot +# cp $< $@ + +all: boot # uxboot + +ourdevice.defs: device.defs + $(CPP) $(CPPFLAGS) -x c $< | sed -e '/out[ ]*device[ ]*:[ ]*device_t/s/device_t/mach_port_send_t/' > $@ + +uxboot.o: boot.c + $(COMPILE.c) -DUX $< -o $@ + +uxboot.0: $(UX-OBJS) ../libthreads/libthreads.a + $(LINK.o) -o $@ -static -nostartfiles -Wl,-T -Wl,$(srcdir)/frank1.ld $^ +uxboot.1: frankemul.ld uxboot.0 + $(LD) -o $@ -T $^ +uxboot: uxboot.1 + -$(OBJCOPY) -S --remove-section=.comment -O a.out-mach3 $< $@ diff --git a/boot-proxy-exc/backup/ourmach.defs b/boot-proxy-exc/backup/ourmach.defs new file mode 100644 index 00000000..67d8475e --- /dev/null +++ b/boot-proxy-exc/backup/ourmach.defs @@ -0,0 +1,770 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * Matchmaker definitions file for Mach kernel interface. + */ + +#ifdef MACH_KERNEL +simport <kern/compat_xxx_defs.h>; /* for obsolete routines */ +#endif /* MACH_KERNEL */ + +subsystem +#if KERNEL_USER + KernelUser +#endif /* KERNEL_USER */ +#if KERNEL_SERVER + KernelServer +#endif /* KERNEL_SERVER */ + mach 2000; + +serverprefix S_; + +#ifdef KERNEL_USER +userprefix r_; +#endif /* KERNEL_USER */ + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +skip; /* old port_allocate */ +skip; /* old port_deallocate */ +skip; /* old port_enable */ +skip; /* old port_disable */ +skip; /* old port_select */ +skip; /* old port_set_backlog */ +skip; /* old port_status */ + +/* + * Create a new task with an empty set of IPC rights, + * and having an address space constructed from the + * target task (or empty, if inherit_memory is FALSE). + */ +routine task_create( + target_task : task_t; + inherit_memory : boolean_t; + out child_task : mach_port_send_t); + +/* + * Destroy the target task, causing all of its threads + * to be destroyed, all of its IPC rights to be deallocated, + * and all of its address space to be deallocated. + */ +routine task_terminate( + target_task : task_t); + +/* + * Get user-level handler entry points for all + * emulated system calls. + */ +routine task_get_emulation_vector( + task : task_t; + out vector_start : int; + out emulation_vector: emulation_vector_t); + +/* + * Establish user-level handlers for the specified + * system calls. Non-emulated system calls are specified + * with emulation_vector[i] == EML_ROUTINE_NULL. + */ +routine task_set_emulation_vector( + task : task_t; + vector_start : int; + emulation_vector: emulation_vector_t); + +/* + * Returns the set of threads belonging to the target task. + */ +routine task_threads( + target_task : task_t; + out thread_list : thread_array_t = + array[] of mach_port_send_t, + dealloc); + +/* + * Returns information about the target task. + */ +routine task_info( + target_task : task_t; + flavor : int; + out task_info_out : task_info_t, CountInOut); + + +skip; /* old task_status */ +skip; /* old task_set_notify */ +skip; /* old thread_create */ + +/* + * Destroy the target thread. + */ +routine thread_terminate( + target_thread : thread_t); + +/* + * Return the selected state information for the target + * thread. If the thread is currently executing, the results + * may be stale. [Flavor THREAD_STATE_FLAVOR_LIST provides a + * list of valid flavors for the target thread.] + */ +routine thread_get_state( + target_thread : thread_t; + flavor : int; + out old_state : thread_state_t, CountInOut); + +/* + * Set the selected state information for the target thread. + * If the thread is currently executing, the state change + * may be ill-defined. + */ +routine thread_set_state( + target_thread : thread_t; + flavor : int; + new_state : thread_state_t); + +/* + * Returns information about the target thread. + */ +routine thread_info( + target_thread : thread_t; + flavor : int; + out thread_info_out : thread_info_t, CountInOut); + +skip; /* old thread_mutate */ + +/* + * Allocate zero-filled memory in the address space + * of the target task, either at the specified address, + * or wherever space can be found (if anywhere is TRUE), + * of the specified size. The address at which the + * allocation actually took place is returned. + */ +#ifdef EMULATOR +skip; /* the emulator redefines vm_allocate using vm_map */ +#else /* EMULATOR */ +routine vm_allocate( + target_task : vm_task_t; + inout address : vm_address_t; + size : vm_size_t; + anywhere : boolean_t); +#endif /* EMULATOR */ + +skip; /* old vm_allocate_with_pager */ + +/* + * Deallocate the specified range from the virtual + * address space of the target task. + */ +routine vm_deallocate( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t); + +/* + * Set the current or maximum protection attribute + * for the specified range of the virtual address + * space of the target task. The current protection + * limits the memory access rights of threads within + * the task; the maximum protection limits the accesses + * that may be given in the current protection. + * Protections are specified as a set of {read, write, execute} + * *permissions*. + */ +routine vm_protect( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + set_maximum : boolean_t; + new_protection : vm_prot_t); + +/* + * Set the inheritance attribute for the specified range + * of the virtual address space of the target task. + * The inheritance value is one of {none, copy, share}, and + * specifies how the child address space should acquire + * this memory at the time of a task_create call. + */ +routine vm_inherit( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + new_inheritance : vm_inherit_t); + +/* + * Returns the contents of the specified range of the + * virtual address space of the target task. [The + * range must be aligned on a virtual page boundary, + * and must be a multiple of pages in extent. The + * protection on the specified range must permit reading.] + */ +routine vm_read( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + out data : pointer_t, dealloc); + +/* + * Writes the contents of the specified range of the + * virtual address space of the target task. [The + * range must be aligned on a virtual page boundary, + * and must be a multiple of pages in extent. The + * protection on the specified range must permit writing.] + */ +routine vm_write( + target_task : vm_task_t; + address : vm_address_t; + data : pointer_t); + +/* + * Copy the contents of the source range of the virtual + * address space of the target task to the destination + * range in that same address space. [Both of the + * ranges must be aligned on a virtual page boundary, + * and must be multiples of pages in extent. The + * protection on the source range must permit reading, + * and the protection on the destination range must + * permit writing.] + */ +routine vm_copy( + target_task : vm_task_t; + source_address : vm_address_t; + size : vm_size_t; + dest_address : vm_address_t); + +/* + * Returns information about the contents of the virtual + * address space of the target task at the specified + * address. The returned protection, inheritance, sharing + * and memory object values apply to the entire range described + * by the address range returned; the memory object offset + * corresponds to the beginning of the address range. + * [If the specified address is not allocated, the next + * highest address range is described. If no addresses beyond + * the one specified are allocated, the call returns KERN_NO_SPACE.] + */ +routine vm_region( + target_task : vm_task_t; + inout address : vm_address_t; + out size : vm_size_t; + out protection : vm_prot_t; + out max_protection : vm_prot_t; + out inheritance : vm_inherit_t; + out is_shared : boolean_t; + /* avoid out-translation of the argument */ + out object_name : memory_object_name_t = + MACH_MSG_TYPE_COPY_SEND + ctype: mach_port_t; + out offset : vm_offset_t); + +/* + * Return virtual memory statistics for the host + * on which the target task resides. [Note that the + * statistics are not specific to the target task.] + */ +routine vm_statistics( + target_task : vm_task_t; + out vm_stats : vm_statistics_data_t); + +skip; /* old task_by_u*x_pid */ +skip; /* old vm_pageable */ + +/* + * Stash a handful of ports for the target task; child + * tasks inherit this stash at task_create time. + */ +routine mach_ports_register( + target_task : task_t; + init_port_set : mach_port_array_t = + ^array[] of mach_port_t); + +/* + * Retrieve the stashed ports for the target task. + */ +routine mach_ports_lookup( + target_task : task_t; + out init_port_set : mach_port_array_t = + ^array[] of mach_port_t); + +skip; /* old u*x_pid */ +skip; /* old netipc_listen */ +skip; /* old netipc_ignore */ + +/* + * Provide the data contents of a range of the given memory + * object, with the access restriction specified. [Only + * whole virtual pages of data can be accepted; partial pages + * will be discarded. Data should be provided on request, but + * may be provided in advance as desired. When data already + * held by this kernel is provided again, the new data is ignored. + * The access restriction is the subset of {read, write, execute} + * which are prohibited. The kernel may not provide any data (or + * protection) consistency among pages with different virtual page + * alignments within the same object.] + */ +simpleroutine memory_object_data_provided( + memory_control : memory_object_control_t; + offset : vm_offset_t; + data : pointer_t; + lock_value : vm_prot_t); + +/* + * Indicate that a range of the given temporary memory object does + * not exist, and that the backing memory object should be used + * instead (or zero-fill memory be used, if no backing object exists). + * [This call is intended for use only by the default memory manager. + * It should not be used to indicate a real error -- + * memory_object_data_error should be used for that purpose.] + */ +simpleroutine memory_object_data_unavailable( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t); + +/* + * Retrieves the attributes currently associated with + * a memory object. + */ +routine memory_object_get_attributes( + memory_control : memory_object_control_t; + out object_ready : boolean_t; + out may_cache : boolean_t; + out copy_strategy : memory_object_copy_strategy_t); + +/* + * Sets the default memory manager, the port to which + * newly-created temporary memory objects are delivered. + * [See (memory_object_default)memory_object_create.] + * The old memory manager port is returned. + */ +routine vm_set_default_memory_manager( + host_priv : host_priv_t; + inout default_manager : mach_port_copy_send_t); + +skip; /* old pager_flush_request */ + +/* + * Control use of the data associated with the given + * memory object. For each page in the given range, + * perform the following operations, in order: + * 1) restrict access to the page (disallow + * forms specified by "prot"); + * 2) write back modifications (if "should_return" + * is RETURN_DIRTY and the page is dirty, or + * "should_return" is RETURN_ALL and the page + * is either dirty or precious); and, + * 3) flush the cached copy (if "should_flush" + * is asserted). + * The set of pages is defined by a starting offset + * ("offset") and size ("size"). Only pages with the + * same page alignment as the starting offset are + * considered. + * + * A single acknowledgement is sent (to the "reply_to" + * port) when these actions are complete. + * + * There are two versions of this routine because IPC distinguishes + * between booleans and integers (a 2-valued integer is NOT a + * boolean). The new routine is backwards compatible at the C + * language interface. + */ +simpleroutine xxx_memory_object_lock_request( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + should_clean : boolean_t; + should_flush : boolean_t; + lock_value : vm_prot_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + + +simpleroutine memory_object_lock_request( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + should_return : memory_object_return_t; + should_flush : boolean_t; + lock_value : vm_prot_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +/* obsolete */ +routine xxx_task_get_emulation_vector( + task : task_t; + out vector_start : int; + out emulation_vector: xxx_emulation_vector_t, IsLong); + +/* obsolete */ +routine xxx_task_set_emulation_vector( + task : task_t; + vector_start : int; + emulation_vector: xxx_emulation_vector_t, IsLong); + +/* + * Returns information about the host on which the + * target object resides. [This object may be + * a task, thread, or memory_object_control port.] + */ +routine xxx_host_info( + target_task : mach_port_t; + out info : machine_info_data_t); + +/* + * Returns information about a particular processor on + * the host on which the target task resides. + */ +routine xxx_slot_info( + target_task : task_t; + slot : int; + out info : machine_slot_data_t); + +/* + * Performs control operations (currently only + * turning off or on) on a particular processor on + * the host on which the target task resides. + */ +routine xxx_cpu_control( + target_task : task_t; + cpu : int; + running : boolean_t); + +skip; /* old thread_statistics */ +skip; /* old task_statistics */ +skip; /* old netport_init */ +skip; /* old netport_enter */ +skip; /* old netport_remove */ +skip; /* old thread_set_priority */ + +/* + * Increment the suspend count for the target task. + * No threads within a task may run when the suspend + * count for that task is non-zero. + */ +routine task_suspend( + target_task : task_t); + +/* + * Decrement the suspend count for the target task, + * if the count is currently non-zero. If the resulting + * suspend count is zero, then threads within the task + * that also have non-zero suspend counts may execute. + */ +routine task_resume( + target_task : task_t); + +/* + * Returns the current value of the selected special port + * associated with the target task. + */ +routine task_get_special_port( + task : task_t; + which_port : int; + out special_port : mach_port_send_t); + +/* + * Set one of the special ports associated with the + * target task. + */ +routine task_set_special_port( + task : task_t; + which_port : int; + special_port : mach_port_t); + +/* obsolete */ +routine xxx_task_info( + target_task : task_t; + flavor : int; + out task_info_out : task_info_t, IsLong); + + +/* + * Create a new thread within the target task, returning + * the port representing that new thread. The + * initial execution state of the thread is undefined. + */ +routine thread_create( + parent_task : task_t; + out child_thread : mach_port_send_t); + +/* + * Increment the suspend count for the target thread. + * Once this call has completed, the thread will not + * execute any further user or meta- instructions. + * Once suspended, a thread may not execute again until + * its suspend count is zero, and the suspend count + * for its task is also zero. + */ +routine thread_suspend( + target_thread : thread_t); + +/* + * Decrement the suspend count for the target thread, + * if that count is not already zero. + */ +routine thread_resume( + target_thread : thread_t); + +/* + * Cause any user or meta- instructions currently being + * executed by the target thread to be aborted. [Meta- + * instructions consist of the basic traps for IPC + * (e.g., msg_send, msg_receive) and self-identification + * (e.g., task_self, thread_self, thread_reply). Calls + * described by MiG interfaces are not meta-instructions + * themselves.] + */ +routine thread_abort( + target_thread : thread_t); + +/* obsolete */ +routine xxx_thread_get_state( + target_thread : thread_t; + flavor : int; + out old_state : thread_state_t, IsLong); + +/* obsolete */ +routine xxx_thread_set_state( + target_thread : thread_t; + flavor : int; + new_state : thread_state_t, IsLong); + +/* + * Returns the current value of the selected special port + * associated with the target thread. + */ +routine thread_get_special_port( + thread : thread_t; + which_port : int; + out special_port : mach_port_t); + +/* + * Set one of the special ports associated with the + * target thread. + */ +routine thread_set_special_port( + thread : thread_t; + which_port : int; + special_port : mach_port_t); + +/* obsolete */ +routine xxx_thread_info( + target_thread : thread_t; + flavor : int; + out thread_info_out : thread_info_t, IsLong); + +/* + * Establish a user-level handler for the specified + * system call. + */ +routine task_set_emulation( + target_port : task_t; + routine_entry_pt: vm_address_t; + routine_number : int); + +/* + * Establish restart pc for interrupted atomic sequences. + * This reuses the message number for the old task_get_io_port. + * See task_info.h for description of flavors. + * + */ +routine task_ras_control( + target_task : task_t; + basepc : vm_address_t; + boundspc : vm_address_t; + flavor : int); + + + +skip; /* old host_ipc_statistics */ +skip; /* old port_names */ +skip; /* old port_type */ +skip; /* old port_rename */ +skip; /* old port_allocate */ +skip; /* old port_deallocate */ +skip; /* old port_set_backlog */ +skip; /* old port_status */ +skip; /* old port_set_allocate */ +skip; /* old port_set_deallocate */ +skip; /* old port_set_add */ +skip; /* old port_set_remove */ +skip; /* old port_set_status */ +skip; /* old port_insert_send */ +skip; /* old port_extract_send */ +skip; /* old port_insert_receive */ +skip; /* old port_extract_receive */ + +/* + * Map a user-defined memory object into the virtual address + * space of the target task. If desired (anywhere is TRUE), + * the kernel will find a suitable address range of the + * specified size; else, the specific address will be allocated. + * + * The beginning address of the range will be aligned on a virtual + * page boundary, be at or beyond the address specified, and + * meet the mask requirements (bits turned on in the mask must not + * be turned on in the result); the size of the range, in bytes, + * will be rounded up to an integral number of virtual pages. + * + * The memory in the resulting range will be associated with the + * specified memory object, with the beginning of the memory range + * referring to the specified offset into the memory object. + * + * The mapping will take the current and maximum protections and + * the inheritance attributes specified; see the vm_protect and + * vm_inherit calls for a description of these attributes. + * + * If desired (copy is TRUE), the memory range will be filled + * with a copy of the data from the memory object; this copy will + * be private to this mapping in this target task. Otherwise, + * the memory in this mapping will be shared with other mappings + * of the same memory object at the same offset (in this task or + * in other tasks). [The Mach kernel only enforces shared memory + * consistency among mappings on one host with similar page alignments. + * The user-defined memory manager for this object is responsible + * for further consistency.] + */ +#ifdef EMULATOR +routine htg_vm_map( + target_task : vm_task_t; + ureplyport reply_port : mach_port_make_send_once_t; + inout address : vm_address_t; + size : vm_size_t; + mask : vm_address_t; + anywhere : boolean_t; + memory_object : memory_object_t; + offset : vm_offset_t; + copy : boolean_t; + cur_protection : vm_prot_t; + max_protection : vm_prot_t; + inheritance : vm_inherit_t); +#else /* EMULATOR */ +routine vm_map( + target_task : vm_task_t; + inout address : vm_address_t; + size : vm_size_t; + mask : vm_address_t; + anywhere : boolean_t; + memory_object : memory_object_t; + offset : vm_offset_t; + copy : boolean_t; + cur_protection : vm_prot_t; + max_protection : vm_prot_t; + inheritance : vm_inherit_t); +#endif /* EMULATOR */ + +/* + * Indicate that a range of the specified memory object cannot + * be provided at this time. [Threads waiting for memory pages + * specified by this call will experience a memory exception. + * Only threads waiting at the time of the call are affected.] + */ +simpleroutine memory_object_data_error( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + error_value : kern_return_t); + +/* + * Make decisions regarding the use of the specified + * memory object. + */ +simpleroutine memory_object_set_attributes( + memory_control : memory_object_control_t; + object_ready : boolean_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t); + +/* + */ +simpleroutine memory_object_destroy( + memory_control : memory_object_control_t; + reason : kern_return_t); + +/* + * Provide the data contents of a range of the given memory + * object, with the access restriction specified, optional + * precious attribute, and reply message. [Only + * whole virtual pages of data can be accepted; partial pages + * will be discarded. Data should be provided on request, but + * may be provided in advance as desired. When data already + * held by this kernel is provided again, the new data is ignored. + * The access restriction is the subset of {read, write, execute} + * which are prohibited. The kernel may not provide any data (or + * protection) consistency among pages with different virtual page + * alignments within the same object. The precious value controls + * how the kernel treats the data. If it is FALSE, the kernel treats + * its copy as a temporary and may throw it away if it hasn't been + * changed. If the precious value is TRUE, the kernel treats its + * copy as a data repository and promises to return it to the manager; + * the manager may tell the kernel to throw it away instead by flushing + * and not cleaning the data -- see memory_object_lock_request. The + * reply_to port is for a compeletion message; it will be + * memory_object_supply_completed.] + */ + +simpleroutine memory_object_data_supply( + memory_control : memory_object_control_t; + offset : vm_offset_t; + data : pointer_t, Dealloc[]; + lock_value : vm_prot_t; + precious : boolean_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +simpleroutine memory_object_ready( + memory_control : memory_object_control_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t); + +simpleroutine memory_object_change_attributes( + memory_control : memory_object_control_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +skip; /* old host_callout_statistics_reset */ +skip; /* old port_set_select */ +skip; /* old port_set_backup */ + +/* + * Set/Get special properties of memory associated + * to some virtual address range, such as cachability, + * migrability, replicability. Machine-dependent. + */ +routine vm_machine_attribute( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + attribute : vm_machine_attribute_t; + inout value : vm_machine_attribute_val_t); + +skip; /* old host_fpa_counters_reset */ + +/* + * There is no more room in this interface for additional calls. + */ diff --git a/boot-proxy-exc/backup/ourmach_host.defs b/boot-proxy-exc/backup/ourmach_host.defs new file mode 100644 index 00000000..0e7e367e --- /dev/null +++ b/boot-proxy-exc/backup/ourmach_host.defs @@ -0,0 +1,381 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * File: mach/mach_host.defs + * + * Abstract: + * Mach host operations support. Includes processor allocation and + * control. + */ + +#ifdef MACH_KERNEL +simport <kern/compat_xxx_defs.h>; /* for obsolete routines */ +#endif + +subsystem +#if KERNEL_SERVER + KernelServer +#endif + mach_host 2600; + +serverprefix S_; + +/* + * Basic types + */ + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +/* + * Get list of processors on this host. + */ + +routine host_processors( + host_priv : host_priv_t; + out processor_list : processor_array_t); + +/* obsolete */ +routine yyy_host_info( + host : host_t; + flavor : int; + out host_info_out : host_info_t, IsLong); + + +/* obsolete */ +routine yyy_processor_info( + processor : processor_t; + flavor : int; + out host : host_t; + out processor_info_out: processor_info_t, IsLong); + +/* + * Start processor. + */ + +routine processor_start( + processor : processor_t); + +/* + * Exit processor -- may not be restartable. + */ + +routine processor_exit( + processor : processor_t); + +/* obsolete */ +routine yyy_processor_control( + processor : processor_t; + processor_cmd : processor_info_t, IsLong); + +/* + * Get default processor set for host. + */ +routine processor_set_default( + host : host_t; + out default_set : processor_set_name_t); + +/* + * Get rights to default processor set for host. + * Replaced by host_processor_set_priv. + */ +routine xxx_processor_set_default_priv( + host : host_priv_t; + out default_set : processor_set_t); + +/* + * Create new processor set. Returns real port for manipulations, + * and name port for obtaining information. + */ +routine processor_set_create( + host : host_t; + out new_set : processor_set_t; + out new_name : processor_set_name_t); + +/* + * Destroy processor set. + */ +routine processor_set_destroy( + set : processor_set_t); + +/* obsolete */ +routine yyy_processor_set_info( + set_name : processor_set_name_t; + flavor : int; + out host : host_t; + out info_out : processor_set_info_t, IsLong); + +/* + * Assign processor to processor set. + */ +routine processor_assign( + processor : processor_t; + new_set : processor_set_t; + wait : boolean_t); + +/* + * Get current assignment for processor. + */ + +routine processor_get_assignment( + processor : processor_t; + out assigned_set : processor_set_name_t); + +/* + * Assign thread to processor set. + */ +routine thread_assign( + thread : thread_t; + new_set : processor_set_t); + +/* + * Assign thread to default set. + */ +routine thread_assign_default( + thread : thread_t); + +/* + * Get current assignment for thread. + */ +routine thread_get_assignment( + thread : thread_t; + out assigned_set : processor_set_name_t); + +/* + * Assign task to processor set. + */ +routine task_assign( + task : task_t; + new_set : processor_set_t; + assign_threads : boolean_t); +/* + * Assign task to default set. + */ +routine task_assign_default( + task : task_t; + assign_threads : boolean_t); + +/* + * Get current assignment for task. + */ +routine task_get_assignment( + task : task_t; + out assigned_set : processor_set_name_t); + +/* + * Get string describing current kernel version. + */ +routine host_kernel_version( + host : host_t; + out kernel_version : kernel_version_t); + +/* + * Set priority for thread. + */ +routine thread_priority( + thread : thread_t; + priority : int; + set_max : boolean_t); + +/* + * Set max priority for thread. + */ +routine thread_max_priority( + thread : thread_t; + processor_set : processor_set_t; + max_priority : int); + +/* + * Set task priority. + */ +routine task_priority( + task : task_t; + priority : int; + change_threads : boolean_t); + +/* + * Set max priority for processor_set. + */ +routine processor_set_max_priority( + processor_set : processor_set_t; + max_priority : int; + change_threads : boolean_t); + +/* + * Set policy for thread + */ +routine thread_policy( + thread : thread_t; + policy : int; + data : int); + +/* + * Enable policy for processor set + */ +routine processor_set_policy_enable( + processor_set : processor_set_t; + policy : int); + +/* + * Disable policy for processor set + */ +routine processor_set_policy_disable( + processor_set : processor_set_t; + policy : int; + change_threads : boolean_t); +/* + * List all tasks in processor set. + */ +routine processor_set_tasks( + processor_set : processor_set_t; + out task_list : task_array_t); + +/* + * List all threads in processor set. + */ +routine processor_set_threads( + processor_set : processor_set_t; + out thread_list : thread_array_t); + +/* + * List all processor sets on host. + */ +routine host_processor_sets( + host : host_t; + out processor_sets : processor_set_name_array_t); + +/* + * Get control port for a processor set. + */ +routine host_processor_set_priv( + host_priv : host_priv_t; + set_name : processor_set_name_t; + out set : mach_port_send_t); + +routine thread_depress_abort( + thread : thread_t); + +/* + * Set the time on this host. + * Only available to privileged users. + */ +routine host_set_time( + host_priv : host_priv_t; + new_time : time_value_t); + +/* + * Arrange for the time on this host to be gradually changed + * by an adjustment value, and return the old value. + * Only available to privileged users. + */ +routine host_adjust_time( + host_priv : host_priv_t; + in new_adjustment : time_value_t; + out old_adjustment : time_value_t); + +/* + * Get the time on this host. + * Available to all. + */ +routine host_get_time( + host : host_t; + out current_time : time_value_t); + +/* + * Reboot this host. + * Only available to privileged users. + */ +routine host_reboot( + host_priv : host_priv_t; + options : int); + +/* + * Specify that the range of the virtual address space + * of the target task must not cause page faults for + * the indicated accesses. + * + * [ To unwire the pages, specify VM_PROT_NONE. ] + */ +routine vm_wire( + host_priv : host_priv_t; + task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + access : vm_prot_t); + +/* + * Specify that the target thread must always be able + * to run and to allocate memory. + */ +routine thread_wire( + host_priv : host_priv_t; + thread : thread_t; + wired : boolean_t); + +/* + * Return information about this host. + */ + +routine host_info( + host : host_t; + flavor : int; + out host_info_out : host_info_t, CountInOut); + + +/* + * Return information about this processor. + */ +routine processor_info( + processor : processor_t; + flavor : int; + out host : host_t; + out processor_info_out: processor_info_t, CountInOut); + +/* + * Get information about processor set. + */ +routine processor_set_info( + set_name : processor_set_name_t; + flavor : int; + out host : host_t; + out info_out : processor_set_info_t, CountInOut); + +/* + * Do something machine-dependent to processor. + */ +routine processor_control( + processor : processor_t; + processor_cmd : processor_info_t); + +/* + * Get boot configuration information from kernel. + */ +routine host_get_boot_info( + host_priv : host_priv_t; + out boot_info : kernel_boot_info_t); diff --git a/boot-proxy-exc/backup/ourmach_port.defs b/boot-proxy-exc/backup/ourmach_port.defs new file mode 100644 index 00000000..4f131bb2 --- /dev/null +++ b/boot-proxy-exc/backup/ourmach_port.defs @@ -0,0 +1,349 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * File: mach/mach_port.defs + * Author: Rich Draves + * + * Copyright (c) 1989 Richard P. Draves, Jr. + * + * Exported kernel calls. + */ + +subsystem +#if KERNEL_SERVER + KernelServer +#endif + mach_port 3200; + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +/* + * Returns the set of port and port set names + * to which the target task has access, along with + * the type (set or port) for each name. + */ + +routine mach_port_names( + task : ipc_space_t; + out names : mach_port_name_array_t = + ^array[] of mach_port_name_t + ctype: mach_port_array_t, + dealloc; + out types : mach_port_type_array_t = + ^array[] of mach_port_type_t, + dealloc); + +/* + * Returns the type (set or port) for the port name + * within the target task. Also indicates whether + * there is a dead-name request for the name. + */ + +routine mach_port_type( + task : ipc_space_t; + name : mach_port_name_t; + out ptype : mach_port_type_t); + +/* + * Changes the name by which a port (or port set) is known to + * the target task. The new name can't be in use. The + * old name becomes available for recycling. + */ + +routine mach_port_rename( + task : ipc_space_t; + old_name : mach_port_name_t; + new_name : mach_port_name_t); + +/* + * Allocates the specified kind of object, with the given name. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * New port sets are empty. New ports don't have any + * send/send-once rights or queued messages. The make-send + * count is zero and their queue limit is MACH_PORT_QLIMIT_DEFAULT. + * New sets, ports, and dead names have one user reference. + */ + +routine mach_port_allocate_name( + task : ipc_space_t; + right : mach_port_right_t; + name : mach_port_name_t); + +/* + * Allocates the specified kind of object. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * Like port_allocate_name, but the kernel picks a name. + * It can use any name not associated with a right. + */ + +routine mach_port_allocate( + task : ipc_space_t; + right : mach_port_right_t; + out name : mach_port_name_t); + +/* + * Destroys all rights associated with the name and makes it + * available for recycling immediately. The name can be a + * port (possibly with multiple user refs), a port set, or + * a dead name (again, with multiple user refs). + */ + +routine mach_port_destroy( + task : ipc_space_t; + name : mach_port_name_t); + +/* + * Releases one send/send-once/dead-name user ref. + * Just like mach_port_mod_refs -1, but deduces the + * correct type of right. This allows a user task + * to release a ref for a port without worrying + * about whether the port has died or not. + */ + +routine mach_port_deallocate( + task : ipc_space_t; + name : mach_port_name_t); + +/* + * A port set always has one user ref. + * A send-once right always has one user ref. + * A dead name always has one or more user refs. + * A send right always has one or more user refs. + * A receive right always has one user ref. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * MACH_PORT_RIGHT_SEND + * MACH_PORT_RIGHT_SEND_ONCE + */ + +routine mach_port_get_refs( + task : ipc_space_t; + name : mach_port_name_t; + right : mach_port_right_t; + out refs : mach_port_urefs_t); + +/* + * The delta is a signed change to the task's + * user ref count for the right. Only dead names + * and send rights can have a positive delta. + * The resulting user ref count can't be negative. + * If it is zero, the right is deallocated. + * If the name isn't a composite right, it becomes + * available for recycling. The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * MACH_PORT_RIGHT_SEND + * MACH_PORT_RIGHT_SEND_ONCE + */ + +routine mach_port_mod_refs( + task : ipc_space_t; + name : mach_port_name_t; + right : mach_port_right_t; + delta : mach_port_delta_t); + +/* + * Temporary compatibility call. + */ + +routine old_mach_port_get_receive_status( + task : ipc_space_t; + name : mach_port_name_t; + out status : old_mach_port_status_t); + +/* + * Only valid for receive rights. + * Sets the queue-limit for the port. + * The limit must be + * 1 <= qlimit <= MACH_PORT_QLIMIT_MAX + */ + +routine mach_port_set_qlimit( + task : ipc_space_t; + name : mach_port_name_t; + qlimit : mach_port_msgcount_t); + +/* + * Only valid for receive rights. + * Sets the make-send count for the port. + */ + +routine mach_port_set_mscount( + task : ipc_space_t; + name : mach_port_name_t; + mscount : mach_port_mscount_t); + +/* + * Only valid for port sets. Returns a list of + * the members. + */ + +routine mach_port_get_set_status( + task : ipc_space_t; + name : mach_port_name_t; + out members : mach_port_name_array_t = + ^array[] of mach_port_name_t + ctype: mach_port_array_t, + dealloc); + +/* + * Puts the member port (the task must have receive rights) + * into the after port set. (Or removes it from any port set + * if after is MACH_PORT_NULL.) If the port is already in + * a set, does an atomic move. + */ + +routine mach_port_move_member( + task : ipc_space_t; + member : mach_port_name_t; + after : mach_port_name_t); + +/* + * Requests a notification from the kernel. The request + * must supply the send-once right which is used for + * the notification. If a send-once right was previously + * registered, it is returned. The msg_id must be one of + * MACH_NOTIFY_PORT_DESTROYED (receive rights) + * MACH_NOTIFY_DEAD_NAME (send/receive/send-once rights) + * MACH_NOTIFY_NO_SENDERS (receive rights) + * + * The sync value specifies whether a notification should + * get sent immediately, if appropriate. The exact meaning + * depends on the notification: + * MACH_NOTIFY_PORT_DESTROYED: must be zero. + * MACH_NOTIFY_DEAD_NAME: if non-zero, then name can be dead, + * and the notification gets sent immediately. + * If zero, then name can't be dead. + * MACH_NOTIFY_NO_SENDERS: the notification gets sent + * immediately if the current mscount is greater + * than or equal to the sync value and there are no + * extant send rights. + */ + +routine mach_port_request_notification( + task : ipc_space_t; + name : mach_port_name_t; + id : mach_msg_id_t; + sync : mach_port_mscount_t; + notify : mach_port_send_once_t; + out previous : mach_port_send_once_t); + +/* + * Inserts the specified rights into the target task, + * using the specified name. If inserting send/receive + * rights and the task already has send/receive rights + * for the port, then the names must agree. In any case, + * the task gains a user ref for the port. + */ + +routine mach_port_insert_right( + task : ipc_space_t; + name : mach_port_name_t; + poly : mach_port_poly_t); + +/* + * Returns the specified right for the named port + * in the target task, extracting that right from + * the target task. The target task loses a user + * ref and the name may be available for recycling. + * msgt_name must be one of + * MACH_MSG_TYPE_MOVE_RECEIVE + * MACH_MSG_TYPE_COPY_SEND + * MACH_MSG_TYPE_MAKE_SEND + * MACH_MSG_TYPE_MOVE_SEND + * MACH_MSG_TYPE_MAKE_SEND_ONCE + * MACH_MSG_TYPE_MOVE_SEND_ONCE + */ + +routine mach_port_extract_right( + task : ipc_space_t; + name : mach_port_name_t; + msgt_name : mach_msg_type_name_t; + out poly : mach_port_poly_t); + +/* + * The task must have receive rights for the named port. + * Returns a status structure (see mach/port.h). + */ + +routine mach_port_get_receive_status( + task : ipc_space_t; + name : mach_port_name_t; + out status : mach_port_status_t); + +/* + * Only valid for receive rights. + * Sets the sequence number for the port. + */ + +routine mach_port_set_seqno( + task : ipc_space_t; + name : mach_port_name_t; + seqno : mach_port_seqno_t); + +#ifdef MIGRATING_THREADS +/* + * Only valid for receive rights. + * Set the user-mode entry info for RPCs coming through this port. + * Do this BEFORE attaching an ActPool to this port, + * unless you can be sure no RPCs will be coming through it yet. + */ + +routine mach_port_set_rpcinfo( + task : ipc_space_t; + name : mach_port_name_t; + rpc_info : thread_info_t); /* XXX */ + +/* + * Only valid for receive rights. + * Create a new activation for migrating RPC, and attach it to the port's ActPool. + * Create an ActPool for the port if it doesn't already have one. + * Supply a stack and receive memory buffer. + */ + +routine mach_port_create_act( + task : task_t; + name : mach_port_name_t; + user_stack : vm_offset_t; + user_rbuf : vm_offset_t; + user_rbuf_size : vm_size_t; + out new_act : thread_t); + +#endif /* MIGRATING_THREADS */ + diff --git a/boot-proxy-exc/boot.c b/boot-proxy-exc/boot.c new file mode 100644 index 00000000..83b69c08 --- /dev/null +++ b/boot-proxy-exc/boot.c @@ -0,0 +1,2150 @@ +/* Load a task using the single server, and then run it + as if we were the kernel. + Copyright (C) 1993,94,95,96,97,98,99,2000,01,02,2006 + Free Software Foundation, Inc. + +This file is part of the GNU Hurd. + +The GNU Hurd is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +The GNU Hurd is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the GNU Hurd; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* Written by Michael I. Bushnell. */ + +#include <mach.h> +#include <mach/notify.h> +#include <device/device.h> +#include <a.out.h> +#include <mach/message.h> +#include <mach/mig_errors.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <cthreads.h> +#include <fcntl.h> +#include <elf.h> +#include <mach/mig_support.h> +#include <mach/default_pager.h> +#include <argp.h> +#include <hurd/store.h> +#include <hurd/ports.h> +#include <sys/mman.h> +#include <version.h> + +#include "notify_S.h" +#include "ourdevice_S.h" +#include "io_S.h" +#include "device_reply_U.h" +#include "io_reply_U.h" +#include "term_S.h" +#include "bootstrap_S.h" +/* #include "tioctl_S.h" */ +#include "util.h" +#include "boot_script.h" +#include "mach_proxy.h" + +#include <hurd/auth.h> + +#ifdef UX +#undef STORE /* We can't use libstore when under UX. */ +#else +#define STORE +#endif + +#ifdef UX + +#include "ux.h" + +#else /* !UX */ + +#include <unistd.h> +#include <fcntl.h> +#include <signal.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <termios.h> +#include <error.h> +#include <hurd.h> +#include <assert.h> + +static struct termios orig_tty_state; +static int isig; +static char *kernel_command_line; + +struct port_bucket *port_bucket; +struct port_class *task_portclass; +struct port_class *exc_portclass; +struct port_class *priv_host_portclass; +struct port_class *other_portclass; + +void destroy_priv_host (void *pi); + +static void +init_termstate () +{ + struct termios tty_state; + + if (tcgetattr (0, &tty_state) < 0) + error (10, errno, "tcgetattr"); + + orig_tty_state = tty_state; + cfmakeraw (&tty_state); + if (isig) + tty_state.c_lflag |= ISIG; + + if (tcsetattr (0, 0, &tty_state) < 0) + error (11, errno, "tcsetattr"); +} + +static void +restore_termstate () +{ + tcsetattr (0, 0, &orig_tty_state); +} + +#define host_fstat fstat +typedef struct stat host_stat_t; +#define host_exit exit + +#endif /* UX */ + +mach_port_t privileged_host_port, master_device_port, defpager; +mach_port_t pseudo_master_device_port; +mach_port_t receive_set; +mach_port_t pseudo_console, pseudo_root; +auth_t authserver; + +struct port_info *pseudo_priv_host_pi; + +struct store *root_store; + +spin_lock_t queuelock = SPIN_LOCK_INITIALIZER; +spin_lock_t readlock = SPIN_LOCK_INITIALIZER; + +mach_port_t php_child_name, psmdp_child_name, taskname; + +task_t child_task; +mach_port_t bootport; + +int console_mscount; + +vm_address_t fs_stack_base; +vm_size_t fs_stack_size; + +void init_termstate (); +void restore_termstate (); + +char *fsname; + +char bootstrap_args[100] = "-"; +char *bootdevice = 0; +char *bootscript = 0; + +boolean_t is_user = 0; + + +void safe_gets (char *buf, int buf_len) +{ + fgets (buf, buf_len, stdin); +} + +char *useropen_dir; + +int +useropen (const char *name, int flags, int mode) +{ + if (useropen_dir) + { + static int dlen; + if (!dlen) dlen = strlen (useropen_dir); + { + int len = strlen (name); + char try[dlen + 1 + len + 1]; + int fd; + memcpy (try, useropen_dir, dlen); + try[dlen] = '/'; + memcpy (&try[dlen + 1], name, len + 1); + fd = open (try, flags, mode); + if (fd >= 0) + return fd; + } + } + return open (name, flags, mode); +} + +int +request_server (mach_msg_header_t *inp, + mach_msg_header_t *outp) +{ + extern int io_server (mach_msg_header_t *, mach_msg_header_t *); + extern int device_server (mach_msg_header_t *, mach_msg_header_t *); + extern int notify_server (mach_msg_header_t *, mach_msg_header_t *); + extern int term_server (mach_msg_header_t *, mach_msg_header_t *); +/* extern int tioctl_server (mach_msg_header_t *, mach_msg_header_t *); */ + extern int bootstrap_server (mach_msg_header_t *, mach_msg_header_t *); + extern boolean_t mach_host_server (mach_msg_header_t *InHeadP, + mach_msg_header_t *OutHeadP); + extern boolean_t mach_server (mach_msg_header_t *InHeadP, + mach_msg_header_t *OutHeadP); + extern void bootstrap_compat (); + +#if 0 + if (inp->msgh_local_port == bootport && boot_like_cmudef) + { + if (inp->msgh_id == 999999) + { + bootstrap_compat (inp, outp); + return 1; + } + else + return bootstrap_server (inp, outp); + } + else +#endif + return (io_server (inp, outp) + || device_server (inp, outp) + || notify_server (inp, outp) + || term_server (inp, outp) + /* || tioctl_server (inp, outp) */); +} + +int +mach_proxy_demuxer (mach_msg_header_t *inp, + mach_msg_header_t *outp) +{ + extern boolean_t mach_server + (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP); + extern boolean_t mach_host_server + (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP); + extern boolean_t mach_port_server + (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP); + extern boolean_t exc_server + (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP); + extern int notify_server (mach_msg_header_t *, mach_msg_header_t *); + return (mach_server (inp, outp) + || mach_host_server (inp, outp) + || mach_port_server (inp, outp) + || notify_server (inp, outp) + || exc_server (inp, outp)); +} + +void +mach_proxy_thread () +{ + ports_manage_port_operations_multithread (port_bucket, + mach_proxy_demuxer, + 30 * 1000, 0, 0); +} + +vm_address_t +load_image (task_t t, + char *file) +{ + int fd; + union + { + struct exec a; + Elf32_Ehdr e; + } hdr; + char msg[] = ": cannot open bootstrap file\n"; + + fd = useropen (file, O_RDONLY, 0); + + if (fd == -1) + { + write (2, file, strlen (file)); + write (2, msg, sizeof msg - 1); + task_terminate (t); + host_exit (1); + } + + read (fd, &hdr, sizeof hdr); + if (*(Elf32_Word *) hdr.e.e_ident == *(Elf32_Word *) "\177ELF") + { + Elf32_Phdr phdrs[hdr.e.e_phnum], *ph; + lseek (fd, hdr.e.e_phoff, SEEK_SET); + read (fd, phdrs, sizeof phdrs); + for (ph = phdrs; ph < &phdrs[sizeof phdrs/sizeof phdrs[0]]; ++ph) + if (ph->p_type == PT_LOAD) + { + vm_address_t buf; + vm_size_t offs = ph->p_offset & (ph->p_align - 1); + vm_size_t bufsz = round_page (ph->p_filesz + offs); + + buf = (vm_address_t) mmap (0, bufsz, + PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + + lseek (fd, ph->p_offset, SEEK_SET); + read (fd, (void *)(buf + offs), ph->p_filesz); + + ph->p_memsz = ((ph->p_vaddr + ph->p_memsz + ph->p_align - 1) + & ~(ph->p_align - 1)); + ph->p_vaddr &= ~(ph->p_align - 1); + ph->p_memsz -= ph->p_vaddr; + + vm_allocate (t, (vm_address_t*)&ph->p_vaddr, ph->p_memsz, 0); + vm_write (t, ph->p_vaddr, buf, bufsz); + munmap ((caddr_t) buf, bufsz); + vm_protect (t, ph->p_vaddr, ph->p_memsz, 0, + ((ph->p_flags & PF_R) ? VM_PROT_READ : 0) | + ((ph->p_flags & PF_W) ? VM_PROT_WRITE : 0) | + ((ph->p_flags & PF_X) ? VM_PROT_EXECUTE : 0)); + } + return hdr.e.e_entry; + } + else + { + /* a.out */ + int magic = N_MAGIC (hdr.a); + int headercruft; + vm_address_t base = 0x10000; + int rndamount, amount; + vm_address_t bsspagestart, bssstart; + char *buf; + + headercruft = sizeof (struct exec) * (magic == ZMAGIC); + + amount = headercruft + hdr.a.a_text + hdr.a.a_data; + rndamount = round_page (amount); + buf = mmap (0, rndamount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + lseek (fd, sizeof hdr.a - headercruft, SEEK_SET); + read (fd, buf, amount); + vm_allocate (t, &base, rndamount, 0); + vm_write (t, base, (vm_address_t) buf, rndamount); + if (magic != OMAGIC) + vm_protect (t, base, trunc_page (headercruft + hdr.a.a_text), + 0, VM_PROT_READ | VM_PROT_EXECUTE); + munmap ((caddr_t) buf, rndamount); + + bssstart = base + hdr.a.a_text + hdr.a.a_data + headercruft; + bsspagestart = round_page (bssstart); + vm_allocate (t, &bsspagestart, + hdr.a.a_bss - (bsspagestart - bssstart), 0); + + return hdr.a.a_entry; + } +} + + +void read_reply (); +void msg_thread (); + +/* Callbacks for boot_script.c; see boot_script.h. */ + +mach_port_t +boot_script_read_file (const char *filename) +{ + static const char msg[] = ": cannot open\n"; + int fd = useropen (filename, O_RDONLY, 0); + host_stat_t st; + error_t err; + mach_port_t memobj; + vm_address_t region; + + write (2, filename, strlen (filename)); + if (fd < 0) + { + write (2, msg, sizeof msg - 1); + host_exit (1); + } + else + write (2, msg + sizeof msg - 2, 1); + + host_fstat (fd, &st); + + err = default_pager_object_create (defpager, &memobj, + round_page (st.st_size)); + if (err) + { + static const char msg[] = "cannot create default-pager object\n"; + write (2, msg, sizeof msg - 1); + host_exit (1); + } + + region = 0; + vm_map (mach_task_self (), ®ion, round_page (st.st_size), + 0, 1, memobj, 0, 0, VM_PROT_ALL, VM_PROT_ALL, VM_INHERIT_NONE); + read (fd, (char *) region, st.st_size); + munmap ((caddr_t) region, round_page (st.st_size)); + + close (fd); + return memobj; +} + +int +boot_script_exec_cmd (void *hook, + mach_port_t task, char *path, int argc, + char **argv, char *strings, int stringlen) +{ + char *args, *p; + int arg_len, i; + size_t reg_size; + void *arg_pos; + vm_offset_t stack_start, stack_end; + vm_address_t startpc, str_start; + thread_t thread; + + write (2, path, strlen (path)); + for (i = 1; i < argc; ++i) + { + write (2, " ", 1); + write (2, argv[i], strlen (argv[i])); + } + write (2, "\r\n", 2); + + startpc = load_image (task, path); + arg_len = stringlen + (argc + 2) * sizeof (char *) + sizeof (integer_t); + arg_len += 5 * sizeof (int); + stack_end = VM_MAX_ADDRESS; + stack_start = VM_MAX_ADDRESS - 16 * 1024 * 1024; + vm_allocate (task, &stack_start, stack_end - stack_start, FALSE); + arg_pos = (void *) ((stack_end - arg_len) & ~(sizeof (natural_t) - 1)); + args = mmap (0, stack_end - trunc_page ((vm_offset_t) arg_pos), + PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + str_start = ((vm_address_t) arg_pos + + (argc + 2) * sizeof (char *) + sizeof (integer_t)); + p = args + ((vm_address_t) arg_pos & (vm_page_size - 1)); + *(int *) p = argc; + p = (void *) p + sizeof (int); + for (i = 0; i < argc; i++) + { + *(char **) p = argv[i] - strings + (char *) str_start; + p = (void *) p + sizeof (char *); + } + *(char **) p = 0; + p = (void *) p + sizeof (char *); + *(char **) p = 0; + p = (void *) p + sizeof (char *); + memcpy (p, strings, stringlen); + bzero (args, (vm_offset_t) arg_pos & (vm_page_size - 1)); + vm_write (task, trunc_page ((vm_offset_t) arg_pos), (vm_address_t) args, + stack_end - trunc_page ((vm_offset_t) arg_pos)); + munmap ((caddr_t) args, + stack_end - trunc_page ((vm_offset_t) arg_pos)); + + thread_create (task, &thread); +#ifdef i386_THREAD_STATE_COUNT + { + struct i386_thread_state regs; + reg_size = i386_THREAD_STATE_COUNT; + thread_get_state (thread, i386_THREAD_STATE, + (thread_state_t) ®s, ®_size); + regs.eip = (int) startpc; + regs.uesp = (int) arg_pos; + thread_set_state (thread, i386_THREAD_STATE, + (thread_state_t) ®s, reg_size); + } +#elif defined(ALPHA_THREAD_STATE_COUNT) + { + struct alpha_thread_state regs; + reg_size = ALPHA_THREAD_STATE_COUNT; + thread_get_state (thread, ALPHA_THREAD_STATE, + (thread_state_t) ®s, ®_size); + regs.r30 = (natural_t) arg_pos; + regs.pc = (natural_t) startpc; + thread_set_state (thread, ALPHA_THREAD_STATE, + (thread_state_t) ®s, reg_size); + } +#else +# error needs to be ported +#endif + + thread_resume (thread); + mach_port_deallocate (mach_task_self (), thread); + return 0; +} + +const char *argp_program_version = STANDARD_HURD_VERSION (boot); + +static struct argp_option options[] = +{ + { "boot-root", 'D', "DIR", 0, + "Root of a directory tree in which to find files specified in BOOT-SCRIPT" }, + { "single-user", 's', 0, 0, + "Boot in single user mode" }, + { "kernel-command-line", 'c', "COMMAND LINE", 0, + "Simulated multiboot command line to supply" }, + { "pause" , 'd', 0, 0, + "Pause for user confirmation at various times during booting" }, + { "isig", 'I', 0, 0, + "Do not disable terminal signals, so you can suspend and interrupt boot."}, + { "device-map", 'm', "DEBICENAME=DEVICEFILE", 0, + "Map the device in subhurd to the device in the main Hurd."}, + { "defpager", 'p', "PAGER TRANSLATOR", 0, + "Specify the default pager for subhurd."}, + { "user", 'u', 0, 0, "For normal user."}, + { 0 } +}; +static char args_doc[] = "BOOT-SCRIPT"; +static char doc[] = "Boot a second hurd"; + +struct dev_map +{ + char *name; + mach_port_t port; + struct dev_map *next; +}; + +static struct dev_map *dev_map_head; + +static struct dev_map *add_dev_map (char *dev_name, char *dev_file) +{ + struct dev_map *map = (struct dev_map *) malloc (sizeof (*map)); + + assert (map); + map->name = dev_name; + map->port = file_name_lookup (dev_file, 0, 0); + if (map->port == MACH_PORT_NULL) + error (1, errno, "file_name_lookup: %s", dev_file); + map->next = dev_map_head; + dev_map_head = map; + return map; +} + +static struct dev_map *lookup_dev (char *dev_name) +{ + struct dev_map *map; + + for (map = dev_map_head; map; map = map->next) + { + if (strcmp (map->name, dev_name) == 0) + return map; + } + return NULL; +} + +char *pager_file; + +static error_t +parse_opt (int key, char *arg, struct argp_state *state) +{ + char *dev_file; + + switch (key) + { + size_t len; + + case 'c': kernel_command_line = arg; break; + + case 'D': useropen_dir = arg; break; + + case 'I': isig = 1; break; + + case 's': case 'd': + len = strlen (bootstrap_args); + if (len >= sizeof bootstrap_args - 1) + argp_error (state, "Too many bootstrap args"); + bootstrap_args[len++] = key; + bootstrap_args[len] = '\0'; + break; + + case 'm': + dev_file = strchr (arg, '='); + if (dev_file == NULL) + return ARGP_ERR_UNKNOWN; + *dev_file = 0; + add_dev_map (arg, dev_file+1); + break; + + case 'p': + pager_file = arg; + break; + + case 'u': + is_user = 1; + break; + + case ARGP_KEY_ARG: + if (state->arg_num == 0) + bootscript = arg; + else + return ARGP_ERR_UNKNOWN; + break; + + case ARGP_KEY_INIT: + state->child_inputs[0] = state->input; break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static void +sigint (int signo) +{ + int kill_task (struct task_info *task_pi) + { + task_terminate (task_pi->task_port); + return 0; + } + + info ("receives an INT"); + foreach_task (kill_task); + exit (0); +} + +void +init_signal () +{ + struct sigaction sa; + sa.sa_handler = sigint; + sa.sa_flags = 0; /* No SA_RESTART! */ + sigemptyset(&sa.sa_mask); + if (sigaction (SIGINT, &sa, NULL)) + error (2, errno, "cannot set SIGHUP handler"); +} + +void +init_kernel_task () +{ + error_t err; + task_t pseudo_task; + task_t pseudo_kernel_task; + process_t real_kernel_task_proc; + process_t proc; + extern int create_pseudo_task (task_t real_task, task_t *ret_pseudo_task); + + err = task_create (mach_task_self (), 0, &pseudo_kernel_task); + if (err) + error (4, err, "cannot create the pseudo kernel task."); + + err = proc_task2proc (getproc (), pseudo_kernel_task, &proc); + if (err) + error (4, err, "cannot get the proc port for the pseudo kernel task."); + + err = task_set_bootstrap_port (pseudo_kernel_task, proc); + if (err) + error (4, err, "cannot set the pseudo kernel task's bootstrap port"); + + err = proc_pid2proc (getproc (), 2, &real_kernel_task_proc); + if (err) + error (4, err, "cannot get the kernel task's proc port"); + + vm_address_t kargv, kenvp; + err = proc_get_arg_locations (real_kernel_task_proc, &kargv, &kenvp); + if (err) + error (4, err, "cannot get the kernel task's argument"); + proc_set_arg_locations (proc, kargv, kenvp); + create_pseudo_task (pseudo_kernel_task, &pseudo_task); + // TODO the pseudo kernel task has to been destroyed after subhurd exits. +} + +FILE *logfile; + +int +main (int argc, char **argv, char **envp) +{ + error_t err; + mach_port_t foo; + char *buf = 0; + int i, len; + char *root_store_name; + const struct argp_child kids[] = { { &store_argp }, { 0 }}; + struct argp argp = { options, parse_opt, args_doc, doc, kids }; + struct store_argp_params store_argp_params = { 0 }; + mach_port_t subhurd_privileged_host_port = MACH_PORT_NULL; + + LOG_START (); + + argp_parse (&argp, argc, argv, 0, 0, &store_argp_params); + err = store_parsed_name (store_argp_params.result, &root_store_name); + if (err) + error (2, err, "store_parsed_name"); + + err = store_parsed_open (store_argp_params.result, 0, &root_store); + if (err) + error (4, err, "%s", root_store_name); + + init_signal (); + if (!is_user) + { + get_privileged_ports (&privileged_host_port, &master_device_port); + defpager = MACH_PORT_NULL; + err = vm_set_default_memory_manager (privileged_host_port, &defpager); + if (err) + error (4, err, "vm_set_default_memory_manager"); + subhurd_privileged_host_port = privileged_host_port; + } + else + { + port_bucket = ports_create_bucket (); + task_portclass = ports_create_class (clean_pseudo_task, 0); + priv_host_portclass = ports_create_class (destroy_priv_host, 0); + exc_portclass = ports_create_class (0, 0); + other_portclass = ports_create_class (0, 0); + init_kernel_task (); + cthread_detach (cthread_fork ((cthread_fn_t) mach_proxy_thread, + (any_t) 0)); + { + mach_port_t priv_host; + get_privileged_ports (&priv_host, NULL); + defpager = MACH_PORT_NULL; + err = vm_set_default_memory_manager (priv_host, &defpager); + if (err) + error (4, err, "vm_set_default_memory_manager"); + mach_port_deallocate (mach_task_self (), priv_host); + } +// if (pager_file == NULL) +// error (4, 0, "The default pager must be specified for subhurd."); +// defpager = file_name_lookup (pager_file, O_EXEC, 0); +// if (defpager == MACH_PORT_NULL) +// error (4, errno, "file_name_look: %s", pager_file); + + /* Initialize the pseudo privileged host port. */ + err = ports_create_port (priv_host_portclass, port_bucket, + sizeof (struct port_info), + &pseudo_priv_host_pi); + if (err) + error (4, err, "fail to create the pseudo privileged host port"); + subhurd_privileged_host_port = ports_get_send_right (pseudo_priv_host_pi); + ports_port_deref (pseudo_priv_host_pi); + } + + strcat (bootstrap_args, "f"); + + mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_PORT_SET, + &receive_set); + + if (root_store->class == &store_device_class && root_store->name + && (root_store->flags & STORE_ENFORCED) + && root_store->num_runs == 1 && root_store->runs[0].start == 0) + /* Let known device nodes pass through directly. */ + bootdevice = root_store->name; + else + /* Pass a magic value that we can use to do I/O to ROOT_STORE. */ + { + bootdevice = "pseudo-root"; + mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &pseudo_root); + mach_port_move_member (mach_task_self (), pseudo_root, receive_set); + } + + /* Initialize the pseudo master device port. */ + mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &pseudo_master_device_port); + mach_port_insert_right (mach_task_self (), + pseudo_master_device_port, + pseudo_master_device_port, + MACH_MSG_TYPE_MAKE_SEND); + mach_port_move_member (mach_task_self (), pseudo_master_device_port, + receive_set); + mach_port_request_notification (mach_task_self (), pseudo_master_device_port, + MACH_NOTIFY_NO_SENDERS, 1, + pseudo_master_device_port, + MACH_MSG_TYPE_MAKE_SEND_ONCE, &foo); + if (foo != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), foo); + + /* Initialize the pseudo console port. */ + mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &pseudo_console); + mach_port_move_member (mach_task_self (), pseudo_console, receive_set); + mach_port_request_notification (mach_task_self (), pseudo_console, + MACH_NOTIFY_NO_SENDERS, 1, pseudo_console, + MACH_MSG_TYPE_MAKE_SEND_ONCE, &foo); + if (foo != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), foo); + + if (kernel_command_line == 0) + asprintf (&kernel_command_line, "%s %s root=%s", + argv[0], bootstrap_args, bootdevice); + + /* Initialize boot script variables. */ + if (boot_script_set_variable ("host-port", VAL_PORT, + (int) subhurd_privileged_host_port) + || boot_script_set_variable ("device-port", VAL_PORT, + (integer_t) pseudo_master_device_port) + || boot_script_set_variable ("kernel-command-line", VAL_STR, + (integer_t) kernel_command_line) + || boot_script_set_variable ("root-device", + VAL_STR, (integer_t) bootdevice) + || boot_script_set_variable ("boot-args", + VAL_STR, (integer_t) bootstrap_args)) + { + static const char msg[] = "error setting variable"; + + write (2, msg, strlen (msg)); + host_exit (1); + } + + /* Turn each `FOO=BAR' word in the command line into a boot script + variable ${FOO} with value BAR. */ + { + int len = strlen (kernel_command_line) + 1; + char *s = memcpy (alloca (len), kernel_command_line, len); + char *word; + + while ((word = strsep (&s, " \t")) != 0) + { + char *eq = strchr (word, '='); + if (eq == 0) + continue; + *eq++ = '\0'; + err = boot_script_set_variable (word, VAL_STR, (integer_t) eq); + if (err) + { + char *msg; + asprintf (&msg, "cannot set boot-script variable %s: %s\n", + word, boot_script_error_string (err)); + assert (msg); + write (2, msg, strlen (msg)); + free (msg); + host_exit (1); + } + } + } + + /* Parse the boot script. */ + { + char *p, *line; + static const char filemsg[] = "Can't open boot script\n"; + static const char memmsg[] = "Not enough memory\n"; + int amt, fd, err; + + fd = open (bootscript, O_RDONLY, 0); + if (fd < 0) + { + write (2, filemsg, sizeof (filemsg)); + host_exit (1); + } + p = buf = malloc (500); + if (!buf) + { + write (2, memmsg, sizeof (memmsg)); + host_exit (1); + } + len = 500; + amt = 0; + while (1) + { + i = read (fd, p, len - (p - buf)); + if (i <= 0) + break; + p += i; + amt += i; + if (p == buf + len) + { + char *newbuf; + + len += 500; + newbuf = realloc (buf, len); + if (!newbuf) + { + write (2, memmsg, sizeof (memmsg)); + host_exit (1); + } + p = newbuf + (p - buf); + buf = newbuf; + } + } + line = p = buf; + while (1) + { + while (p < buf + amt && *p != '\n') + p++; + *p = '\0'; + err = boot_script_parse_line (0, line); + if (err) + { + char *str; + int i; + + str = boot_script_error_string (err); + i = strlen (str); + write (2, str, i); + write (2, " in `", 5); + write (2, line, strlen (line)); + write (2, "'\n", 2); + host_exit (1); + } + if (p == buf + amt) + break; + line = ++p; + } + } + + if (index (bootstrap_args, 'd')) + { + static const char msg[] = "Pausing. . ."; + char c; + write (2, msg, sizeof (msg) - 1); + read (0, &c, 1); + } + + init_termstate (); + + /* The boot script has now been parsed into internal data structures. + Now execute its directives. */ + { + int err; + + err = boot_script_exec (); + if (err) + { + char *str = boot_script_error_string (err); + int i = strlen (str); + + write (2, str, i); + host_exit (1); + } + free (buf); + } + + mach_port_deallocate (mach_task_self (), pseudo_master_device_port); + if (is_user) + mach_port_deallocate (mach_task_self (), subhurd_privileged_host_port); + + cthread_detach (cthread_fork ((cthread_fn_t) msg_thread, (any_t) 0)); + + for (;;) + { + fd_set rmask; + FD_ZERO (&rmask); + FD_SET (0, &rmask); + if (select (1, &rmask, 0, 0, 0) == 1) + read_reply (); + else /* We hosed */ + error (5, errno, "select"); + } + + LOG_END (); +/* mach_msg_server (request_server, __vm_page_size * 2, receive_set); */ +} + +void +msg_thread() +{ + while (1) + mach_msg_server (request_server, 0, receive_set); +} + + +enum read_type +{ + DEV_READ, + DEV_READI, + IO_READ, +}; +struct qr +{ + enum read_type type; + mach_port_t reply_port; + mach_msg_type_name_t reply_type; + int amount; + struct qr *next; +}; +struct qr *qrhead, *qrtail; + +/* Queue a read for later reply. */ +kern_return_t +queue_read (enum read_type type, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int amount) +{ + struct qr *qr; + + qr = malloc (sizeof (struct qr)); + if (!qr) + return D_NO_MEMORY; + + spin_lock (&queuelock); + + qr->type = type; + qr->reply_port = reply_port; + qr->reply_type = reply_type; + qr->amount = amount; + qr->next = 0; + if (qrtail) + qrtail->next = qr; + else + qrhead = qrtail = qr; + + spin_unlock (&queuelock); + return D_SUCCESS; +} + +/* TRUE if there's data available on stdin, which should be used to satisfy + console read requests. */ +static int should_read = 0; + +/* Reply to a queued read. */ +void +read_reply () +{ + int avail; + struct qr *qr; + char * buf; + int amtread; + + /* By forcing SHOULD_READ to true before trying the lock, we ensure that + either we get the lock ourselves or that whoever currently holds the + lock will service this read when he unlocks it. */ + should_read = 1; + if (! spin_try_lock (&readlock)) + return; + + /* Since we're commited to servicing the read, no one else need do so. */ + should_read = 0; + + ioctl (0, FIONREAD, &avail); + if (!avail) + { + spin_unlock (&readlock); + return; + } + + spin_lock (&queuelock); + + if (!qrhead) + { + spin_unlock (&queuelock); + spin_unlock (&readlock); + return; + } + + qr = qrhead; + qrhead = qr->next; + if (qr == qrtail) + qrtail = 0; + + spin_unlock (&queuelock); + + if (qr->type == DEV_READ) + buf = mmap (0, qr->amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + else + buf = alloca (qr->amount); + amtread = read (0, buf, qr->amount); + + spin_unlock (&readlock); + + switch (qr->type) + { + case DEV_READ: + if (amtread >= 0) + ds_device_read_reply (qr->reply_port, qr->reply_type, 0, + (io_buf_ptr_t) buf, amtread); + else + ds_device_read_reply (qr->reply_port, qr->reply_type, errno, 0, 0); + break; + + case DEV_READI: + if (amtread >= 0) + ds_device_read_reply_inband (qr->reply_port, qr->reply_type, 0, + buf, amtread); + else + ds_device_read_reply_inband (qr->reply_port, qr->reply_type, errno, + 0, 0); + break; + + case IO_READ: + if (amtread >= 0) + io_read_reply (qr->reply_port, qr->reply_type, 0, + buf, amtread); + else + io_read_reply (qr->reply_port, qr->reply_type, errno, 0, 0); + break; + } + + free (qr); +} + +/* Unlock READLOCK, and also service any new read requests that it was + blocking. */ +static void +unlock_readlock () +{ + spin_unlock (&readlock); + while (should_read) + read_reply (); +} + +/* + * Handle bootstrap requests. + */ +/* These two functions from .../mk/bootstrap/default_pager.c. */ + +kern_return_t +do_bootstrap_privileged_ports(bootstrap, hostp, devicep) + mach_port_t bootstrap; + mach_port_t *hostp, *devicep; +{ + if (is_user) + /* I cannot use ports_get_right() here, + * because the port will be copied to the client. */ + *hostp = pseudo_priv_host_pi->port_right; + else + *hostp = privileged_host_port; + *devicep = pseudo_master_device_port; + return KERN_SUCCESS; +} + +void +bootstrap_compat(in, out) + mach_msg_header_t *in, *out; +{ + mig_reply_header_t *reply = (mig_reply_header_t *) out; + mach_msg_return_t mr; + + struct imsg { + mach_msg_header_t hdr; + mach_msg_type_t port_desc_1; + mach_port_t port_1; + mach_msg_type_t port_desc_2; + mach_port_t port_2; + } imsg; + + /* + * Send back the host and device ports. + */ + + imsg.hdr.msgh_bits = MACH_MSGH_BITS_COMPLEX | + MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(in->msgh_bits), 0); + /* msgh_size doesn't need to be initialized */ + imsg.hdr.msgh_remote_port = in->msgh_remote_port; + imsg.hdr.msgh_local_port = MACH_PORT_NULL; + /* msgh_seqno doesn't need to be initialized */ + imsg.hdr.msgh_id = in->msgh_id + 100; /* this is a reply msg */ + + imsg.port_desc_1.msgt_name = MACH_MSG_TYPE_COPY_SEND; + imsg.port_desc_1.msgt_size = (sizeof(mach_port_t) * 8); + imsg.port_desc_1.msgt_number = 1; + imsg.port_desc_1.msgt_inline = TRUE; + imsg.port_desc_1.msgt_longform = FALSE; + imsg.port_desc_1.msgt_deallocate = FALSE; + imsg.port_desc_1.msgt_unused = 0; + + if (is_user) + imsg.port_1 = pseudo_priv_host_pi->port_right; + else + imsg.port_1 = privileged_host_port; + + imsg.port_desc_2 = imsg.port_desc_1; + + imsg.port_desc_2.msgt_name = MACH_MSG_TYPE_MAKE_SEND; + imsg.port_2 = pseudo_master_device_port; + + /* + * Send the reply message. + * (mach_msg_server can not do this, because the reply + * is not in standard format.) + */ + + mr = mach_msg(&imsg.hdr, MACH_SEND_MSG, + sizeof imsg, 0, MACH_PORT_NULL, + MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + if (mr != MACH_MSG_SUCCESS) + (void) mach_port_deallocate(mach_task_self (), + imsg.hdr.msgh_remote_port); + + /* + * Tell mach_msg_server to do nothing. + */ + + reply->RetCode = MIG_NO_REPLY; +} + +/* Implementation of device interface */ + +kern_return_t +ds_device_open (mach_port_t master_port, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + dev_mode_t mode, + dev_name_t name, + mach_port_t *device, + mach_msg_type_name_t *devicetype) +{ + struct dev_map *map; + + if (master_port != pseudo_master_device_port) + return D_INVALID_OPERATION; + + debug ("open %s", name); + if (!strcmp (name, "console")) + { +#if 0 + mach_port_insert_right (mach_task_self (), pseudo_console, + pseudo_console, MACH_MSG_TYPE_MAKE_SEND); + console_send_rights++; +#endif + console_mscount++; + *device = pseudo_console; + *devicetype = MACH_MSG_TYPE_MAKE_SEND; + return 0; + } + else if (strcmp (name, "pseudo-root") == 0) + /* Magic root device. */ + { + *device = pseudo_root; + *devicetype = MACH_MSG_TYPE_MAKE_SEND; + return 0; + } + + map = lookup_dev (name); + if (map) + { + error_t err; + *devicetype = MACH_MSG_TYPE_MOVE_SEND; + err = device_open (map->port, mode, "", device); + return err; + } + + if (is_user) + return D_NO_SUCH_DEVICE; + else + { + *devicetype = MACH_MSG_TYPE_MOVE_SEND; + return device_open (master_device_port, mode, name, device); + } +} + +kern_return_t +ds_device_close (device_t device) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return 0; +} + +kern_return_t +ds_device_write (device_t device, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + dev_mode_t mode, + recnum_t recnum, + io_buf_ptr_t data, + size_t datalen, + int *bytes_written) +{ + if (device == pseudo_console) + { +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + *bytes_written = write (1, data, datalen); + + return (*bytes_written == -1 ? D_IO_ERROR : D_SUCCESS); + } + else if (device == pseudo_root) + { + size_t wrote; + if (store_write (root_store, recnum, data, datalen, &wrote) != 0) + return D_IO_ERROR; + *bytes_written = wrote; + return D_SUCCESS; + } + else + return D_NO_SUCH_DEVICE; +} + +kern_return_t +ds_device_write_inband (device_t device, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + dev_mode_t mode, + recnum_t recnum, + io_buf_ptr_inband_t data, + size_t datalen, + int *bytes_written) +{ + if (device == pseudo_console) + { +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + *bytes_written = write (1, data, datalen); + + return (*bytes_written == -1 ? D_IO_ERROR : D_SUCCESS); + } + else if (device == pseudo_root) + { + size_t wrote; + if (store_write (root_store, recnum, data, datalen, &wrote) != 0) + return D_IO_ERROR; + *bytes_written = wrote; + return D_SUCCESS; + } + else + return D_NO_SUCH_DEVICE; +} + +kern_return_t +ds_device_read (device_t device, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + dev_mode_t mode, + recnum_t recnum, + int bytes_wanted, + io_buf_ptr_t *data, + size_t *datalen) +{ + if (device == pseudo_console) + { + int avail; + +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + spin_lock (&readlock); + ioctl (0, FIONREAD, &avail); + if (avail) + { + *data = mmap (0, bytes_wanted, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + *datalen = read (0, *data, bytes_wanted); + unlock_readlock (); + return (*datalen == -1 ? D_IO_ERROR : D_SUCCESS); + } + else + { + kern_return_t err; + + unlock_readlock (); + err = queue_read (DEV_READ, reply_port, reply_type, bytes_wanted); + if (err) + return err; + return MIG_NO_REPLY; + } + } + else if (device == pseudo_root) + { + *datalen = 0; + return + (store_read (root_store, recnum, bytes_wanted, (void **)data, datalen) == 0 + ? D_SUCCESS + : D_IO_ERROR); + } + else + return D_NO_SUCH_DEVICE; +} + +kern_return_t +ds_device_read_inband (device_t device, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + dev_mode_t mode, + recnum_t recnum, + int bytes_wanted, + io_buf_ptr_inband_t data, + size_t *datalen) +{ + if (device == pseudo_console) + { + int avail; + +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + spin_lock (&readlock); + ioctl (0, FIONREAD, &avail); + if (avail) + { + *datalen = read (0, data, bytes_wanted); + unlock_readlock (); + return (*datalen == -1 ? D_IO_ERROR : D_SUCCESS); + } + else + { + kern_return_t err; + + unlock_readlock (); + err = queue_read (DEV_READI, reply_port, reply_type, bytes_wanted); + if (err) + return err; + return MIG_NO_REPLY; + } + } + else if (device == pseudo_root) + { + error_t err; + void *returned = data; + + *datalen = bytes_wanted; + err = + store_read (root_store, recnum, bytes_wanted, (void **)&returned, datalen); + + if (! err) + { + if (returned != data) + { + bcopy (returned, (void *)data, *datalen); + munmap ((caddr_t) returned, *datalen); + } + return D_SUCCESS; + } + else + return D_IO_ERROR; + } + else + return D_NO_SUCH_DEVICE; +} + +kern_return_t +ds_xxx_device_set_status (device_t device, + dev_flavor_t flavor, + dev_status_t status, + size_t statu_cnt) +{ + if (device != pseudo_console) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + +kern_return_t +ds_xxx_device_get_status (device_t device, + dev_flavor_t flavor, + dev_status_t status, + size_t *statuscnt) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + +kern_return_t +ds_xxx_device_set_filter (device_t device, + mach_port_t rec, + int pri, + filter_array_t filt, + size_t len) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + +kern_return_t +ds_device_map (device_t device, + vm_prot_t prot, + vm_offset_t offset, + vm_size_t size, + memory_object_t *pager, + int unmap) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + +kern_return_t +ds_device_set_status (device_t device, + dev_flavor_t flavor, + dev_status_t status, + size_t statuslen) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + +kern_return_t +ds_device_get_status (device_t device, + dev_flavor_t flavor, + dev_status_t status, + size_t *statuslen) +{ + if (device == pseudo_console) + return D_INVALID_OPERATION; + else if (device == pseudo_root) + if (flavor == DEV_GET_SIZE) + if (*statuslen < DEV_GET_SIZE_COUNT) + return D_INVALID_SIZE; + else + { + status[DEV_GET_SIZE_DEVICE_SIZE] = root_store->size; + status[DEV_GET_SIZE_RECORD_SIZE] = root_store->block_size; + *statuslen = DEV_GET_SIZE_COUNT; + return D_SUCCESS; + } + else + return D_INVALID_OPERATION; + else + return D_NO_SUCH_DEVICE; +} + +kern_return_t +ds_device_set_filter (device_t device, + mach_port_t receive_port, + int priority, + filter_array_t filter, + size_t filterlen) +{ + if (device != pseudo_console && device != pseudo_root) + return D_NO_SUCH_DEVICE; + return D_INVALID_OPERATION; +} + + +/* Implementation of notify interface */ +kern_return_t +do_mach_notify_port_deleted (mach_port_t notify, + mach_port_t name) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_msg_accepted (mach_port_t notify, + mach_port_t name) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_port_destroyed (mach_port_t notify, + mach_port_t port) +{ + return EOPNOTSUPP; +} + +boolean_t pseudo_priv_host_destroyed = FALSE; + +void +destroy_priv_host (void *pi) +{ + pseudo_priv_host_destroyed = TRUE; + info ("pseudo privileged host port is destroyed"); +} + +kern_return_t +do_mach_notify_no_senders (mach_port_t notify, + mach_port_mscount_t mscount) +{ + static int no_console; + mach_port_t foo; + error_t err = EOPNOTSUPP; + + if (notify == pseudo_master_device_port) + { + info ("pseudo master device port has no senders"); + /* for the root */ + if (no_console && !is_user) + goto bye; + /* for the normal user */ + if (no_console && is_user && pseudo_priv_host_destroyed) + goto bye; + pseudo_master_device_port = MACH_PORT_NULL; + return 0; + } + if (pseudo_priv_host_pi->port_right == notify && is_user) + { + if (no_console && pseudo_master_device_port == MACH_PORT_NULL) + goto bye; + pseudo_priv_host_destroyed = TRUE; + return 0; + } + if (notify == pseudo_console) + { + info ("pseudo console has no senders"); + if ( + /* for the root */ + (mscount == console_mscount && + pseudo_master_device_port == MACH_PORT_NULL && + !is_user) || + /* for the normal user */ + (mscount == console_mscount && + pseudo_master_device_port == MACH_PORT_NULL && + pseudo_priv_host_destroyed && + is_user)) + { + bye: + restore_termstate (); + write (2, "bye\n", 4); + host_exit (0); + } + else + { + no_console = (mscount == console_mscount); + info ("no console: %d", no_console); + + mach_port_request_notification (mach_task_self (), pseudo_console, + MACH_NOTIFY_NO_SENDERS, + console_mscount == mscount + ? mscount + 1 + : console_mscount, + pseudo_console, + MACH_MSG_TYPE_MAKE_SEND_ONCE, &foo); + if (foo != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), foo); + } + } + + err = ports_do_mach_notify_no_senders (notify, mscount); + + return err; +} + +kern_return_t +do_mach_notify_send_once (mach_port_t notify) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_dead_name (mach_port_t notify, + mach_port_t name) +{ +#if 0 + if (name == child_task && notify == bootport) + host_exit (0); +#endif + return EOPNOTSUPP; +} + + +/* Implementation of the Hurd I/O interface, which + we support for the console port only. */ + +kern_return_t +S_io_write (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + char *data, + mach_msg_type_number_t datalen, + off_t offset, + mach_msg_type_number_t *amtwritten) +{ + if (object != pseudo_console) + return EOPNOTSUPP; + +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + *amtwritten = write (1, data, datalen); + return *amtwritten == -1 ? errno : 0; +} + +kern_return_t +S_io_read (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + char **data, + mach_msg_type_number_t *datalen, + off_t offset, + mach_msg_type_number_t amount) +{ + mach_msg_type_number_t avail; + + if (object != pseudo_console) + return EOPNOTSUPP; + +#if 0 + if (console_send_rights) + { + mach_port_mod_refs (mach_task_self (), pseudo_console, + MACH_PORT_TYPE_SEND, -console_send_rights); + console_send_rights = 0; + } +#endif + + spin_lock (&readlock); + ioctl (0, FIONREAD, &avail); + if (avail) + { + if (amount > *datalen) + *data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + *datalen = read (0, *data, amount); + unlock_readlock (); + return *datalen == -1 ? errno : 0; + } + else + { + kern_return_t err; + unlock_readlock (); + err = queue_read (IO_READ, reply_port, reply_type, amount); + if (err) + return err; + return MIG_NO_REPLY; + } +} + +kern_return_t +S_io_seek (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + off_t offset, + int whence, + off_t *newp) +{ + return object == pseudo_console ? ESPIPE : EOPNOTSUPP; +} + +kern_return_t +S_io_readable (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_msg_type_number_t *amt) +{ + if (object != pseudo_console) + return EOPNOTSUPP; + ioctl (0, FIONREAD, amt); + return 0; +} + +kern_return_t +S_io_set_all_openmodes (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int bits) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_get_openmodes (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int *modes) +{ + *modes = O_READ | O_WRITE; + return object == pseudo_console ? 0 : EOPNOTSUPP; +} + +kern_return_t +S_io_set_some_openmodes (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int bits) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_clear_some_openmodes (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int bits) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_async (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t notify, + mach_port_t *id, + mach_msg_type_name_t *idtype) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_mod_owner (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + pid_t owner) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_get_owner (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + pid_t *owner) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_get_icky_async_id (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t *id, + mach_msg_type_name_t *idtype) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_select (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int *type) +{ + fd_set r, w, x; + int n; + + if (object != pseudo_console) + return EOPNOTSUPP; + + FD_ZERO (&r); + FD_ZERO (&w); + FD_ZERO (&x); + FD_SET (0, &r); + FD_SET (0, &w); + FD_SET (0, &x); + + n = select (1, + (*type & SELECT_READ) ? &r : 0, + (*type & SELECT_WRITE) ? &w : 0, + (*type & SELECT_URG) ? &x : 0, + 0); + if (n < 0) + return errno; + + if (! FD_ISSET (0, &r)) + *type &= ~SELECT_READ; + if (! FD_ISSET (0, &w)) + *type &= ~SELECT_WRITE; + if (! FD_ISSET (0, &x)) + *type &= ~SELECT_URG; + + return 0; +} + +kern_return_t +S_io_stat (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + struct stat *st) +{ + if (object != pseudo_console) + return EOPNOTSUPP; + + bzero (st, sizeof (struct stat)); + st->st_blksize = 1024; + return 0; +} + +kern_return_t +S_io_reauthenticate (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t rend) +{ + uid_t *gu, *au; + gid_t *gg, *ag; + size_t gulen = 0, aulen = 0, gglen = 0, aglen = 0; + error_t err; + + err = mach_port_insert_right (mach_task_self (), object, object, + MACH_MSG_TYPE_MAKE_SEND); + assert_perror (err); + + if (! auth_server_authenticate (authserver, + rend, MACH_MSG_TYPE_COPY_SEND, + object, MACH_MSG_TYPE_COPY_SEND, + &gu, &gulen, + &au, &aulen, + &gg, &gglen, + &ag, &aglen)) + { + mig_deallocate ((vm_address_t) gu, gulen * sizeof *gu); + mig_deallocate ((vm_address_t) au, aulen * sizeof *gu); + mig_deallocate ((vm_address_t) gg, gglen * sizeof *gu); + mig_deallocate ((vm_address_t) au, aulen * sizeof *gu); + } + mach_port_deallocate (mach_task_self (), rend); + mach_port_deallocate (mach_task_self (), object); + + return 0; +} + +kern_return_t +S_io_restrict_auth (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t *newobject, + mach_msg_type_name_t *newobjtype, + uid_t *uids, + size_t nuids, + uid_t *gids, + size_t ngids) +{ + if (object != pseudo_console) + return EOPNOTSUPP; + *newobject = pseudo_console; + *newobjtype = MACH_MSG_TYPE_MAKE_SEND; + console_mscount++; + return 0; +} + +kern_return_t +S_io_duplicate (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t *newobj, + mach_msg_type_name_t *newobjtype) +{ + if (object != pseudo_console) + return EOPNOTSUPP; + *newobj = pseudo_console; + *newobjtype = MACH_MSG_TYPE_MAKE_SEND; + console_mscount++; + return 0; +} + +kern_return_t +S_io_server_version (mach_port_t object, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + char *name, + int *maj, + int *min, + int *edit) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_map (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t *rd, + mach_msg_type_name_t *rdtype, + mach_port_t *wr, + mach_msg_type_name_t *wrtype) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_map_cntl (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + mach_port_t *mem, + mach_msg_type_name_t *memtype) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_get_conch (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_release_conch (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_eofnotify (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) + +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_prenotify (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + vm_offset_t start, + vm_offset_t end) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_postnotify (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + vm_offset_t start, + vm_offset_t end) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_readsleep (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_readnotify (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) +{ + return EOPNOTSUPP; +} + + +kern_return_t +S_io_sigio (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type) +{ + return EOPNOTSUPP; +} + + +kern_return_t +S_io_pathconf (mach_port_t obj, + mach_port_t reply_port, + mach_msg_type_name_t reply_type, + int name, int *value) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_identity (mach_port_t obj, + mach_port_t reply, + mach_msg_type_name_t replytype, + mach_port_t *id, + mach_msg_type_name_t *idtype, + mach_port_t *fsid, + mach_msg_type_name_t *fsidtype, + ino_t *fileno) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_io_revoke (mach_port_t obj, + mach_port_t reply, mach_msg_type_name_t replyPoly) +{ + return EOPNOTSUPP; +} + + + +/* Implementation of the Hurd terminal driver interface, which we only + support on the console device. */ + +kern_return_t +S_termctty_open_terminal (mach_port_t object, + int flags, + mach_port_t *result, + mach_msg_type_name_t *restype) +{ + return EOPNOTSUPP; +} + +kern_return_t +S_term_getctty (mach_port_t object, + mach_port_t *cttyid, mach_msg_type_name_t *cttyPoly) +{ + static mach_port_t id = MACH_PORT_NULL; + + if (object != pseudo_console) + return EOPNOTSUPP; + + if (id == MACH_PORT_NULL) + mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_DEAD_NAME, &id); + + *cttyid = id; + *cttyPoly = MACH_MSG_TYPE_COPY_SEND; + return 0; +} + + +kern_return_t S_term_open_ctty +( + io_t terminal, + pid_t pid, + pid_t pgrp, + mach_port_t *newtty, + mach_msg_type_name_t *newttytype +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_set_nodename +( + io_t terminal, + string_t name +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_get_nodename +( + io_t terminal, + string_t name +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_get_peername +( + io_t terminal, + string_t name +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_set_filenode +( + io_t terminal, + file_t filenode +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_get_bottom_type +( + io_t terminal, + int *ttype +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_on_machdev +( + io_t terminal, + mach_port_t machdev +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_on_hurddev +( + io_t terminal, + io_t hurddev +) +{ return EOPNOTSUPP; } + +kern_return_t S_term_on_pty +( + io_t terminal, + io_t *ptymaster +) +{ return EOPNOTSUPP; } diff --git a/boot-proxy-exc/boot_script.c b/boot-proxy-exc/boot_script.c new file mode 100644 index 00000000..f95cc5c4 --- /dev/null +++ b/boot-proxy-exc/boot_script.c @@ -0,0 +1,791 @@ +/* Boot script parser for Mach. */ + +/* Written by Shantanu Goel (goel@cs.columbia.edu). */ + +#include <mach/mach_types.h> +#if !KERNEL || OSKIT_MACH +#include <string.h> +#endif +#include "boot_script.h" + + +/* This structure describes a symbol. */ +struct sym +{ + /* Symbol name. */ + const char *name; + + /* Type of value returned by function. */ + int type; + + /* Symbol value. */ + integer_t val; + + /* For function symbols; type of value returned by function. */ + int ret_type; + + /* For function symbols; if set, execute function at the time + of command execution, not during parsing. A function with + this field set must also have `no_arg' set. Also, the function's + `val' argument will always be NULL. */ + int run_on_exec; +}; + +/* Additional values symbols can take. + These are only used internally. */ +#define VAL_SYM 10 /* symbol table entry */ +#define VAL_FUNC 11 /* function pointer */ + +/* This structure describes an argument. */ +struct arg +{ + /* Argument text copied verbatim. 0 if none. */ + char *text; + + /* Type of value assigned. 0 if none. */ + int type; + + /* Argument value. */ + integer_t val; +}; + +/* List of commands. */ +static struct cmd **cmds = 0; + +/* Amount allocated for `cmds'. */ +static int cmds_alloc = 0; + +/* Next available slot in `cmds'. */ +static int cmds_index = 0; + +/* Symbol table. */ +static struct sym **symtab = 0; + +/* Amount allocated for `symtab'. */ +static int symtab_alloc = 0; + +/* Next available slot in `symtab'. */ +static int symtab_index = 0; + +/* Create a task and suspend it. */ +static int +create_task (struct cmd *cmd, int *val) +{ + int err = boot_script_task_create (cmd); + *val = (int) cmd->task; + return err; +} + +/* Resume a task. */ +static int +resume_task (struct cmd *cmd, int *val) +{ + return boot_script_task_resume (cmd); +} + +/* Resume a task when the user hits return. */ +static int +prompt_resume_task (struct cmd *cmd, int *val) +{ + return boot_script_prompt_task_resume (cmd); +} + +/* List of builtin symbols. */ +static struct sym builtin_symbols[] = +{ + { "task-create", VAL_FUNC, (integer_t) create_task, VAL_TASK, 0 }, + { "task-resume", VAL_FUNC, (integer_t) resume_task, VAL_NONE, 1 }, + { "prompt-task-resume", + VAL_FUNC, (integer_t) prompt_resume_task, VAL_NONE, 1 }, +}; +#define NUM_BUILTIN (sizeof (builtin_symbols) / sizeof (builtin_symbols[0])) + +/* Free CMD and all storage associated with it. + If ABORTING is set, terminate the task associated with CMD, + otherwise just deallocate the send right. */ +static void +free_cmd (struct cmd *cmd, int aborting) +{ + if (cmd->task) + boot_script_free_task (cmd->task, aborting); + if (cmd->args) + { + int i; + for (i = 0; i < cmd->args_index; i++) + boot_script_free (cmd->args[i], sizeof *cmd->args[i]); + boot_script_free (cmd->args, sizeof cmd->args[0] * cmd->args_alloc); + } + if (cmd->exec_funcs) + boot_script_free (cmd->exec_funcs, + sizeof cmd->exec_funcs[0] * cmd->exec_funcs_alloc); + boot_script_free (cmd, sizeof *cmd); +} + +/* Free all storage allocated by the parser. + If ABORTING is set, terminate all tasks. */ +static void +cleanup (int aborting) +{ + int i; + + for (i = 0; i < cmds_index; i++) + free_cmd (cmds[i], aborting); + boot_script_free (cmds, sizeof cmds[0] * cmds_alloc); + cmds = 0; + cmds_index = cmds_alloc = 0; + + for (i = 0; i < symtab_index; i++) + boot_script_free (symtab[i], sizeof *symtab[i]); + boot_script_free (symtab, sizeof symtab[0] * symtab_alloc); + symtab = 0; + symtab_index = symtab_alloc = 0; +} + +/* Add PTR to the list of pointers PTR_LIST, which + currently has ALLOC amount of space allocated to it, and + whose next available slot is INDEX. If more space + needs to to allocated, INCR is the amount by which + to increase it. Return 0 on success, non-zero otherwise. */ +static int +add_list (void *ptr, void ***ptr_list, int *alloc, int *index, int incr) +{ + if (*index == *alloc) + { + void **p; + + *alloc += incr; + p = boot_script_malloc (*alloc * sizeof (void *)); + if (! p) + { + *alloc -= incr; + return 1; + } + if (*ptr_list) + { + memcpy (p, *ptr_list, *index * sizeof (void *)); + boot_script_free (*ptr_list, (*alloc - incr) * sizeof (void *)); + } + *ptr_list = p; + } + *(*ptr_list + *index) = ptr; + *index += 1; + return 0; +} + +/* Create an argument with TEXT, value type TYPE, and value VAL. + Add the argument to the argument list of CMD. */ +static struct arg * +add_arg (struct cmd *cmd, const char *text, int textlen, int type, int val) +{ + struct arg *arg; + + arg = boot_script_malloc (sizeof (struct arg) + textlen); + if (arg) + { + arg->text = text == 0 ? 0 : memcpy (arg + 1, text, textlen); + arg->type = type; + arg->val = val; + if (add_list (arg, (void ***) (void *)&cmd->args, + &cmd->args_alloc, &cmd->args_index, 5)) + { + boot_script_free (arg, sizeof *arg); + return 0; + } + } + return arg; +} + +/* Search for the symbol NAME in the symbol table. */ +static struct sym * +sym_lookup (const char *name) +{ + int i; + + for (i = 0; i < symtab_index; i++) + if (! strcmp (name, symtab[i]->name)) + return symtab[i]; + return 0; +} + +/* Create an entry for symbol NAME in the symbol table. */ +static struct sym * +sym_enter (const char *name) +{ + struct sym *sym; + + sym = boot_script_malloc (sizeof (struct sym)); + if (sym) + { + memset (sym, 0, sizeof (struct sym)); + sym->name = name; + if (add_list (sym, (void ***) (void *)&symtab, &symtab_alloc, &symtab_index, 20)) + { + boot_script_free (sym, sizeof *sym); + return 0; + } + } + return sym; +} + +/* Parse the command line CMDLINE. */ +int +boot_script_parse_line (void *hook, char *cmdline) +{ + char *p, *q; + int error; + struct cmd *cmd; + struct arg *arg; + + /* Extract command name. Ignore line if it lacks a command. */ + for (p = cmdline; *p == ' ' || *p == '\t'; p++) + ; + if (*p == '#') + /* Ignore comment line. */ + return 0; + +#if 0 + if (*p && *p != ' ' && *p != '\t' && *p != '\n') + { + printf ("(bootstrap): %s\n", cmdline); + } +#endif + + for (q = p; *q && *q != ' ' && *q != '\t' && *q != '\n'; q++) + ; + if (p == q) + return 0; + + *q++ = '\0'; + + /* Allocate a command structure. */ + cmd = boot_script_malloc (sizeof (struct cmd) + (q - p)); + if (! cmd) + return BOOT_SCRIPT_NOMEM; + memset (cmd, 0, sizeof (struct cmd)); + cmd->hook = hook; + cmd->path = memcpy (cmd + 1, p, q - p); + p = q; + + for (arg = 0;;) + { + if (! arg) + { + /* Skip whitespace. */ + while (*p == ' ' || *p == '\t') + p++; + + /* End of command line. */ + if (! *p || *p == '\n') + { + /* Add command to list. */ + if (add_list (cmd, (void ***) (void *) &cmds, + &cmds_alloc, &cmds_index, 10)) + { + error = BOOT_SCRIPT_NOMEM; + goto bad; + } + return 0; + } + } + + /* Look for a symbol. */ + if (arg || (*p == '$' && (*(p + 1) == '{' || *(p + 1) == '('))) + { + char end_char = (*(p + 1) == '{') ? '}' : ')'; + struct sym *sym = 0; + + for (p += 2;;) + { + char c; + int i, type; + integer_t val; + struct sym *s; + + /* Parse symbol name. */ + for (q = p; *q && *q != '\n' && *q != end_char && *q != '='; q++) + ; + if (p == q || ! *q || *q == '\n' + || (end_char == '}' && *q != '}')) + { + error = BOOT_SCRIPT_SYNTAX_ERROR; + goto bad; + } + c = *q; + *q = '\0'; + + /* See if this is a builtin symbol. */ + for (i = 0; i < NUM_BUILTIN; i++) + if (! strcmp (p, builtin_symbols[i].name)) + break; + + if (i < NUM_BUILTIN) + s = &builtin_symbols[i]; + else + { + /* Look up symbol in symbol table. + If no entry exists, create one. */ + s = sym_lookup (p); + if (! s) + { + s = sym_enter (p); + if (! s) + { + error = BOOT_SCRIPT_NOMEM; + goto bad; + } + } + } + + /* Only values are allowed in ${...} constructs. */ + if (end_char == '}' && s->type == VAL_FUNC) + return BOOT_SCRIPT_INVALID_SYM; + + /* Check that assignment is valid. */ + if (c == '=' && s->type == VAL_FUNC) + { + error = BOOT_SCRIPT_INVALID_ASG; + goto bad; + } + + /* For function symbols, execute the function. */ + if (s->type == VAL_FUNC) + { + if (! s->run_on_exec) + { + (error + = ((*((int (*) (struct cmd *, integer_t *)) s->val)) + (cmd, &val))); + if (error) + goto bad; + type = s->ret_type; + } + else + { + if (add_list (s, (void ***) (void *) &cmd->exec_funcs, + &cmd->exec_funcs_alloc, + &cmd->exec_funcs_index, 5)) + { + error = BOOT_SCRIPT_NOMEM; + goto bad; + } + type = VAL_NONE; + goto out; + } + } + else if (s->type == VAL_NONE) + { + type = VAL_SYM; + val = (integer_t) s; + } + else + { + type = s->type; + val = s->val; + } + + if (sym) + { + sym->type = type; + sym->val = val; + } + else if (arg) + { + arg->type = type; + arg->val = val; + } + + out: + p = q + 1; + if (c == end_char) + { + /* Create an argument if necessary. + We create an argument if the symbol appears + in the expression by itself. + + NOTE: This is temporary till the boot filesystem + servers support arguments. When that happens, + symbol values will only be printed if they're + associated with an argument. */ + if (! arg && end_char == '}') + { + if (! add_arg (cmd, 0, 0, type, val)) + { + error = BOOT_SCRIPT_NOMEM; + goto bad; + } + } + arg = 0; + break; + } + if (s->type != VAL_FUNC) + sym = s; + } + } + else + { + char c; + + /* Command argument; just copy the text. */ + for (q = p;; q++) + { + if (! *q || *q == ' ' || *q == '\t' || *q == '\n') + break; + if (*q == '$' && *(q + 1) == '{') + break; + } + c = *q; + *q = '\0'; + + /* Add argument to list. */ + arg = add_arg (cmd, p, q + 1 - p, VAL_NONE, 0); + if (! arg) + { + error = BOOT_SCRIPT_NOMEM; + goto bad; + } + if (c == '$') + p = q; + else + { + if (c) + p = q + 1; + else + p = q; + arg = 0; + } + } + } + + + bad: + free_cmd (cmd, 1); + cleanup (1); + return error; +} + +/* Ensure that the command line buffer can accommodate LEN bytes of space. */ +#define CHECK_CMDLINE_LEN(len) \ +{ \ + if (cmdline_alloc - cmdline_index < len) \ + { \ + char *ptr; \ + int alloc, i; \ + alloc = cmdline_alloc + len - (cmdline_alloc - cmdline_index) + 100; \ + ptr = boot_script_malloc (alloc); \ + if (! ptr) \ + { \ + error = BOOT_SCRIPT_NOMEM; \ + goto done; \ + } \ + memcpy (ptr, cmdline, cmdline_index); \ + for (i = 0; i < argc; ++i) \ + argv[i] = ptr + (argv[i] - cmdline); \ + boot_script_free (cmdline, cmdline_alloc); \ + cmdline = ptr; \ + cmdline_alloc = alloc; \ + } \ +} + +/* Execute commands previously parsed. */ +int +boot_script_exec () +{ + int cmd_index; + + for (cmd_index = 0; cmd_index < cmds_index; cmd_index++) + { + char **argv, *cmdline; + int i, argc, cmdline_alloc; + int cmdline_index, error, arg_index; + struct cmd *cmd = cmds[cmd_index]; + + /* Skip command if it doesn't have an associated task. */ + if (cmd->task == 0) + continue; + + /* Allocate a command line and copy command name. */ + cmdline_index = strlen (cmd->path) + 1; + cmdline_alloc = cmdline_index + 100; + cmdline = boot_script_malloc (cmdline_alloc); + if (! cmdline) + { + cleanup (1); + return BOOT_SCRIPT_NOMEM; + } + memcpy (cmdline, cmd->path, cmdline_index); + + /* Allocate argument vector. */ + argv = boot_script_malloc (sizeof (char *) * (cmd->args_index + 2)); + if (! argv) + { + boot_script_free (cmdline, cmdline_alloc); + cleanup (1); + return BOOT_SCRIPT_NOMEM; + } + argv[0] = cmdline; + argc = 1; + + /* Build arguments. */ + for (arg_index = 0; arg_index < cmd->args_index; arg_index++) + { + struct arg *arg = cmd->args[arg_index]; + + /* Copy argument text. */ + if (arg->text) + { + int len = strlen (arg->text); + + if (arg->type == VAL_NONE) + len++; + CHECK_CMDLINE_LEN (len); + memcpy (cmdline + cmdline_index, arg->text, len); + argv[argc++] = &cmdline[cmdline_index]; + cmdline_index += len; + } + + /* Add value of any symbol associated with this argument. */ + if (arg->type != VAL_NONE) + { + char *p, buf[50]; + int len; + mach_port_t name; + + if (arg->type == VAL_SYM) + { + struct sym *sym = (struct sym *) arg->val; + + /* Resolve symbol value. */ + while (sym->type == VAL_SYM) + sym = (struct sym *) sym->val; + if (sym->type == VAL_NONE) + { + error = BOOT_SCRIPT_UNDEF_SYM; + goto done; + } + arg->type = sym->type; + arg->val = sym->val; + } + + /* Print argument value. */ + switch (arg->type) + { + case VAL_STR: + p = (char *) arg->val; + len = strlen (p); + break; + + case VAL_TASK: + case VAL_PORT: + if (arg->type == VAL_TASK) + /* Insert send right to task port. */ + error = boot_script_insert_task_port + (cmd, (task_t) arg->val, &name); + else + /* Insert send right. */ + error = boot_script_insert_right (cmd, + (mach_port_t) arg->val, + &name); + if (error) + goto done; + + i = name; + p = buf + sizeof (buf); + len = 0; + do + { + *--p = i % 10 + '0'; + len++; + } + while (i /= 10); + break; + + default: + error = BOOT_SCRIPT_BAD_TYPE; + goto done; + } + len++; + CHECK_CMDLINE_LEN (len); + memcpy (cmdline + cmdline_index, p, len - 1); + *(cmdline + cmdline_index + len - 1) = '\0'; + if (! arg->text) + argv[argc++] = &cmdline[cmdline_index]; + cmdline_index += len; + } + } + + /* Terminate argument vector. */ + argv[argc] = 0; + + /* Execute the command. */ + if (boot_script_exec_cmd (cmd->hook, cmd->task, cmd->path, + argc, argv, cmdline, cmdline_index)) + { + error = BOOT_SCRIPT_EXEC_ERROR; + goto done; + } + + error = 0; + + done: + boot_script_free (cmdline, cmdline_alloc); + boot_script_free (argv, sizeof (char *) * (cmd->args_index + 2)); + if (error) + { + cleanup (1); + return error; + } + } + + for (cmd_index = 0; cmd_index < cmds_index; cmd_index++) + { + int i; + struct cmd *cmd = cmds[cmd_index]; + + /* Execute functions that want to be run on exec. */ + for (i = 0; i < cmd->exec_funcs_index; i++) + { + struct sym *sym = cmd->exec_funcs[i]; + int error = ((*((int (*) (struct cmd *, integer_t *)) sym->val)) + (cmd, 0)); + if (error) + { + cleanup (1); + return error; + } + } + } + + cleanup (0); + return 0; +} + +/* Create an entry for the variable NAME with TYPE and value VAL, + in the symbol table. */ +int +boot_script_set_variable (const char *name, int type, integer_t val) +{ + struct sym *sym = sym_enter (name); + + if (sym) + { + sym->type = type; + sym->val = val; + } + return sym ? 0 : 1; +} + + +/* Define the function NAME, which will return type RET_TYPE. */ +int +boot_script_define_function (const char *name, int ret_type, + int (*func) (const struct cmd *cmd, + integer_t *val)) +{ + struct sym *sym = sym_enter (name); + + if (sym) + { + sym->type = VAL_FUNC; + sym->val = (integer_t) func; + sym->ret_type = ret_type; + sym->run_on_exec = ret_type == VAL_NONE; + } + return sym ? 0 : 1; +} + + +/* Return a string describing ERR. */ +char * +boot_script_error_string (int err) +{ + switch (err) + { + case BOOT_SCRIPT_NOMEM: + return "no memory"; + + case BOOT_SCRIPT_SYNTAX_ERROR: + return "syntax error"; + + case BOOT_SCRIPT_INVALID_ASG: + return "invalid variable in assignment"; + + case BOOT_SCRIPT_MACH_ERROR: + return "mach error"; + + case BOOT_SCRIPT_UNDEF_SYM: + return "undefined symbol"; + + case BOOT_SCRIPT_EXEC_ERROR: + return "exec error"; + + case BOOT_SCRIPT_INVALID_SYM: + return "invalid variable in expression"; + + case BOOT_SCRIPT_BAD_TYPE: + return "invalid value type"; + } + return 0; +} + +#ifdef BOOT_SCRIPT_TEST +#include <stdio.h> + +int +boot_script_exec_cmd (void *hook, + mach_port_t task, char *path, int argc, + char **argv, char *strings, int stringlen) +{ + int i; + + printf ("port = %d: ", (int) task); + for (i = 0; i < argc; i++) + printf ("%s ", argv[i]); + printf ("\n"); + return 0; +} + +void +main (int argc, char **argv) +{ + char buf[500], *p; + int len; + FILE *fp; + mach_port_t host_port, device_port; + + if (argc < 2) + { + fprintf (stderr, "Usage: %s <script>\n", argv[0]); + exit (1); + } + fp = fopen (argv[1], "r"); + if (! fp) + { + fprintf (stderr, "Can't open %s\n", argv[1]); + exit (1); + } + host_port = 1; + device_port = 2; + boot_script_set_variable ("host-port", VAL_PORT, (int) host_port); + boot_script_set_variable ("device-port", VAL_PORT, (int) device_port); + boot_script_set_variable ("root-device", VAL_STR, (int) "hd0a"); + boot_script_set_variable ("boot-args", VAL_STR, (int) "-ad"); + p = buf; + len = sizeof (buf); + while (fgets (p, len, fp)) + { + int i, err; + + i = strlen (p) + 1; + err = boot_script_parse_line (0, p); + if (err) + { + fprintf (stderr, "error %s\n", boot_script_error_string (err)); + exit (1); + } + p += i; + len -= i; + } + boot_script_exec (); + exit (0); +} +#endif /* BOOT_SCRIPT_TEST */ diff --git a/boot-proxy-exc/boot_script.h b/boot-proxy-exc/boot_script.h new file mode 100644 index 00000000..62458693 --- /dev/null +++ b/boot-proxy-exc/boot_script.h @@ -0,0 +1,116 @@ +/* Definitions for boot script parser for Mach. */ + +#ifndef _boot_script_h +#define _boot_script_h + +/* Written by Shantanu Goel (goel@cs.columbia.edu). */ + +/* Error codes returned by boot_script_parse_line() + and boot_script_exec_cmd(). */ +#define BOOT_SCRIPT_NOMEM 1 +#define BOOT_SCRIPT_SYNTAX_ERROR 2 +#define BOOT_SCRIPT_INVALID_ASG 3 +#define BOOT_SCRIPT_MACH_ERROR 4 +#define BOOT_SCRIPT_UNDEF_SYM 5 +#define BOOT_SCRIPT_EXEC_ERROR 6 +#define BOOT_SCRIPT_INVALID_SYM 7 +#define BOOT_SCRIPT_BAD_TYPE 8 + +/* Legal values for argument `type' to function + boot_script_set_variable and boot_script_define_function. */ +#define VAL_NONE 0 /* none -- function runs at exec time */ +#define VAL_STR 1 /* string */ +#define VAL_PORT 2 /* port */ +#define VAL_TASK 3 /* task port */ + +/* This structure describes a command. */ +struct cmd +{ + /* Cookie passed in to boot_script_parse_line. */ + void *hook; + + /* Path of executable. */ + char *path; + + /* Task port. */ + task_t task; + + /* Argument list. */ + struct arg **args; + + /* Amount allocated for `args'. */ + int args_alloc; + + /* Next available slot in `args'. */ + int args_index; + + /* List of functions that want to be run on command execution. */ + struct sym **exec_funcs; + + /* Amount allocated for `exec_funcs'. */ + int exec_funcs_alloc; + + /* Next available slot in `exec_funcs'. */ + int exec_funcs_index; +}; + + +/* The user must define these functions, we work like malloc and free. */ +void *boot_script_malloc (unsigned int); +void boot_script_free (void *, unsigned int); + +/* The user must define this function. Load the image of the + executable specified by PATH in TASK. Create a thread + in TASK and point it at the executable's entry point. Initialize + TASK's stack with argument vector ARGV of length ARGC whose + strings are STRINGS. STRINGS has length STRINGLEN. + Return 0 for success, non-zero otherwise. */ +int boot_script_exec_cmd (void *hook, + task_t task, char *path, int argc, + char **argv, char *strings, int stringlen); + +/* The user must define this function. Load the contents of FILE + into a fresh anonymous memory object and return the memory object port. */ +mach_port_t boot_script_read_file (const char *file); + +/* The user must define this functions to perform the corresponding + Mach task manipulations. */ +int boot_script_task_create (struct cmd *); /* task_create + task_suspend */ +int boot_script_task_resume (struct cmd *); +int boot_script_prompt_task_resume (struct cmd *); +int boot_script_insert_right (struct cmd *, mach_port_t, mach_port_t *namep); +int boot_script_insert_task_port (struct cmd *, task_t, mach_port_t *namep); + +/* The user must define this function to clean up the `task_t' + returned by boot_script_task_create. */ +void boot_script_free_task (task_t task, int aborting); + + +/* Parse the command line LINE. This causes the command line to be + converted into an internal format. Returns 0 for success, non-zero + otherwise. + + NOTE: The parser writes into the line so it must not be a string constant. + It is also the responsibility of the caller not to deallocate the line + across calls to the parser. */ +int boot_script_parse_line (void *hook, char *cmdline); + +/* Execute the command lines prevously parsed. + Returns 0 for success, non-zero otherwise. */ +int boot_script_exec (void); + +/* Create an entry in the symbol table for variable NAME, + whose type is TYPE and value is VAL. Returns 0 on success, + non-zero otherwise. */ +int boot_script_set_variable (const char *name, int type, integer_t val); + +/* Define the function NAME, which will return type RET_TYPE. */ +int boot_script_define_function (const char *name, int ret_type, + int (*func) (const struct cmd *cmd, + integer_t *val)); + +/* Returns a string describing the error ERR. */ +char *boot_script_error_string (int err); + + +#endif /* _boot_script_h */ diff --git a/boot-proxy-exc/bootstrap.defs b/boot-proxy-exc/bootstrap.defs new file mode 100644 index 00000000..ad4bac91 --- /dev/null +++ b/boot-proxy-exc/bootstrap.defs @@ -0,0 +1 @@ +#include <mach/bootstrap.defs> diff --git a/boot-proxy-exc/device.defs b/boot-proxy-exc/device.defs new file mode 100644 index 00000000..70472689 --- /dev/null +++ b/boot-proxy-exc/device.defs @@ -0,0 +1 @@ +#include <device/device.defs> diff --git a/boot-proxy-exc/device_reply.defs b/boot-proxy-exc/device_reply.defs new file mode 100644 index 00000000..69930311 --- /dev/null +++ b/boot-proxy-exc/device_reply.defs @@ -0,0 +1 @@ +#include <device/device_reply.defs> diff --git a/boot-proxy-exc/exc.defs b/boot-proxy-exc/exc.defs new file mode 100644 index 00000000..ab864488 --- /dev/null +++ b/boot-proxy-exc/exc.defs @@ -0,0 +1 @@ +#include <mach/exc.defs> diff --git a/boot-proxy-exc/exc_impl.c b/boot-proxy-exc/exc_impl.c new file mode 100644 index 00000000..1c6900bb --- /dev/null +++ b/boot-proxy-exc/exc_impl.c @@ -0,0 +1,69 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This file implements the server-side RPC functions of mach_host. */ + +#include <mach.h> +#include <hurd.h> +#include <assert.h> + +#include "util.h" +#include "mach_proxy.h" + +kern_return_t +catch_exception_raise (mach_port_t exception_port, mach_port_t thread, + mach_port_t task, integer_t exception, + integer_t code, integer_t subcode) +{ + error_t err; + struct task_info *fault_task_pi = NULL; + debug (""); + + int match_task (struct task_info *task_pi) + { + if (task_pi->task_port == task) + { + fault_task_pi = task_pi; + ports_port_ref (fault_task_pi); + return 1; + } + return 0; + } + foreach_task (match_task); + + if (fault_task_pi == NULL) + { + fault_task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (fault_task_pi) + info ("find the task: %d from libports", task); + } + + if (fault_task_pi == NULL) + { + info ("cannot find the task: %d", task); + return EINVAL; + } + + err = catch_exception_raise (fault_task_pi->user_exc_port, + thread, fault_task_pi->task.port_right, + exception, code, subcode); + ports_port_deref (fault_task_pi); + return err; +} diff --git a/boot-proxy-exc/frank1.ld b/boot-proxy-exc/frank1.ld new file mode 100644 index 00000000..9de827ae --- /dev/null +++ b/boot-proxy-exc/frank1.ld @@ -0,0 +1,94 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", + "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) + SEARCH_DIR(/usr/local/i386-gnuelf/lib); +/* Do we need any of these for elf? + __DYNAMIC = 0; */ +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + . = 0x10020; + .text : + { + *(.text) + *(.interp) + *(.hash) + *(.dynsym) + *(.dynstr) + *(.rel.text) + *(.rela.text) + *(.rel.data) + *(.rela.data) + *(.rel.rodata) + *(.rela.rodata) + *(.rel.got) + *(.rela.got) + *(.rel.ctors) + *(.rela.ctors) + *(.rel.dtors) + *(.rela.dtors) + *(.rel.init) + *(.rela.init) + *(.rel.fini) + *(.rela.fini) + *(.rel.bss) + *(.rela.bss) + *(.rel.plt) + *(.rela.plt) + *(.init) + *(.plt) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.fini) + *(.rodata) + *(.rodata1) + _etext = .; + PROVIDE (etext = .); + . = ALIGN(0x1000); + } =0x9090 + . = ALIGN(0x1000); + .data : + { + *(.data) + CONSTRUCTORS + + *(.data1) + *(.ctors) + *(.dtors) + *(.got.plt) *(.got) + *(.dynamic) + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + *(.sdata) + _edata = .; + PROVIDE (edata = .); + . = ALIGN(0x10); +} + __bss_start = .; + .bss : + { + *(.sbss) *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + _end = ALIGN(4) ; + PROVIDE (end = ALIGN(4)); + } + /* These are needed for ELF backends which have not yet been + converted to the new style linker. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + /* DWARF debug sections. + Symbols in the .debug DWARF section are relative to the beginning of the + section so we begin .debug at 0. It's not clear yet what needs to happen + for the others. */ + .debug 0 : { *(.debug) } + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_sfnames 0 : { *(.debug_sfnames) } + .line 0 : { *(.line) } + /* These must appear regardless of . */ +} diff --git a/boot-proxy-exc/frankemul.ld b/boot-proxy-exc/frankemul.ld new file mode 100644 index 00000000..413953ef --- /dev/null +++ b/boot-proxy-exc/frankemul.ld @@ -0,0 +1,107 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", + "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) + SEARCH_DIR(/usr/local/i386-gnuelf/lib); +/* Do we need any of these for elf? + __DYNAMIC = 0; */ +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + . = 0x10020; + .text : + { + *(.text) + *(.interp) + *(.hash) + *(.dynsym) + *(.dynstr) + *(.rel.text) + *(.rela.text) + *(.rel.data) + *(.rela.data) + *(.rel.rodata) + *(.rela.rodata) + *(.rel.got) + *(.rela.got) + *(.rel.ctors) + *(.rela.ctors) + *(.rel.dtors) + *(.rela.dtors) + *(.rel.init) + *(.rela.init) + *(.rel.fini) + *(.rela.fini) + *(.rel.bss) + *(.rela.bss) + *(.rel.plt) + *(.rela.plt) + *(.init) + *(.plt) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.fini) + *(.rodata) + *(.rodata1) +*(_hurd_ioctl_handler_lists) +*(_hurd_pgrp_changed_hook) +*(_hurd_fork_locks) +*(_hurd_subinit) +*(__libc_atexit) +*(_hurd_fd_subinit) +*(_hurd_preinit_hook) +*(_hurd_fork_child_hook) +*(_hurd_fork_parent_hook) +*(_hurd_fork_prepare_hook) +*(_hurd_reauth_hook) +*(_hurd_proc_subinit) +*(__libc_subinit) + _etext = .; + PROVIDE (etext = .); + . = ALIGN(0x1000); + } =0x9090 + . = ALIGN(0x1000); + .data : + { + *(.data) + CONSTRUCTORS + + *(.data1) + *(.ctors) + *(.dtors) + *(.got.plt) *(.got) + *(.dynamic) + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + *(.sdata) + _edata = .; + PROVIDE (edata = .); + . = ALIGN(0x10); +} + __bss_start = .; + .bss : + { + *(.sbss) *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + _end = ALIGN(4) ; + PROVIDE (end = ALIGN(4)); + } + /* These are needed for ELF backends which have not yet been + converted to the new style linker. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + /* DWARF debug sections. + Symbols in the .debug DWARF section are relative to the beginning of the + section so we begin .debug at 0. It's not clear yet what needs to happen + for the others. */ + .debug 0 : { *(.debug) } + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_sfnames 0 : { *(.debug_sfnames) } + .line 0 : { *(.line) } + /* These must appear regardless of . */ +} diff --git a/boot-proxy-exc/list.c b/boot-proxy-exc/list.c new file mode 100644 index 00000000..db555f35 --- /dev/null +++ b/boot-proxy-exc/list.c @@ -0,0 +1,52 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This file implements a double linked list. */ + +#include "list.h" + +void entry_init (struct list *entry) +{ + entry->next = entry; + entry->prev = entry; +} + +void add_entry_head (struct list *head, struct list *entry) +{ + entry->next = head->next; + head->next->prev = entry; + head->next = entry; + entry->prev = head; +} + +void add_entry_end (struct list *head, struct list *entry) +{ + entry->next = head; + entry->prev = head->prev; + head->prev->next = entry; + head->prev = entry; +} + +void remove_entry (struct list *entry) +{ + entry->next->prev = entry->prev; + entry->prev->next = entry->next; +} + diff --git a/boot-proxy-exc/list.h b/boot-proxy-exc/list.h new file mode 100644 index 00000000..f3f7585f --- /dev/null +++ b/boot-proxy-exc/list.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef __LIST_H__ +#define __LIST_H__ + +#include <stddef.h> + +struct list +{ + struct list *next, *prev; +}; + +void entry_init (struct list *entry); +void add_entry_head (struct list *head, struct list *entry); +void add_entry_end (struct list *head, struct list *entry); +void remove_entry (struct list *entry); + +#define LIST_HEADER(head) struct list head = {&head, &head} +#define EMPTY_LIST(head) ((head)->next == (head)) +#define LIST_ENTRY(entry, type, field) ((type *) (((char *) entry) - offsetof (type, field))) + +#endif diff --git a/boot-proxy-exc/mach-crt0.c b/boot-proxy-exc/mach-crt0.c new file mode 100644 index 00000000..0469424e --- /dev/null +++ b/boot-proxy-exc/mach-crt0.c @@ -0,0 +1,158 @@ +/* + * 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. + */ +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms are permitted + * provided that: (1) source distributions retain this entire copyright + * notice and comment, and (2) distributions including binaries display + * the following acknowledgement: ``This product includes software + * developed by the University of California, Berkeley and its contributors'' + * in the documentation or other materials provided with the distribution + * and in all advertising materials mentioning features or use of this + * software. Neither the name of the University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static char sccsid[] = "@(#)crt0.c 5.2 (Berkeley) 5/14/90"; +#endif /* not lint */ + +/* + * C start up routine. + * Robert Henry, UCB, 20 Oct 81 + * + * We make the following (true) assumptions: + * 1) when the kernel calls start, it does a jump to location 2, + * and thus avoids the register save mask. We are NOT called + * with a calls! see sys1.c:setregs(). + * 2) The only register variable that we can trust is sp, + * which points to the base of the kernel calling frame. + * Do NOT believe the documentation in exec(2) regarding the + * values of fp and ap. + * 3) We can allocate as many register variables as we want, + * and don't have to save them for anybody. + * 4) Because of the ways that asm's work, we can't have + * any automatic variables allocated on the stack, because + * we must catch the value of sp before any automatics are + * allocated. + */ + +#include <mach/machine/asm.h> + +int __data_start = 0; +char **environ = (char **)0; +#ifdef paranoid +static int fd; +#endif paranoid + +int (*mach_init_routine)(); +int (*_cthread_init_routine)(); +int (*_cthread_exit_routine)(); +int (*_monstartup_routine)(); +int (*_StrongBox_init_routine)(); +int errno = 0; +int exit(); + +extern int main(); + +extern unsigned char etext; +int _start() +{ + __label__ eprol; + struct kframe { + int kargc; + char *kargv[1]; /* size depends on kargc */ + char kargstr[1]; /* size varies */ + char kenvstr[1]; /* size varies */ + }; + /* + * ALL REGISTER VARIABLES!!! + */ + register struct kframe *kfp; /* r10 */ + register char **targv; + register char **argv; + +#ifdef lint + kfp = 0; + initcode = initcode = 0; +#else not lint +#define Entry_sp() \ +({ int _spl__, _tmp1__; \ + asm volatile("leal 4(%%ebp), %0" : "=r" (_spl__) : "r" (_tmp1__)); \ + _spl__; }) + + kfp = (struct kframe *)Entry_sp(); +#endif not lint + for (argv = targv = &kfp->kargv[0]; *targv++; /* void */) + /* void */ ; + if (targv >= (char **)(*argv)) + --targv; + environ = targv; + if (mach_init_routine) + (void) mach_init_routine(); + + eprol: +#ifdef paranoid + /* + * The standard I/O library assumes that file descriptors 0, 1, and 2 + * are open. If one of these descriptors is closed prior to the start + * of the process, I/O gets very confused. To avoid this problem, we + * insure that the first three file descriptors are open before calling + * main(). Normally this is undefined, as it adds two unnecessary + * system calls. + */ + do { + fd = open("/dev/null", 2); + } while (fd >= 0 && fd < 3); + close(fd); +#endif paranoid + + + if (_cthread_init_routine) { + int new_sp; + new_sp = (*_cthread_init_routine)(); + if (new_sp) { + asm volatile("movl %0, %%esp" : : "g" (new_sp) ); + } + } + if (_StrongBox_init_routine) (*_StrongBox_init_routine)(); + + if (_monstartup_routine) { + _monstartup_routine(&&eprol, &etext); + } + + (* (_cthread_exit_routine ? _cthread_exit_routine : exit)) + (main(kfp->kargc, argv, targv)); +} diff --git a/boot-proxy-exc/mach_host_impl.c b/boot-proxy-exc/mach_host_impl.c new file mode 100644 index 00000000..c5fc8967 --- /dev/null +++ b/boot-proxy-exc/mach_host_impl.c @@ -0,0 +1,544 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This file implements the server-side RPC functions of mach_host. */ + +#include <stdio.h> +#include <assert.h> + +#include <mach.h> +#include <hurd.h> +#include <hurd/ports.h> + +#include "util.h" +#include "list.h" +#include "mach_proxy.h" + +extern mach_port_t privileged_host_port; + +/* Set task priority. */ +kern_return_t +S_task_priority (mach_port_t task, int priority, boolean_t change_threads) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = task_priority (task_pi->task_port, priority, change_threads); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine processor_set_tasks */ +kern_return_t +S_processor_set_tasks (mach_port_t processor_set, task_array_t *task_list, + mach_msg_type_number_t *task_listCnt) +{ + error_t err = 0; + mach_port_t *subhurd_tasks = NULL; + int size = 0; + /* no pseudo task port is created for the kernel task. */ + int num = 0; + int tot_nbtasks = ports_count_class (task_portclass) + num; + + size = tot_nbtasks * sizeof (mach_port_t); + err = vm_allocate (mach_task_self (), + (vm_address_t *) (void *) &subhurd_tasks, + size, 1); + if (err) + goto out; + + int get_pseudo_task_port (struct task_info *task_pi) + { + assert (num < tot_nbtasks); + subhurd_tasks[num++] = ports_get_right (task_pi); + return 0; + } + + foreach_task (get_pseudo_task_port); + assert (num == tot_nbtasks); + debug ("get %d tasks", tot_nbtasks); + *task_list = subhurd_tasks; + *task_listCnt = tot_nbtasks; + +out: + /* I enable the class here, + * so no pseudo task port can be created when I count the number of tasks. */ + ports_enable_class (task_portclass); + /* The array will be deallocated after it is sent, + * but the task ports in it don't need to, + * because I only call ports_get_right() + * and the reference count isn't increased. */ + return err; +} + +/* Get control port for a processor set. */ +kern_return_t +S_host_processor_set_priv (mach_port_t host_priv, mach_port_t set_name, + mach_port_t *set, mach_msg_type_name_t *setPoly) +{ + extern struct port_class *other_portclass; + struct port_info *pi; + kern_return_t ret = 0; + + // TODO create a port for each processor set + // I should create the port for the processor set only once. + ret = ports_create_port (other_portclass, port_bucket, + sizeof (*pi), &pi); + debug ("%s", strerror (ret)); + if (ret) + return ret; + *set = ports_get_right (pi); + *setPoly = MACH_MSG_TYPE_MAKE_SEND; + ports_port_deref (pi); + return ret; +} + +/* Routine host_reboot */ +kern_return_t +S_host_reboot (mach_port_t host_priv, int options) +{ + debug (""); + assert (0); + // TODO + return EOPNOTSUPP; +} + +/* Routine vm_wire */ +kern_return_t +S_vm_wire (mach_port_t host_priv, mach_port_t task, + vm_address_t address, vm_size_t size, vm_prot_t access) +{ + debug (""); + assert (0); + // TODO + return EOPNOTSUPP; +} + +/* Routine thread_wire */ +kern_return_t +S_thread_wire (mach_port_t host_priv, mach_port_t thread, boolean_t wired) +{ + debug (""); + assert (0); + // TODO + return EOPNOTSUPP; +} + +//////////the request to the host isn't forwarded by the proxy////////// + +/* Routine host_processor_sets */ +kern_return_t +S_host_processor_sets (mach_port_t host, + processor_set_name_array_t *processor_sets, + mach_msg_type_number_t *processor_setsCnt) +{ + debug (""); + assert (0); + // the request to the host isn't forwarded. + return EOPNOTSUPP; +} + +/* Routine host_get_time */ +kern_return_t +S_host_get_time (mach_port_t host, time_value_t *current_time) +{ + debug (""); + assert (0); + // the request to the host isn't forwarded. + return EOPNOTSUPP; +} + +/* Routine host_info */ +kern_return_t +S_host_info (mach_port_t host, int flavor, host_info_t host_info_out, + mach_msg_type_number_t *host_info_outCnt) +{ + debug (""); + assert (0); + // the request to the host isn't forwarded. + return EOPNOTSUPP; +} + +/* Get string describing current kernel version. */ +kern_return_t +S_host_kernel_version (mach_port_t host, kernel_version_t kernel_version) +{ + debug (""); + assert (0); + // the proxy doesn't forward the request to the host port. + return EOPNOTSUPP; +} + +///////////////////the RPCs not used by Hurd////////////////////// + +/* Get list of processors on this host. */ +kern_return_t +S_host_processors (mach_port_t host_priv, + processor_array_t *processor_list, + mach_msg_type_number_t *processor_listCnt) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Start processor. */ +kern_return_t +S_processor_start (mach_port_t processor) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Exit processor -- may not be restartable. */ +kern_return_t +S_processor_exit (mach_port_t processor) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Get default processor set for host. */ +kern_return_t +S_processor_set_default (mach_port_t host, mach_port_t *default_set) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* + * Create new processor set. Returns real port for manipulations, + * and name port for obtaining information. + */ +kern_return_t +S_processor_set_create (mach_port_t host, mach_port_t *new_set, + mach_port_t *new_name) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Destroy processor set. */ +kern_return_t +S_processor_set_destroy (mach_port_t set) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Assign processor to processor set. */ +kern_return_t +S_processor_assign (mach_port_t processor, mach_port_t new_set, boolean_t wait) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Get current assignment for thread. */ +kern_return_t +S_processor_get_assignment (mach_port_t processor, mach_port_t *assigned_set) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Assign task to processor set. */ +kern_return_t +S_task_assign (mach_port_t task, mach_port_t new_set, boolean_t assign_threads) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Assign task to default set. */ +kern_return_t +S_task_assign_default (mach_port_t task, boolean_t assign_threads) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Get current assignment for task. */ +kern_return_t +S_task_get_assignment (mach_port_t task, mach_port_t *assigned_set) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Set max priority for processor_set. */ +kern_return_t +S_processor_set_max_priority (mach_port_t processor_set, int max_priority, + boolean_t change_threads) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_set_policy_enable */ +kern_return_t +S_processor_set_policy_enable (mach_port_t processor_set, int policy) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_set_policy_disable */ +kern_return_t +S_processor_set_policy_disable (mach_port_t processor_set, int policy, + boolean_t change_threads) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_set_threads */ +kern_return_t +S_processor_set_threads (mach_port_t processor_set, + thread_array_t *thread_list, + mach_msg_type_number_t *thread_listCnt) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine host_set_time */ +kern_return_t +S_host_set_time (mach_port_t host_priv, time_value_t new_time) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine host_adjust_time */ +kern_return_t +S_host_adjust_time (mach_port_t host_priv, time_value_t new_adjustment, + time_value_t *old_adjustment) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_info */ +kern_return_t +S_processor_info (mach_port_t processor, int flavor, mach_port_t *host, + processor_info_t processor_info_out, + mach_msg_type_number_t *processor_info_outCnt) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_set_info */ +kern_return_t +S_processor_set_info (mach_port_t set_name, int flavor, mach_port_t *host, + processor_set_info_t info_out, + mach_msg_type_number_t *info_outCnt) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine processor_control */ +kern_return_t +S_processor_control (mach_port_t processor, processor_info_t processor_cmd, + mach_msg_type_number_t processor_cmdCnt) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +/* Routine host_get_boot_info */ +kern_return_t +S_host_get_boot_info (mach_port_t host_priv, kernel_boot_info_t boot_info) +{ + debug (""); + assert (0); + // Hurd currently doesn't use it. + return EOPNOTSUPP; +} + +///////////////////it's not a proxy for thread requests/////////////////// + +/* Assign thread to processor set. */ +kern_return_t +S_thread_assign (mach_port_t thread, mach_port_t new_set) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Assign thread to default set. */ +kern_return_t +S_thread_assign_default (mach_port_t thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Get current assignment for thread. */ +kern_return_t +S_thread_get_assignment (mach_port_t thread, mach_port_t *assigned_set) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Set priority for thread. */ +kern_return_t S_thread_priority (mach_port_t thread, int priority, + boolean_t set_max) +{ + debug (""); + assert (0); + return thread_priority (thread, priority, set_max); +} + +/* Set max priority for thread. */ +kern_return_t S_thread_max_priority (mach_port_t thread, + mach_port_t processor_set, + int max_priority) +{ + debug (""); + assert (0); + return thread_max_priority (thread, processor_set, max_priority); +} + +/* Routine thread_depress_abort */ +kern_return_t S_thread_depress_abort (mach_port_t thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Set policy for thread */ +kern_return_t S_thread_policy (mach_port_t thread, int policy, int data) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +////////////////////don't support obsolete requests/////////////////////// + +/* Routine yyy_host_info */ +/* obsolete */ +kern_return_t +S_yyy_host_info (mach_port_t host, int flavor, host_info_t host_info_out, + mach_msg_type_number_t *host_info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine yyy_processor_info */ +/* obsolete */ +kern_return_t +S_yyy_processor_info (mach_port_t processor, int flavor, mach_port_t *host, + processor_info_t processor_info_out, + mach_msg_type_number_t *processor_info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine yyy_processor_control */ +/* obsolete */ +kern_return_t +S_yyy_processor_control (mach_port_t processor, + processor_info_t processor_cmd, + mach_msg_type_number_t processor_cmdCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* + * Get rights to default processor set for host. + * Replaced by host_processor_set_priv. + */ +kern_return_t +S_xxx_processor_set_default_priv (mach_port_t host, mach_port_t *default_set) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine yyy_processor_set_info */ +/* obsolete */ +kern_return_t +S_yyy_processor_set_info (mach_port_t set_name, int flavor, + mach_port_t *host, processor_set_info_t info_out, + mach_msg_type_number_t *info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} diff --git a/boot-proxy-exc/mach_impl.c b/boot-proxy-exc/mach_impl.c new file mode 100644 index 00000000..abead5a9 --- /dev/null +++ b/boot-proxy-exc/mach_impl.c @@ -0,0 +1,909 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This file implements the server-side RPC functions of mach_host. */ + +#include <string.h> +#include <mach.h> +#include <hurd.h> +#include <assert.h> + +#include "util.h" +#include "mach_proxy.h" +#include "list.h" + +/* Routine task_create */ +kern_return_t +S_task_create (mach_port_t target_task, boolean_t inherit_memory, + mach_port_t *child_task, mach_msg_type_name_t *child_taskPoly) +{ + struct task_info *target_task_pi; + task_t real_child_task; + task_t pseudo_child_task; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = task_create (target_task_pi->task_port, + inherit_memory, &real_child_task); + debug ("get a request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + if (err) + return err; + + err = create_pseudo_task (real_child_task, &pseudo_child_task); + if (err) + { + task_terminate (real_child_task); + return err; + } + + *child_task = pseudo_child_task; + *child_taskPoly = MACH_MSG_TYPE_COPY_SEND; + + debug ("new task: %d", real_child_task); + return err; +} + +/* Routine task_terminate */ +kern_return_t +S_task_terminate (mach_port_t target_task) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = task_terminate (target_task_pi->task_port); + debug ("get request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_destroy_right (target_task_pi); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine task_info */ +kern_return_t +S_task_info (mach_port_t target_task, int flavor, + task_info_t task_info_out, + mach_msg_type_number_t *task_info_outCnt) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = task_info (target_task_pi->task_port, flavor, + task_info_out, task_info_outCnt); + debug ("%s", strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_allocate */ +kern_return_t +S_vm_allocate (mach_port_t target_task, vm_address_t *address, + vm_size_t size, boolean_t anywhere) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + /* This should be enough. */ + err = vm_allocate (target_task_pi->task_port, address, size, anywhere); + debug ("request is from task %d, address: %d, size: %d, anywhere: %d, %s", + target_task_pi->task_port, *address, size, anywhere, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_deallocate */ +kern_return_t +S_vm_deallocate (mach_port_t target_task, + vm_address_t address, vm_size_t size) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_deallocate (target_task_pi->task_port, address, size); + debug ("get a request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_protect */ +kern_return_t +S_vm_protect (mach_port_t target_task, vm_address_t address, + vm_size_t size, boolean_t set_maximum, + vm_prot_t new_protection) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_protect (target_task_pi->task_port, address, + size, set_maximum, new_protection); + debug ("request is from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_inherit */ +kern_return_t +S_vm_inherit (mach_port_t target_task, vm_address_t address, + vm_size_t size, vm_inherit_t new_inheritance) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_inherit (target_task_pi->task_port, address, + size, new_inheritance); + debug ("%s", strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_read */ +kern_return_t +S_vm_read (mach_port_t target_task, vm_address_t address, + vm_size_t size, vm_offset_t *data, + mach_msg_type_number_t *dataCnt) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = vm_read (target_task_pi->task_port, address, size, data, dataCnt); + debug ("get a request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + /* The deallocation bit is set.*/ + return err; +} + +/* Routine vm_write */ +kern_return_t +S_vm_write (mach_port_t target_task, vm_address_t address, + vm_offset_t data, mach_msg_type_number_t dataCnt) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_write (target_task_pi->task_port, address, data, dataCnt); + debug ("get a request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + /* the proxy get the mapped pages from the client, + * deallocate it here. */ + vm_deallocate (mach_task_self (), data, dataCnt); + return err; +} + +/* Routine vm_copy */ +kern_return_t +S_vm_copy (mach_port_t target_task, vm_address_t source_address, + vm_size_t size, vm_address_t dest_address) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = vm_copy (target_task_pi->task_port, source_address, + size, dest_address); + debug ("%s", strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_region */ +kern_return_t +S_vm_region (mach_port_t target_task, vm_address_t *address, + vm_size_t *size, vm_prot_t *protection, + vm_prot_t *max_protection, vm_inherit_t *inheritance, + boolean_t *is_shared, mach_port_t *object_name, + vm_offset_t *offset) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = vm_region (target_task_pi->task_port, address, size, protection, + max_protection, inheritance, is_shared, object_name, offset); + debug ("get a request from task %d: %s, object: %d", + target_task_pi->task_port, strerror (err), *object_name); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_statistics */ +kern_return_t +S_vm_statistics (mach_port_t target_task, vm_statistics_data_t *vm_stats) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = vm_statistics (target_task_pi->task_port, vm_stats); + debug ("request is from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine mach_ports_register */ +kern_return_t +S_mach_ports_register (mach_port_t target_task, + mach_port_array_t init_port_set, + mach_msg_type_number_t init_port_setCnt) +{ + debug (""); + assert (0); + // not used by Hurd + return EOPNOTSUPP; +} + +/* Routine mach_ports_lookup */ +kern_return_t +S_mach_ports_lookup (mach_port_t target_task, + mach_port_array_t *init_port_set, + mach_msg_type_number_t *init_port_setCnt) +{ + debug (""); + assert (0); + // not used by Hurd + return EOPNOTSUPP; +} + +/* Routine vm_set_default_memory_manager */ +kern_return_t +S_vm_set_default_memory_manager (mach_port_t host_priv, + mach_port_t *default_manager) +{ + extern mach_port_t defpager; + debug (""); + *default_manager = defpager; + return 0; +} + + +/* Routine xxx_task_info */ +kern_return_t +S_xxx_task_info (mach_port_t target_task, int flavor, + task_info_t task_info_out, + mach_msg_type_number_t *task_info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_host_info */ +kern_return_t +S_xxx_host_info (mach_port_t target_task, machine_info_data_t *info) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_slot_info */ +kern_return_t +S_xxx_slot_info (mach_port_t target_task, int slot, machine_slot_data_t *info) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_cpu_control */ +kern_return_t +S_xxx_cpu_control (mach_port_t target_task, int cpu, boolean_t running) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine task_suspend */ +kern_return_t +S_task_suspend (mach_port_t target_task) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = task_suspend (target_task_pi->task_port); + debug ("get request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine task_resume */ +kern_return_t +S_task_resume (mach_port_t target_task) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = task_resume (target_task_pi->task_port); + debug ("get request from task %d: %s", + target_task_pi->task_port, strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine task_get_special_port */ +kern_return_t +S_task_get_special_port (mach_port_t target_task, int which_port, + mach_port_t *special_port, + mach_msg_type_name_t *special_portPoly) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + err = task_get_special_port (target_task_pi->task_port, + which_port, special_port); + debug ("request is from task %d (%d, %d): %s\n", + target_task_pi->task_port, which_port, *special_port, strerror (err)); + ports_port_deref (target_task_pi); + if (err) + return err; + *special_portPoly = MACH_MSG_TYPE_MOVE_SEND; + return err; +} + +/* Routine task_set_special_port */ +kern_return_t +S_task_set_special_port (mach_port_t target_task, int which_port, + mach_port_t special_port) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + if (which_port == TASK_EXCEPTION_PORT) + { + struct port_info *new_exc_pi; + struct port_info *old_exc_pi; + mach_port_t old_user_exc_port; + mach_port_t new_exc_port; + + err = ports_create_port (exc_portclass, port_bucket, + sizeof (new_exc_pi), &new_exc_pi); + if (err) + { + ports_port_deref (target_task_pi); + return err; + } + new_exc_port = ports_get_send_right (new_exc_pi); + + mutex_lock (&target_task_pi->lock); + old_exc_pi = target_task_pi->exc_pi; + old_user_exc_port = target_task_pi->user_exc_port; + err = task_set_special_port (target_task_pi->task_port, + which_port, new_exc_port); + target_task_pi->user_exc_port = special_port; + target_task_pi->exc_pi = new_exc_pi; + mutex_unlock (&target_task_pi->lock); + + ports_port_deref (new_exc_pi); + if (old_user_exc_port) + mach_port_deallocate (mach_task_self (), old_user_exc_port); + if (old_exc_pi) + ports_destroy_right (old_exc_pi); + debug ("get request from task %d (%d, %d): %s", + target_task_pi->task_port, which_port, + special_port, strerror (err)); + } + else + { + err = task_set_special_port (target_task_pi->task_port, + which_port, special_port); + debug ("get request from task %d (%d, %d): %s", + target_task_pi->task_port, which_port, + special_port, strerror (err)); + mach_port_deallocate (mach_task_self (), special_port); + } + ports_port_deref (target_task_pi); + return err; +} + +/* Routine task_ras_control */ +kern_return_t +S_task_ras_control (mach_port_t target_task, vm_address_t basepc, + vm_address_t boundspc, int flavor) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = task_ras_control (target_task_pi->task_port, basepc, boundspc, flavor); + debug ("%s", strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine vm_map */ +kern_return_t +S_vm_map (mach_port_t target_task, vm_address_t *address, vm_size_t size, + vm_address_t mask, boolean_t anywhere, mach_port_t memory_object, + vm_offset_t offset, boolean_t copy, vm_prot_t cur_protection, + vm_prot_t max_protection, vm_inherit_t inheritance) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_map (target_task_pi->task_port, address, size, mask, + anywhere, memory_object, offset, copy, + cur_protection, max_protection, inheritance); + debug ("request is from task %d, anywhere: %d: %s", + target_task_pi->task_port, anywhere, strerror (err)); + ports_port_deref (target_task_pi); + mach_port_deallocate (mach_task_self (), memory_object); + return err; +} + +/* Routine vm_machine_attribute */ +kern_return_t +S_vm_machine_attribute (mach_port_t target_task, vm_address_t address, + vm_size_t size, vm_machine_attribute_t attribute, + vm_machine_attribute_val_t *value) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = vm_machine_attribute (target_task_pi->task_port, address, + size, attribute, value); + debug ("%s", strerror (err)); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine task_threads */ +kern_return_t +S_task_threads (mach_port_t target_task, thread_array_t *thread_list, + mach_msg_type_number_t *thread_listCnt) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + target_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + + // TODO: use move send + err = task_threads (target_task_pi->task_port, + thread_list, thread_listCnt); + debug ("get a request from task %d: %s", + target_task_pi->task_port, strerror (err)); +// info ("task_threads: %s, number of threads: %d", +// strerror (err), *thread_listCnt); + ports_port_deref (target_task_pi); + return err; +} + +/* Routine thread_create */ +kern_return_t +S_thread_create (mach_port_t parent_task, mach_port_t *child_thread, + mach_msg_type_name_t *child_threadPoly) +{ + struct task_info *target_task_pi; + error_t err; + + target_task_pi = ports_lookup_port (port_bucket, + parent_task, task_portclass); + if (target_task_pi == NULL) + return EOPNOTSUPP; + err = thread_create (target_task_pi->task_port, child_thread); + debug ("get a request from task %d: thread port: %d: %s", + target_task_pi->task_port, *child_thread, strerror (err)); + ports_port_deref (target_task_pi); + *child_threadPoly = MACH_MSG_TYPE_MOVE_SEND; + return err; +} + +////////////////////it doesn't forward thread request//////////////// + +/* Routine thread_suspend */ +kern_return_t +S_thread_suspend (mach_port_t target_thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_resume */ +kern_return_t +S_thread_resume (mach_port_t target_thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_abort */ +kern_return_t +S_thread_abort (mach_port_t target_thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_thread_get_state */ +kern_return_t +S_xxx_thread_get_state (mach_port_t target_thread, int flavor, + thread_state_t old_state, + mach_msg_type_number_t *old_stateCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_thread_set_state */ +kern_return_t +S_xxx_thread_set_state (mach_port_t target_thread, int flavor, + thread_state_t new_state, + mach_msg_type_number_t new_stateCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_thread_info */ +kern_return_t +S_xxx_thread_info (mach_port_t target_thread, int flavor, + thread_info_t thread_info_out, + mach_msg_type_number_t *thread_info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_get_special_port */ +kern_return_t +S_thread_get_special_port (mach_port_t thread, int which_port, + mach_port_t *special_port) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_set_special_port */ +kern_return_t +S_thread_set_special_port (mach_port_t thread, int which_port, + mach_port_t special_port) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_terminate */ +kern_return_t +S_thread_terminate (mach_port_t target_thread) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_get_state */ +kern_return_t +S_thread_get_state (mach_port_t target_thread, int flavor, + thread_state_t old_state, + mach_msg_type_number_t *old_stateCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_set_state */ +kern_return_t +S_thread_set_state (mach_port_t target_thread, int flavor, + thread_state_t new_state, + mach_msg_type_number_t new_stateCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine thread_info */ +kern_return_t +S_thread_info (mach_port_t target_thread, int flavor, + thread_info_t thread_info_out, + mach_msg_type_number_t *thread_info_outCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/////////////////////RPC related to memory object//////////////////// +//////////////////they are not needed to be forwarded//////////////// + +/* SimpleRoutine memory_object_data_provided */ +kern_return_t +S_memory_object_data_provided (mach_port_t memory_control, + vm_offset_t offset, vm_offset_t data, + mach_msg_type_number_t dataCnt, + vm_prot_t lock_value) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_data_unavailable */ +kern_return_t +S_memory_object_data_unavailable (mach_port_t memory_control, + vm_offset_t offset, vm_size_t size) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine memory_object_get_attributes */ +kern_return_t +S_memory_object_get_attributes (mach_port_t memory_control, + boolean_t *object_ready, boolean_t *may_cache, + memory_object_copy_strategy_t *copy_strategy) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine xxx_memory_object_lock_request */ +kern_return_t +S_xxx_memory_object_lock_request (mach_port_t memory_control, + vm_offset_t offset, vm_size_t size, + boolean_t should_clean, + boolean_t should_flush, + vm_prot_t lock_value, + mach_port_t reply_to, + mach_msg_type_name_t reply_toPoly) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_lock_request */ +kern_return_t +S_memory_object_lock_request ( mach_port_t memory_control, + vm_offset_t offset, vm_size_t size, + memory_object_return_t should_return, + boolean_t should_flush, + vm_prot_t lock_value, mach_port_t reply_to, + mach_msg_type_name_t reply_toPoly) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_data_error */ +kern_return_t +S_memory_object_data_error (mach_port_t memory_control, + vm_offset_t offset, vm_size_t size, + kern_return_t error_value) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_set_attributes */ +kern_return_t +S_memory_object_set_attributes (mach_port_t memory_control, + boolean_t object_ready, boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_destroy */ +kern_return_t +S_memory_object_destroy (mach_port_t memory_control, kern_return_t reason) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_data_supply */ +kern_return_t +S_memory_object_data_supply (mach_port_t memory_control, + vm_offset_t offset, vm_offset_t data, + mach_msg_type_number_t dataCnt, + vm_prot_t lock_value, boolean_t precious, + mach_port_t reply_to, + mach_msg_type_name_t reply_toPoly) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_ready */ +kern_return_t +S_memory_object_ready (mach_port_t memory_control, boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* SimpleRoutine memory_object_change_attributes */ +kern_return_t +S_memory_object_change_attributes (mach_port_t memory_control, + boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy, + mach_port_t reply_to, + mach_msg_type_name_t reply_toPoly) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +///////////////////////RPCs related to emulation///////////////////// +//////////////////////subhurd doesn't support it.//////////////////// + +/* Routine task_get_emulation_vector */ +kern_return_t +S_task_get_emulation_vector (mach_port_t task, int *vector_start, + emulation_vector_t *emulation_vector, + mach_msg_type_number_t *emulation_vectorCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine task_set_emulation_vector */ +kern_return_t +S_task_set_emulation_vector (mach_port_t task, int vector_start, + emulation_vector_t emulation_vector, + mach_msg_type_number_t emulation_vectorCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_task_get_emulation_vector */ +kern_return_t +S_xxx_task_get_emulation_vector (mach_port_t task, int *vector_start, + emulation_vector_t emulation_vector, + mach_msg_type_number_t *emulation_vectorCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine xxx_task_set_emulation_vector */ +kern_return_t +S_xxx_task_set_emulation_vector (mach_port_t task, int vector_start, + emulation_vector_t emulation_vector, + mach_msg_type_number_t emulation_vectorCnt) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} + +/* Routine task_set_emulation */ +kern_return_t +S_task_set_emulation (mach_port_t target_port, + vm_address_t routine_entry_pt, int routine_number) +{ + debug (""); + assert (0); + return EOPNOTSUPP; +} diff --git a/boot-proxy-exc/mach_port_impl.c b/boot-proxy-exc/mach_port_impl.c new file mode 100644 index 00000000..b421280b --- /dev/null +++ b/boot-proxy-exc/mach_port_impl.c @@ -0,0 +1,375 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* This file implements the server-side RPC functions of mach_host. */ + +#include <mach.h> +#include <hurd.h> +#include <string.h> +#include <assert.h> + +#include "util.h" +#include "mach_proxy.h" + +kern_return_t +S_mach_port_names (mach_port_t task, mach_port_array_t *names, + mach_msg_type_number_t *namesCnt, + mach_port_type_array_t *types, + mach_msg_type_number_t *typesCnt) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_names (task_pi->task_port, + names, namesCnt, types, typesCnt); + debug ("%s", strerror (err)); + /* The deallocation bit is set, + * so 'names' and 'types' will be deallocated after the reply is sent. */ + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_type */ +kern_return_t +S_mach_port_type (mach_port_t task, mach_port_t name, mach_port_type_t *ptype) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_type (task_pi->task_port, name, ptype); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_rename */ +kern_return_t +S_mach_port_rename (mach_port_t task, + mach_port_t old_name, mach_port_t new_name) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + /* old_name and new_name are just names, + * so I don't need to deallocate them. + * It should be the same for other RPCs that only deal with port names */ + err = mach_port_rename (task_pi->task_port, old_name, new_name); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_allocate_name */ +kern_return_t +S_mach_port_allocate_name (mach_port_t task, + mach_port_right_t right, mach_port_t name) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_allocate_name (task_pi->task_port, right, name); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_allocate */ +kern_return_t +S_mach_port_allocate (mach_port_t task, + mach_port_right_t right, mach_port_t *name) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_allocate (task_pi->task_port, right, name); + debug ("get a request from task %d: %s", task_pi->task_port, strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_destroy */ +kern_return_t +S_mach_port_destroy (mach_port_t task, mach_port_t name) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_destroy (task_pi->task_port, name); + debug ("get a request from port %d: %s", + task_pi->task_port, strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_deallocate */ +kern_return_t +S_mach_port_deallocate (mach_port_t task, mach_port_t name) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_deallocate (task_pi->task_port, name); + debug ("get a request from task %d, name: %d, %s", + task_pi->task_port, name, strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_get_refs */ +kern_return_t +S_mach_port_get_refs (mach_port_t task, mach_port_t name, + mach_port_right_t right, mach_port_urefs_t *refs) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_get_refs (task_pi->task_port, name, right, refs); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_mod_refs */ +kern_return_t +S_mach_port_mod_refs (mach_port_t task, mach_port_t name, + mach_port_right_t right, mach_port_delta_t delta) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_mod_refs (task_pi->task_port, name, right, delta); + debug ("get a request from task %d: port: %d, right: %d, delta: %d, %s", + task_pi->task_port, name, right, delta, strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine old_mach_port_get_receive_status */ +kern_return_t +S_old_mach_port_get_receive_status (mach_port_t task, mach_port_t name, + old_mach_port_status_t *status) +{ + debug ("%s", strerror (EOPNOTSUPP)); + assert (0); + /* Hurd currently doesn't use it. */ + return EOPNOTSUPP; +} + +/* Routine mach_port_set_qlimit */ +kern_return_t +S_mach_port_set_qlimit (mach_port_t task, mach_port_t name, + mach_port_msgcount_t qlimit) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_set_qlimit (task_pi->task_port, name, qlimit); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_set_mscount */ +kern_return_t +S_mach_port_set_mscount (mach_port_t task, mach_port_t name, + mach_port_mscount_t mscount) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_set_mscount (task_pi->task_port, name, mscount); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_get_set_status */ +kern_return_t +S_mach_port_get_set_status (mach_port_t task, mach_port_t name, + mach_port_array_t *members, + mach_msg_type_number_t *membersCnt) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_get_set_status (task_pi->task_port, + name, members, membersCnt); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + /* The deallocation bit is set, + * so 'members' will be deallocated after the reply is sent. */ + return err; +} + +/* Routine mach_port_move_member */ +kern_return_t +S_mach_port_move_member (mach_port_t task, mach_port_t member, + mach_port_t after) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_move_member (task_pi->task_port, member, after); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_request_notification */ +kern_return_t +S_mach_port_request_notification (mach_port_t task, mach_port_t name, + mach_msg_id_t id, mach_port_mscount_t sync, + mach_port_t notify, mach_port_t *previous, + mach_msg_type_name_t *previousPoly) +{ + struct task_info *task_pi; + mach_msg_type_name_t notify_type = MACH_MSG_TYPE_MOVE_SEND_ONCE; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + /* notify is send-once right from the client. */ + err = mach_port_request_notification (task_pi->task_port, name, id, sync, + notify, notify_type, previous); + debug ("get a request from task %d, port: %d, id: %d, notify: %d, notify_type: %d, old port: %d, %s", + task_pi->task_port, name, id, notify, notify_type, *previous, strerror (err)); + ports_port_deref (task_pi); + if (err) + return err; + *previousPoly = MACH_MSG_TYPE_MOVE_SEND_ONCE; + + return 0; +} + +/* Routine mach_port_insert_right */ +kern_return_t +S_mach_port_insert_right (mach_port_t task, mach_port_t name, + mach_port_t poly, mach_msg_type_name_t polyPoly) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + /* polyPoly can only be three possible values: MACH_MSG_TYPE_PORT_SEND, + * MACH_MSG_TYPE_PORT_SEND_ONCE and MACH_MSG_TYPE_PORT_RECEIVE, + * so port will be deallocated when mach_port_insert_right is called. */ + err = mach_port_insert_right (task_pi->task_port, name, poly, polyPoly); + debug ("get a request from task %d: %s", task_pi->task_port, strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_extract_right */ +kern_return_t +S_mach_port_extract_right (mach_port_t task, mach_port_t name, + mach_msg_type_name_t msgt_name, mach_port_t *poly, + mach_msg_type_name_t *polyPoly) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_extract_right (task_pi->task_port, name, msgt_name, + poly, polyPoly); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + /* *polyPoly can only be MACH_MSG_TYPE_PORT_SEND, MACH_MSG_TYPE_PORT_RECEIVE, + * or MACH_MSG_TYPE_PORT_SEND_ONCE, so the port extracted from 'task' + * will be moved to the client. */ + return err; +} + +/* Routine mach_port_get_receive_status */ +kern_return_t +S_mach_port_get_receive_status (mach_port_t task, mach_port_t name, + mach_port_status_t *status) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_get_receive_status (task_pi->task_port, name, status); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} + +/* Routine mach_port_set_seqno */ +kern_return_t +S_mach_port_set_seqno (mach_port_t task, mach_port_t name, + mach_port_seqno_t seqno) +{ + struct task_info *task_pi; + error_t err; + + task_pi = ports_lookup_port (port_bucket, task, task_portclass); + if (task_pi == NULL) + return EOPNOTSUPP; + err = mach_port_set_seqno (task_pi->task_port, name, seqno); + debug ("%s", strerror (err)); + ports_port_deref (task_pi); + return err; +} diff --git a/boot-proxy-exc/mach_proxy.c b/boot-proxy-exc/mach_proxy.c new file mode 100644 index 00000000..cc599353 --- /dev/null +++ b/boot-proxy-exc/mach_proxy.c @@ -0,0 +1,97 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <string.h> + +#include "util.h" +#include "mach_proxy.h" + +static LIST_HEADER (tasks_head); + +static struct mutex tasks_lock = MUTEX_INITIALIZER; + +int create_pseudo_task (task_t real_task, task_t *ret_pseudo_task) +{ + /* the first task is the kernel task. */ + struct task_info *task_pi; + task_t pseudo_task; + error_t err; + + err = ports_create_port (task_portclass, port_bucket, + sizeof (struct task_info), &task_pi); + if (err) + return err; + + task_pi->task_port = real_task; + task_pi->exc_pi = NULL; + task_pi->user_exc_port = 0; + mutex_init (&task_pi->lock); + entry_init (&task_pi->list); + mutex_lock (&tasks_lock); + add_entry_end (&tasks_head, &task_pi->list); + mutex_unlock (&tasks_lock); + + pseudo_task = ports_get_right (task_pi); + mach_port_insert_right (mach_task_self (), pseudo_task, pseudo_task, + MACH_MSG_TYPE_MAKE_SEND); + ports_port_deref (task_pi); + + if (ret_pseudo_task) + *ret_pseudo_task = pseudo_task; + + err = task_set_kernel_port (real_task, pseudo_task); + if (err) + { + debug ("fail to set the kernel port: %s", strerror (err)); + ports_destroy_right (task_pi); + } + + return err; +} + +void clean_pseudo_task (void *pi) +{ + struct task_info *task = pi; + + debug ("remove a pseudo task from the list"); + mutex_lock (&tasks_lock); + remove_entry (&task->list); + mutex_unlock (&tasks_lock); + + if (task->exc_pi) + ports_destroy_right (task->exc_pi); + if (task->user_exc_port) + mach_port_deallocate (mach_task_self (), task->user_exc_port); +} + +void foreach_task (task_callback_t callback) +{ + struct list *entry = &tasks_head; + mutex_lock (&tasks_lock); + for (entry = tasks_head.next; entry != &tasks_head; entry = entry->next) + { +// mutex_unlock (&tasks_lock); + struct task_info *task_pi = LIST_ENTRY (entry, struct task_info, list); + if (callback (task_pi)) + break; +// mutex_lock (&tasks_lock); + } + mutex_unlock (&tasks_lock); +} diff --git a/boot-proxy-exc/mach_proxy.h b/boot-proxy-exc/mach_proxy.h new file mode 100644 index 00000000..15f9c397 --- /dev/null +++ b/boot-proxy-exc/mach_proxy.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef PROXY_H +#define PROXY_H + +#include <mach.h> +#include <hurd.h> +#include <hurd/ports.h> + +#include "list.h" + +struct task_info +{ + struct port_info task; + task_t task_port; + struct port_info *exc_pi; + volatile mach_port_t user_exc_port; + struct mutex lock; + /* The linked list is used to keep the order of tasks */ + struct list list; +}; + +struct thread_info +{ + struct port_info thread; + thread_t thread_port; +}; + +typedef int (*task_callback_t) (struct task_info *); + +extern struct port_bucket *port_bucket; +extern struct port_class *task_portclass; +extern struct port_class *exc_portclass; +extern struct port_class *thread_portclass; + +int create_pseudo_task (task_t real_task, task_t *ret_pseudo_task); +void clean_pseudo_task (void *pi); +void foreach_task (task_callback_t callback); + +#define UNTESTED + +#endif diff --git a/boot-proxy-exc/notify.defs b/boot-proxy-exc/notify.defs new file mode 100644 index 00000000..2014be5c --- /dev/null +++ b/boot-proxy-exc/notify.defs @@ -0,0 +1 @@ +#include <mach/notify.defs> diff --git a/boot-proxy-exc/ourdevice.defs b/boot-proxy-exc/ourdevice.defs new file mode 100644 index 00000000..1b8ac442 --- /dev/null +++ b/boot-proxy-exc/ourdevice.defs @@ -0,0 +1,383 @@ +# 1 "device.defs" +# 1 "<built-in>" +# 1 "<command-line>" +# 1 "device.defs" +# 1 "/usr/local/include/device/device.defs" 1 3 +# 39 "/usr/local/include/device/device.defs" 3 +subsystem + + + + device 2800; + +# 1 "/usr/local/include/mach/std_types.defs" 1 3 +# 33 "/usr/local/include/mach/std_types.defs" 3 +type char = MACH_MSG_TYPE_CHAR; +type short = MACH_MSG_TYPE_INTEGER_16; +type int = MACH_MSG_TYPE_INTEGER_32; +type int32 = MACH_MSG_TYPE_INTEGER_32; +type int64 = MACH_MSG_TYPE_INTEGER_64; +type boolean_t = MACH_MSG_TYPE_BOOLEAN; +type unsigned = MACH_MSG_TYPE_INTEGER_32; +type unsigned32 = MACH_MSG_TYPE_INTEGER_32; +type unsigned64 = MACH_MSG_TYPE_INTEGER_64; + + +# 1 "/usr/local/include/mach/machine/machine_types.defs" 1 3 +# 50 "/usr/local/include/mach/machine/machine_types.defs" 3 +type natural_t = unsigned32; +# 59 "/usr/local/include/mach/machine/machine_types.defs" 3 +type integer_t = int32; +# 45 "/usr/local/include/mach/std_types.defs" 2 3 + +type kern_return_t = int; + +type pointer_t = ^array[] of MACH_MSG_TYPE_BYTE + ctype: vm_offset_t; + + +type mach_port_t = MACH_MSG_TYPE_COPY_SEND; +type mach_port_array_t = array[] of mach_port_t; + +type mach_port_name_t = MACH_MSG_TYPE_PORT_NAME + ctype: mach_port_t; +type mach_port_name_array_t = array[] of mach_port_name_t + ctype: mach_port_array_t; + +type mach_port_right_t = natural_t; + +type mach_port_type_t = natural_t; +type mach_port_type_array_t = array[] of mach_port_type_t; + +type mach_port_urefs_t = natural_t; +type mach_port_delta_t = integer_t; +type mach_port_seqno_t = natural_t; +type mach_port_mscount_t = unsigned; +type mach_port_msgcount_t = unsigned; +type mach_port_rights_t = unsigned; +type mach_msg_id_t = integer_t; +type mach_msg_type_name_t = unsigned; +type mach_msg_type_number_t = natural_t; + +type mach_port_move_receive_t = MACH_MSG_TYPE_MOVE_RECEIVE + ctype: mach_port_t; +type mach_port_copy_send_t = MACH_MSG_TYPE_COPY_SEND + ctype: mach_port_t; +type mach_port_make_send_t = MACH_MSG_TYPE_MAKE_SEND + ctype: mach_port_t; +type mach_port_move_send_t = MACH_MSG_TYPE_MOVE_SEND + ctype: mach_port_t; +type mach_port_make_send_once_t = MACH_MSG_TYPE_MAKE_SEND_ONCE + ctype: mach_port_t; +type mach_port_move_send_once_t = MACH_MSG_TYPE_MOVE_SEND_ONCE + ctype: mach_port_t; + +type mach_port_receive_t = MACH_MSG_TYPE_PORT_RECEIVE + ctype: mach_port_t; +type mach_port_send_t = MACH_MSG_TYPE_PORT_SEND + ctype: mach_port_t; +type mach_port_send_once_t = MACH_MSG_TYPE_PORT_SEND_ONCE + ctype: mach_port_t; + +type mach_port_poly_t = polymorphic + ctype: mach_port_t; + +import <mach/std_types.h>; +# 46 "/usr/local/include/device/device.defs" 2 3 +# 1 "/usr/local/include/mach/mach_types.defs" 1 3 +# 61 "/usr/local/include/mach/mach_types.defs" 3 +type mach_port_status_t = struct[9] of integer_t; + +type old_mach_port_status_t = struct[8] of integer_t; + +type task_t = mach_port_t + ctype: mach_port_t + + + + + + ; +# 85 "/usr/local/include/mach/mach_types.defs" 3 +type thread_t = mach_port_t + ctype: mach_port_t + + + + + + ; + +type thread_state_t = array[*:1024] of natural_t; + +type task_array_t = ^array[] of task_t; +type thread_array_t = ^array[] of thread_t; + +type vm_task_t = mach_port_t + ctype: mach_port_t + + + + + ; + +type ipc_space_t = mach_port_t + ctype: mach_port_t + + + + + ; + +type vm_address_t = natural_t; +type vm_offset_t = natural_t; +type vm_size_t = natural_t; +type vm_prot_t = int; +type vm_inherit_t = int; +type vm_statistics_data_t = struct[13] of integer_t; +type vm_machine_attribute_t = int; +type vm_machine_attribute_val_t = int; + +type thread_info_t = array[*:1024] of natural_t; +type thread_basic_info_data_t = struct[11] of integer_t; +type thread_sched_info_data_t = struct[7] of integer_t; + +type task_info_t = array[*:1024] of natural_t; +type task_basic_info_data_t = struct[8] of integer_t; +type task_events_info = struct[7] of natural_t; +type task_thread_times_info_data_t = struct[4] of integer_t; + + +type memory_object_t = mach_port_t + ctype: mach_port_t + + + + ; + +type memory_object_control_t = mach_port_t + ctype: mach_port_t + + + + ; + +type memory_object_name_t = mach_port_t + ctype: mach_port_t + + + + + ; + +type memory_object_copy_strategy_t = int; +type memory_object_return_t = int; + +type machine_info_data_t = struct[5] of integer_t; +type machine_slot_data_t = struct[8] of integer_t; + +type host_t = mach_port_t + ctype: mach_port_t + + + + + ; + +type host_priv_t = mach_port_t + ctype: mach_port_t + + + + ; + +type host_info_t = array[*:1024] of natural_t; +type host_basic_info_data_t = struct[5] of integer_t; +type host_sched_info_data_t = struct[2] of integer_t; +type host_load_info_data_t = struct[6] of integer_t; + + +type processor_t = mach_port_t + ctype: mach_port_t + + + + + ; + +type processor_array_t = ^array[] of processor_t; +type processor_info_t = array[*:1024] of natural_t; +type processor_basic_info_data_t = struct[5] of integer_t; + + +type processor_set_t = mach_port_t + ctype: mach_port_t + + + + + + ; + +type processor_set_array_t = ^array[] of processor_set_t; + +type processor_set_name_t = mach_port_t + ctype: mach_port_t + + + + + + ; + +type processor_set_name_array_t = ^array[] of processor_set_name_t; + +type processor_set_info_t = array[*:1024] of natural_t; +type processor_set_basic_info_data_t = struct[5] of integer_t; +type processor_set_sched_info_data_t = struct[2] of integer_t; + + +type kernel_version_t = (MACH_MSG_TYPE_STRING, 512*8); + +type kernel_boot_info_t = (MACH_MSG_TYPE_STRING, 4096*8); + +type time_value_t = struct[2] of integer_t; + +type emulation_vector_t = ^array[] of vm_offset_t; + +type xxx_emulation_vector_t = array[*:1024] of vm_offset_t + ctype: emulation_vector_t; + + +type rpc_signature_info_t = array[*:1024] of int; +# 250 "/usr/local/include/mach/mach_types.defs" 3 +import <mach/mach_types.h>; +# 47 "/usr/local/include/device/device.defs" 2 3 +# 1 "/usr/local/include/device/device_types.defs" 1 3 +# 42 "/usr/local/include/device/device_types.defs" 3 +type recnum_t = unsigned32; +type dev_mode_t = unsigned32; +type dev_flavor_t = unsigned32; +type dev_name_t = (MACH_MSG_TYPE_STRING_C, 8*128); +type dev_status_t = array[*:1024] of int; +type io_buf_ptr_t = ^array[] of MACH_MSG_TYPE_INTEGER_8; +type io_buf_ptr_inband_t= array[*:128] of char; +type filter_t = short; +type filter_array_t = array[*:128] of filter_t; + +type device_t = mach_port_t + ctype: mach_port_t + + + + + + ; + +import <device/device_types.h>; +import <device/net_status.h>; +# 48 "/usr/local/include/device/device.defs" 2 3 + +serverprefix ds_; + +type reply_port_t = MACH_MSG_TYPE_MAKE_SEND_ONCE | polymorphic + ctype: mach_port_t; + +routine device_open( + master_port : mach_port_t; + sreplyport reply_port : reply_port_t; + mode : dev_mode_t; + name : dev_name_t; + out device : mach_port_send_t + ); + +routine device_close( + device : device_t + ); + +routine device_write( + device : device_t; + sreplyport reply_port : reply_port_t; + in mode : dev_mode_t; + in recnum : recnum_t; + in data : io_buf_ptr_t; + out bytes_written : int + ); + +routine device_write_inband( + device : device_t; + sreplyport reply_port : reply_port_t; + in mode : dev_mode_t; + in recnum : recnum_t; + in data : io_buf_ptr_inband_t; + out bytes_written : int + ); + +routine device_read( + device : device_t; + sreplyport reply_port : reply_port_t; + in mode : dev_mode_t; + in recnum : recnum_t; + in bytes_wanted : int; + out data : io_buf_ptr_t + ); + +routine device_read_inband( + device : device_t; + sreplyport reply_port : reply_port_t; + in mode : dev_mode_t; + in recnum : recnum_t; + in bytes_wanted : int; + out data : io_buf_ptr_inband_t + ); + + +routine xxx_device_set_status( + device : device_t; + in flavor : dev_flavor_t; + in status : dev_status_t, IsLong + ); + + +routine xxx_device_get_status( + device : device_t; + in flavor : dev_flavor_t; + out status : dev_status_t, IsLong + ); + + +routine xxx_device_set_filter( + device : device_t; + in receive_port : mach_port_send_t; + in priority : int; + in filter : filter_array_t, IsLong + ); + +routine device_map( + device : device_t; + in prot : vm_prot_t; + in offset : vm_offset_t; + in size : vm_size_t; + out pager : memory_object_t; + in unmap : int + ); + +routine device_set_status( + device : device_t; + in flavor : dev_flavor_t; + in status : dev_status_t + ); + +routine device_get_status( + device : device_t; + in flavor : dev_flavor_t; + out status : dev_status_t, CountInOut + ); + +routine device_set_filter( + device : device_t; + in receive_port : mach_port_send_t; + in priority : int; + in filter : filter_array_t + ); +# 1 "device.defs" 2 diff --git a/boot-proxy-exc/ourmach.defs b/boot-proxy-exc/ourmach.defs new file mode 100644 index 00000000..a257d954 --- /dev/null +++ b/boot-proxy-exc/ourmach.defs @@ -0,0 +1,772 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * Matchmaker definitions file for Mach kernel interface. + */ + +#ifdef MACH_KERNEL +simport <kern/compat_xxx_defs.h>; /* for obsolete routines */ +#endif /* MACH_KERNEL */ + +subsystem +#if KERNEL_USER + KernelUser +#endif /* KERNEL_USER */ +#if KERNEL_SERVER + KernelServer +#endif /* KERNEL_SERVER */ + mach 2000; + +serverprefix S_; + +#ifdef KERNEL_USER +userprefix r_; +#endif /* KERNEL_USER */ + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +skip; /* old port_allocate */ +skip; /* old port_deallocate */ +skip; /* old port_enable */ +skip; /* old port_disable */ +skip; /* old port_select */ +skip; /* old port_set_backlog */ +skip; /* old port_status */ + +/* + * Create a new task with an empty set of IPC rights, + * and having an address space constructed from the + * target task (or empty, if inherit_memory is FALSE). + */ +routine task_create( + target_task : task_t; + inherit_memory : boolean_t; + out child_task : mach_port_send_t); + +/* + * Destroy the target task, causing all of its threads + * to be destroyed, all of its IPC rights to be deallocated, + * and all of its address space to be deallocated. + */ +routine task_terminate( + target_task : task_t); + +/* + * Get user-level handler entry points for all + * emulated system calls. + */ +routine task_get_emulation_vector( + task : task_t; + out vector_start : int; + out emulation_vector: emulation_vector_t); + +/* + * Establish user-level handlers for the specified + * system calls. Non-emulated system calls are specified + * with emulation_vector[i] == EML_ROUTINE_NULL. + */ +routine task_set_emulation_vector( + task : task_t; + vector_start : int; + emulation_vector: emulation_vector_t); + + +/* + * Returns the set of threads belonging to the target task. + */ +routine task_threads( + target_task : task_t; + out thread_list : thread_array_t); +/* out thread_list : thread_send_array_t = + array[] of mach_port_send_t + ctype: thread_array_t);*/ + +/* + * Returns information about the target task. + */ +routine task_info( + target_task : task_t; + flavor : int; + out task_info_out : task_info_t, CountInOut); + + +skip; /* old task_status */ +skip; /* old task_set_notify */ +skip; /* old thread_create */ + +/* + * Destroy the target thread. + */ +routine thread_terminate( + target_thread : thread_t); + +/* + * Return the selected state information for the target + * thread. If the thread is currently executing, the results + * may be stale. [Flavor THREAD_STATE_FLAVOR_LIST provides a + * list of valid flavors for the target thread.] + */ +routine thread_get_state( + target_thread : thread_t; + flavor : int; + out old_state : thread_state_t, CountInOut); + +/* + * Set the selected state information for the target thread. + * If the thread is currently executing, the state change + * may be ill-defined. + */ +routine thread_set_state( + target_thread : thread_t; + flavor : int; + new_state : thread_state_t); + +/* + * Returns information about the target thread. + */ +routine thread_info( + target_thread : thread_t; + flavor : int; + out thread_info_out : thread_info_t, CountInOut); + +skip; /* old thread_mutate */ + +/* + * Allocate zero-filled memory in the address space + * of the target task, either at the specified address, + * or wherever space can be found (if anywhere is TRUE), + * of the specified size. The address at which the + * allocation actually took place is returned. + */ +#ifdef EMULATOR +skip; /* the emulator redefines vm_allocate using vm_map */ +#else /* EMULATOR */ +routine vm_allocate( + target_task : vm_task_t; + inout address : vm_address_t; + size : vm_size_t; + anywhere : boolean_t); +#endif /* EMULATOR */ + +skip; /* old vm_allocate_with_pager */ + +/* + * Deallocate the specified range from the virtual + * address space of the target task. + */ +routine vm_deallocate( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t); + +/* + * Set the current or maximum protection attribute + * for the specified range of the virtual address + * space of the target task. The current protection + * limits the memory access rights of threads within + * the task; the maximum protection limits the accesses + * that may be given in the current protection. + * Protections are specified as a set of {read, write, execute} + * *permissions*. + */ +routine vm_protect( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + set_maximum : boolean_t; + new_protection : vm_prot_t); + +/* + * Set the inheritance attribute for the specified range + * of the virtual address space of the target task. + * The inheritance value is one of {none, copy, share}, and + * specifies how the child address space should acquire + * this memory at the time of a task_create call. + */ +routine vm_inherit( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + new_inheritance : vm_inherit_t); + +/* + * Returns the contents of the specified range of the + * virtual address space of the target task. [The + * range must be aligned on a virtual page boundary, + * and must be a multiple of pages in extent. The + * protection on the specified range must permit reading.] + */ +routine vm_read( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + out data : pointer_t, dealloc); + +/* + * Writes the contents of the specified range of the + * virtual address space of the target task. [The + * range must be aligned on a virtual page boundary, + * and must be a multiple of pages in extent. The + * protection on the specified range must permit writing.] + */ +routine vm_write( + target_task : vm_task_t; + address : vm_address_t; + data : pointer_t); + +/* + * Copy the contents of the source range of the virtual + * address space of the target task to the destination + * range in that same address space. [Both of the + * ranges must be aligned on a virtual page boundary, + * and must be multiples of pages in extent. The + * protection on the source range must permit reading, + * and the protection on the destination range must + * permit writing.] + */ +routine vm_copy( + target_task : vm_task_t; + source_address : vm_address_t; + size : vm_size_t; + dest_address : vm_address_t); + +/* + * Returns information about the contents of the virtual + * address space of the target task at the specified + * address. The returned protection, inheritance, sharing + * and memory object values apply to the entire range described + * by the address range returned; the memory object offset + * corresponds to the beginning of the address range. + * [If the specified address is not allocated, the next + * highest address range is described. If no addresses beyond + * the one specified are allocated, the call returns KERN_NO_SPACE.] + */ +routine vm_region( + target_task : vm_task_t; + inout address : vm_address_t; + out size : vm_size_t; + out protection : vm_prot_t; + out max_protection : vm_prot_t; + out inheritance : vm_inherit_t; + out is_shared : boolean_t; + /* avoid out-translation of the argument */ + out object_name : memory_object_name_t = + MACH_MSG_TYPE_COPY_SEND + ctype: mach_port_t; + out offset : vm_offset_t); + +/* + * Return virtual memory statistics for the host + * on which the target task resides. [Note that the + * statistics are not specific to the target task.] + */ +routine vm_statistics( + target_task : vm_task_t; + out vm_stats : vm_statistics_data_t); + +skip; /* old task_by_u*x_pid */ +skip; /* old vm_pageable */ + +/* + * Stash a handful of ports for the target task; child + * tasks inherit this stash at task_create time. + */ +routine mach_ports_register( + target_task : task_t; + init_port_set : mach_port_array_t = + ^array[] of mach_port_t); + +/* + * Retrieve the stashed ports for the target task. + */ +routine mach_ports_lookup( + target_task : task_t; + out init_port_set : mach_port_array_t = + ^array[] of mach_port_t); + +skip; /* old u*x_pid */ +skip; /* old netipc_listen */ +skip; /* old netipc_ignore */ + +/* + * Provide the data contents of a range of the given memory + * object, with the access restriction specified. [Only + * whole virtual pages of data can be accepted; partial pages + * will be discarded. Data should be provided on request, but + * may be provided in advance as desired. When data already + * held by this kernel is provided again, the new data is ignored. + * The access restriction is the subset of {read, write, execute} + * which are prohibited. The kernel may not provide any data (or + * protection) consistency among pages with different virtual page + * alignments within the same object.] + */ +simpleroutine memory_object_data_provided( + memory_control : memory_object_control_t; + offset : vm_offset_t; + data : pointer_t; + lock_value : vm_prot_t); + +/* + * Indicate that a range of the given temporary memory object does + * not exist, and that the backing memory object should be used + * instead (or zero-fill memory be used, if no backing object exists). + * [This call is intended for use only by the default memory manager. + * It should not be used to indicate a real error -- + * memory_object_data_error should be used for that purpose.] + */ +simpleroutine memory_object_data_unavailable( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t); + +/* + * Retrieves the attributes currently associated with + * a memory object. + */ +routine memory_object_get_attributes( + memory_control : memory_object_control_t; + out object_ready : boolean_t; + out may_cache : boolean_t; + out copy_strategy : memory_object_copy_strategy_t); + +/* + * Sets the default memory manager, the port to which + * newly-created temporary memory objects are delivered. + * [See (memory_object_default)memory_object_create.] + * The old memory manager port is returned. + */ +routine vm_set_default_memory_manager( + host_priv : host_priv_t; + inout default_manager : mach_port_copy_send_t); + +skip; /* old pager_flush_request */ + +/* + * Control use of the data associated with the given + * memory object. For each page in the given range, + * perform the following operations, in order: + * 1) restrict access to the page (disallow + * forms specified by "prot"); + * 2) write back modifications (if "should_return" + * is RETURN_DIRTY and the page is dirty, or + * "should_return" is RETURN_ALL and the page + * is either dirty or precious); and, + * 3) flush the cached copy (if "should_flush" + * is asserted). + * The set of pages is defined by a starting offset + * ("offset") and size ("size"). Only pages with the + * same page alignment as the starting offset are + * considered. + * + * A single acknowledgement is sent (to the "reply_to" + * port) when these actions are complete. + * + * There are two versions of this routine because IPC distinguishes + * between booleans and integers (a 2-valued integer is NOT a + * boolean). The new routine is backwards compatible at the C + * language interface. + */ +simpleroutine xxx_memory_object_lock_request( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + should_clean : boolean_t; + should_flush : boolean_t; + lock_value : vm_prot_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + + +simpleroutine memory_object_lock_request( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + should_return : memory_object_return_t; + should_flush : boolean_t; + lock_value : vm_prot_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +/* obsolete */ +routine xxx_task_get_emulation_vector( + task : task_t; + out vector_start : int; + out emulation_vector: xxx_emulation_vector_t, IsLong); + +/* obsolete */ +routine xxx_task_set_emulation_vector( + task : task_t; + vector_start : int; + emulation_vector: xxx_emulation_vector_t, IsLong); + +/* + * Returns information about the host on which the + * target object resides. [This object may be + * a task, thread, or memory_object_control port.] + */ +routine xxx_host_info( + target_task : mach_port_t; + out info : machine_info_data_t); + +/* + * Returns information about a particular processor on + * the host on which the target task resides. + */ +routine xxx_slot_info( + target_task : task_t; + slot : int; + out info : machine_slot_data_t); + +/* + * Performs control operations (currently only + * turning off or on) on a particular processor on + * the host on which the target task resides. + */ +routine xxx_cpu_control( + target_task : task_t; + cpu : int; + running : boolean_t); + +skip; /* old thread_statistics */ +skip; /* old task_statistics */ +skip; /* old netport_init */ +skip; /* old netport_enter */ +skip; /* old netport_remove */ +skip; /* old thread_set_priority */ + +/* + * Increment the suspend count for the target task. + * No threads within a task may run when the suspend + * count for that task is non-zero. + */ +routine task_suspend( + target_task : task_t); + +/* + * Decrement the suspend count for the target task, + * if the count is currently non-zero. If the resulting + * suspend count is zero, then threads within the task + * that also have non-zero suspend counts may execute. + */ +routine task_resume( + target_task : task_t); + +/* + * Returns the current value of the selected special port + * associated with the target task. + */ +routine task_get_special_port( + task : task_t; + which_port : int; + out special_port : mach_port_send_t); + +/* + * Set one of the special ports associated with the + * target task. + */ +routine task_set_special_port( + task : task_t; + which_port : int; + special_port : mach_port_t); + +/* obsolete */ +routine xxx_task_info( + target_task : task_t; + flavor : int; + out task_info_out : task_info_t, IsLong); + + +/* + * Create a new thread within the target task, returning + * the port representing that new thread. The + * initial execution state of the thread is undefined. + */ +routine thread_create( + parent_task : task_t; + out child_thread : mach_port_send_t); + +/* + * Increment the suspend count for the target thread. + * Once this call has completed, the thread will not + * execute any further user or meta- instructions. + * Once suspended, a thread may not execute again until + * its suspend count is zero, and the suspend count + * for its task is also zero. + */ +routine thread_suspend( + target_thread : thread_t); + +/* + * Decrement the suspend count for the target thread, + * if that count is not already zero. + */ +routine thread_resume( + target_thread : thread_t); + +/* + * Cause any user or meta- instructions currently being + * executed by the target thread to be aborted. [Meta- + * instructions consist of the basic traps for IPC + * (e.g., msg_send, msg_receive) and self-identification + * (e.g., task_self, thread_self, thread_reply). Calls + * described by MiG interfaces are not meta-instructions + * themselves.] + */ +routine thread_abort( + target_thread : thread_t); + +/* obsolete */ +routine xxx_thread_get_state( + target_thread : thread_t; + flavor : int; + out old_state : thread_state_t, IsLong); + +/* obsolete */ +routine xxx_thread_set_state( + target_thread : thread_t; + flavor : int; + new_state : thread_state_t, IsLong); + +/* + * Returns the current value of the selected special port + * associated with the target thread. + */ +routine thread_get_special_port( + thread : thread_t; + which_port : int; + out special_port : mach_port_t); + +/* + * Set one of the special ports associated with the + * target thread. + */ +routine thread_set_special_port( + thread : thread_t; + which_port : int; + special_port : mach_port_t); + +/* obsolete */ +routine xxx_thread_info( + target_thread : thread_t; + flavor : int; + out thread_info_out : thread_info_t, IsLong); + +/* + * Establish a user-level handler for the specified + * system call. + */ +routine task_set_emulation( + target_port : task_t; + routine_entry_pt: vm_address_t; + routine_number : int); + +/* + * Establish restart pc for interrupted atomic sequences. + * This reuses the message number for the old task_get_io_port. + * See task_info.h for description of flavors. + * + */ +routine task_ras_control( + target_task : task_t; + basepc : vm_address_t; + boundspc : vm_address_t; + flavor : int); + + + +skip; /* old host_ipc_statistics */ +skip; /* old port_names */ +skip; /* old port_type */ +skip; /* old port_rename */ +skip; /* old port_allocate */ +skip; /* old port_deallocate */ +skip; /* old port_set_backlog */ +skip; /* old port_status */ +skip; /* old port_set_allocate */ +skip; /* old port_set_deallocate */ +skip; /* old port_set_add */ +skip; /* old port_set_remove */ +skip; /* old port_set_status */ +skip; /* old port_insert_send */ +skip; /* old port_extract_send */ +skip; /* old port_insert_receive */ +skip; /* old port_extract_receive */ + +/* + * Map a user-defined memory object into the virtual address + * space of the target task. If desired (anywhere is TRUE), + * the kernel will find a suitable address range of the + * specified size; else, the specific address will be allocated. + * + * The beginning address of the range will be aligned on a virtual + * page boundary, be at or beyond the address specified, and + * meet the mask requirements (bits turned on in the mask must not + * be turned on in the result); the size of the range, in bytes, + * will be rounded up to an integral number of virtual pages. + * + * The memory in the resulting range will be associated with the + * specified memory object, with the beginning of the memory range + * referring to the specified offset into the memory object. + * + * The mapping will take the current and maximum protections and + * the inheritance attributes specified; see the vm_protect and + * vm_inherit calls for a description of these attributes. + * + * If desired (copy is TRUE), the memory range will be filled + * with a copy of the data from the memory object; this copy will + * be private to this mapping in this target task. Otherwise, + * the memory in this mapping will be shared with other mappings + * of the same memory object at the same offset (in this task or + * in other tasks). [The Mach kernel only enforces shared memory + * consistency among mappings on one host with similar page alignments. + * The user-defined memory manager for this object is responsible + * for further consistency.] + */ +#ifdef EMULATOR +routine htg_vm_map( + target_task : vm_task_t; + ureplyport reply_port : mach_port_make_send_once_t; + inout address : vm_address_t; + size : vm_size_t; + mask : vm_address_t; + anywhere : boolean_t; + memory_object : memory_object_t; + offset : vm_offset_t; + copy : boolean_t; + cur_protection : vm_prot_t; + max_protection : vm_prot_t; + inheritance : vm_inherit_t); +#else /* EMULATOR */ +routine vm_map( + target_task : vm_task_t; + inout address : vm_address_t; + size : vm_size_t; + mask : vm_address_t; + anywhere : boolean_t; + memory_object : memory_object_t; + offset : vm_offset_t; + copy : boolean_t; + cur_protection : vm_prot_t; + max_protection : vm_prot_t; + inheritance : vm_inherit_t); +#endif /* EMULATOR */ + +/* + * Indicate that a range of the specified memory object cannot + * be provided at this time. [Threads waiting for memory pages + * specified by this call will experience a memory exception. + * Only threads waiting at the time of the call are affected.] + */ +simpleroutine memory_object_data_error( + memory_control : memory_object_control_t; + offset : vm_offset_t; + size : vm_size_t; + error_value : kern_return_t); + +/* + * Make decisions regarding the use of the specified + * memory object. + */ +simpleroutine memory_object_set_attributes( + memory_control : memory_object_control_t; + object_ready : boolean_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t); + +/* + */ +simpleroutine memory_object_destroy( + memory_control : memory_object_control_t; + reason : kern_return_t); + +/* + * Provide the data contents of a range of the given memory + * object, with the access restriction specified, optional + * precious attribute, and reply message. [Only + * whole virtual pages of data can be accepted; partial pages + * will be discarded. Data should be provided on request, but + * may be provided in advance as desired. When data already + * held by this kernel is provided again, the new data is ignored. + * The access restriction is the subset of {read, write, execute} + * which are prohibited. The kernel may not provide any data (or + * protection) consistency among pages with different virtual page + * alignments within the same object. The precious value controls + * how the kernel treats the data. If it is FALSE, the kernel treats + * its copy as a temporary and may throw it away if it hasn't been + * changed. If the precious value is TRUE, the kernel treats its + * copy as a data repository and promises to return it to the manager; + * the manager may tell the kernel to throw it away instead by flushing + * and not cleaning the data -- see memory_object_lock_request. The + * reply_to port is for a compeletion message; it will be + * memory_object_supply_completed.] + */ + +simpleroutine memory_object_data_supply( + memory_control : memory_object_control_t; + offset : vm_offset_t; + data : pointer_t, Dealloc[]; + lock_value : vm_prot_t; + precious : boolean_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +simpleroutine memory_object_ready( + memory_control : memory_object_control_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t); + +simpleroutine memory_object_change_attributes( + memory_control : memory_object_control_t; + may_cache : boolean_t; + copy_strategy : memory_object_copy_strategy_t; + reply_to : mach_port_t = + MACH_MSG_TYPE_MAKE_SEND_ONCE|polymorphic); + +skip; /* old host_callout_statistics_reset */ +skip; /* old port_set_select */ +skip; /* old port_set_backup */ + +/* + * Set/Get special properties of memory associated + * to some virtual address range, such as cachability, + * migrability, replicability. Machine-dependent. + */ +routine vm_machine_attribute( + target_task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + attribute : vm_machine_attribute_t; + inout value : vm_machine_attribute_val_t); + +skip; /* old host_fpa_counters_reset */ + +/* + * There is no more room in this interface for additional calls. + */ diff --git a/boot-proxy-exc/ourmach_host.defs b/boot-proxy-exc/ourmach_host.defs new file mode 100644 index 00000000..c8576ddb --- /dev/null +++ b/boot-proxy-exc/ourmach_host.defs @@ -0,0 +1,381 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * File: mach/mach_host.defs + * + * Abstract: + * Mach host operations support. Includes processor allocation and + * control. + */ + +#ifdef MACH_KERNEL +simport <kern/compat_xxx_defs.h>; /* for obsolete routines */ +#endif + +subsystem +#if KERNEL_SERVER + KernelServer +#endif + mach_host 2600; + +serverprefix S_; + +/* + * Basic types + */ + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +/* + * Get list of processors on this host. + */ + +routine host_processors( + host_priv : host_priv_t; + out processor_list : processor_array_t); + +/* obsolete */ +routine yyy_host_info( + host : host_t; + flavor : int; + out host_info_out : host_info_t, IsLong); + + +/* obsolete */ +routine yyy_processor_info( + processor : processor_t; + flavor : int; + out host : host_t; + out processor_info_out: processor_info_t, IsLong); + +/* + * Start processor. + */ + +routine processor_start( + processor : processor_t); + +/* + * Exit processor -- may not be restartable. + */ + +routine processor_exit( + processor : processor_t); + +/* obsolete */ +routine yyy_processor_control( + processor : processor_t; + processor_cmd : processor_info_t, IsLong); + +/* + * Get default processor set for host. + */ +routine processor_set_default( + host : host_t; + out default_set : processor_set_name_t); + +/* + * Get rights to default processor set for host. + * Replaced by host_processor_set_priv. + */ +routine xxx_processor_set_default_priv( + host : host_priv_t; + out default_set : processor_set_t); + +/* + * Create new processor set. Returns real port for manipulations, + * and name port for obtaining information. + */ +routine processor_set_create( + host : host_t; + out new_set : processor_set_t; + out new_name : processor_set_name_t); + +/* + * Destroy processor set. + */ +routine processor_set_destroy( + set : processor_set_t); + +/* obsolete */ +routine yyy_processor_set_info( + set_name : processor_set_name_t; + flavor : int; + out host : host_t; + out info_out : processor_set_info_t, IsLong); + +/* + * Assign processor to processor set. + */ +routine processor_assign( + processor : processor_t; + new_set : processor_set_t; + wait : boolean_t); + +/* + * Get current assignment for processor. + */ + +routine processor_get_assignment( + processor : processor_t; + out assigned_set : processor_set_name_t); + +/* + * Assign thread to processor set. + */ +routine thread_assign( + thread : thread_t; + new_set : processor_set_t); + +/* + * Assign thread to default set. + */ +routine thread_assign_default( + thread : thread_t); + +/* + * Get current assignment for thread. + */ +routine thread_get_assignment( + thread : thread_t; + out assigned_set : processor_set_name_t); + +/* + * Assign task to processor set. + */ +routine task_assign( + task : task_t; + new_set : processor_set_t; + assign_threads : boolean_t); +/* + * Assign task to default set. + */ +routine task_assign_default( + task : task_t; + assign_threads : boolean_t); + +/* + * Get current assignment for task. + */ +routine task_get_assignment( + task : task_t; + out assigned_set : processor_set_name_t); + +/* + * Get string describing current kernel version. + */ +routine host_kernel_version( + host : host_t; + out kernel_version : kernel_version_t); + +/* + * Set priority for thread. + */ +routine thread_priority( + thread : thread_t; + priority : int; + set_max : boolean_t); + +/* + * Set max priority for thread. + */ +routine thread_max_priority( + thread : thread_t; + processor_set : processor_set_t; + max_priority : int); + +/* + * Set task priority. + */ +routine task_priority( + task : task_t; + priority : int; + change_threads : boolean_t); + +/* + * Set max priority for processor_set. + */ +routine processor_set_max_priority( + processor_set : processor_set_t; + max_priority : int; + change_threads : boolean_t); + +/* + * Set policy for thread + */ +routine thread_policy( + thread : thread_t; + policy : int; + data : int); + +/* + * Enable policy for processor set + */ +routine processor_set_policy_enable( + processor_set : processor_set_t; + policy : int); + +/* + * Disable policy for processor set + */ +routine processor_set_policy_disable( + processor_set : processor_set_t; + policy : int; + change_threads : boolean_t); +/* + * List all tasks in processor set. + */ +routine processor_set_tasks( + processor_set : processor_set_t; + out task_list : task_array_t, dealloc); + +/* + * List all threads in processor set. + */ +routine processor_set_threads( + processor_set : processor_set_t; + out thread_list : thread_array_t); + +/* + * List all processor sets on host. + */ +routine host_processor_sets( + host : host_t; + out processor_sets : processor_set_name_array_t); + +/* + * Get control port for a processor set. + */ +routine host_processor_set_priv( + host_priv : host_priv_t; + set_name : processor_set_name_t; + out set : mach_port_send_t); + +routine thread_depress_abort( + thread : thread_t); + +/* + * Set the time on this host. + * Only available to privileged users. + */ +routine host_set_time( + host_priv : host_priv_t; + new_time : time_value_t); + +/* + * Arrange for the time on this host to be gradually changed + * by an adjustment value, and return the old value. + * Only available to privileged users. + */ +routine host_adjust_time( + host_priv : host_priv_t; + in new_adjustment : time_value_t; + out old_adjustment : time_value_t); + +/* + * Get the time on this host. + * Available to all. + */ +routine host_get_time( + host : host_t; + out current_time : time_value_t); + +/* + * Reboot this host. + * Only available to privileged users. + */ +routine host_reboot( + host_priv : host_priv_t; + options : int); + +/* + * Specify that the range of the virtual address space + * of the target task must not cause page faults for + * the indicated accesses. + * + * [ To unwire the pages, specify VM_PROT_NONE. ] + */ +routine vm_wire( + host_priv : host_priv_t; + task : vm_task_t; + address : vm_address_t; + size : vm_size_t; + access : vm_prot_t); + +/* + * Specify that the target thread must always be able + * to run and to allocate memory. + */ +routine thread_wire( + host_priv : host_priv_t; + thread : thread_t; + wired : boolean_t); + +/* + * Return information about this host. + */ + +routine host_info( + host : host_t; + flavor : int; + out host_info_out : host_info_t, CountInOut); + + +/* + * Return information about this processor. + */ +routine processor_info( + processor : processor_t; + flavor : int; + out host : host_t; + out processor_info_out: processor_info_t, CountInOut); + +/* + * Get information about processor set. + */ +routine processor_set_info( + set_name : processor_set_name_t; + flavor : int; + out host : host_t; + out info_out : processor_set_info_t, CountInOut); + +/* + * Do something machine-dependent to processor. + */ +routine processor_control( + processor : processor_t; + processor_cmd : processor_info_t); + +/* + * Get boot configuration information from kernel. + */ +routine host_get_boot_info( + host_priv : host_priv_t; + out boot_info : kernel_boot_info_t); diff --git a/boot-proxy-exc/ourmach_port.defs b/boot-proxy-exc/ourmach_port.defs new file mode 100644 index 00000000..4f131bb2 --- /dev/null +++ b/boot-proxy-exc/ourmach_port.defs @@ -0,0 +1,349 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University. + * Copyright (c) 1993,1994 The University of Utah and + * the Computer Systems Laboratory (CSL). + * 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, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF + * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM 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. + */ +/* + * File: mach/mach_port.defs + * Author: Rich Draves + * + * Copyright (c) 1989 Richard P. Draves, Jr. + * + * Exported kernel calls. + */ + +subsystem +#if KERNEL_SERVER + KernelServer +#endif + mach_port 3200; + +#include <mach/std_types.defs> +#include <mach/mach_types.defs> + +/* + * Returns the set of port and port set names + * to which the target task has access, along with + * the type (set or port) for each name. + */ + +routine mach_port_names( + task : ipc_space_t; + out names : mach_port_name_array_t = + ^array[] of mach_port_name_t + ctype: mach_port_array_t, + dealloc; + out types : mach_port_type_array_t = + ^array[] of mach_port_type_t, + dealloc); + +/* + * Returns the type (set or port) for the port name + * within the target task. Also indicates whether + * there is a dead-name request for the name. + */ + +routine mach_port_type( + task : ipc_space_t; + name : mach_port_name_t; + out ptype : mach_port_type_t); + +/* + * Changes the name by which a port (or port set) is known to + * the target task. The new name can't be in use. The + * old name becomes available for recycling. + */ + +routine mach_port_rename( + task : ipc_space_t; + old_name : mach_port_name_t; + new_name : mach_port_name_t); + +/* + * Allocates the specified kind of object, with the given name. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * New port sets are empty. New ports don't have any + * send/send-once rights or queued messages. The make-send + * count is zero and their queue limit is MACH_PORT_QLIMIT_DEFAULT. + * New sets, ports, and dead names have one user reference. + */ + +routine mach_port_allocate_name( + task : ipc_space_t; + right : mach_port_right_t; + name : mach_port_name_t); + +/* + * Allocates the specified kind of object. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * Like port_allocate_name, but the kernel picks a name. + * It can use any name not associated with a right. + */ + +routine mach_port_allocate( + task : ipc_space_t; + right : mach_port_right_t; + out name : mach_port_name_t); + +/* + * Destroys all rights associated with the name and makes it + * available for recycling immediately. The name can be a + * port (possibly with multiple user refs), a port set, or + * a dead name (again, with multiple user refs). + */ + +routine mach_port_destroy( + task : ipc_space_t; + name : mach_port_name_t); + +/* + * Releases one send/send-once/dead-name user ref. + * Just like mach_port_mod_refs -1, but deduces the + * correct type of right. This allows a user task + * to release a ref for a port without worrying + * about whether the port has died or not. + */ + +routine mach_port_deallocate( + task : ipc_space_t; + name : mach_port_name_t); + +/* + * A port set always has one user ref. + * A send-once right always has one user ref. + * A dead name always has one or more user refs. + * A send right always has one or more user refs. + * A receive right always has one user ref. + * The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * MACH_PORT_RIGHT_SEND + * MACH_PORT_RIGHT_SEND_ONCE + */ + +routine mach_port_get_refs( + task : ipc_space_t; + name : mach_port_name_t; + right : mach_port_right_t; + out refs : mach_port_urefs_t); + +/* + * The delta is a signed change to the task's + * user ref count for the right. Only dead names + * and send rights can have a positive delta. + * The resulting user ref count can't be negative. + * If it is zero, the right is deallocated. + * If the name isn't a composite right, it becomes + * available for recycling. The right must be one of + * MACH_PORT_RIGHT_RECEIVE + * MACH_PORT_RIGHT_PORT_SET + * MACH_PORT_RIGHT_DEAD_NAME + * MACH_PORT_RIGHT_SEND + * MACH_PORT_RIGHT_SEND_ONCE + */ + +routine mach_port_mod_refs( + task : ipc_space_t; + name : mach_port_name_t; + right : mach_port_right_t; + delta : mach_port_delta_t); + +/* + * Temporary compatibility call. + */ + +routine old_mach_port_get_receive_status( + task : ipc_space_t; + name : mach_port_name_t; + out status : old_mach_port_status_t); + +/* + * Only valid for receive rights. + * Sets the queue-limit for the port. + * The limit must be + * 1 <= qlimit <= MACH_PORT_QLIMIT_MAX + */ + +routine mach_port_set_qlimit( + task : ipc_space_t; + name : mach_port_name_t; + qlimit : mach_port_msgcount_t); + +/* + * Only valid for receive rights. + * Sets the make-send count for the port. + */ + +routine mach_port_set_mscount( + task : ipc_space_t; + name : mach_port_name_t; + mscount : mach_port_mscount_t); + +/* + * Only valid for port sets. Returns a list of + * the members. + */ + +routine mach_port_get_set_status( + task : ipc_space_t; + name : mach_port_name_t; + out members : mach_port_name_array_t = + ^array[] of mach_port_name_t + ctype: mach_port_array_t, + dealloc); + +/* + * Puts the member port (the task must have receive rights) + * into the after port set. (Or removes it from any port set + * if after is MACH_PORT_NULL.) If the port is already in + * a set, does an atomic move. + */ + +routine mach_port_move_member( + task : ipc_space_t; + member : mach_port_name_t; + after : mach_port_name_t); + +/* + * Requests a notification from the kernel. The request + * must supply the send-once right which is used for + * the notification. If a send-once right was previously + * registered, it is returned. The msg_id must be one of + * MACH_NOTIFY_PORT_DESTROYED (receive rights) + * MACH_NOTIFY_DEAD_NAME (send/receive/send-once rights) + * MACH_NOTIFY_NO_SENDERS (receive rights) + * + * The sync value specifies whether a notification should + * get sent immediately, if appropriate. The exact meaning + * depends on the notification: + * MACH_NOTIFY_PORT_DESTROYED: must be zero. + * MACH_NOTIFY_DEAD_NAME: if non-zero, then name can be dead, + * and the notification gets sent immediately. + * If zero, then name can't be dead. + * MACH_NOTIFY_NO_SENDERS: the notification gets sent + * immediately if the current mscount is greater + * than or equal to the sync value and there are no + * extant send rights. + */ + +routine mach_port_request_notification( + task : ipc_space_t; + name : mach_port_name_t; + id : mach_msg_id_t; + sync : mach_port_mscount_t; + notify : mach_port_send_once_t; + out previous : mach_port_send_once_t); + +/* + * Inserts the specified rights into the target task, + * using the specified name. If inserting send/receive + * rights and the task already has send/receive rights + * for the port, then the names must agree. In any case, + * the task gains a user ref for the port. + */ + +routine mach_port_insert_right( + task : ipc_space_t; + name : mach_port_name_t; + poly : mach_port_poly_t); + +/* + * Returns the specified right for the named port + * in the target task, extracting that right from + * the target task. The target task loses a user + * ref and the name may be available for recycling. + * msgt_name must be one of + * MACH_MSG_TYPE_MOVE_RECEIVE + * MACH_MSG_TYPE_COPY_SEND + * MACH_MSG_TYPE_MAKE_SEND + * MACH_MSG_TYPE_MOVE_SEND + * MACH_MSG_TYPE_MAKE_SEND_ONCE + * MACH_MSG_TYPE_MOVE_SEND_ONCE + */ + +routine mach_port_extract_right( + task : ipc_space_t; + name : mach_port_name_t; + msgt_name : mach_msg_type_name_t; + out poly : mach_port_poly_t); + +/* + * The task must have receive rights for the named port. + * Returns a status structure (see mach/port.h). + */ + +routine mach_port_get_receive_status( + task : ipc_space_t; + name : mach_port_name_t; + out status : mach_port_status_t); + +/* + * Only valid for receive rights. + * Sets the sequence number for the port. + */ + +routine mach_port_set_seqno( + task : ipc_space_t; + name : mach_port_name_t; + seqno : mach_port_seqno_t); + +#ifdef MIGRATING_THREADS +/* + * Only valid for receive rights. + * Set the user-mode entry info for RPCs coming through this port. + * Do this BEFORE attaching an ActPool to this port, + * unless you can be sure no RPCs will be coming through it yet. + */ + +routine mach_port_set_rpcinfo( + task : ipc_space_t; + name : mach_port_name_t; + rpc_info : thread_info_t); /* XXX */ + +/* + * Only valid for receive rights. + * Create a new activation for migrating RPC, and attach it to the port's ActPool. + * Create an ActPool for the port if it doesn't already have one. + * Supply a stack and receive memory buffer. + */ + +routine mach_port_create_act( + task : task_t; + name : mach_port_name_t; + user_stack : vm_offset_t; + user_rbuf : vm_offset_t; + user_rbuf_size : vm_size_t; + out new_act : thread_t); + +#endif /* MIGRATING_THREADS */ + diff --git a/boot-proxy-exc/sigvec.S b/boot-proxy-exc/sigvec.S new file mode 100644 index 00000000..cc7bb94e --- /dev/null +++ b/boot-proxy-exc/sigvec.S @@ -0,0 +1,23 @@ +#include <i386/asm.h> + +.text +ENTRY(sigreturn) + movl $0x67,%eax + lcall $0x7,$0x0 + jb error + ret +ENTRY(_sigreturn) + addl $0xc,%esp + call EXT(sigreturn) + ret +ENTRY(sigvec) + movl $0x6c,%eax + movl $EXT(_sigreturn),%edx + orl $0x80000000,%edx + lcall $0x7,$0x0 + jb error + ret +error: + movl %eax,EXT(errno) + movl $-1,%eax + ret diff --git a/boot-proxy-exc/syscall.S b/boot-proxy-exc/syscall.S new file mode 100644 index 00000000..a04ab28d --- /dev/null +++ b/boot-proxy-exc/syscall.S @@ -0,0 +1,35 @@ +/* Temporary.... + Copyright (C) 1993, 1995 Free Software Foundation + +This file is part of the GNU Hurd. + +The GNU Hurd is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +The GNU Hurd is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the GNU Hurd; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <i386/asm.h> + +/* .globl EXT(errno)*/ +.text +ENTRY(syscall) + pop %ecx + pop %eax + push %ecx + lcall $7, $0 + push %ecx /* Restore stack position. */ + jb error + ret +error: + movl %eax,EXT(errno) + movl $-1,%eax + ret diff --git a/boot-proxy-exc/userland-boot.c b/boot-proxy-exc/userland-boot.c new file mode 100644 index 00000000..20c818ff --- /dev/null +++ b/boot-proxy-exc/userland-boot.c @@ -0,0 +1,122 @@ +/* boot_script.c support functions for running in a Mach user task. + Copyright (C) 2001 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <mach.h> +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <error.h> +#include "boot_script.h" +#include "mach_proxy.h" +#include "util.h" + +extern boolean_t is_user; + +void * +boot_script_malloc (unsigned int size) +{ + return malloc (size); +} + +void +boot_script_free (void *ptr, unsigned int size) +{ + free (ptr); +} + +int +boot_script_task_create (struct cmd *cmd) +{ + error_t err = task_create (mach_task_self (), 0, &cmd->task); + if (err) + { + error (0, err, "%s: task_create", cmd->path); + return BOOT_SCRIPT_MACH_ERROR; + } + debug ("creating task: %s, task port: %d", cmd->path, cmd->task); + if (is_user) + { + task_t pseudo_task = 0; + create_pseudo_task (cmd->task, &pseudo_task); + /* now it is the pseudo task port. */ + cmd->task = pseudo_task; + } + err = task_suspend (cmd->task); + if (err) + { + error (0, err, "%s: task_suspend", cmd->path); + return BOOT_SCRIPT_MACH_ERROR; + } + return 0; +} + +int +boot_script_task_resume (struct cmd *cmd) +{ + debug ("resume task %s: %d", cmd->path, cmd->task); + error_t err = task_resume (cmd->task); + if (err) + { + error (0, err, "%s: task_resume", cmd->path); + return BOOT_SCRIPT_MACH_ERROR; + } + return 0; +} + +int +boot_script_prompt_task_resume (struct cmd *cmd) +{ + char xx[5]; + + printf ("Hit return to resume %s...", cmd->path); + fgets (xx, sizeof xx, stdin); + + return boot_script_task_resume (cmd); +} + +void +boot_script_free_task (task_t task, int aborting) +{ + if (aborting) + task_terminate (task); + else if (!is_user) + mach_port_deallocate (mach_task_self (), task); + /* For the normal user, the task port will still be used, + * so we cannot deallocate the task port here.*/ +} + +int +boot_script_insert_right (struct cmd *cmd, mach_port_t port, mach_port_t *name) +{ + error_t err = mach_port_insert_right (cmd->task, + port, port, MACH_MSG_TYPE_COPY_SEND); + if (err) + { + error (0, err, "%s: mach_port_insert_right", cmd->path); + return BOOT_SCRIPT_MACH_ERROR; + } + *name = port; + return 0; +} + +int +boot_script_insert_task_port (struct cmd *cmd, task_t task, mach_port_t *name) +{ + return boot_script_insert_right (cmd, task, name); +} diff --git a/boot-proxy-exc/util.h b/boot-proxy-exc/util.h new file mode 100644 index 00000000..e82a8626 --- /dev/null +++ b/boot-proxy-exc/util.h @@ -0,0 +1,113 @@ +/* + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef UTIL_H +#define UTIL_H + +#include <stdio.h> +#include <string.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/ip.h> +#include <syslog.h> + +#include <mach.h> +#include <hurd.h> + +#define DEBUG 0 +#define INFO 1 +#define LOGLEVEL DEBUG + +extern FILE *logfile; + +#define LOG_START() do \ +{ \ + logfile = fopen("boot.log", "a"); \ + assert (logfile != NULL); \ +} while (0) + +#define LOG_END() fclose (logfile) + +#define output(format, ...) do \ +{ \ + char buf[1024]; \ + snprintf (buf, 1024, "boot: %s: %s\r\n", __func__, format); \ + fprintf (stderr , buf, ## __VA_ARGS__); \ + fflush (stderr); \ +} while (0) + +#if DEBUG >= LOGLEVEL +#define debug(format, ...) do \ +{ \ + char buf[1024]; \ + snprintf (buf, 1024, "boot: %s: %s\r\n", __func__, format); \ + fprintf (logfile , buf, ## __VA_ARGS__); \ + fflush (logfile); \ +} while (0) +#else +#define debug(format, ...) do {} while (0) +#endif + +#if INFO >= LOGLEVEL +#define info output +#else +#define info(format, ...) do {} while (0) +#endif + +#if ERROR >= LOGLEVEL +#define logerror(format, ...) do \ +{ \ + char buf[1024]; \ + snprintf (buf, 1024, "boot ERROR: %s: %s\r\n", __func__, format); \ + fprintf (stderr , buf, ## __VA_ARGS__); \ + fflush (stderr); \ +} while (0) +#else +#define logerror(format, ...) do {} while (0) +#endif + +#define print_port_type(port) do \ +{ \ + mach_port_type_t ptype; \ + error_t err = mach_port_type (mach_task_self (), port, &ptype); \ + if (err) \ + debug ("mach_port_type: %s", strerror (err)); \ + else if (ptype & MACH_PORT_TYPE_SEND) \ + debug ("port %d has send right", port); \ + else if (ptype & MACH_PORT_TYPE_RECEIVE) \ + debug ("port %d has receive right", port); \ + else if (ptype & MACH_PORT_TYPE_SEND_ONCE) \ + debug ("port %d has send once right", port); \ + else if (ptype & MACH_PORT_TYPE_PORT_SET) \ + debug ("port %d is port set", port); \ + else if (ptype & MACH_PORT_TYPE_DEAD_NAME) \ + debug ("port %d is a dead name", port); \ + else \ + debug ("the type of port %d is %d", port, ptype); \ + mach_port_urefs_t refs; \ + err = mach_port_get_refs (mach_task_self (), port, \ + MACH_PORT_RIGHT_SEND, &refs); \ + if (!err) \ + debug ("port send right references: %d", refs); \ +} while (0) + +#endif diff --git a/boot-proxy-exc/ux.c b/boot-proxy-exc/ux.c new file mode 100644 index 00000000..b532f19e --- /dev/null +++ b/boot-proxy-exc/ux.c @@ -0,0 +1,303 @@ +/* Hacks to make boot work under UX + + Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <mach.h> +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <cthreads.h> + +#include "ux.h" + +#if 0 +static int (* const _sc)(int, ...) = &syscall; +int _sc_print = 1; + +#define syscall(num, args...) \ + ({ int _rv, _num = (num), _pr = _sc_print; \ + _sc_print = 0; \ + if (_pr) printf ("syscall (%d) start\r\n", _num); \ + _rv = (*_sc) (_num , ##args); \ + if (_pr) printf ("syscall (%d) end\r\n", _num); \ + _sc_print = _pr; \ + _rv; \ + }) +#endif + +extern void __mach_init (); +void (*mach_init_routine)() = __mach_init; + +/* These will prevent the Hurd-ish versions from being used */ + +struct free_reply_port +{ + mach_port_t port; + struct free_reply_port *next; +}; +static struct free_reply_port *free_reply_ports = NULL; +static spin_lock_t free_reply_ports_lock = SPIN_LOCK_INITIALIZER; + +mach_port_t __mig_get_reply_port () +{ + spin_lock (&free_reply_ports_lock); + if (free_reply_ports == NULL) + { + spin_unlock (&free_reply_ports_lock); + return __mach_reply_port (); + } + else + { + struct free_reply_port *frp = free_reply_ports; + mach_port_t reply_port = frp->port; + free_reply_ports = free_reply_ports->next; + spin_unlock (&free_reply_ports_lock); + free (frp); + return reply_port; + } +} +mach_port_t mig_get_reply_port () +{ + return __mig_get_reply_port (); +} +void __mig_put_reply_port (mach_port_t port) +{ + struct free_reply_port *frp = malloc (sizeof (struct free_reply_port)); + frp->port = port; + spin_lock (&free_reply_ports_lock); + frp->next = free_reply_ports; + free_reply_ports = frp; + spin_unlock (&free_reply_ports_lock); +} +void mig_put_reply_port (mach_port_t port) +{ + __mig_put_reply_port (port); +} +void __mig_dealloc_reply_port (mach_port_t port) +{ + mach_port_mod_refs (__mach_task_self (), port, + MACH_PORT_RIGHT_RECEIVE, -1); +} +void mig_dealloc_reply_port (mach_port_t port) +{ + __mig_dealloc_reply_port (port); +} +void __mig_init (void *stack) {} +void mig_init (void *stack) {} + +int +task_by_pid (int pid) +{ + return syscall (-33, pid); +} + +int +write (int fd, + const void *buf, + int buflen) +{ + return syscall (4, fd, buf, buflen); +} + +int +read (int fd, + void *buf, + int buflen) +{ + return syscall (3, fd, buf, buflen); +} + +int +open (const char *name, + int flags, + int mode) +{ + return syscall (5, name, flags, mode); +} + +int +uxfstat (int fd, struct uxstat *buf) +{ + return syscall (62, fd, buf); +} + +int +close (int fd) +{ + return syscall (6, fd); +} + +int +lseek (int fd, + int off, + int whence) +{ + return syscall (19, fd, off, whence); +} + +int +uxexit (int code) +{ + return syscall (1, code); +} + +int +getpid () +{ + return syscall (20); +} + +int +ioctl (int fd, int code, void *buf) +{ + return syscall (54, fd, code, buf); +} + +int +sigblock (int mask) +{ + return syscall (109, mask); +} + +int +sigsetmask (int mask) +{ + return syscall (110, mask); +} + +int +sigpause (int mask) +{ + return syscall (111, mask); +} + + +#if 0 +void +sigreturn () +{ + asm volatile ("movl $0x67,%eax\n" + "lcall $0x7, $0x0\n" + "ret"); +} + +void +_sigreturn () +{ + asm volatile ("addl $0xc, %%esp\n" + "call %0\n" + "ret"::"m" (sigreturn)); +} + +int +sigvec (int sig, struct sigvec *vec, struct sigvec *ovec) +{ + asm volatile ("movl $0x6c,%%eax\n" + "movl %0, %%edx\n" + "orl $0x80000000, %%edx\n" + "lcall $0x7,$0x0\n" + "ret"::"g" (_sigreturn)); +} +#else +int sigvec (); +#endif + +void get_privileged_ports (mach_port_t *host_port, mach_port_t *device_port) +{ + *host_port = task_by_pid (-1); + *device_port = task_by_pid (-2); +} + +/* A *really* stupid printf that only understands %s & %d. */ +int +printf (const char *fmt, ...) +{ + va_list ap; + const char *p = fmt, *q = p; + + void flush (const char *new) + { + if (p > q) + write (1, q, p - q); + q = p = new; + } + + va_start (ap, fmt); + while (*p) + if (*p == '%' && p[1] == 's') + { + char *str = va_arg (ap, char *); + flush (p + 2); + write (1, str, strlen (str)); + } + else if (*p == '%' && p[1] == 'd') + { + int i = va_arg (ap, int); + char rbuf[20], *e = rbuf + sizeof (rbuf), *b = e; + + if (i == 0) + *--b = '0'; + else + while (i) + { + *--b = i % 10 + '0'; + i /= 10; + } + + flush (p + 2); + write (1, b, e - b); + } + else + p++; + va_end (ap); + + flush (0); + + return 0; +} + +static struct sgttyb term_sgb; +static int localbits; + +void +init_termstate () +{ + struct sgttyb sgb; + int bits; + ioctl (0, TIOCGETP, &term_sgb); + ioctl (0, TIOCLGET, &localbits); + /* Enter raw made. Rather than try and interpret these bits, + we just do what emacs does in .../emacs/src/sysdep.c for + an old style terminal driver. */ + bits = localbits | LDECCTQ | LLITOUT | LPASS8 | LNOFLSH; + ioctl (0, TIOCLSET, &bits); + sgb = term_sgb; + sgb.sg_flags &= ~ECHO; + sgb.sg_flags |= RAW | ANYP; + ioctl (0, TIOCSETN, &sgb); +} + +void +restore_termstate () +{ + ioctl (0, TIOCLSET, &localbits); + ioctl (0, TIOCSETN, &term_sgb); +} diff --git a/boot-proxy-exc/ux.h b/boot-proxy-exc/ux.h new file mode 100644 index 00000000..d3787c54 --- /dev/null +++ b/boot-proxy-exc/ux.h @@ -0,0 +1,114 @@ +/* Hacks to make boot work under UX + + Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#define sigmask(m) (1 << ((m)-1)) + +#define IOCPARM_MASK 0x7f +#define IOC_OUT 0x40000000 +#define IOC_IN 0x80000000 +#define _IOR(x,y,t) (IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) +#define _IOW(x,y,t) (IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) +#define FIONREAD _IOR('f', 127, int) +#define FIOASYNC _IOW('f', 125, int) +#define TIOCGETP _IOR('t', 8, struct sgttyb) +#define TIOCLGET _IOR('t', 124, int) +#define TIOCLSET _IOW('t', 125, int) +#define TIOCSETN _IOW('t', 10, struct sgttyb) +#define LDECCTQ 0x4000 +#define LLITOUT 0x0020 +#define LPASS8 0x0800 +#define LNOFLSH 0x8000 +#define RAW 0x0020 +#define ANYP 0x00c0 +#define ECHO 8 + + +struct sgttyb +{ + char unused[4]; + short sg_flags; +}; + +#define SIGIO 23 + +struct sigvec +{ + void (*sv_handler)(); + int sv_mask; + int sv_flags; +}; + +struct uxstat + { + short int st_dev; /* Device containing the file. */ + __ino_t st_ino; /* File serial number. */ + unsigned short int st_mode; /* File mode. */ + __nlink_t st_nlink; /* Link count. */ + unsigned short int st_uid; /* User ID of the file's owner. */ + unsigned short int st_gid; /* Group ID of the file's group.*/ + short int st_rdev; /* Device number, if device. */ + __off_t st_size; /* Size of file, in bytes. */ + __time_t st_atime; /* Time of last access. */ + unsigned long int st_atime_usec; + __time_t st_mtime; /* Time of last modification. */ + unsigned long int st_mtime_usec; + __time_t st_ctime; /* Time of last status change. */ + unsigned long int st_ctime_usec; + unsigned long int st_blksize; /* Optimal block size for I/O. */ + unsigned long int st_blocks; /* Number of 512-byte blocks allocated. */ + long int st_spare[2]; + }; + +void get_privileged_ports (mach_port_t *host_port, mach_port_t *device_port); + +/* We can't include <unistd.h> for this, because that will fight witho + our definitions of syscalls below. */ +int syscall (int, ...); + +int open (const char *name, int flags, int mode); +int write (int fd, const void *buf, int len); +int read (int fd, void *buf, int len); +int uxfstat (int fd, struct uxstat *buf); +int close (int fd); +int lseek (int fd, int off, int whence); +int uxexit (int code); +int getpid (); +int ioctl (int fd, int code, void *buf); +int sigblock (int mask); +int sigsetmask (int mask); +int sigpause (int mask); +int sigvec (int sig, struct sigvec *vec, struct sigvec *ovec); + +#undef O_RDONLY +#undef O_WRONLY +#undef O_RDWR +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 + +#define host_exit(c) uxexit(c) + +typedef struct uxstat host_stat_t; +#define host_fstat(fd, st) uxfstat (fd, st) + +void init_stdio (); + +#undef errno +int errno; |