[PATCH gnumach] Unmask irq 12 - fixes stuck console with apic

2023-02-18 Thread Damien Zammit
---
 i386/i386at/model_dep.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index baff8da1..73b99f94 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -177,6 +177,8 @@ void machine_init(void)
 #warning FIXME: Rather unmask them from their respective drivers
/* kd */
unmask_irq(1);
+   /* mouse ? */
+   unmask_irq(12);
/* com0 */
unmask_irq(4);
/* com1 */
--
2.34.1





[PATCH gnumach] model_dep: Call acpi_apic_init if APIC defined

2023-02-18 Thread Damien Zammit
Fixes boot --enable-ncpus=1 with --enable-apic configuration
albeit the keyboard is stuck and network cannot be accessed.

Error messages:

Timeout reached while wating for return value
/bin/console: Could not receive return value from daemon process: Connection 
timed out
---
 i386/i386at/model_dep.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index 5bde5d17..baff8da1 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -162,9 +162,10 @@ void machine_init(void)
 #ifdef MACH_HYP
hyp_init();
 #else  /* MACH_HYP */
-
-#if (NCPUS > 1)
+#if defined(APIC)
acpi_apic_init();
+#endif
+#if (NCPUS > 1)
smp_init();
 #endif
 #if defined(APIC)
--
2.34.1





