Re: [PATCH 2/2] Add thread_set_name RPC.

2024-02-12 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le lun. 12 févr. 2024 01:26:34 -0500, a ecrit:
> Like task_set_name, we use the same size as the task name and will
> inherit the task name, whenever it exists. This will be used to
> implement pthread_setname_np.
> ---
>  ddb/db_print.c|  9 +
>  include/mach/gnumach.defs |  8 
>  kern/thread.c | 20 
>  kern/thread.h |  8 
>  4 files changed, 41 insertions(+), 4 deletions(-)
> 
> diff --git a/ddb/db_print.c b/ddb/db_print.c
> index c8d85d2..f08dd6c 100644
> --- a/ddb/db_print.c
> +++ b/ddb/db_print.c
> @@ -222,10 +222,11 @@ db_print_thread(
>   }
>   } else {
>   if (flag & OPTION_INDENT)
> - db_printf("%3d (%0*X) ", thread_id,
> -   2*sizeof(vm_offset_t), thread);
> - else
> - db_printf("(%0*X) ", 2*sizeof(vm_offset_t), thread);
> + db_printf("%3d ", thread_id);
> + if (thread->name[0] &&
> + strncmp (thread->name, thread->task->name, THREAD_NAME_SIZE))
> + db_printf("%s ", thread->name);
> + db_printf("(%0*X) ", 2*sizeof(vm_offset_t), thread);
>   char status[8];
>   db_printf("%s", db_thread_stat(thread, status));
>   if (thread->state & TH_SWAPPED) {
> diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs
> index 6252de9..7ecf74d 100644
> --- a/include/mach/gnumach.defs
> +++ b/include/mach/gnumach.defs
> @@ -207,3 +207,11 @@ routine vm_pages_phys(
>   vaddr   : vm_address_t;
>   size: vm_size_t;
>   out pages   : rpc_phys_addr_array_t);
> +
> +/*
> + *   Set the name of thread THREAD to NAME.  This is a debugging aid.
> + *   NAME will be used in error messages printed by the kernel.
> + */
> +simpleroutine thread_set_name(
> + thread  : thread_t;
> + name: kernel_debug_name_t);
> diff --git a/kern/thread.c b/kern/thread.c
> index 23ee8b0..2eab1ca 100644
> --- a/kern/thread.c
> +++ b/kern/thread.c
> @@ -46,6 +46,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -551,6 +552,10 @@ kern_return_t thread_create(
>  #endif   /* MACH_PCSAMPLE */
>  
>   new_thread->pc_sample.buffer = 0;
> +
> + /* Inherit the task name as the thread name. */
> + memcpy (new_thread->name, parent_task->name, THREAD_NAME_SIZE);
> +
>   /*
>*  Add the thread to the task`s list of threads.
>*  The new thread holds another reference to the task.
> @@ -2624,3 +2629,18 @@ thread_stats(void)
>   printf("%d using rpc_reply.\n", rpcreply);
>  }
>  #endif   /* MACH_DEBUG */
> +
> +/*
> + *   thread_set_name
> + *
> + *   Set the name of thread THREAD to NAME.
> + */
> +kern_return_t
> +thread_set_name(
> + thread_tthread,
> + const_kernel_debug_name_t   name)
> +{
> + strncpy(thread->name, name, sizeof thread->name - 1);
> + thread->name[sizeof thread->name - 1] = '\0';
> + return KERN_SUCCESS;
> +}
> diff --git a/kern/thread.h b/kern/thread.h
> index 7bfe2e8..21b2503 100644
> --- a/kern/thread.h
> +++ b/kern/thread.h
> @@ -54,6 +54,12 @@
>  #include 
>  #include 
>  
> +/*
> + * Thread name buffer size. Use the same size as the task so
> + * the thread can inherit the task's name.
> + */
> +#define THREAD_NAME_SIZE TASK_NAME_SIZE
> +
>  struct thread {
>   /* Run queues */
>   queue_chain_t   links;  /* current run queue links */
> @@ -232,6 +238,8 @@ struct thread {
>  #if  MACH_LOCK_MON
>   unsigned lock_stack;
>  #endif
> +
> + charname[THREAD_NAME_SIZE];
>  };
>  
>  #include 
> -- 
> 2.39.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



Re: [PATCH gnumach] smp: Set processor set to non-empty when adding a processor

2024-02-12 Thread Samuel Thibault
Applied, thanks!

Damien Zammit, le lun. 12 févr. 2024 05:38:24 +, a ecrit:
> This allows the slave_pset to be used for actual tasks
> with the processor_set RPCs.
> ---
>  kern/processor.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kern/processor.c b/kern/processor.c
> index f06b5d62..71bbb757 100644
> --- a/kern/processor.c
> +++ b/kern/processor.c
> @@ -245,6 +245,7 @@ void pset_add_processor(
>   queue_enter(&pset->processors, processor, processor_t, processors);
>   processor->processor_set = pset;
>   pset->processor_count++;
> + pset->empty = FALSE;
>   quantum_set(pset);
>  }
>  
> -- 
> 2.43.0
> 
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



[PATCH] Port GDB to Hurd x86_64.

2024-02-12 Thread Flavio Cruz
This port extends the existing i686 port to support x86_64 by trying to
reuse existing code whenever it makes sense.

* gdb/amd64-gnu-tdep.c: Adds logic for handling signal frames and
  position of amd64 registers in the different Hurd structs, including
  i386_thread_state. The signal code is very similar to i686, except the
  trampoline code is adapted.
* gdb/amd64-gnu-tdep.h: export register offsets for x86-gnu-nat.c.
* gdb/config/i386/nm-i386gnu.h: renamed to gdb/config/i386/nm-x86-gnu.h
  and adapt it for x86_64.
* gdb/config/i386/i386gnu.mn: renamed to gdb/config/i386/nm-x86-gnu.mn
  and reuse it for x86_64.
* gdb/configure.host: recognize gnu64 as a host.
* gdb/configure.nat: recognize gnu64 host and update existing i386gnu to
  reuse the new shared files.
* gdb/configure.tgt: recognize x86_64-*-gnu* triplet and use
  amd64-gnu-tdep.c.
* gdb/i386-gnu-tdep.c: added i386_gnu_thread_state_reg_offset that is
  copied from i386-gnu-nat.c. This makes it similar to amd64.
* gdb/i386-gnu-tdep.h: export register offsets and number of registers.
* gdb/i386-gnu-nat.c: rename it to x86-gnu-nat.c since we reuse this for
  i386 and amd64. Updated REG_ADDR to use one of the structures. Added
  VALID_REGISTER to make sure it's a register we can provide at this time
  (not all of them are available in amd64). FLAGS_REGISTER is either rfl
  or efl depending on the arch. Renamed functions and class from i386 to x86
  whenever they can be reused.

Tested on Hurd x86_64 and i686.
---

For Hurd x86_64 to work, "[PATCH] Hurd port: update interface to match 
upstream and fix warnings" needs to be applied too.

 gdb/amd64-gnu-tdep.c  | 256 ++
 gdb/amd64-gnu-tdep.h  |  29 ++
 .../i386/{nm-i386gnu.h => nm-x86-gnu.h}   |   7 +
 gdb/config/i386/{i386gnu.mn => x86-gnu.mn}|   0
 gdb/configure.host|   1 +
 gdb/configure.nat |  27 +-
 gdb/configure.tgt |   4 +
 gdb/i386-gnu-tdep.c   |  37 ++-
 gdb/i386-gnu-tdep.h   |  29 ++
 gdb/{i386-gnu-nat.c => x86-gnu-nat.c} | 128 +
 10 files changed, 457 insertions(+), 61 deletions(-)
 create mode 100644 gdb/amd64-gnu-tdep.c
 create mode 100644 gdb/amd64-gnu-tdep.h
 rename gdb/config/i386/{nm-i386gnu.h => nm-x86-gnu.h} (83%)
 rename gdb/config/i386/{i386gnu.mn => x86-gnu.mn} (100%)
 create mode 100644 gdb/i386-gnu-tdep.h
 rename gdb/{i386-gnu-nat.c => x86-gnu-nat.c} (75%)

diff --git a/gdb/amd64-gnu-tdep.c b/gdb/amd64-gnu-tdep.c
new file mode 100644
index 000..57aeccea8b9
--- /dev/null
+++ b/gdb/amd64-gnu-tdep.c
@@ -0,0 +1,256 @@
+/* Target-dependent code for the GNU Hurd.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 3 of the License, or
+   (at your option) any later version.
+
+   This program 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, see .  */
+
+#include "defs.h"
+#include "gdbcore.h"
+#include "osabi.h"
+#include "solib-svr4.h"
+
+#include "amd64-tdep.h"
+#include "amd64-gnu-tdep.h"
+
+extern "C"
+{
+#include 
+}
+
+/* Recognizing signal handler frames.  */
+
+/* When the GNU/Hurd libc calls a signal handler, the return address points
+   inside the trampoline assembly snippet.
+
+   If the trampoline function name can not be identified, we resort to reading
+   memory from the process in order to identify it.  */
+
+static const gdb_byte gnu_sigtramp_code[] =
+{
+/* rpc_wait_trampoline: */
+  0x48, 0xc7, 0xc0, 0xe7, 0xff, 0xff, 0xff,/* mov$-25,%rax */
+  0x0f, 0x05,  /* syscall */
+  0x49, 0x89, 0x04, 0x24,  /* mov%rax,(%r12) */
+  0x48, 0x89, 0xdc,/* mov%rbx,%rsp */
+
+/* trampoline: */
+  0x5f,/* pop%rdi */
+  0x5e,/* pop%rsi */
+  0x5a,/* pop%rdx */
+  0x48, 0x83, 0xc4, 0x08,  /* add$0x8,%rsp */
+  0x41, 0xff, 0xd5,/* call   *%r13 */
+
+/* RA HERE */
+  0x48, 0x8b, 0x7c, 0x24, 0x10,/* mov
0x10(%rsp),%rdi */
+  0xc3,/* ret */
+
+/* firewall: */
+  0xf4,/* hlt */
+};
+
+#define GNU_SIG