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.
This commit is contained in:
Jan Nieuwenhuizen 2019-03-13 03:51:44 -04:00
parent 72c76d6b3a
commit 67d82a6de5
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
10 changed files with 83 additions and 37 deletions

View file

@ -63,6 +63,7 @@ lib/mach/mach_reply_port.S
lib/mach/mach_task_self.S lib/mach/mach_task_self.S
lib/mach/mach_thread_self.S lib/mach/mach_thread_self.S
lib/mach/msg.c lib/mach/msg.c
lib/string/argz-extract.c
" "
fi fi
fi fi

View file

@ -29,13 +29,11 @@
#else // ! SYSTEM_LIBC #else // ! SYSTEM_LIBC
#ifndef libc_hidden_def #include <mes/lib-mini.h>
#define libc_hidden_def(x)
#define weak_alias(x,y)
#endif
size_t __argz_count (char const *argz, size_t len); size_t __argz_count (char const *argz, size_t len);
void __argz_extract (char const *argz, size_t len, char **argv); 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 #endif // ! SYSTEM_LIBC

View file

@ -41,24 +41,42 @@ typedef off64_t loff_t;
struct hurd_startup_data struct hurd_startup_data
{ {
int flags; int flags;
mach_port_t *dtable; 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_port_t *portarray;
mach_msg_type_number_t portarraysize; mach_msg_type_number_t portarray_count;
int *intarray; int *intarray;
mach_msg_type_number_t intarraysize; mach_msg_type_number_t intarray_count;
vm_address_t stack_base; vm_address_t stack_base;
vm_size_t stack_size; vm_size_t stack_count;
vm_address_t phdr; vm_address_t phdr;
vm_size_t phdrsz; vm_size_t phdr_count;
vm_address_t user_entry; vm_address_t user_entry;
}; };
#define _HURD_DTABLE_MAX 1024 #define _HURD_DTABLE_MAX 1024
extern mach_port_t _hurd_dtable[_HURD_DTABLE_MAX]; 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; 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); 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_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); error_t fd_read (mach_port_t port, void *buffer, size_t *size, loff_t offset);

View file

@ -34,5 +34,9 @@ _exit (int status)
{ {
__proc_mark_exit (_hurd_startup_data.portarray[INIT_PORT_PROC], status, 0); __proc_mark_exit (_hurd_startup_data.portarray[INIT_PORT_PROC], status, 0);
__task_terminate (__mach_task_self ()); __task_terminate (__mach_task_self ());
#if 0 // FIXME: this was needed?
while (1) {* (int *) 0 = 0;} while (1) {* (int *) 0 = 0;}
#else
asm ("hlt");
#endif
} }

View file

@ -18,7 +18,6 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
//#include <gnu/hurd.h>
#include <gnu/syscall.h> #include <gnu/syscall.h>
static void static void
@ -27,15 +26,26 @@ mach_startup_info2hurd_startup_data (struct mach_msg_startup_info *info,
{ {
data->flags = info->flags; data->flags = info->flags;
data->dtable = info->dtable; 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->portarray = info->portarray;
data->portarraysize = info->portarrayType.msgtl_number; data->portarray_count = info->portarrayType.msgtl_number;
data->intarray = info->intarray; 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_base = info->stack_base;
data->stack_size = info->stack_size; data->stack_count = info->stack_size;
data->phdr = info->phdr; data->phdr = info->phdr;
data->phdrsz = info->phdr_size; data->phdr_count = info->phdr_size;
data->user_entry = info->user_entry; data->user_entry = info->user_entry;
} }

View file

@ -31,7 +31,7 @@
mach_port_t mach_port_t
fd_get (int filedes) fd_get (int filedes)
{ {
if (filedes >=0 && filedes <= _hurd_dtable_size) if (filedes >=0 && filedes <= _hurd_dtable_count)
return _hurd_dtable[filedes]; return _hurd_dtable[filedes];
return 0; return 0;
} }

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -24,6 +24,8 @@
Copyright (C) 1995-2016 Free Software Foundation, Inc. Copyright (C) 1995-2016 Free Software Foundation, Inc.
*/ */
#include <mes/lib-mini.h>
#include <argz.h>
#include <gnu/hurd.h> #include <gnu/hurd.h>
#include <gnu/syscall.h> #include <gnu/syscall.h>
@ -34,7 +36,10 @@
struct hurd_startup_data _hurd_startup_data; struct hurd_startup_data _hurd_startup_data;
mach_port_t _hurd_dtable[_HURD_DTABLE_MAX]; 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); void __mach_init (void);
@ -46,7 +51,10 @@ _hurd_start ()
__task_get_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT, __task_get_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT,
&bootstrap); &bootstrap);
__exec_startup_get_data (bootstrap, &_hurd_startup_data); __exec_startup_get_data (bootstrap, &_hurd_startup_data);
_hurd_dtable_size = _hurd_startup_data.dtablesize; _hurd_dtable_count = _hurd_startup_data.dtable_count;
for (int i = 0; i < _hurd_dtable_size; i++) for (int i = 0; i < _hurd_dtable_count; i++)
_hurd_dtable[i] = _hurd_startup_data.dtable[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;
} }

View file

@ -18,26 +18,27 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>. * along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#if 0 #include <gnu/hurd.h>
#include <mes/lib-mini.h>
#else // FIXME
#define __MES_LIB_MINI_H 1
char **environ; char **environ;
int __stdin; int __stdin;
int __stdout; int __stdout;
int __stderr; int __stderr;
#endif
int main ();
void _exit (int status);
void _hurd_start (void); void _hurd_start (void);
void _posix_start (void);
void void
_start () _start ()
{ {
_hurd_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 <linux/x86-mes-gcc/crt1.c>

View file

@ -40,5 +40,3 @@ __argz_count (const char *argz, size_t len)
} }
return count; return count;
} }
libc_hidden_def (__argz_count) weak_alias (__argz_count, argz_count)

View file

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * 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 <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -28,16 +29,23 @@
/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into /* Puts pointers to each string in ARGZ, plus a terminating 0 element, into
ARGV, which must be large enough to hold them all. */ ARGV, which must be large enough to hold them all. */
void 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) while (len > 0)
{ {
size_t part_len = strlen (argz); size_t part_len = strlen (argz);
*argv++ = (char *) argz; *argv++ = (char *) argz;
argz += part_len + 1; argz += part_len + 1;
len -= part_len + 1; len -= part_len + 1;
count ++;
} }
*argv = 0; *argv = 0;
return count;
} }
weak_alias (__argz_extract, argz_extract)