Re: [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state

2023-02-18 Thread Sergey Bugaev
On Sun, Feb 19, 2023 at 12:34 AM Luca  wrote:
>
> Hi!
>
> Il 18/02/23 21:37, Sergey Bugaev ha scritto:
> > +struct i386_fsgs_base_state {
> > + unsigned long fs_base;
> > + unsigned long gs_base;
> > +};
>
> The fs and gs registers are also set by i386_REGS_SEGS_STATE. If they
> are better set separately (as it seems from the other patch, but I don't
> really know the glibc hurd part) should we remove them from the
> i386_REGS_SEGS_STATE case for x86_64, to avoid conflicts?

Hi!

This state controls fs/gs *base* addresses, not the actual values of
the fs/gs registers. Base addresses are used when you use fs- (or gs-)
relative addressing:

mov %fs, %rbx  // rbx = fs (the register itself)
mov %fs:0x1234, %rax  // rax = memory[fs_base + 0x1234] (the base address)

On i386, fs/gs _base addresses_ are set by setting up some segment
descriptors (no idea if that's the correct term) and placing the
segment selector into the fs/gs *register*. On x86_64, you're
apparently not supposed to use segmentation, and instead there is a
MSR that you write to (and read from?) to access fs and gs base
addresses. I don't know whether fs/gs values actually influence
anything, or are relevant/significant for anything on x86_64. I don't
know how segmentation and MSR values interact / don't conflict when a
x86_64 machine runs i386 code (maybe it's dependent on long mode or
something?).

Should the same i386_fsgs_base_state API be made available on i386? On
the one hand, this seems like a nice abstraction, but on the other
hand userland would not be able to use it anyway out of compatibility
concerns -- even now glibc has two different code paths for kernels
that do or do not support i386_{g,s}et_gdt ...

Please also see this discussion from last week:
https://sourceware.org/pipermail/libc-alpha/2023-February/145516.html

And again, I don't really know anything about this, mabe what I'm
saying makes no sense. That's why I'm asking for feedback: whether
this API looks reasonable or not.

Sergey



Re: [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state

2023-02-18 Thread Luca

Hi!

Il 18/02/23 21:37, Sergey Bugaev ha scritto:

+struct i386_fsgs_base_state {
+   unsigned long fs_base;
+   unsigned long gs_base;
+};


The fs and gs registers are also set by i386_REGS_SEGS_STATE. If they 
are better set separately (as it seems from the other patch, but I don't 
really know the glibc hurd part) should we remove them from the 
i386_REGS_SEGS_STATE case for x86_64, to avoid conflicts?


Luca




[RFC PATCH 4/9] hurd: Make timer_t pointer-sized

2023-02-18 Thread Sergey Bugaev
This ensures that a timer_t value can be cast to struct timer_node *
and back.

Signed-off-by: Sergey Bugaev 
---
 sysdeps/mach/hurd/bits/typesizes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/mach/hurd/bits/typesizes.h 
b/sysdeps/mach/hurd/bits/typesizes.h
index 725a0cb1..7b95bb0b 100644
--- a/sysdeps/mach/hurd/bits/typesizes.h
+++ b/sysdeps/mach/hurd/bits/typesizes.h
@@ -54,7 +54,7 @@
 #define __DADDR_T_TYPE __S32_TYPE
 #define __KEY_T_TYPE   __S32_TYPE
 #define __CLOCKID_T_TYPE   __S32_TYPE
-#define __TIMER_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE __UWORD_TYPE
 #define __BLKSIZE_T_TYPE   __SLONGWORD_TYPE
 #define __FSID_T_TYPE  __UQUAD_TYPE
 #define __SSIZE_T_TYPE __SWORD_TYPE
-- 
2.39.2




[RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code

2023-02-18 Thread Sergey Bugaev
Signed-off-by: Sergey Bugaev 
---
 sysdeps/mach/hurd/x86/init-first.c  |  14 +-
 sysdeps/mach/hurd/x86_64/tls.h  | 257 
 sysdeps/mach/x86_64/thread_state.h  |  51 
 sysdeps/x86_64/htl/bits/pthreadtypes-arch.h |  36 +++
 sysdeps/x86_64/htl/pt-machdep.h |  28 +++
 5 files changed, 385 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/mach/hurd/x86_64/tls.h
 create mode 100644 sysdeps/mach/x86_64/thread_state.h
 create mode 100644 sysdeps/x86_64/htl/bits/pthreadtypes-arch.h
 create mode 100644 sysdeps/x86_64/htl/pt-machdep.h

diff --git a/sysdeps/mach/hurd/x86/init-first.c 
b/sysdeps/mach/hurd/x86/init-first.c
index 75ac1ff2..d4e6a4d6 100644
--- a/sysdeps/mach/hurd/x86/init-first.c
+++ b/sysdeps/mach/hurd/x86/init-first.c
@@ -43,8 +43,14 @@ extern char **__libc_argv attribute_hidden;
 extern char **_dl_argv;
 
 #ifndef SHARED
-unsigned short __init1_desc;
 static tcbhead_t __init1_tcbhead;
+# ifndef __x86_64__
+unsigned short __init1_desc;
+# endif
+#endif
+
+#ifdef __x86_64__
+unsigned char __libc_tls_initialized;
 #endif
 
 /* Things that want to be run before _hurd_init or much anything else.
@@ -248,7 +254,13 @@ first_init (void)
   /* In the static case, we need to set up TLS early so that the stack
  protection guard can be read at gs:0x14 by the gcc-generated snippets.  */
   _hurd_tls_init (&__init1_tcbhead);
+
+  /* Make sure __LIBC_NO_TLS () keeps evaluating to 1.  */
+# ifdef __x86_64__
+  __libc_tls_initialized = 0;
+# else
   asm ("movw %%gs,%w0" : "=m" (__init1_desc));
+# endif
 #endif
 
   RUN_RELHOOK (_hurd_preinit_hook, ());
diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h
new file mode 100644
index ..644dcb1a
--- /dev/null
+++ b/sysdeps/mach/hurd/x86_64/tls.h
@@ -0,0 +1,257 @@
+/* Definitions for thread-local data handling.  Hurd/x86_64 version.
+   Copyright (C) 2003-2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   .  */
+
+#ifndef _X86_64_TLS_H
+#define _X86_64_TLS_H
+
+
+/* Some things really need not be machine-dependent.  */
+#include 
+
+
+#ifndef __ASSEMBLER__
+# include 
+# include 
+# include 
+# include 
+
+/* Type of the TCB.  */
+typedef struct
+{
+  void *tcb;   /* Points to this structure.  */
+  dtv_t *dtv;  /* Vector of pointers to TLS data.  */
+  thread_t self;   /* This thread's control port.  */
+  int __glibc_padding1;
+  int multiple_threads;
+  int gscope_flag;
+  uintptr_t sysinfo;
+  uintptr_t stack_guard;
+  uintptr_t pointer_guard;
+  long __glibc_padding2[2];
+  int private_futex;
+  int __glibc_padding3;
+  /* Reservation of some values for the TM ABI.  */
+  void *__private_tm[4];
+  /* GCC split stack support.  */
+  void *__private_ss;
+  /* The lowest address of shadow stack.  */
+  unsigned long long int ssp_base;
+
+  /* Keep these fields last, so offsets of fields above can continue being
+ compatible with the x86_64 NPTL version.  */
+  mach_port_t reply_port;  /* This thread's reply port.  */
+  struct hurd_sigstate *_hurd_sigstate;
+
+  /* Used by the exception handling implementation in the dynamic loader.  */
+  struct rtld_catch *rtld_catch;
+} tcbhead_t;
+
+/* GCC generates %fs:0x28 to access the stack guard.  */
+_Static_assert (offsetof (tcbhead_t, stack_guard) == 0x28,
+"stack guard offset");
+/* libgcc uses %fs:0x70 to access the split stack pointer.  */
+_Static_assert (offsetof (tcbhead_t, __private_ss) == 0x70,
+"split stack pointer offset");
+
+extern unsigned char __libc_tls_initialized;
+# define __LIBC_NO_TLS() __builtin_expect (!__libc_tls_initialized, 0)
+
+/* The TCB can have any size and the memory following the address the
+   thread pointer points to is unspecified.  Allocate the TCB there.  */
+# define TLS_TCB_AT_TP 1
+# define TLS_DTV_AT_TP 0
+
+# define TCB_ALIGNMENT 64
+
+
+# define TLS_INIT_TP(descr) _hurd_tls_init ((tcbhead_t *) (descr))
+
+# if __GNUC_PREREQ (6, 0)
+
+#  define THREAD_SELF  \
+  (*(tcbhead_t * __seg_fs *) offsetof (tcbhead_t, tcb))
+#  define THREAD_GETMEM(descr, member) \
+  (*(__typeof (descr->member) __seg_fs *) offsetof 

[RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state

2023-02-18 Thread Sergey Bugaev
---
 i386/include/mach/i386/thread_status.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/i386/include/mach/i386/thread_status.h 
b/i386/include/mach/i386/thread_status.h
index 3de22ff3..32e40686 100644
--- a/i386/include/mach/i386/thread_status.h
+++ b/i386/include/mach/i386/thread_status.h
@@ -57,6 +57,7 @@
 #definei386_V86_ASSIST_STATE   4
 #definei386_REGS_SEGS_STATE5
 #definei386_DEBUG_STATE6
+#definei386_FSGS_BASE_STATE7
 
 /*
  * This structure is used for both
@@ -179,4 +180,11 @@ struct i386_debug_state {
 #definei386_DEBUG_STATE_COUNT \
(sizeof(struct i386_debug_state)/sizeof(unsigned int))
 
+struct i386_fsgs_base_state {
+   unsigned long fs_base;
+   unsigned long gs_base;
+};
+#define i386_FSGS_BASE_STATE_COUNT \
+   (sizeof(struct i386_fsgs_base_state)/sizeof(unsigned int))
+
 #endif /* _MACH_I386_THREAD_STATUS_H_ */
-- 
2.39.2




[RFC PATCH 6/9] mach: Use PAGE_SIZE

2023-02-18 Thread Sergey Bugaev
The PAGE_SIZE from the Mach headers statically defines the machine's
page size. There's no need to query it dynamically; furthermore, the
implementation of the vm_statistics () RPC unconditionally fills in

pagesize = PAGE_SIZE;

Not doing the extra RPC shaves off 2 RPCs from the start-up of every
process!

Signed-off-by: Sergey Bugaev 
---
 mach/mach_init.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mach/mach_init.c b/mach/mach_init.c
index a0d9f7f5..42b9cacf 100644
--- a/mach/mach_init.c
+++ b/mach/mach_init.c
@@ -17,6 +17,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 mach_port_t __mach_task_self_;
@@ -38,7 +39,10 @@ __mach_init (void)
   __mach_host_self_ = (__mach_host_self) ();
   __mig_init (0);
 
-#ifdef HAVE_HOST_PAGE_SIZE
+#ifdef PAGE_SIZE
+  __vm_page_size = PAGE_SIZE;
+  (void) err;
+#elif defined (HAVE_HOST_PAGE_SIZE)
   if (err = __host_page_size (__mach_host_self (), &__vm_page_size))
 _exit (err);
 #else
-- 
2.39.2




[RFC PATCH 3/9] hurd: Fix xattr function return type

2023-02-18 Thread Sergey Bugaev
They all return int, not size_t.

Signed-off-by: Sergey Bugaev 
---
 sysdeps/mach/hurd/fsetxattr.c| 2 +-
 sysdeps/mach/hurd/lremovexattr.c | 2 +-
 sysdeps/mach/hurd/lsetxattr.c| 2 +-
 sysdeps/mach/hurd/removexattr.c  | 2 +-
 sysdeps/mach/hurd/setxattr.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/mach/hurd/fsetxattr.c b/sysdeps/mach/hurd/fsetxattr.c
index 71ee7599..dcc48fa0 100644
--- a/sysdeps/mach/hurd/fsetxattr.c
+++ b/sysdeps/mach/hurd/fsetxattr.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 
-ssize_t
+int
 fsetxattr (int fd, const char *name, const void *value, size_t size, int flags)
 {
   error_t err;
diff --git a/sysdeps/mach/hurd/lremovexattr.c b/sysdeps/mach/hurd/lremovexattr.c
index 1d761e2d..cb6a1f8f 100644
--- a/sysdeps/mach/hurd/lremovexattr.c
+++ b/sysdeps/mach/hurd/lremovexattr.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 
-ssize_t
+int
 lremovexattr (const char *path, const char *name)
 {
   error_t err;
diff --git a/sysdeps/mach/hurd/lsetxattr.c b/sysdeps/mach/hurd/lsetxattr.c
index 56c138dc..4e1e2de2 100644
--- a/sysdeps/mach/hurd/lsetxattr.c
+++ b/sysdeps/mach/hurd/lsetxattr.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 
-ssize_t
+int
 lsetxattr (const char *path, const char *name, const void *value, size_t size,
   int flags)
 {
diff --git a/sysdeps/mach/hurd/removexattr.c b/sysdeps/mach/hurd/removexattr.c
index 128d0e01..fedc5370 100644
--- a/sysdeps/mach/hurd/removexattr.c
+++ b/sysdeps/mach/hurd/removexattr.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 
-ssize_t
+int
 removexattr (const char *path, const char *name)
 {
   error_t err;
diff --git a/sysdeps/mach/hurd/setxattr.c b/sysdeps/mach/hurd/setxattr.c
index be3b172b..ba6047cd 100644
--- a/sysdeps/mach/hurd/setxattr.c
+++ b/sysdeps/mach/hurd/setxattr.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 
-ssize_t
+int
 setxattr (const char *path, const char *name, const void *value, size_t size,
  int flags)
 {
-- 
2.39.2




[RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new ()

2023-02-18 Thread Sergey Bugaev
This is going to be done differently on x86_64.

Signed-off-by: Sergey Bugaev 
---
 mach/setup-thread.c  | 18 ++
 sysdeps/mach/hurd/i386/tls.h | 25 -
 2 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/mach/setup-thread.c b/mach/setup-thread.c
index 6ce5c13d..ae24a149 100644
--- a/mach/setup-thread.c
+++ b/mach/setup-thread.c
@@ -83,25 +83,11 @@ weak_alias (__mach_setup_thread, mach_setup_thread)
 kern_return_t
 __mach_setup_tls (thread_t thread)
 {
-  kern_return_t error;
-  struct machine_thread_state ts;
-  mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
-  tcbhead_t *tcb;
-
-  tcb = _dl_allocate_tls (NULL);
+  tcbhead_t *tcb = _dl_allocate_tls (NULL);
   if (tcb == NULL)
 return KERN_RESOURCE_SHORTAGE;
 
-  if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR,
-(natural_t *) , ))
-return error;
-  assert (tssize == MACHINE_THREAD_STATE_COUNT);
-
-  _hurd_tls_new (thread, , tcb);
-
-  error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
- (natural_t *) , tssize);
-  return error;
+  return _hurd_tls_new (thread, tcb);
 }
 
 weak_alias (__mach_setup_tls, mach_setup_tls)
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 590abd47..0f8dd241 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -378,16 +378,25 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct 
i386_thread_state *state)
 }
 
 static inline kern_return_t __attribute__ ((unused))
-_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
+_hurd_tls_new (thread_t child, tcbhead_t *tcb)
 {
+  error_t err;
+  /* Fetch the target thread's state.  */
+  struct i386_thread_state state;
+  mach_msg_type_number_t state_count = i386_THREAD_STATE_COUNT;
+  err = __thread_get_state (child, i386_REGS_SEGS_STATE,
+(thread_state_t) ,
+_count);
+  if (err)
+return err;
+  assert (state_count == i386_THREAD_STATE_COUNT);
   /* Fetch the selector set by _hurd_tls_init.  */
   int sel;
   asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
-  if (sel == state->ds)/* _hurd_tls_init was never called.  */
+  if (sel == state.ds) /* _hurd_tls_init was never called.  */
 return 0;
 
   HURD_TLS_DESC_DECL (desc, tcb);
-  error_t err;
 
   tcb->tcb = tcb;
   tcb->self = child;
@@ -397,8 +406,14 @@ _hurd_tls_new (thread_t child, struct i386_thread_state 
*state, tcbhead_t *tcb)
   else
 err = __i386_set_gdt (child, , desc);
 
-  state->gs = sel;
-  return err;
+  if (err)
+return err;
+
+  /* Update gs to use the selector.  */
+  state.gs = sel;
+  return __thread_set_state (child, i386_REGS_SEGS_STATE,
+ (thread_state_t) ,
+ state_count);
 }
 
 /* Global scope switch support.  */
-- 
2.39.2




[RFC PATCH 2/9] hurd: Use proper integer types

2023-02-18 Thread Sergey Bugaev
Fix a few more cases of build errors caused by mismatched types. This is a
continuation of f4315054b46d5e58b44a709a51943fb73f846afb.

Signed-off-by: Sergey Bugaev 
---
 hurd/hurdsig.c  | 6 +++---
 sysdeps/mach/hurd/getpriority.c | 6 +++---
 sysdeps/mach/hurd/if_index.c| 2 +-
 sysdeps/mach/hurd/ifreq.c   | 2 +-
 sysdeps/mach/hurd/readdir64.c   | 4 +++-
 sysdeps/mach/hurd/readdir64_r.c | 4 +++-
 6 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 56e8e614..ea79ffb5 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -430,8 +430,8 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, 
int sigthread,
  receive completes immediately or aborts.  */
   abort_thread (ss, state, reply);
 
-  if (state->basic.PC >= (natural_t) &_hurd_intr_rpc_msg_about_to
-  && state->basic.PC < (natural_t) &_hurd_intr_rpc_msg_in_trap)
+  if (state->basic.PC >= (uintptr_t) &_hurd_intr_rpc_msg_about_to
+  && state->basic.PC < (uintptr_t) &_hurd_intr_rpc_msg_in_trap)
 {
   /* The thread is about to do the RPC, but hasn't yet entered
 mach_msg.  Mutate the thread's state so it knows not to try
@@ -442,7 +442,7 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, 
int sigthread,
   state->basic.SYSRETURN = MACH_SEND_INTERRUPTED;
   *state_change = 1;
 }
-  else if (state->basic.PC == (natural_t) &_hurd_intr_rpc_msg_in_trap
+  else if (state->basic.PC == (uintptr_t) &_hurd_intr_rpc_msg_in_trap
   /* The thread was blocked in the system call.  After thread_abort,
  the return value register indicates what state the RPC was in
  when interrupted.  */
diff --git a/sysdeps/mach/hurd/getpriority.c b/sysdeps/mach/hurd/getpriority.c
index 9869c2f5..45b32215 100644
--- a/sysdeps/mach/hurd/getpriority.c
+++ b/sysdeps/mach/hurd/getpriority.c
@@ -30,7 +30,7 @@ __getpriority (enum __priority_which which, id_t who)
   int maxpri = INT_MIN;
   struct procinfo *pip;/* Just for sizeof.  */
   int pibuf[sizeof *pip + 2 * sizeof (pip->threadinfos[0])], *pi = pibuf;
-  size_t pisize = sizeof pibuf / sizeof pibuf[0];
+  mach_msg_type_number_t pisize = sizeof pibuf / sizeof pibuf[0];
 
   error_t getonepriority (pid_t pid, struct procinfo *pip)
 {
@@ -39,9 +39,9 @@ __getpriority (enum __priority_which which, id_t who)
   else
{
  int *oldpi = pi;
- size_t oldpisize = pisize;
+ mach_msg_type_number_t oldpisize = pisize;
  char *tw = 0;
- size_t twsz = 0;
+ mach_msg_type_number_t twsz = 0;
  int flags = PI_FETCH_TASKINFO;
  onerr = __USEPORT (PROC, __proc_getprocinfo (port, pid, ,
   , ,
diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c
index a4472269..c8ad7e72 100644
--- a/sysdeps/mach/hurd/if_index.c
+++ b/sysdeps/mach/hurd/if_index.c
@@ -99,7 +99,7 @@ __if_nameindex (void)
 nifs = 0;
   else
 {
-  size_t len = sizeof data;
+  mach_msg_type_number_t len = sizeof data;
   err = __pfinet_siocgifconf (server, -1, _buf, );
   if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED)
{
diff --git a/sysdeps/mach/hurd/ifreq.c b/sysdeps/mach/hurd/ifreq.c
index ef210c32..394d020c 100644
--- a/sysdeps/mach/hurd/ifreq.c
+++ b/sysdeps/mach/hurd/ifreq.c
@@ -37,7 +37,7 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
   else
 {
   char *data = NULL;
-  size_t len = 0;
+  mach_msg_type_number_t len = 0;
   error_t err = __pfinet_siocgifconf (server, -1, , );
   if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED)
{
diff --git a/sysdeps/mach/hurd/readdir64.c b/sysdeps/mach/hurd/readdir64.c
index 47829d9e..cf98bbb1 100644
--- a/sysdeps/mach/hurd/readdir64.c
+++ b/sysdeps/mach/hurd/readdir64.c
@@ -43,12 +43,13 @@ __readdir64 (DIR *dirp)
  /* We've emptied out our buffer.  Refill it.  */
 
  char *data = dirp->__data;
+ mach_msg_type_number_t data_size = dirp->__size;
  int nentries;
  error_t err;
 
  if (err = HURD_FD_PORT_USE (dirp->__fd,
  __dir_readdir (port,
-, >__size,
+, _size,
 dirp->__entry_ptr,
 -1, 0, )))
{
@@ -57,6 +58,7 @@ __readdir64 (DIR *dirp)
  break;
}
 
+  dirp->__size = data_size;
  /* DATA now corresponds to entry index DIRP->__entry_ptr.  */
  dirp->__entry_data = dirp->__entry_ptr;
 
diff --git a/sysdeps/mach/hurd/readdir64_r.c b/sysdeps/mach/hurd/readdir64_r.c
index 7e438aaf..4f4252c2 100644
--- a/sysdeps/mach/hurd/readdir64_r.c
+++ b/sysdeps/mach/hurd/readdir64_r.c
@@ -45,11 +45,12 @@ 

[RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64

2023-02-18 Thread Sergey Bugaev
Signed-off-by: Sergey Bugaev 
---
 sysdeps/mach/hurd/{i386 => x86}/init-first.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
 rename sysdeps/mach/hurd/{i386 => x86}/init-first.c (96%)

diff --git a/sysdeps/mach/hurd/i386/init-first.c 
b/sysdeps/mach/hurd/x86/init-first.c
similarity index 96%
rename from sysdeps/mach/hurd/i386/init-first.c
rename to sysdeps/mach/hurd/x86/init-first.c
index a558da16..75ac1ff2 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/x86/init-first.c
@@ -227,10 +227,15 @@ init (int *data)
values we set just above.  We have stashed in %eax the user code
return address.  Push it on the top of the stack so it acts as
init1's return address, and then jump there.  */
+#ifdef __x86_64__
+asm ("call_init1:\n"
+ "  push %rax\n"
+ "  jmp *%rcx\n");
+#else
 asm ("call_init1:\n"
  " push %eax\n"
  " jmp *%ecx\n");
-
+#endif
 
 /* Do the first essential initializations that must precede all else.  */
 static inline void
@@ -242,7 +247,7 @@ first_init (void)
 #ifndef SHARED
   /* In the static case, we need to set up TLS early so that the stack
  protection guard can be read at gs:0x14 by the gcc-generated snippets.  */
-  _hurd_tls_init(&__init1_tcbhead);
+  _hurd_tls_init (&__init1_tcbhead);
   asm ("movw %%gs,%w0" : "=m" (__init1_desc));
 #endif
 
@@ -300,7 +305,7 @@ _hurd_stack_setup (void)
{
  /* If we use ``__builtin_frame_address (0) + 2'' here, GCC gets
 confused.  */
- init ((int *) );
+ init ();
}
 
   /* Push the user return address after the argument data, and then
@@ -308,9 +313,15 @@ _hurd_stack_setup (void)
 caller had called `doinit1' with the argument data already on the
 stack.  */
   *--data = caller;
+# ifdef __x86_64__
+  asm volatile ("movq %0, %%rsp\n" /* Switch to new outermost stack.  */
+"movq $0, %%rbp\n" /* Clear outermost frame pointer.  */
+"jmp *%1" : : "r" (data), "r" ());
+# else
   asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack.  */
"movl $0, %%ebp\n" /* Clear outermost frame pointer.  */
"jmp *%1" : : "r" (data), "r" ());
+# endif
   /* NOTREACHED */
 }
 
-- 
2.39.2




[RFC PATCH 5/9] hurd: Simplify init-first.c a bit

2023-02-18 Thread Sergey Bugaev
And make it a bit more 64-bit ready. This is in preparation to moving this
file into x86/

Signed-off-by: Sergey Bugaev 
---
 sysdeps/mach/hurd/i386/init-first.c | 23 +++
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/sysdeps/mach/hurd/i386/init-first.c 
b/sysdeps/mach/hurd/i386/init-first.c
index 94c94651..a558da16 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -195,7 +195,7 @@ init (int *data)
   /* Call `init1' (above) with the user code as the return address, and the
  argument data immediately above that on the stack.  */
 
-  int usercode;
+  void *usercode, **ret_address;
 
   void call_init1 (void);
 
@@ -206,10 +206,11 @@ init (int *data)
  recognize that this read operation may alias the following write
  operation, and thus is free to reorder the two, clobbering the
  original return address.  */
-  usercode = *((int *) __builtin_frame_address (0) + 1);
+  ret_address = (void **) __builtin_frame_address (0) + 1;
+  usercode = *ret_address;
   /* GCC 4.4.6 also wants us to force loading USERCODE already here.  */
   asm volatile ("# %0" : : "X" (usercode));
-  *((void **) __builtin_frame_address (0) + 1) = _init1;
+  *ret_address = _init1;
   /* Force USERCODE into %eax and  into %ecx, which are not
  restored by function return.  */
   asm volatile ("# a %0 c %1" : : "a" (usercode), "c" ());
@@ -223,19 +224,9 @@ init (int *data)
 /* The return address of `init' above, was redirected to here, so at
this point our stack is unwound and callers' registers restored.
Only %ecx and %eax are call-clobbered and thus still have the
-   values we set just above.  Fetch from there the new stack pointer
-   we will run on, and jmp to the run-time address of `init1'; when it
-   returns, it will run the user code with the argument data at the
-   top of the stack.  */
-asm ("switch_stacks:\n"
- " movl %eax, %esp\n"
- " jmp *%ecx");
-
-/* As in the stack-switching case, at this point our stack is unwound
-   and callers' registers restored, and only %ecx and %eax communicate
-   values from the lines above.  In this case we have stashed in %eax
-   the user code return address.  Push it on the top of the stack so
-   it acts as init1's return address, and then jump there.  */
+   values we set just above.  We have stashed in %eax the user code
+   return address.  Push it on the top of the stack so it acts as
+   init1's return address, and then jump there.  */
 asm ("call_init1:\n"
  " push %eax\n"
  " jmp *%ecx\n");
-- 
2.39.2




[RFC PATCH 0/9] More x86_64-gnu glibc work

2023-02-18 Thread Sergey Bugaev
Hello,

here's some more work on the x86_64-gnu glibc port. Large parts of glibc
(almost all of it?) builds, in particular mach/subdir_lib builds cleanly.

Patch 6 is really unrelated to the rest of the changes, it's just a small thing
that I've noticed while single-stepping through glibc startup, trying to
understand which order things are getting called in, and from where.

Patch 8/9 adds i386_fsgs_base_state to Mach headers. Does this look reasonable?
I have not written an implementation. Any volunteers? :)

Then patch 9/9 adds a fairly complete implementation of tls.h based on that
API. It turned out that thread_state.h did not need large changes compared to
the i386 version after all, so consider applying Flavio's patch ("Define PC, SP
and SYSRETURN for hurd x86_64") instead of the version my patch adds (but keep
the rest of my patch).

I'm not super sure that the thing I've done with __libc_tls_initialized is
correct / makes sense; please do take a look!

Large parts remaining:
* ucontext / sigcontext
* intr_msg / signal trampoline

Sergey



[sr #110199] Cross-building of GNU/Hurd and additional packages

2023-02-18 Thread Svante Signell
Follow-up Comment #37, sr #110199 (project administration):

Hello,

Thank you for your reply. If I understand correctly all files under the BSD-3
licence have to contain a copy of the license text. Secondly for other
licences every file has to carry a copyright and license notice.

All of the above applies to files longer that 10 lines, according to the link
you gave above. What to do with such files?

I made an attempt to add a copyright file in every directory, listing all
files with their copyright and license information. This is what Debian does
for their packages. This solution does not seem to be accepted, right? Please
confirm and I'll make all changes according to your wishes. (Even if very
small files, > 10 lines, are cluttered with the license and copyright
information, making them harder to read). 

Thanks!


___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.nongnu.org/