From 67d82a6de5f4cd717882fb1d87793b9ecc1b4baa Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 13 Mar 2019 03:51:44 -0400 Subject: [PATCH] hurd: Add argv and environ. * include/gnu/hurd.h (struct hurd_startup_data): Add argp, envp. * lib/gnu/hurd-start.c (__argv, __env): Define them. * lib/gnu/exec-startup-get-data.c (mach_startup_info2hurd_startup_data): Set them. * lib/gnu/x86-mes-gcc/crt1.c (_start): Use them. * build-aux/configure-lib.sh (libc_mini_SOURCES): Add argz-extract.c. * include/argz.h: Build fix. * lib/string/argz-count.c: Likewise. * lib/string/argz-extract.c: Likewise. --- build-aux/configure-lib.sh | 1 + include/argz.h | 6 ++---- include/gnu/hurd.h | 30 ++++++++++++++++++++++++------ lib/gnu/_exit.c | 4 ++++ lib/gnu/exec-startup-get-data.c | 22 ++++++++++++++++------ lib/gnu/fd-get.c | 2 +- lib/gnu/hurd-start.c | 16 ++++++++++++---- lib/gnu/x86-mes-gcc/crt1.c | 21 +++++++++++---------- lib/string/argz-count.c | 2 -- lib/string/argz-extract.c | 16 ++++++++++++---- 10 files changed, 83 insertions(+), 37 deletions(-) diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 08ad2baa..58af71d0 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -63,6 +63,7 @@ lib/mach/mach_reply_port.S lib/mach/mach_task_self.S lib/mach/mach_thread_self.S lib/mach/msg.c +lib/string/argz-extract.c " fi fi diff --git a/include/argz.h b/include/argz.h index 685c7e10..4664e7e4 100644 --- a/include/argz.h +++ b/include/argz.h @@ -29,13 +29,11 @@ #else // ! SYSTEM_LIBC -#ifndef libc_hidden_def -#define libc_hidden_def(x) -#define weak_alias(x,y) -#endif +#include size_t __argz_count (char const *argz, size_t len); void __argz_extract (char const *argz, size_t len, char **argv); +size_t __argz_extract_count (char const *argz, size_t len, char **argv); #endif // ! SYSTEM_LIBC diff --git a/include/gnu/hurd.h b/include/gnu/hurd.h index 419cc606..0d6a23f4 100644 --- a/include/gnu/hurd.h +++ b/include/gnu/hurd.h @@ -41,24 +41,42 @@ typedef off64_t loff_t; struct hurd_startup_data { int flags; + mach_port_t *dtable; - mach_msg_type_number_t dtablesize; + mach_msg_type_number_t dtable_count; + + char *argp; + int arg_size; + + char *envp; + int env_size; + mach_port_t *portarray; - mach_msg_type_number_t portarraysize; + mach_msg_type_number_t portarray_count; + int *intarray; - mach_msg_type_number_t intarraysize; + mach_msg_type_number_t intarray_count; + vm_address_t stack_base; - vm_size_t stack_size; + vm_size_t stack_count; + vm_address_t phdr; - vm_size_t phdrsz; + vm_size_t phdr_count; + vm_address_t user_entry; }; #define _HURD_DTABLE_MAX 1024 extern mach_port_t _hurd_dtable[_HURD_DTABLE_MAX]; -extern int _hurd_dtable_size; +extern int _hurd_dtable_count; extern struct hurd_startup_data _hurd_startup_data; +#define _HURD_ARGV_MAX 1000 +#define _HURD_ENVV_MAX 1000 +extern size_t __argc; +extern char *__argv[_HURD_ARGV_MAX]; +extern char *__envv[_HURD_ENVV_MAX]; + mach_port_t fd_get (int filedes); error_t fd_write (mach_port_t port, void const *buffer, size_t *size, loff_t offset); error_t fd_read (mach_port_t port, void *buffer, size_t *size, loff_t offset); diff --git a/lib/gnu/_exit.c b/lib/gnu/_exit.c index bca85d5c..82908d47 100644 --- a/lib/gnu/_exit.c +++ b/lib/gnu/_exit.c @@ -34,5 +34,9 @@ _exit (int status) { __proc_mark_exit (_hurd_startup_data.portarray[INIT_PORT_PROC], status, 0); __task_terminate (__mach_task_self ()); +#if 0 // FIXME: this was needed? while (1) {* (int *) 0 = 0;} +#else + asm ("hlt"); +#endif } diff --git a/lib/gnu/exec-startup-get-data.c b/lib/gnu/exec-startup-get-data.c index 142d712e..9c6c8b21 100644 --- a/lib/gnu/exec-startup-get-data.c +++ b/lib/gnu/exec-startup-get-data.c @@ -18,7 +18,6 @@ * along with GNU Mes. If not, see . */ -//#include #include static void @@ -27,15 +26,26 @@ mach_startup_info2hurd_startup_data (struct mach_msg_startup_info *info, { data->flags = info->flags; data->dtable = info->dtable; - data->dtablesize = info->dtableType.msgtl_number; + data->dtable_count = info->dtableType.msgtl_number; + + data->argp = info->argv; + data->arg_size = info->argvType.msgtl_number; + + data->envp = info->envp; + data->env_size = info->envpType.msgtl_number; + data->portarray = info->portarray; - data->portarraysize = info->portarrayType.msgtl_number; + data->portarray_count = info->portarrayType.msgtl_number; + data->intarray = info->intarray; - data->intarraysize = info->intarrayType.msgtl_number; + data->intarray_count = info->intarrayType.msgtl_number; + data->stack_base = info->stack_base; - data->stack_size = info->stack_size; + data->stack_count = info->stack_size; + data->phdr = info->phdr; - data->phdrsz = info->phdr_size; + data->phdr_count = info->phdr_size; + data->user_entry = info->user_entry; } diff --git a/lib/gnu/fd-get.c b/lib/gnu/fd-get.c index 23f42b2a..2165c23f 100644 --- a/lib/gnu/fd-get.c +++ b/lib/gnu/fd-get.c @@ -31,7 +31,7 @@ mach_port_t fd_get (int filedes) { - if (filedes >=0 && filedes <= _hurd_dtable_size) + if (filedes >=0 && filedes <= _hurd_dtable_count) return _hurd_dtable[filedes]; return 0; } diff --git a/lib/gnu/hurd-start.c b/lib/gnu/hurd-start.c index fcaaba61..043d676b 100644 --- a/lib/gnu/hurd-start.c +++ b/lib/gnu/hurd-start.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -24,6 +24,8 @@ Copyright (C) 1995-2016 Free Software Foundation, Inc. */ +#include +#include #include #include @@ -34,7 +36,10 @@ struct hurd_startup_data _hurd_startup_data; mach_port_t _hurd_dtable[_HURD_DTABLE_MAX]; -int _hurd_dtable_size; +int _hurd_dtable_count; +size_t __argc; +char *__argv[_HURD_ARGV_MAX]; +char *__envv[_HURD_ENVV_MAX]; void __mach_init (void); @@ -46,7 +51,10 @@ _hurd_start () __task_get_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT, &bootstrap); __exec_startup_get_data (bootstrap, &_hurd_startup_data); - _hurd_dtable_size = _hurd_startup_data.dtablesize; - for (int i = 0; i < _hurd_dtable_size; i++) + _hurd_dtable_count = _hurd_startup_data.dtable_count; + for (int i = 0; i < _hurd_dtable_count; i++) _hurd_dtable[i] = _hurd_startup_data.dtable[i]; + __argc = __argz_extract_count (_hurd_startup_data.argp, _hurd_startup_data.arg_size, __argv); + __argz_extract (_hurd_startup_data.envp, _hurd_startup_data.env_size, __envv); + environ = __envv; } diff --git a/lib/gnu/x86-mes-gcc/crt1.c b/lib/gnu/x86-mes-gcc/crt1.c index 0485c64a..bdab8051 100644 --- a/lib/gnu/x86-mes-gcc/crt1.c +++ b/lib/gnu/x86-mes-gcc/crt1.c @@ -18,26 +18,27 @@ * along with Mes. If not, see . */ -#if 0 -#include -#else // FIXME -#define __MES_LIB_MINI_H 1 +#include char **environ; int __stdin; int __stdout; int __stderr; -#endif + +int main (); +void _exit (int status); void _hurd_start (void); -void _posix_start (void); void _start () { _hurd_start (); - _posix_start (); + __stdin = 0; + __stdout = 1; + __stderr = 2; + int argc = _hurd_startup_data.arg_count; + int r = main (argc, __argv, environ); + _exit (r); + asm ("hlt"); } - -#define _start _posix_start -#include diff --git a/lib/string/argz-count.c b/lib/string/argz-count.c index b5e8e6cd..98f8ceec 100644 --- a/lib/string/argz-count.c +++ b/lib/string/argz-count.c @@ -40,5 +40,3 @@ __argz_count (const char *argz, size_t len) } return count; } - -libc_hidden_def (__argz_count) weak_alias (__argz_count, argz_count) diff --git a/lib/string/argz-extract.c b/lib/string/argz-extract.c index bbf6292c..7175e8dc 100644 --- a/lib/string/argz-extract.c +++ b/lib/string/argz-extract.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright (C) 1995-2018 Free Software Foundation, Inc. + * Copyright © 1995-2018 Free Software Foundation, Inc. + * Copyright © 2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -28,16 +29,23 @@ /* Puts pointers to each string in ARGZ, plus a terminating 0 element, into ARGV, which must be large enough to hold them all. */ void -__argz_extract (const char *argz, size_t len, char **argv) +__argz_extract (char const *argz, size_t len, char **argv) { + __argz_extract_count (argz, len, argv); +} + +size_t +__argz_extract_count (char const *argz, size_t len, char **argv) +{ + size_t count = 0; while (len > 0) { size_t part_len = strlen (argz); *argv++ = (char *) argz; argz += part_len + 1; len -= part_len + 1; + count ++; } *argv = 0; + return count; } - -weak_alias (__argz_extract, argz_extract)