From 2059697c29c926c3ad42efb61993baf2723f0b0e Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Thu, 3 Apr 1997 23:28:32 +0000 Subject: Initial Revision --- serverboot/load.c | 406 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 serverboot/load.c (limited to 'serverboot/load.c') diff --git a/serverboot/load.c b/serverboot/load.c new file mode 100644 index 00000000..9a3e3b98 --- /dev/null +++ b/serverboot/load.c @@ -0,0 +1,406 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#include +#include +#include +#include +#include "../boot/boot_script.h" + +#include + + +boolean_t load_protect_text = TRUE; + + +struct stuff +{ + struct file *fp; + task_t user_task; + + vm_offset_t aout_symtab_ofs; + vm_size_t aout_symtab_size; + vm_offset_t aout_strtab_ofs; + vm_size_t aout_strtab_size; +}; + +char *set_regs( + mach_port_t user_task, + mach_port_t user_thread, + struct exec_info *info, + int arg_size); + +static void read_symtab_from_file( + struct file *fp, + mach_port_t host_port, + task_t task, + char * symtab_name, + struct stuff *st); + +/* Callback functions for reading the executable file. */ +static int prog_read(void *handle, vm_offset_t file_ofs, void *buf, vm_size_t size, + vm_size_t *out_actual) +{ + struct stuff *st = handle; + vm_size_t resid; + int result; + + result = read_file(st->fp, file_ofs, buf, size, &resid); + if (result) + return result; + *out_actual = size - resid; + return 0; +} + +static int prog_read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size, + vm_offset_t mem_addr, vm_size_t mem_size, + exec_sectype_t sec_type) +{ + struct stuff *st = handle; + vm_offset_t page_start = trunc_page(mem_addr); + vm_offset_t page_end = round_page(mem_addr + mem_size); + vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK; + vm_offset_t area_start; + int result; + + if (sec_type & EXEC_SECTYPE_AOUT_SYMTAB) + { + st->aout_symtab_ofs = file_ofs; + st->aout_symtab_size = file_size; + } + if (sec_type & EXEC_SECTYPE_AOUT_STRTAB) + { + st->aout_strtab_ofs = file_ofs; + st->aout_strtab_size = file_size; + } + + if (!(sec_type & EXEC_SECTYPE_ALLOC)) + return 0; + + assert(mem_size > 0); + assert(mem_size > file_size); + + /* + printf("section %08x-%08x-%08x prot %08x (%08x-%08x)\n", + mem_addr, mem_addr+file_size, mem_addr+mem_size, mem_prot, page_start, page_end); + */ + + result = vm_allocate(mach_task_self(), &area_start, page_end - page_start, TRUE); + if (result) return (result); + + if (file_size > 0) + { + vm_size_t resid; + + result = read_file(st->fp, file_ofs, area_start + (mem_addr - page_start), + file_size, &resid); + if (result) return result; + if (resid) return EX_CORRUPT; + } + + if (mem_size > file_size) + { + bzero((void*)area_start + (mem_addr + file_size - page_start), + mem_size - file_size); + } + + result = vm_allocate(st->user_task, &page_start, page_end - page_start, FALSE); + if (result) return (result); + assert(page_start == trunc_page(mem_addr)); + + result = vm_write(st->user_task, page_start, area_start, page_end - page_start); + if (result) return (result); + + result = vm_deallocate(mach_task_self(), area_start, page_end - page_start); + if (result) return (result); + + /* + * Protect the segment. + */ + if (load_protect_text && (mem_prot != VM_PROT_ALL)) { + result = vm_protect(st->user_task, page_start, page_end - page_start, + FALSE, mem_prot); + if (result) return (result); + } + + return 0; +} + +mach_port_t boot_script_read_file (const char *file) +{ return MACH_PORT_NULL; } /* XXX */ + +int +boot_script_exec_cmd (task_t user_task, + char *file_name, + int arg_count, char **argv, + char *argstrings, int argslen) +{ + extern mach_port_t bootstrap_master_device_port, bootstrap_master_host_port; + extern char *root_name; + int arg_len = argslen; + char *arg_pos; + + kern_return_t result; + thread_t user_thread; + struct file file; + char namebuf[MAXPATHLEN+1]; + + struct stuff st; + struct exec_info info; + + extern char * strbuild(); + + if (strcmp (file_name, "/dev/")) + (void) strbuild(namebuf, "/dev/", root_name, "/", file_name, + (char *)0); + else + strcpy (namebuf, file_name); + + /* + * Open the file + */ + bzero((char *)&file, sizeof(file)); + + result = open_file(bootstrap_master_device_port, namebuf, &file); + if (result != 0) { + panic("openi %d", result); + } + + /* + * Add space for: + * arg_count + * pointers to arguments + * trailing 0 pointer + * dummy 0 pointer to environment variables + * and align to integer boundary + */ + arg_len += sizeof(integer_t) + (2 + arg_count) * sizeof(char *); + arg_len = (arg_len + (sizeof(integer_t) - 1)) & ~(sizeof(integer_t)-1); + + /* + * We refrain from checking IEXEC bits to make + * things a little easier when things went bad. + * Say you have ftp(1) but chmod(1) is gone. + */ + if (!file_is_regular(&file)) + panic("boot_load_program: %s is not a regular file", namebuf); + + /* + * Load the executable file. + */ + st.fp = &file; + st.user_task = user_task; + st.aout_symtab_size = 0; + st.aout_strtab_size = 0; + result = exec_load(prog_read, prog_read_exec, &st, &info); + if (result) + panic("(bootstrap) exec_load %s: error %d", namebuf, result); +#if 0 + printf("(bootstrap): loaded %s; entrypoint %08x\n", namebuf, info.entry); +#endif + + /* + * Set up the stack and user registers. + */ + result = thread_create (user_task, &user_thread); + if (result) + panic ("can't create user thread for %s: %x", namebuf, result); + arg_pos = set_regs(user_task, user_thread, &info, arg_len); + + /* + * Read symbols from the executable file. + */ +#if 0 + printf("(bootstrap): loading symbols from %s\n", namebuf); + read_symtab_from_file(&file, bootstrap_master_host_port, user_task, namebuf, &st); +#endif + + /* + * Copy out the arguments. + */ + { + vm_offset_t u_arg_start; + /* user start of argument list block */ + vm_offset_t k_arg_start; + /* kernel start of argument list block */ + vm_offset_t u_arg_page_start; + /* user start of args, page-aligned */ + vm_size_t arg_page_size; + /* page_aligned size of args */ + vm_offset_t k_arg_page_start; + /* kernel start of args, page-aligned */ + + register + char ** k_ap; /* kernel arglist address */ + char * u_cp; /* user argument string address */ + register + char * k_cp; /* kernel argument string address */ + register + int i; + + /* + * Get address of argument list in user space + */ + u_arg_start = (vm_offset_t)arg_pos; + + /* + * Round to page boundaries, and allocate kernel copy + */ + u_arg_page_start = trunc_page(u_arg_start); + arg_page_size = (vm_size_t)(round_page(u_arg_start + arg_len) + - u_arg_page_start); + + result = vm_allocate(mach_task_self(), + &k_arg_page_start, + (vm_size_t)arg_page_size, + TRUE); + if (result) + panic("boot_load_program: arg size"); + + /* + * Set up addresses corresponding to user pointers + * in the kernel block + */ + k_arg_start = k_arg_page_start + (u_arg_start - u_arg_page_start); + + k_ap = (char **)k_arg_start; + + /* + * Start the strings after the arg-count and pointers + */ + u_cp = (char *)u_arg_start + arg_count * sizeof(char *) + + 2 * sizeof(char *) + + sizeof(integer_t); + k_cp = (char *)k_arg_start + arg_count * sizeof(char *) + + 2 * sizeof(char *) + + sizeof(integer_t); + + /* + * first the argument count + */ + *k_ap++ = (char *)arg_count; + + /* + * Then the strings and string pointers for each argument + */ + for (i = 0; i < arg_count; i++) + *k_ap++ = argv[i] - argstrings + u_cp; + bcopy (argstrings, k_cp, argslen); + + /* + * last, the trailing 0 argument and a null environment pointer. + */ + *k_ap++ = (char *)0; + *k_ap = (char *)0; + + /* + * Now write all of this to user space. + */ + (void) vm_write(user_task, + u_arg_page_start, + k_arg_page_start, + arg_page_size); + + (void) vm_deallocate(mach_task_self(), + k_arg_page_start, + arg_page_size); + } + + /* + * Close the file. + */ + close_file(&file); + + /* Resume the thread. */ + thread_resume (user_thread); + mach_port_deallocate (mach_task_self (), user_thread); + + return (0); +} + +/* + * Load symbols from file into kernel debugger. + */ +static void read_symtab_from_file( + struct file *fp, + mach_port_t host_port, + task_t task, + char * symtab_name, + struct stuff *st) +{ + vm_size_t resid; + kern_return_t result; + vm_size_t table_size; + vm_offset_t symtab; + +#if 0 + + if (!st->aout_symtab_size || !st->aout_strtab_size) + return; + + /* + * Allocate space for the symbol table. + */ + table_size = sizeof(vm_size_t) + + st->aout_symtab_size + + st->aout_strtab_size; + result= vm_allocate(mach_task_self(), + &symtab, + table_size, + TRUE); + if (result) { + printf("[ error %d allocating space for %s symbol table ]\n", + result, symtab_name); + return; + } + + /* + * Set the symbol table length word, + * then read in the symbol table and string table. + */ + *(vm_size_t*)symtab = st->aout_symtab_size; + result = read_file(fp, st->aout_symtab_ofs, + symtab + sizeof(vm_size_t), + st->aout_symtab_size + st->aout_strtab_size, + &resid); + if (result || resid) { + printf("[ no valid symbol table present for %s ]\n", + symtab_name); + } + else { + /* + * Load the symbols into the kernel. + */ + result = host_load_symbol_table( + host_port, + task, + symtab_name, + symtab, + table_size); + } + (void) vm_deallocate(mach_task_self(), symtab, table_size); +#endif +} -- cgit v1.2.3 From 8e98bdc7a128545a0b7a8d4686f822719ac74ecb Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Fri, 4 Apr 1997 01:13:44 +0000 Subject: Thu Apr 3 20:00:58 1997 Thomas Bushnell, n/BSG * elf-load.c (exec_load): Include instead of . Include "mach-exec.h" instead of . (exec_load) [i386]: Check for i386 types directly; abandon old MY_EI_DATA and MY_E_MACHINE. * load.c: Include "mach-exec.h" instead of . * exec.c: Likewise. * mach-exec.h: New file. --- serverboot/ChangeLog | 11 +++++ serverboot/elf-load.c | 12 +++-- serverboot/exec.c | 2 +- serverboot/load.c | 2 +- serverboot/mach-exec.h | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 serverboot/mach-exec.h (limited to 'serverboot/load.c') diff --git a/serverboot/ChangeLog b/serverboot/ChangeLog index 52f60f35..c2caea69 100644 --- a/serverboot/ChangeLog +++ b/serverboot/ChangeLog @@ -1,3 +1,14 @@ +Thu Apr 3 20:00:58 1997 Thomas Bushnell, n/BSG + + * elf-load.c (exec_load): Include instead of + . Include "mach-exec.h" instead of + . + (exec_load) [i386]: Check for i386 types directly; abandon old + MY_EI_DATA and MY_E_MACHINE. + * load.c: Include "mach-exec.h" instead of . + * exec.c: Likewise. + * mach-exec.h: New file. + Wed Mar 19 14:45:27 1997 Thomas Bushnell, n/BSG * panic.c (panic): Clear possible errors on stdout before printing diff --git a/serverboot/elf-load.c b/serverboot/elf-load.c index 1d103d3c..a30124a2 100644 --- a/serverboot/elf-load.c +++ b/serverboot/elf-load.c @@ -24,8 +24,8 @@ #include #include -#include -#include +#include +#include "mach-exec.h" int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, void *handle, exec_info_t *out_info) @@ -50,10 +50,14 @@ int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, return EX_NOT_EXECUTABLE; /* Make sure the file is of the right architecture. */ +#ifdef i386 if ((x.e_ident[EI_CLASS] != ELFCLASS32) || - (x.e_ident[EI_DATA] != MY_EI_DATA) || - (x.e_machine != MY_E_MACHINE)) + (x.e_ident[EI_DATA] != ELFDATA2LSB) || + (x.e_machine != EM_386)) return EX_WRONG_ARCH; +#else +#error Not ported to this architecture! +#endif /* XXX others */ out_info->entry = (vm_offset_t) x.e_entry; diff --git a/serverboot/exec.c b/serverboot/exec.c index 5b5feedc..a0773f4c 100644 --- a/serverboot/exec.c +++ b/serverboot/exec.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include "mach-exec.h" #include diff --git a/serverboot/load.c b/serverboot/load.c index 9a3e3b98..36e8307b 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include "mach-exec.h" #include "../boot/boot_script.h" #include diff --git a/serverboot/mach-exec.h b/serverboot/mach-exec.h new file mode 100644 index 00000000..94b234b0 --- /dev/null +++ b/serverboot/mach-exec.h @@ -0,0 +1,130 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#ifndef _MACH_EXEC_H_ +#define _MACH_EXEC_H_ + +#include +#include + +/* XXX */ +typedef enum +{ + EXEC_ELF = 1, + EXEC_AOUT = 2, +} exec_format_t; + +typedef struct exec_info +{ + /* Format of executable loaded - see above. */ + exec_format_t format; + + /* Program entrypoint. */ + vm_offset_t entry; + + /* Initial data pointer - only some architectures use this. */ + vm_offset_t init_dp; + + /* (ELF) Address of interpreter string for loading shared libraries, null if none. */ + vm_offset_t interp; + +} exec_info_t; + +typedef int exec_sectype_t; +#define EXEC_SECTYPE_READ VM_PROT_READ +#define EXEC_SECTYPE_WRITE VM_PROT_WRITE +#define EXEC_SECTYPE_EXECUTE VM_PROT_EXECUTE +#define EXEC_SECTYPE_PROT_MASK VM_PROT_ALL +#define EXEC_SECTYPE_ALLOC ((exec_sectype_t)0x000100) +#define EXEC_SECTYPE_LOAD ((exec_sectype_t)0x000200) +#define EXEC_SECTYPE_DEBUG ((exec_sectype_t)0x010000) +#define EXEC_SECTYPE_AOUT_SYMTAB ((exec_sectype_t)0x020000) +#define EXEC_SECTYPE_AOUT_STRTAB ((exec_sectype_t)0x040000) + +typedef int exec_read_func_t(void *handle, vm_offset_t file_ofs, + void *buf, vm_size_t size, + vm_size_t *out_actual); + +typedef int exec_read_exec_func_t(void *handle, + vm_offset_t file_ofs, vm_size_t file_size, + vm_offset_t mem_addr, vm_size_t mem_size, + exec_sectype_t section_type); + +/* + * Routines exported from libmach_exec.a + */ + +/* Generic function to interpret an executable "file" + and "load" it into "memory". + Doesn't really know about files, loading, or memory; + all file I/O and destination memory accesses + go through provided functions. + Thus, this is a very generic loading mechanism. + + The read() function is used to read metadata from the file + into the local address space. + + The read_exec() function is used to load the actual sections. + It is used for all kinds of sections - code, data, bss, debugging data. + The 'section_type' parameter specifies what type of section is being loaded. + + For code, data, and bss, the EXEC_SECTYPE_ALLOC flag will be set. + For code and data (i.e. stuff that's actually loaded from the file), + EXEC_SECTYPE_LOAD will also be set. + The EXEC_SECTYPE_PROT_MASK contains the intended access permissions + for the section. + 'file_size' may be less than 'mem_size'; + the remaining data must be zero-filled. + 'mem_size' is always greater than zero, but 'file_size' may be zero + (e.g. in the case of a bss section). + No two read_exec() calls for one executable + will load data into the same virtual memory page, + although they may load from arbitrary (possibly overlapping) file positions. + + For sections that aren't normally loaded into the process image + (e.g. debug sections), EXEC_SECTYPE_ALLOC isn't set, + but some other appropriate flag is set to indicate the type of section. + + The 'handle' is an opaque pointer which is simply passed on + to the read() and read_exec() functions. + + On return, the specified info structure is filled in + with information about the loaded executable. +*/ +int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, + void *handle, exec_info_t *out_info); + +/* + * Error codes + */ + +#define EX_NOT_EXECUTABLE 6000 /* not a recognized executable format */ +#define EX_WRONG_ARCH 6001 /* valid executable, but wrong arch. */ +#define EX_CORRUPT 6002 /* recognized executable, but mangled */ +#define EX_BAD_LAYOUT 6003 /* something wrong with the memory or file image layout */ + + +#endif /* _MACH_EXEC_H_ */ -- cgit v1.2.3 From dfaca19f19b2b5f3773a806c65dc3bae1ed865c5 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 15 Jul 1997 22:32:41 +0000 Subject: (boot_script_exec_cmd): Change "(bootstrap)" to "(serverboot)" in msgs. --- serverboot/load.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/load.c b/serverboot/load.c index 36e8307b..a4bb43c3 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -217,9 +217,9 @@ boot_script_exec_cmd (task_t user_task, st.aout_strtab_size = 0; result = exec_load(prog_read, prog_read_exec, &st, &info); if (result) - panic("(bootstrap) exec_load %s: error %d", namebuf, result); + panic("(serverboot) exec_load %s: error %d", namebuf, result); #if 0 - printf("(bootstrap): loaded %s; entrypoint %08x\n", namebuf, info.entry); + printf("(serverboot): loaded %s; entrypoint %08x\n", namebuf, info.entry); #endif /* @@ -234,7 +234,7 @@ boot_script_exec_cmd (task_t user_task, * Read symbols from the executable file. */ #if 0 - printf("(bootstrap): loading symbols from %s\n", namebuf); + printf("(serverboot): loading symbols from %s\n", namebuf); read_symtab_from_file(&file, bootstrap_master_host_port, user_task, namebuf, &st); #endif -- cgit v1.2.3 From d3fe02c2d320bfde339c87981c32f1d9b3581952 Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Fri, 30 Apr 1999 11:04:07 +0000 Subject: 1998-09-06 OKUJI Yoshinori * bunzip2.c: New file. * load.c (GZIP) (BZIP2): New cpp constants. (boot_script_exec_cmd): If GZIP is defined, gunzip engine is enabled. If BZIP2 is defined, bunzip2 engine is enabled. * Makefile (SRCS): Add bunzip2.c. (UNZIP_OBJS): Add do-bunzip2.o. (CPPFLAGS): Add -DGZIP, -DBZIP2 and -DSMALL_BZIP2. 1998-09-03 OKUJI Yoshinori * gunzip.c: New file. Copy libstore/gunzip.c and modify for use in serverboot. * load.c (struct stuff): Add members, image_addr and image_size. (mem_read) (mem_read_exec): New functions. (boot_script_exec_cmd): Add gzexe feature. * Makefile: Add unzip stuffs. --- serverboot/ChangeLog | 19 ++++++ serverboot/Makefile | 16 +++-- serverboot/bunzip2.c | 169 +++++++++++++++++++++++++++++++++++++++++++++ serverboot/gunzip.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++ serverboot/load.c | 134 ++++++++++++++++++++++++++++++++++++ 5 files changed, 522 insertions(+), 4 deletions(-) create mode 100644 serverboot/bunzip2.c create mode 100644 serverboot/gunzip.c (limited to 'serverboot/load.c') diff --git a/serverboot/ChangeLog b/serverboot/ChangeLog index 850a82dc..715145c4 100644 --- a/serverboot/ChangeLog +++ b/serverboot/ChangeLog @@ -1,3 +1,22 @@ +1998-09-06 OKUJI Yoshinori + + * bunzip2.c: New file. + * load.c (GZIP) (BZIP2): New cpp constants. + (boot_script_exec_cmd): If GZIP is defined, gunzip engine is enabled. + If BZIP2 is defined, bunzip2 engine is enabled. + * Makefile (SRCS): Add bunzip2.c. + (UNZIP_OBJS): Add do-bunzip2.o. + (CPPFLAGS): Add -DGZIP, -DBZIP2 and -DSMALL_BZIP2. + +1998-09-03 OKUJI Yoshinori + + * gunzip.c: New file. + Copy libstore/gunzip.c and modify for use in serverboot. + * load.c (struct stuff): Add members, image_addr and image_size. + (mem_read) (mem_read_exec): New functions. + (boot_script_exec_cmd): Add gzexe feature. + * Makefile: Add unzip stuffs. + 1999-03-06 Roland McGrath * def_pager_setup.c (default_pager_setup): #if 0 out unused function. diff --git a/serverboot/Makefile b/serverboot/Makefile index 12ff6375..d2ab975d 100644 --- a/serverboot/Makefile +++ b/serverboot/Makefile @@ -21,10 +21,7 @@ makemode := utility SRCS = bootstrap.c ffs_compat.c load.c wiring.c def_pager_setup.c \ ffs_file_io.c minix_ffs_compat.c default_pager.c file_io.c\ minix_file_io.c ext2_file_io.c kalloc.c strfcns.c exec.c \ - panic.c elf-load.c -OBJS = $(subst .c,.o,$(SRCS)) boot_script.o memory_objectServer.o \ - default_pagerServer.o excServer.o bootstrapServer.o \ - memory_object_defaultServer.o + panic.c elf-load.c gunzip.c bunzip2.c LCLHDRS = assert.h disk_inode_ffs.h fs.h queue.h defs.h ext2_fs.h \ minix_ffs_compat.h wiring.h dir.h ffs_compat.h minix_fs.h \ disk_inode.h file_io.h minix_super.h mach-exec.h @@ -32,8 +29,19 @@ target = serverboot HURDLIBS = threads installationdir = $(prefix)/boot +UNZIP_OBJS = unzip.o inflate.o util.o do-bunzip2.o +OBJS = $(subst .c,.o,$(SRCS)) boot_script.o memory_objectServer.o \ + default_pagerServer.o excServer.o bootstrapServer.o \ + memory_object_defaultServer.o $(UNZIP_OBJS) + vpath boot_script.c $(srcdir)/../boot +# Look for zip stuff +VPATH += $(srcdir)/../exec +# If SMALL_BZIP2 is defined, use relatively small memory. +# It's crucial for serverboot, because swap is not enabled yet. +CPPFLAGS += -I$(srcdir)/../exec -DGZIP -DBZIP2 -DSMALL_BZIP2 + MIGSFLAGS = -DSEQNOS LDFLAGS += -static diff --git a/serverboot/bunzip2.c b/serverboot/bunzip2.c new file mode 100644 index 00000000..9f79ade5 --- /dev/null +++ b/serverboot/bunzip2.c @@ -0,0 +1,169 @@ +/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */ +/* Decompressing store backend + + Copyright (C) 1997 Free Software Foundation, Inc. + Written by Miles Bader + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include +#include +#include +#include +#include + +#include + +#define IN_BUFFERING (256*1024) +#define OUT_BUFFERING (512*1024) + +static struct mutex bunzip2_lock = MUTEX_INITIALIZER; + +/* Uncompress the contents of FROM, which should contain a valid bzip2 file, + into memory, returning the result buffer in BUF & BUF_LEN. */ +int +serverboot_bunzip2 (struct file *from, void **buf, size_t *buf_len) +{ + /* Callbacks from do_bunzip2 for I/O and error interface. */ + extern int (*unzip_read) (char *buf, size_t maxread); + extern void (*unzip_write) (const char *buf, size_t nwrite); + extern void (*unzip_read_error) (void); + extern void (*unzip_error) (const char *msg); + + /* How we return errors from our hook functions. */ + jmp_buf zerr_jmp_buf; + int zerr; + + size_t offset = 0; /* Offset of read point in FROM. */ + + /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current + position in FROM. */ + int zread (char *buf, size_t maxread) + { + vm_size_t resid; + size_t did_read; + + if (from->f_size - offset < maxread) + did_read = from->f_size - offset; + else + did_read = maxread; + + zerr = read_file (from, offset, buf, did_read, &resid); + if (zerr) + longjmp (zerr_jmp_buf, 1); + + did_read -= resid; + offset += did_read; + + return did_read; + } + + size_t out_buf_offs = 0; /* Position in the output buffer. */ + + /* Write uncompress data to our output buffer. */ + void zwrite (const char *wbuf, size_t nwrite) + { + size_t old_buf_len = *buf_len; + + if (out_buf_offs + nwrite > old_buf_len) + /* Have to grow the output buffer. */ + { + void *old_buf = *buf; + void *new_buf = old_buf + old_buf_len; /* First try. */ + size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite); + + /* Try to grow the buffer. */ + zerr = + vm_allocate (mach_task_self (), + (vm_address_t *)&new_buf, new_buf_len - old_buf_len, + 0); + if (zerr) + /* Can't do that, try to make a bigger buffer elsewhere. */ + { + new_buf = old_buf; + zerr = + vm_allocate (mach_task_self (), + (vm_address_t *)&new_buf, new_buf_len, 1); + if (zerr) + longjmp (zerr_jmp_buf, 1); + + if (out_buf_offs > 0) + /* Copy the old buffer into the start of the new & free it. */ + bcopy (old_buf, new_buf, out_buf_offs); + + vm_deallocate (mach_task_self (), + (vm_address_t)old_buf, old_buf_len); + + *buf = new_buf; + } + + *buf_len = new_buf_len; + } + + bcopy (wbuf, *buf + out_buf_offs, nwrite); + out_buf_offs += nwrite; + } + + void zreaderr (void) + { + zerr = EIO; + longjmp (zerr_jmp_buf, 1); + } + void zerror (const char *msg) + { + zerr = EINVAL; + longjmp (zerr_jmp_buf, 2); + } + + /* Try to guess a reasonable output buffer size. */ + *buf_len = round_page (from->f_size * 2); + zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); + if (zerr) + return zerr; + + mutex_lock (&bunzip2_lock); + + unzip_read = zread; + unzip_write = zwrite; + unzip_read_error = zreaderr; + unzip_error = zerror; + + if (! setjmp (zerr_jmp_buf)) + { + /* Call the bunzip2 engine. */ + do_bunzip2 (); + zerr = 0; + } + + mutex_unlock (&bunzip2_lock); + + if (zerr) + { + if (*buf_len > 0) + vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len); + } + else if (out_buf_offs < *buf_len) + /* Trim the output buffer to be the right length. */ + { + size_t end = round_page (out_buf_offs); + if (end < *buf_len) + vm_deallocate (mach_task_self (), + (vm_address_t)(*buf + end), *buf_len - end); + *buf_len = out_buf_offs; + } + + return zerr; +} diff --git a/serverboot/gunzip.c b/serverboot/gunzip.c new file mode 100644 index 00000000..f74da111 --- /dev/null +++ b/serverboot/gunzip.c @@ -0,0 +1,188 @@ +/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */ +/* Decompressing store backend + + Copyright (C) 1997 Free Software Foundation, Inc. + Written by Miles Bader + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include +#include +#include +#include +#include + +#include + +/* gzip.h makes several annoying defines & decls, which we have to work + around. */ +#define file_t gzip_file_t +#include "gzip.h" +#undef file_t +#undef head + +#define IN_BUFFERING (256*1024) +#define OUT_BUFFERING (512*1024) + +static struct mutex unzip_lock = MUTEX_INITIALIZER; + +/* Uncompress the contents of FROM, which should contain a valid gzip file, + into memory, returning the result buffer in BUF & BUF_LEN. */ +int +serverboot_gunzip (struct file *from, void **buf, size_t *buf_len) +{ + /* Entry points to unzip engine. */ + int get_method (int); + extern long int bytes_out; + /* Callbacks from unzip for I/O and error interface. */ + extern int (*unzip_read) (char *buf, size_t maxread); + extern void (*unzip_write) (const char *buf, size_t nwrite); + extern void (*unzip_read_error) (void); + extern void (*unzip_error) (const char *msg); + + /* How we return errors from our hook functions. */ + jmp_buf zerr_jmp_buf; + int zerr; + + size_t offset = 0; /* Offset of read point in FROM. */ + + /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current + position in FROM. */ + int zread (char *buf, size_t maxread) + { + vm_size_t resid; + size_t did_read; + + if (from->f_size - offset < maxread) + did_read = from->f_size - offset; + else + did_read = maxread; + + zerr = read_file (from, offset, buf, did_read, &resid); + if (zerr) + longjmp (zerr_jmp_buf, 1); + + did_read -= resid; + offset += did_read; + + return did_read; + } + + size_t out_buf_offs = 0; /* Position in the output buffer. */ + + /* Write uncompress data to our output buffer. */ + void zwrite (const char *wbuf, size_t nwrite) + { + size_t old_buf_len = *buf_len; + + if (out_buf_offs + nwrite > old_buf_len) + /* Have to grow the output buffer. */ + { + void *old_buf = *buf; + void *new_buf = old_buf + old_buf_len; /* First try. */ + size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite); + + /* Try to grow the buffer. */ + zerr = + vm_allocate (mach_task_self (), + (vm_address_t *)&new_buf, new_buf_len - old_buf_len, + 0); + if (zerr) + /* Can't do that, try to make a bigger buffer elsewhere. */ + { + new_buf = old_buf; + zerr = + vm_allocate (mach_task_self (), + (vm_address_t *)&new_buf, new_buf_len, 1); + if (zerr) + longjmp (zerr_jmp_buf, 1); + + if (out_buf_offs > 0) + /* Copy the old buffer into the start of the new & free it. */ + bcopy (old_buf, new_buf, out_buf_offs); + + vm_deallocate (mach_task_self (), + (vm_address_t)old_buf, old_buf_len); + + *buf = new_buf; + } + + *buf_len = new_buf_len; + } + + bcopy (wbuf, *buf + out_buf_offs, nwrite); + out_buf_offs += nwrite; + } + + void zreaderr (void) + { + zerr = EIO; + longjmp (zerr_jmp_buf, 1); + } + void zerror (const char *msg) + { + zerr = EINVAL; + longjmp (zerr_jmp_buf, 2); + } + + /* Try to guess a reasonable output buffer size. */ + *buf_len = round_page (from->f_size * 2); + zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); + if (zerr) + return zerr; + + mutex_lock (&unzip_lock); + + unzip_read = zread; + unzip_write = zwrite; + unzip_read_error = zreaderr; + unzip_error = zerror; + + if (! setjmp (zerr_jmp_buf)) + { + if (get_method (0) != 0) + /* Not a happy gzip file. */ + zerr = EINVAL; + else + /* Matched gzip magic number. Ready to unzip. + Set up the output stream and let 'er rip. */ + { + /* Call the gunzip engine. */ + bytes_out = 0; + unzip (17, 23); /* Arguments ignored. */ + zerr = 0; + } + } + + mutex_unlock (&unzip_lock); + + if (zerr) + { + if (*buf_len > 0) + vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len); + } + else if (out_buf_offs < *buf_len) + /* Trim the output buffer to be the right length. */ + { + size_t end = round_page (out_buf_offs); + if (end < *buf_len) + vm_deallocate (mach_task_self (), + (vm_address_t)(*buf + end), *buf_len - end); + *buf_len = out_buf_offs; + } + + return zerr; +} diff --git a/serverboot/load.c b/serverboot/load.c index a4bb43c3..878bddb9 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -41,6 +41,10 @@ struct stuff struct file *fp; task_t user_task; + /* uncompressed image */ + vm_offset_t image_addr; + vm_size_t image_size; + vm_offset_t aout_symtab_ofs; vm_size_t aout_symtab_size; vm_offset_t aout_strtab_ofs; @@ -149,6 +153,86 @@ static int prog_read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_siz return 0; } +/* Callback functions for reading the uncompressed image. */ +static int image_read(void *handle, vm_offset_t file_ofs, void *buf, + vm_size_t size, vm_size_t *out_actual) +{ + struct stuff *st = handle; + bcopy(st->image_addr + file_ofs, buf, size); + *out_actual = size; + return 0; +} + +static int image_read_exec(void *handle, vm_offset_t file_ofs, + vm_size_t file_size, vm_offset_t mem_addr, + vm_size_t mem_size, exec_sectype_t sec_type) +{ + struct stuff *st = handle; + vm_offset_t page_start = trunc_page(mem_addr); + vm_offset_t page_end = round_page(mem_addr + mem_size); + vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK; + vm_offset_t area_start; + int result; + + if (sec_type & EXEC_SECTYPE_AOUT_SYMTAB) + { + st->aout_symtab_ofs = file_ofs; + st->aout_symtab_size = file_size; + } + if (sec_type & EXEC_SECTYPE_AOUT_STRTAB) + { + st->aout_strtab_ofs = file_ofs; + st->aout_strtab_size = file_size; + } + + if (!(sec_type & EXEC_SECTYPE_ALLOC)) + return 0; + + assert(mem_size > 0); + assert(mem_size > file_size); + + /* + printf("section %08x-%08x-%08x prot %08x (%08x-%08x)\n", + mem_addr, mem_addr+file_size, mem_addr+mem_size, mem_prot, page_start, page_end); + */ + + result = vm_allocate(mach_task_self(), &area_start, page_end - page_start, TRUE); + if (result) return (result); + + if (file_size > 0) + { + bcopy(st->image_addr + file_ofs, area_start + (mem_addr - page_start), + file_size); + } + + if (mem_size > file_size) + { + bzero((void*)area_start + (mem_addr + file_size - page_start), + mem_size - file_size); + } + + result = vm_allocate(st->user_task, &page_start, page_end - page_start, FALSE); + if (result) return (result); + assert(page_start == trunc_page(mem_addr)); + + result = vm_write(st->user_task, page_start, area_start, page_end - page_start); + if (result) return (result); + + result = vm_deallocate(mach_task_self(), area_start, page_end - page_start); + if (result) return (result); + + /* + * Protect the segment. + */ + if (load_protect_text && (mem_prot != VM_PROT_ALL)) { + result = vm_protect(st->user_task, page_start, page_end - page_start, + FALSE, mem_prot); + if (result) return (result); + } + + return 0; +} + mach_port_t boot_script_read_file (const char *file) { return MACH_PORT_NULL; } /* XXX */ @@ -216,6 +300,56 @@ boot_script_exec_cmd (task_t user_task, st.aout_symtab_size = 0; st.aout_strtab_size = 0; result = exec_load(prog_read, prog_read_exec, &st, &info); +#ifdef GZIP + if (result) + { + /* + * It might be gzip file. + */ + int err; + extern int + serverboot_gunzip(struct file *, void **, size_t *); + + err = serverboot_gunzip(st.fp, + &(st.image_addr), + &(st.image_size)); + if (!err) + { + result = exec_load(image_read, + image_read_exec, + &st, + &info); + vm_deallocate(mach_task_self(), + st.image_addr, + st.image_size); + } + } +#endif GZIP +#ifdef BZIP2 + if (result) + { + /* + * It might be bzip2 file. + */ + int err; + extern int + serverboot_bunzip2(struct file *, void **, size_t *); + + err = serverboot_bunzip2(st.fp, + &(st.image_addr), + &(st.image_size)); + if (!err) + { + result = exec_load(image_read, + image_read_exec, + &st, + &info); + vm_deallocate(mach_task_self(), + st.image_addr, + st.image_size); + } + } +#endif BZIP2 if (result) panic("(serverboot) exec_load %s: error %d", namebuf, result); #if 0 -- cgit v1.2.3 From ee7847780e05f6d78ae014bad1ce798b370713ef Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 2 Jun 1999 06:56:34 +0000 Subject: 1999-06-02 Roland McGrath * load.c (boot_script_exec_cmd): Copy environment from our `environ' onto the new task's stack along with its arguments. --- serverboot/load.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/load.c b/serverboot/load.c index 878bddb9..3898eac6 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -244,6 +244,9 @@ boot_script_exec_cmd (task_t user_task, { extern mach_port_t bootstrap_master_device_port, bootstrap_master_host_port; extern char *root_name; + extern char **environ; + int envc, env_len; + int arg_len = argslen; char *arg_pos; @@ -273,15 +276,21 @@ boot_script_exec_cmd (task_t user_task, panic("openi %d", result); } + env_len = 0; + for (envc = 0; environ[envc]; ++envc) + env_len += strlen (environ[envc]) + 1; + /* * Add space for: * arg_count * pointers to arguments * trailing 0 pointer - * dummy 0 pointer to environment variables + * environment variables + * trailing 0 pointer * and align to integer boundary */ - arg_len += sizeof(integer_t) + (2 + arg_count) * sizeof(char *); + arg_len += sizeof(integer_t) + (envc + 2 + arg_count) * sizeof(char *); + arg_len += env_len; arg_len = (arg_len + (sizeof(integer_t) - 1)) & ~(sizeof(integer_t)-1); /* @@ -307,7 +316,7 @@ boot_script_exec_cmd (task_t user_task, * It might be gzip file. */ int err; - extern int + extern int serverboot_gunzip(struct file *, void **, size_t *); err = serverboot_gunzip(st.fp, @@ -332,7 +341,7 @@ boot_script_exec_cmd (task_t user_task, * It might be bzip2 file. */ int err; - extern int + extern int serverboot_bunzip2(struct file *, void **, size_t *); err = serverboot_bunzip2(st.fp, @@ -426,9 +435,11 @@ boot_script_exec_cmd (task_t user_task, * Start the strings after the arg-count and pointers */ u_cp = (char *)u_arg_start + arg_count * sizeof(char *) + + envc * sizeof(char *) + 2 * sizeof(char *) + sizeof(integer_t); k_cp = (char *)k_arg_start + arg_count * sizeof(char *) + + envc * sizeof(char *) + 2 * sizeof(char *) + sizeof(integer_t); @@ -442,13 +453,15 @@ boot_script_exec_cmd (task_t user_task, */ for (i = 0; i < arg_count; i++) *k_ap++ = argv[i] - argstrings + u_cp; + *k_ap++ = (char *)0; bcopy (argstrings, k_cp, argslen); + k_cp += argslen; + u_cp += argslen; - /* - * last, the trailing 0 argument and a null environment pointer. - */ - *k_ap++ = (char *)0; + for (i = 0; i < envc; i++) + *k_ap++ = environ[i] - environ[0] + u_cp; *k_ap = (char *)0; + bcopy (environ[0], k_cp, env_len); /* * Now write all of this to user space. -- cgit v1.2.3 From febab894f78d6cf509544872e075c3204d35b9d6 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 28 Oct 1999 20:51:36 +0000 Subject: 1999-10-28 Roland McGrath * file_io.h: Include . (FS_* macros): Define these to equivalent errno codes. * def_pager_setup.c (add_paging_file): Put strerror of result code in error messages. * bootstrap.c (parse_script): Likewise. * load.c (boot_script_exec_cmd): Include NAMEBUF in error messages, and use strerror to format result code. * panic.c (panic): Use program_invocation_name in message. --- serverboot/bootstrap.c | 35 ++++++++++++++++++++++++----------- serverboot/def_pager_setup.c | 5 +++-- serverboot/file_io.h | 21 +++++++++++++++++++-- serverboot/load.c | 18 +++++++++++++----- serverboot/panic.c | 15 ++++++++------- 5 files changed, 67 insertions(+), 27 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/bootstrap.c b/serverboot/bootstrap.c index f6d6050a..41fe7591 100644 --- a/serverboot/bootstrap.c +++ b/serverboot/bootstrap.c @@ -29,6 +29,7 @@ #include #include +#include #include @@ -112,8 +113,12 @@ boot_panic (kern_return_t err) void safe_gets (char *str, int maxlen) { - char *c; - c = strchr (fgets (str, maxlen, stdin), '\n'); + char *c = fgets (str, maxlen, stdin); + if (c == 0) { + perror ("fgets"); + panic ("cannot read from console"); + } + c = strchr (c, '\n'); if (c) *c = '\0'; printf ("\r\n"); @@ -122,7 +127,14 @@ safe_gets (char *str, int maxlen) printf_init (device_t master) { mach_port_t cons; - device_open (master, D_READ|D_WRITE, "console", &cons); + kern_return_t rc; + rc = device_open (master, D_READ|D_WRITE, "console", &cons); + if (rc) + while (1) { + volatile int x = 0; + (void) host_reboot(bootstrap_master_host_port, RB_DEBUGGER); + x = x / x; + } stdin = mach_open_devstream (cons, "r"); stdout = stderr = mach_open_devstream (cons, "w"); mach_port_deallocate (mach_task_self (), cons); @@ -224,22 +236,22 @@ main(argc, argv) &bootstrap_master_device_port); } - - - printf_init(bootstrap_master_device_port); #ifdef pleasenoXXX panic_init(bootstrap_master_host_port); #endif + printf ("serverboot flags %s root=%s\n", flag_string, root_name); + + /* - * If the '-a' (ask) switch was specified, or if no + * If the '-a' (ask) switch was specified, or if no * root device was specificed, ask for the root device. */ if (!root_name || root_name [0] == '\0' || index(flag_string, 'a')) { - static char new_root[16]; - + static char new_root[MAXPATHLEN/2]; + printf("root device? [%s] ", root_name); safe_gets(new_root, sizeof(new_root)); @@ -431,8 +443,9 @@ parse_script (struct file *f) int n = 0; buf = malloc (f->f_size + 1); /* add one for null terminator we will write */ - if (read_file (f, 0, buf, f->f_size, 0)) - panic ("bootstrap: error reading boot script file"); + err = read_file (f, 0, buf, f->f_size, 0); + if (err) + panic ("bootstrap: error reading boot script file: %s", strerror (err)); line = p = buf; while (1) diff --git a/serverboot/def_pager_setup.c b/serverboot/def_pager_setup.c index 194f0355..8834a379 100644 --- a/serverboot/def_pager_setup.c +++ b/serverboot/def_pager_setup.c @@ -58,11 +58,12 @@ add_paging_file(master_device_port, file_name, linux_signature) result = open_file_direct(pfile.f_dev, fdp, isa_file); if (result) - panic("Can't open paging file %s\n", file_name); + panic("Can't open paging file %s: %s\n", + file_name, strerror (result)); result = add_file_direct(fdp, &pfile); if (result) - panic("Can't read disk addresses: %d\n", result); + panic("Can't read disk addresses: %s\n", strerror (result)); close_file(&pfile); diff --git a/serverboot/file_io.h b/serverboot/file_io.h index 5706ce5b..8a1a6e34 100644 --- a/serverboot/file_io.h +++ b/serverboot/file_io.h @@ -162,13 +162,30 @@ extern int page_write_file_direct(); * Error codes for file system errors. */ +#include + +/* Just use the damn Hurd error numbers. This is old CMU/Utah code from + the days of personality-independent Mach where it made sense for this to + be a standalone universe. In the Hurd, we compile serverboot against + the regular C library anyway. */ + +#define FS_NOT_DIRECTORY ENOTDIR +#define FS_NO_ENTRY ENOENT +#define FS_NAME_TOO_LONG ENAMETOOLONG +#define FS_SYMLINK_LOOP ELOOP +#define FS_INVALID_FS EFTYPE /* ? */ +#define FS_NOT_IN_FILE EINVAL +#define FS_INVALID_PARAMETER EINVAL + +#if 0 #define FS_NOT_DIRECTORY 5000 /* not a directory */ #define FS_NO_ENTRY 5001 /* name not found */ #define FS_NAME_TOO_LONG 5002 /* name too long */ #define FS_SYMLINK_LOOP 5003 /* symbolic link loop */ #define FS_INVALID_FS 5004 /* bad file system */ #define FS_NOT_IN_FILE 5005 /* offset not in file */ -#define FS_INVALID_PARAMETER 5006 /* bad parameter to - a routine */ +#define FS_INVALID_PARAMETER 5006 /* bad parameter to routine */ +#endif + #endif /* _FILE_IO_H_ */ diff --git a/serverboot/load.c b/serverboot/load.c index 3898eac6..a4f48ba3 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -273,7 +273,7 @@ boot_script_exec_cmd (task_t user_task, result = open_file(bootstrap_master_device_port, namebuf, &file); if (result != 0) { - panic("openi %d", result); + panic ("%s: %s", namebuf, strerror (result)); } env_len = 0; @@ -308,6 +308,7 @@ boot_script_exec_cmd (task_t user_task, st.user_task = user_task; st.aout_symtab_size = 0; st.aout_strtab_size = 0; +printf("serverboot loading %s\n", file_name); result = exec_load(prog_read, prog_read_exec, &st, &info); #ifdef GZIP if (result) @@ -360,7 +361,7 @@ boot_script_exec_cmd (task_t user_task, } #endif BZIP2 if (result) - panic("(serverboot) exec_load %s: error %d", namebuf, result); + panic ("cannot load %s: %s", namebuf, strerror (result)); #if 0 printf("(serverboot): loaded %s; entrypoint %08x\n", namebuf, info.entry); #endif @@ -370,9 +371,11 @@ boot_script_exec_cmd (task_t user_task, */ result = thread_create (user_task, &user_thread); if (result) - panic ("can't create user thread for %s: %x", namebuf, result); + panic ("can't create user thread for %s: %s", namebuf, + strerror (result)); arg_pos = set_regs(user_task, user_thread, &info, arg_len); +printf("set up user thread\n"); /* * Read symbols from the executable file. */ @@ -451,15 +454,19 @@ boot_script_exec_cmd (task_t user_task, /* * Then the strings and string pointers for each argument */ - for (i = 0; i < arg_count; i++) + for (i = 0; i < arg_count; i++) { + printf("\targv[%d] = %s\n", i, argv[i]); *k_ap++ = argv[i] - argstrings + u_cp; + } *k_ap++ = (char *)0; bcopy (argstrings, k_cp, argslen); k_cp += argslen; u_cp += argslen; - for (i = 0; i < envc; i++) + for (i = 0; i < envc; i++) { + printf("\tenviron[%d] = %s\n", i, environ[i]); *k_ap++ = environ[i] - environ[0] + u_cp; + } *k_ap = (char *)0; bcopy (environ[0], k_cp, env_len); @@ -481,6 +488,7 @@ boot_script_exec_cmd (task_t user_task, */ close_file(&file); +printf ("resume user thread...\n"); /* Resume the thread. */ thread_resume (user_thread); mach_port_deallocate (mach_task_self (), user_thread); diff --git a/serverboot/panic.c b/serverboot/panic.c index 80197500..87428429 100644 --- a/serverboot/panic.c +++ b/serverboot/panic.c @@ -1,25 +1,25 @@ -/* +/* * 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. */ @@ -27,6 +27,7 @@ #include #include #include +#include static mach_port_t master_host_port; @@ -44,7 +45,7 @@ panic(s, va_alist) va_list listp; clearerr (stdout); - printf("bootstrap/default-pager panic: "); + printf("%s: panic: ", program_invocation_name); va_start(listp); vprintf(s, listp); va_end(listp); -- cgit v1.2.3 From 36cc6f5c3c22d63b427ead67d8ed3449f8ac6835 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 28 Oct 1999 21:16:57 +0000 Subject: 1999-10-28 Roland McGrath * load.c, bootstrap.c: Back out some debugging printfs accidentally included in the last commit. * bootstrap.c (main): Increase size of NEW_ROOT buffer. This change was included in the last commit, but not logged then. --- serverboot/bootstrap.c | 2 -- serverboot/load.c | 11 ++--------- 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/bootstrap.c b/serverboot/bootstrap.c index 41fe7591..7ac38a2c 100644 --- a/serverboot/bootstrap.c +++ b/serverboot/bootstrap.c @@ -241,8 +241,6 @@ main(argc, argv) panic_init(bootstrap_master_host_port); #endif - printf ("serverboot flags %s root=%s\n", flag_string, root_name); - /* * If the '-a' (ask) switch was specified, or if no diff --git a/serverboot/load.c b/serverboot/load.c index a4f48ba3..fc16baf1 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -308,7 +308,6 @@ boot_script_exec_cmd (task_t user_task, st.user_task = user_task; st.aout_symtab_size = 0; st.aout_strtab_size = 0; -printf("serverboot loading %s\n", file_name); result = exec_load(prog_read, prog_read_exec, &st, &info); #ifdef GZIP if (result) @@ -375,7 +374,6 @@ printf("serverboot loading %s\n", file_name); strerror (result)); arg_pos = set_regs(user_task, user_thread, &info, arg_len); -printf("set up user thread\n"); /* * Read symbols from the executable file. */ @@ -454,19 +452,15 @@ printf("set up user thread\n"); /* * Then the strings and string pointers for each argument */ - for (i = 0; i < arg_count; i++) { - printf("\targv[%d] = %s\n", i, argv[i]); + for (i = 0; i < arg_count; i++) *k_ap++ = argv[i] - argstrings + u_cp; - } *k_ap++ = (char *)0; bcopy (argstrings, k_cp, argslen); k_cp += argslen; u_cp += argslen; - for (i = 0; i < envc; i++) { - printf("\tenviron[%d] = %s\n", i, environ[i]); + for (i = 0; i < envc; i++) *k_ap++ = environ[i] - environ[0] + u_cp; - } *k_ap = (char *)0; bcopy (environ[0], k_cp, env_len); @@ -488,7 +482,6 @@ printf("set up user thread\n"); */ close_file(&file); -printf ("resume user thread...\n"); /* Resume the thread. */ thread_resume (user_thread); mach_port_deallocate (mach_task_self (), user_thread); -- cgit v1.2.3 From e09a35d0336517a074db32d91b4d2b4188269e0a Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 1 Apr 2001 01:41:05 +0000 Subject: 2001-03-31 Roland McGrath * assert.h: Fix obsolescent #endif syntax. * default_pager.c: Likewise. * queue.h: Likewise. * load.c: Likewise. --- serverboot/assert.h | 16 ++++++++-------- serverboot/default_pager.c | 30 +++++++++++++++--------------- serverboot/load.c | 4 ++-- serverboot/queue.h | 10 +++++----- 4 files changed, 30 insertions(+), 30 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/assert.h b/serverboot/assert.h index 9bcab69e..9f70aec3 100644 --- a/serverboot/assert.h +++ b/serverboot/assert.h @@ -1,25 +1,25 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -38,9 +38,9 @@ extern void Assert(); #ifdef lint #define assert_static(x) -#else lint +#else /* lint */ #define assert_static(x) assert(x) -#endif lint +#endif /* lint */ #else /* ASSERTIONS */ #define assert(ex) diff --git a/serverboot/default_pager.c b/serverboot/default_pager.c index d5dbcf9b..a7625447 100644 --- a/serverboot/default_pager.c +++ b/serverboot/default_pager.c @@ -655,7 +655,7 @@ struct dpager { #ifdef CHECKSUM vm_offset_t *checksum; /* checksum - parallel to block map */ #define NO_CHECKSUM ((vm_offset_t)-1) -#endif CHECKSUM +#endif /* CHECKSUM */ }; typedef struct dpager *dpager_t; @@ -752,7 +752,7 @@ pager_alloc(pager, part, size) mapptr[i] = NO_CHECKSUM; } pager->checksum = mapptr; -#endif CHECKSUM +#endif /* CHECKSUM */ } /* @@ -908,7 +908,7 @@ pager_extend(pager, new_size) new_mapptr[i] = 0; kfree((char *)old_mapptr, INDIRECT_PAGEMAP_SIZE(old_size)); pager->checksum = new_mapptr; -#endif CHECKSUM +#endif /* CHECKSUM */ #if DEBUG_READER_CONFLICTS pager->writer = FALSE; #endif @@ -979,7 +979,7 @@ pager_extend(pager, new_size) for (i = 1; i < INDIRECT_PAGEMAP_ENTRIES(new_size); i++) new_mapptr[i] = 0; pager->checksum = new_mapptr; -#endif CHECKSUM +#endif /* CHECKSUM */ #if DEBUG_READER_CONFLICTS pager->writer = FALSE; #endif @@ -1008,7 +1008,7 @@ pager_extend(pager, new_size) new_mapptr[i] = NO_CHECKSUM; kfree((char *)old_mapptr, PAGEMAP_SIZE(old_size)); pager->checksum = new_mapptr; -#endif CHECKSUM +#endif /* CHECKSUM */ #if DEBUG_READER_CONFLICTS pager->writer = FALSE; #endif @@ -1254,7 +1254,7 @@ compute_checksum(addr, size) return (checksum); } -#endif CHECKSUM +#endif /* CHECKSUM */ /* * Given an offset within a paging object, find the @@ -1364,7 +1364,7 @@ pager_write_offset(pager, offset) for (j = 0; j < PAGEMAP_ENTRIES; j++) cksumptr[j] = NO_CHECKSUM; } -#endif CHECKSUM +#endif /* CHECKSUM */ } f_page %= PAGEMAP_ENTRIES; } @@ -1465,7 +1465,7 @@ pager_dealloc(pager) } kfree((char *)pager->checksum, INDIRECT_PAGEMAP_SIZE(pager->size)); -#endif CHECKSUM +#endif /* CHECKSUM */ } else { mapptr = pager->map; @@ -1478,7 +1478,7 @@ pager_dealloc(pager) kfree((char *)pager->map, PAGEMAP_SIZE(pager->size)); #ifdef CHECKSUM kfree((char *)pager->checksum, PAGEMAP_SIZE(pager->size)); -#endif CHECKSUM +#endif /* CHECKSUM */ } } @@ -1573,7 +1573,7 @@ default_read(ds, addr, size, offset, out_addr, deallocate) register partition_t part; #ifdef CHECKSUM vm_size_t original_size = size; -#endif CHECKSUM +#endif /* CHECKSUM */ vm_offset_t original_offset = offset; /* @@ -1638,7 +1638,7 @@ ddprintf ("default_read(%x,%x,%x,%d)\n",addr,size,offset,block.block.p_index); original_offset, write_checksum, read_checksum); } } -#endif CHECKSUM +#endif /* CHECKSUM */ return (PAGER_SUCCESS); } @@ -1673,7 +1673,7 @@ default_write(ds, addr, size, offset) checksum = compute_checksum(addr, size); pager_put_checksum(ds, offset, checksum); } -#endif CHECKSUM +#endif /* CHECKSUM */ offset = ptoa(block.block.p_offset); ddprintf ("default_write(%x,%x,%x,%d)\n",addr,size,offset,block.block.p_index); part = partition_of(block.block.p_index); @@ -2606,7 +2606,7 @@ seqnos_memory_object_data_initialize(pager, seqno, pager_request, #ifdef lint pager_request++; -#endif lint +#endif /* lint */ ds = pager_port_lookup(pager); if (ds == DEFAULT_PAGER_NULL) @@ -2670,7 +2670,7 @@ seqnos_memory_object_data_write(pager, seqno, pager_request, #ifdef lint pager_request++; -#endif lint +#endif /* lint */ ddprintf ("seqnos_memory_object_data_write <%p>: 1\n", &err); if ((data_cnt % vm_page_size) != 0) @@ -2773,7 +2773,7 @@ seqnos_memory_object_lock_completed(pager, seqno, pager_request, { #ifdef lint pager++; seqno++; pager_request++; offset++; length++; -#endif lint +#endif /* lint */ panic("%slock_completed",my_name); return(KERN_FAILURE); diff --git a/serverboot/load.c b/serverboot/load.c index fc16baf1..1665868b 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -333,7 +333,7 @@ boot_script_exec_cmd (task_t user_task, st.image_size); } } -#endif GZIP +#endif /* GZIP */ #ifdef BZIP2 if (result) { @@ -358,7 +358,7 @@ boot_script_exec_cmd (task_t user_task, st.image_size); } } -#endif BZIP2 +#endif /* BZIP2 */ if (result) panic ("cannot load %s: %s", namebuf, strerror (result)); #if 0 diff --git a/serverboot/queue.h b/serverboot/queue.h index 3e93476f..00619174 100644 --- a/serverboot/queue.h +++ b/serverboot/queue.h @@ -1,18 +1,18 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU @@ -313,4 +313,4 @@ typedef struct queue_entry *queue_entry_t; -#endif _QUEUE_H_ +#endif /* _QUEUE_H_ */ -- cgit v1.2.3 From 8e7cfa8a006ba1e1616d8f88767666e4dda96de2 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 17 Aug 2001 04:48:03 +0000 Subject: 2001-08-16 Roland McGrath * Makefile (OBJS): Add userland-boot.o here. Add a vpath to find userland-boot.c in boot/ too. * bootstrap.c (parse_script): Pass new arg to boot_script_parse_line. * load.c: Include before "boot_script.h". --- serverboot/Makefile | 11 +++++++---- serverboot/bootstrap.c | 2 +- serverboot/load.c | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/Makefile b/serverboot/Makefile index b274717e..b6b16c99 100644 --- a/serverboot/Makefile +++ b/serverboot/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1997, 1999 Free Software Foundation, Inc. +# Copyright (C) 1997,99,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 @@ -30,11 +30,14 @@ HURDLIBS = threads installationdir = $(prefix)/boot UNZIP_OBJS = unzip.o inflate.o util.o do-bunzip2.o -OBJS = $(subst .c,.o,$(SRCS)) boot_script.o memory_objectServer.o \ - default_pagerServer.o excServer.o bootstrapServer.o \ - memory_object_defaultServer.o $(UNZIP_OBJS) +OBJS = $(subst .c,.o,$(SRCS)) \ + boot_script.o userland-boot.o \ + memory_objectServer.o \ + default_pagerServer.o excServer.o bootstrapServer.o \ + memory_object_defaultServer.o $(UNZIP_OBJS) vpath boot_script.c $(srcdir)/../boot +vpath userland-boot.c $(srcdir)/../boot # Look for zip stuff VPATH += $(srcdir)/../exec diff --git a/serverboot/bootstrap.c b/serverboot/bootstrap.c index 46935a26..3d298a5a 100644 --- a/serverboot/bootstrap.c +++ b/serverboot/bootstrap.c @@ -474,7 +474,7 @@ parse_script (struct file *f) while (p < buf + f->f_size && *p != '\n') p++; *p = '\0'; - err = boot_script_parse_line (line); + err = boot_script_parse_line (0, line); if (err) boot_panic (err); if (p == buf + f->f_size) diff --git a/serverboot/load.c b/serverboot/load.c index 1665868b..21289bf1 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -24,6 +24,7 @@ * the rights to redistribute these changes. */ +#include #include #include #include @@ -237,7 +238,8 @@ mach_port_t boot_script_read_file (const char *file) { return MACH_PORT_NULL; } /* XXX */ int -boot_script_exec_cmd (task_t user_task, +boot_script_exec_cmd (void *hook, + task_t user_task, char *file_name, int arg_count, char **argv, char *argstrings, int argslen) -- cgit v1.2.3 From 3e452f9fd0628d41f39f1e6a265f04c07eb0c958 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 23 Jun 2002 04:29:11 +0000 Subject: 2002-06-22 Roland McGrath * load.c (boot_script_exec_cmd): Twiddle decls of serverboot_bunzip2 and serverboot_gunzip. * load.c (boot_script_exec_cmd): Cast int to intptr_t before char *. --- serverboot/load.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/load.c b/serverboot/load.c index 21289bf1..e95a64d7 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -318,8 +318,8 @@ boot_script_exec_cmd (void *hook, * It might be gzip file. */ int err; - extern int - serverboot_gunzip(struct file *, void **, size_t *); + extern int serverboot_gunzip(struct file *, + vm_offset_t *, size_t *); err = serverboot_gunzip(st.fp, &(st.image_addr), @@ -343,8 +343,8 @@ boot_script_exec_cmd (void *hook, * It might be bzip2 file. */ int err; - extern int - serverboot_bunzip2(struct file *, void **, size_t *); + extern int serverboot_bunzip2(struct file *, + vm_offset_t *, size_t *); err = serverboot_bunzip2(st.fp, &(st.image_addr), @@ -449,7 +449,7 @@ boot_script_exec_cmd (void *hook, /* * first the argument count */ - *k_ap++ = (char *)arg_count; + *k_ap++ = (char *)(intptr_t)arg_count; /* * Then the strings and string pointers for each argument -- cgit v1.2.3 From de1fc902c7f387657d792191efb092127950c08c Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 7 May 2003 13:42:14 +0000 Subject: 2003-05-07 Ognyan Kulev * strfcns.c: #include instead of . (strbuild): Use -style for handling variable argument list. * load.c: Don't #include . --- serverboot/load.c | 1 - serverboot/strfcns.c | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'serverboot/load.c') diff --git a/serverboot/load.c b/serverboot/load.c index e95a64d7..aa481943 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "mach-exec.h" #include "../boot/boot_script.h" diff --git a/serverboot/strfcns.c b/serverboot/strfcns.c index 82a76728..cbead7e4 100644 --- a/serverboot/strfcns.c +++ b/serverboot/strfcns.c @@ -27,7 +27,7 @@ * Character subroutines */ -#include +#include #define EXPORT_BOOLEAN #include @@ -40,21 +40,20 @@ */ /*VARARGS1*/ char * -strbuild(dest, va_alist) - register char * dest; - va_dcl +strbuild(char *dest, ...) { va_list argptr; register char * src; register int c; - va_start(argptr); + va_start(argptr, dest); while ((src = va_arg(argptr, char *)) != (char *)0) { while ((c = *src++) != '\0') *dest++ = c; } *dest = '\0'; + va_end(argptr); return (dest); } -- cgit v1.2.3