[PATCH v2 rumpkernel] pci-userspace: Add acpi lookup of irqs with fallback

2023-01-17 Thread Damien Zammit
---
 debian/patches/acpi.diff | 78 
 debian/patches/series|  1 +
 2 files changed, 79 insertions(+)
 create mode 100644 debian/patches/acpi.diff

diff --git a/debian/patches/acpi.diff b/debian/patches/acpi.diff
new file mode 100644
index 0..3ee6d2151
--- /dev/null
+++ b/debian/patches/acpi.diff
@@ -0,0 +1,78 @@
+--- a/pci-userspace/src-gnu/Makefile.inc
 b/pci-userspace/src-gnu/Makefile.inc
+@@ -3,7 +3,7 @@
+ PCIDIR:=  ${.PARSEDIR}
+ .PATH:${PCIDIR}
+
+-RUMPCOMP_USER_SRCS=   pci_user-gnu.c mach_debugUser.c
++RUMPCOMP_USER_SRCS=   pci_user-gnu.c mach_debugUser.c acpiUser.c
+ RUMPCOMP_USER_CPPFLAGS+=-I${PCIDIR} -I${DESTDIR}/usr/include
+ RUMPCOMP_CPPFLAGS+=   -I${PCIDIR} -I${DESTDIR}/usr/include
+ CPPFLAGS+=-I${PCIDIR}
+@@ -16,3 +16,11 @@
+   -user mach_debugUser.c \
+   -server /dev/null \
+   -header mach_debug_U.h
++
++acpiUser.c:
++  echo '#include ' \
++  | ${CC} -E -x c - -o - \
++  | mig -cc cat - /dev/null -subrprefix __ \
++  -user acpiUser.c \
++  -server /dev/null \
++  -header acpi_U.h
+--- a/pci-userspace/src-gnu/pci_user-gnu.c
 b/pci-userspace/src-gnu/pci_user-gnu.c
+@@ -67,6 +67,7 @@
+ #include 
+ #include 
+ #include "mach_debug_U.h"
++#include "acpi_U.h"
+ #include 
+ #include 
+
+@@ -90,6 +91,7 @@
+ static mach_port_t master_host;
+ static mach_port_t master_device;
+ static device_t irq_dev;
++static device_t acpi_dev;
+
+ #define PCI_CFG1_START 0xcf8
+ #define PCI_CFG1_END   0xcff
+@@ -130,6 +132,12 @@
+   if (device_open (master_device, D_READ, "irq", _dev))
+   err(2, "device_open irq");
+
++  /* Optional */
++  if (device_open (master_device, D_READ, "acpi", _dev)) {
++  MACH_PRINT("device_open acpi failed... continue\n");
++  acpi_dev = MACH_PORT_NULL;
++  }
++
+   pci_system_init ();
+   struct pci_device_iterator *dev_iter;
+   struct pci_device *pci_dev;
+@@ -363,6 +371,7 @@
+ rumpcomp_pci_irq_map(unsigned bus, unsigned dev, unsigned fun,
+   int intrline, unsigned cookie)
+ {
++  int ret;
+   struct irq *irq;
+   irq = malloc(sizeof(*irq));
+   if (irq == NULL)
+@@ -374,6 +383,15 @@
+   irq->fun = fun;
+   irq->intrline = intrline;
+
++  /* We can do better by reading irq from acpi device, but with fallback 
*/
++  if (acpi_dev != MACH_PORT_NULL) {
++  ret = acpi_get_pci_irq (acpi_dev, bus, dev, fun, 
>intrline);
++  if (ret) {
++  MACH_PRINT("acpi_get_pci_irq failed, continue with 
intrline\n");
++  irq->intrline = intrline;
++  }
++  }
++
+   pthread_mutex_lock();
+   LIST_INSERT_HEAD(, irq, entries);
+   pthread_mutex_unlock();
diff --git a/debian/patches/series b/debian/patches/series
index 5654d3549..adbc5acb9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -14,3 +14,4 @@ pci-userspace-rump.diff
 rumpuser-evcnt.diff
 ps-comm.diff
 idtype_t.diff
+acpi.diff
--
2.34.1





Re: [PATCH 2/7] x86_64: expand and shrink messages in copy{in, out}msg routines

2023-01-17 Thread Luca

Luca Dariz, le lun. 16 janv. 2023 11:58:52 +0100, a ecrit:

+static inline int copyin_address(const rpc_vm_offset_t *uaddr, vm_offset_t 
*kaddr)
+{
+#ifdef __x86_64
+  return copyin_32to64(uaddr, kaddr);
+#else /* __x86_64__ */
+  return copyin(uaddr, kaddr, sizeof(*uaddr));
+#endif /* __x86_64__ */
+}
+
+static inline int copyout_address(const vm_offset_t *kaddr, rpc_vm_offset_t 
*uaddr)
+{
+#ifdef __x86_64
+  return copyout_64to32(kaddr, uaddr);
+#else /* __x86_64__ */
+  return copyout(kaddr, uaddr, sizeof(*kaddr));
+#endif /* __x86_64__ */
+}


These were to be USER32 rather than __86_64, to properly handle the case
of 64-on-64.


Ah you're right, thanks!

Luca




Re: [PATCH] Add kern/mach.h and kern/gnumach.h to define rpc prototypes

2023-01-17 Thread Flávio Cruz
On Tue, Jan 17, 2023 at 8:08 PM Samuel Thibault 
wrote:

> Flavio Cruz, le mar. 17 janv. 2023 00:11:49 -0500, a ecrit:
> > +kern_return_t
> > +register_new_task_notification(
> > + const host_t host,
> > + ipc_port_t notification);
>
> Err, but aren't these declared in the generated gnumach.server.h?
>

Oops, I think you are right. Initially I thought that those headers were
generated for the
stubs since I got compiler failures when trying to use them. However it
seems that we
just need to align the types used in the definitions with the prototypes
(nice benefit of fixing these warnings).

Sent a patch in a separate email to revert the two other commits that I
submitted before.


> And similarly for function declarations added in
> 566c227636481b246d928772ebeaacbc7c37145b
>
> Create kern/mach4.h and kern/mach_host.h and define the RPC prototypes for
> mach4.defs and mach_host.defs.
>
> Samuel
>


[PATCH] Include mig generated headers to avoid warnings with -Wmissing-prototypes.

2023-01-17 Thread Flavio Cruz
This also reverts 566c227636481b246d928772ebeaacbc7c37145b and
963b1794d7117064cee8ab5638b329db51dad854
---
 Makefrag.am  |   3 -
 ddb/db_aout.c|   2 +-
 ddb/db_ext_symtab.c  |   4 +-
 ddb/db_sym.c |   4 +-
 ddb/db_sym.h |   6 +-
 ipc/mach_debug.c |   2 +-
 ipc/mach_port.c  |   1 +
 ipc/mach_port.h  | 132 ---
 kern/bootstrap.c |   2 +-
 kern/host.c  |   2 +-
 kern/ipc_host.c  |   2 +-
 kern/ipc_mig.c   |   2 +-
 kern/ipc_tt.c|   5 +-
 kern/mach4.h |  66 
 kern/mach_debug.h| 113 -
 kern/mach_host.h |  86 -
 kern/machine.c   |   2 +-
 kern/pc_sample.c |   8 +--
 kern/slab.c  |   1 +
 kern/syscall_emulation.c |   1 +
 kern/syscall_sw.c|   2 +-
 kern/task.c  |   3 +
 kern/thread.c|   6 +-
 vm/memory_object.c   |   4 +-
 vm/vm_debug.c|   2 +-
 vm/vm_map.c  |   1 +
 vm/vm_object.c   |   1 +
 vm/vm_user.c |   4 +-
 28 files changed, 40 insertions(+), 427 deletions(-)
 delete mode 100644 kern/mach4.h
 delete mode 100644 kern/mach_debug.h
 delete mode 100644 kern/mach_host.h

diff --git a/Makefrag.am b/Makefrag.am
index 60aeffe0..bdf61246 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -169,11 +169,8 @@ libkernel_a_SOURCES += \
kern/log2.h \
kern/mach_clock.c \
kern/mach_clock.h \
-   kern/mach_debug.h \
kern/mach_factor.c \
kern/mach_factor.h \
-   kern/mach_host.h \
-   kern/mach4.h \
kern/machine.c \
kern/machine.h \
kern/macros.h \
diff --git a/ddb/db_aout.c b/ddb/db_aout.c
index 8f344d6d..7b769c1c 100644
--- a/ddb/db_aout.c
+++ b/ddb/db_aout.c
@@ -75,7 +75,7 @@ aout_db_sym_init(
char *  esymtab,/* pointer to end of string table,
   for checking - may be rounded up to
   integer boundary */
-   char *  name,
+   const char *name,
char *  task_addr)  /* use for this task only */
 {
struct nlist*sym_start, *sym_end;
diff --git a/ddb/db_ext_symtab.c b/ddb/db_ext_symtab.c
index 9c89fb95..db7bec25 100644
--- a/ddb/db_ext_symtab.c
+++ b/ddb/db_ext_symtab.c
@@ -35,7 +35,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -50,7 +50,7 @@ kern_return_t
 host_load_symbol_table(
host_t  host,
task_t  task,
-   char *  name,
+   const char *name,
pointer_t   symtab,
unsigned intsymtab_count)
 {
diff --git a/ddb/db_sym.c b/ddb/db_sym.c
index d205ff74..a247b645 100644
--- a/ddb/db_sym.c
+++ b/ddb/db_sym.c
@@ -60,7 +60,7 @@ db_add_symbol_table(
int  type,
char *start,
char *end,
-   char *name,
+   const char *name,
char *ref,
char *map_pointer)
 {
@@ -506,7 +506,7 @@ void db_free_symbol(db_sym_t s)
  */
 
 static void dummy_db_free_symbol(db_sym_t symbol) { }
-static boolean_t dummy_db_sym_init(char *a, char *b, char *c, char *d) {
+static boolean_t dummy_db_sym_init(char *a, char *b, const char *c, char *d) {
   return FALSE;
 }
 
diff --git a/ddb/db_sym.h b/ddb/db_sym.h
index 8b586996..bc8a10dd 100644
--- a/ddb/db_sym.h
+++ b/ddb/db_sym.h
@@ -94,7 +94,7 @@ extern boolean_t  db_qualify_ambiguous_names;
 extern boolean_t   db_add_symbol_table(int type,
char * start,
char * end,
-   char *name,
+   const char *name,
char *ref,
char *map_pointer );
 
@@ -186,7 +186,7 @@ extern struct db_sym_switch {
boolean_t   (*init)(
char *start,
char *end,
-   char *name,
+   const char *name,
char *task_addr
);
 
@@ -241,7 +241,7 @@ extern boolean_t db_line_at_pc(
 extern boolean_t aout_db_sym_init(
char *symtab,
char *esymtab,
-   char *name,
+   const char *name,
char *task_addr);
 
 extern boolean_t elf_db_sym_init (
diff --git a/ipc/mach_debug.c b/ipc/mach_debug.c
index 57c3133a..7dca4b6b 100644
--- a/ipc/mach_debug.c
+++ b/ipc/mach_debug.c
@@ -41,7 +41,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/ipc/mach_port.c b/ipc/mach_port.c
index 67713a50..b35d8bcf 100644
--- a/ipc/mach_port.c
+++ b/ipc/mach_port.c
@@ -60,6 +60,7 @@
 #include 
 #include 
 #include 

Re: [PATCH 7/7] replace mach_port_t with mach_port_name_t

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:57 +0100, a ecrit:
> This is a cleanup following the introduction of mach_port_name_t.
> The same set of changes is applied to all files:
> - rename mach_port_t to mach_port_name_t where a port name is used,
> - use MACH_PORT_NAME_NULL and MACH_PORT_NAME_DEAD where appropriate,
> - use invalid_port_to_name() and invalid_name_to_port() for conversion
>   where appropriate,
> - use regular copyout() insted of copyout_port() when we deal with
>   mach_port_name_t already before copyout,
> - use the new helper ipc_kmsg_copyout_object_to_port() when we really
>   want to place a port name in the space of a mach_port_t.
> 
> * include/mach/notify.h: Likewise
> * ipc/ipc_entry.c: Likewise
> * ipc/ipc_kmsg.c: Likewise
> * ipc/ipc_kmsg.h: Likewise, and add ipc_kmsg_copyout_object_to_port()
> * ipc/ipc_marequest.c: Likewise
> * ipc/ipc_object.c: Likewise
> * ipc/ipc_port.c: Likewise
> * ipc/ipc_space.h: Likewise
> * ipc/mach_msg.c: Likewise
> * ipc/mach_port.c: Likewise
> * kern/exception.c: Likewise
> * kern/ipc_mig.c: Likewise
> ---
>  include/mach/notify.h |  6 +++---
>  ipc/ipc_entry.c   |  2 +-
>  ipc/ipc_kmsg.c| 40 +++-
>  ipc/ipc_kmsg.h| 11 +++
>  ipc/ipc_marequest.c   |  4 ++--
>  ipc/ipc_object.c  |  4 ++--
>  ipc/ipc_port.c|  6 +++---
>  ipc/ipc_space.h   |  2 +-
>  ipc/mach_msg.c|  2 +-
>  ipc/mach_port.c   | 14 +++---
>  kern/exception.c  | 12 ++--
>  kern/ipc_mig.c| 16 
>  12 files changed, 64 insertions(+), 55 deletions(-)
> 
> diff --git a/include/mach/notify.h b/include/mach/notify.h
> index 6d783dde..14bcd6f6 100644
> --- a/include/mach/notify.h
> +++ b/include/mach/notify.h
> @@ -58,13 +58,13 @@
>  typedef struct {
>  mach_msg_header_tnot_header;
>  mach_msg_type_t  not_type;   /* MACH_MSG_TYPE_PORT_NAME */
> -mach_port_t  not_port;
> +mach_port_name_t not_port;
>  } mach_port_deleted_notification_t;
>  
>  typedef struct {
>  mach_msg_header_tnot_header;
>  mach_msg_type_t  not_type;   /* MACH_MSG_TYPE_PORT_NAME */
> -mach_port_t  not_port;
> +mach_port_name_t not_port;
>  } mach_msg_accepted_notification_t;
>  
>  typedef struct {
> @@ -86,7 +86,7 @@ typedef struct {
>  typedef struct {
>  mach_msg_header_tnot_header;
>  mach_msg_type_t  not_type;   /* MACH_MSG_TYPE_PORT_NAME */
> -mach_port_t  not_port;
> +mach_port_name_t not_port;
>  } mach_dead_name_notification_t;
>  
>  #endif   /* _MACH_NOTIFY_H_ */
> diff --git a/ipc/ipc_entry.c b/ipc/ipc_entry.c
> index c24ea46c..f13c442f 100644
> --- a/ipc/ipc_entry.c
> +++ b/ipc/ipc_entry.c
> @@ -127,7 +127,7 @@ ipc_entry_alloc_name(
>   kern_return_t kr;
>   ipc_entry_t entry, e, *prevp;
>   void **slot;
> - assert(MACH_PORT_VALID(name));
> + assert(MACH_PORT_NAME_VALID(name));
>  
>   if (!space->is_active) {
>   return KERN_INVALID_TASK;
> diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
> index 495c4672..2477c576 100644
> --- a/ipc/ipc_kmsg.c
> +++ b/ipc/ipc_kmsg.c
> @@ -44,6 +44,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -1078,7 +1079,7 @@ ipc_kmsg_copyin_header(
>   reply_soright = soright;
>   }
>   }
> - } else if (!MACH_PORT_VALID(reply_name)) {
> + } else if (!MACH_PORT_NAME_VALID(reply_name)) {
>   ipc_entry_t entry;
>  
>   /*
> @@ -1101,7 +1102,7 @@ ipc_kmsg_copyin_header(
>   if (IE_BITS_TYPE(entry->ie_bits) == MACH_PORT_TYPE_NONE)
>   ipc_entry_dealloc(space, dest_name, entry);
>  
> - reply_port = (ipc_object_t) reply_name;
> + reply_port = (ipc_object_t) invalid_name_to_port(reply_name);
>   reply_soright = IP_NULL;
>   } else {
>   ipc_entry_t dest_entry, reply_entry;
> @@ -1461,10 +1462,10 @@ ipc_kmsg_copyin_body(
>   ((mach_msg_type_t*)type)->msgt_name = newname;
>  
>   for (i = 0; i < number; i++) {
> - mach_port_name_t port = (mach_port_name_t) 
> objects[i];
> + mach_port_name_t port = ((mach_port_t*)data)[i];
>   ipc_object_t object;
>  
> - if (!MACH_PORT_VALID(port))
> + if (!MACH_PORT_NAME_VALID(port))
>   continue;
>  
>   kr = ipc_object_copyin(space, port,
> @@ -1846,7 +1847,7 @@ ipc_kmsg_copyout_header(
>   entry->ie_bits = gen | (MACH_PORT_TYPE_SEND_ONCE | 1);
>   }
>  
> - assert(MACH_PORT_VALID(reply_name));
> + assert(MACH_PORT_NAME_VALID(reply_name));

Re: [PATCH 6/7] add conversion helpers for invalid mach port names

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:56 +0100, a ecrit:
> * include/mach/port.h: add _NAME_ variants for port NULL and DEAD and
>   add helpers to check for invalid  port names
> * ipc/port.h: add helpers to properly convert to/from invalid mach
>   port names.
> ---
>  include/mach/port.h |  8 ++--
>  ipc/port.h  | 20 
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/include/mach/port.h b/include/mach/port.h
> index e38be614..c9bbcf17 100644
> --- a/include/mach/port.h
> +++ b/include/mach/port.h
> @@ -72,9 +72,13 @@ typedef int *rpc_signature_info_t;
>  
>  #define MACH_PORT_NULL   0 /* works with both user and kernel 
> ports */
>  #define MACH_PORT_DEAD   ((mach_port_t) ~0)
> +#define MACH_PORT_NAME_NULL  ((mach_port_name_t) 0)
> +#define MACH_PORT_NAME_DEAD  ((mach_port_name_t) ~0)
>  
> -#define  MACH_PORT_VALID(name)   \
> - (((name) != MACH_PORT_NULL) && ((name) != MACH_PORT_DEAD))
> +#define  MACH_PORT_VALID(port)   \
> + (((port) != MACH_PORT_NULL) && ((port) != MACH_PORT_DEAD))
> +#define  MACH_PORT_NAME_VALID(name)  \
> + (((name) != MACH_PORT_NAME_NULL) && ((name) != 
> MACH_PORT_NAME_DEAD))
>  
>  /*
>   *  These are the different rights a task may have.
> diff --git a/ipc/port.h b/ipc/port.h
> index 9ef586c1..c85685d7 100644
> --- a/ipc/port.h
> +++ b/ipc/port.h
> @@ -39,6 +39,7 @@
>  #ifndef  _IPC_PORT_H_
>  #define _IPC_PORT_H_
>  
> +#include 
>  #include 
>  
>  /*
> @@ -83,4 +84,23 @@ typedef mach_port_name_t mach_port_gen_t;  /* generation 
> numbers */
>  #define  MACH_PORT_UREFS_UNDERFLOW(urefs, delta) 
> \
>   (((delta) < 0) && (-(delta) > (urefs)))
>  
> +
> +static inline mach_port_t invalid_name_to_port(mach_port_name_t name)
> +{
> +  if (name == MACH_PORT_NAME_NULL)
> +return MACH_PORT_NULL;
> +  if (name == MACH_PORT_NAME_DEAD)
> +return MACH_PORT_DEAD;
> +  panic("invalid_name_to_port() called with a valid port");
> +}
> +
> +static inline mach_port_name_t invalid_port_to_name(mach_port_t port)
> +{
> +  if (port == MACH_PORT_NULL)
> +return MACH_PORT_NAME_NULL;
> +  if (port == MACH_PORT_DEAD)
> +return MACH_PORT_NAME_DEAD;
> +  panic("invalid_port_to_name() called with a valid name");
> +}
> +
>  #endif   /* _IPC_PORT_H_ */
> -- 
> 2.30.2
> 
> 

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



Re: [PATCH 5/7] adjust rdxtree key to the correct size

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:55 +0100, a ecrit:
> * Makefile.am: define RDXTREE_KEY_32
> ---
>  Makefile.am | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Makefile.am b/Makefile.am
> index fb557ba6..54fcf685 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -82,6 +82,9 @@ endif
>  # We do not support or need position-independent
>  AM_CFLAGS += \
>   -no-pie -fno-PIE -fno-pie -fno-pic
> +
> +# This must be the same size as port names, see e.g. ipc/ipc_entry.c
> +AM_CFLAGS += -DRDXTREE_KEY_32
>  
>  #
>  # Silent build support.
> -- 
> 2.30.2
> 
> 

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



Re: [PATCH 4/7] update writev syscall signature with rpc types

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:54 +0100, a ecrit:
> * device/device_emul.h: write/writev: update trap argument types
> * device/ds_routines.c: update argument types and adjust copyin
> * device/ds_routines.h: write/writev: update trap argument type
> * include/device/device_types.h: add rpc_io_buf_vec_t type
> * kern/ipc_mig.c: write/writev: update trap argument type
> * kern/ipc_mig.h: Likewise
> ---
>  device/device_emul.h  |  4 ++--
>  device/ds_routines.c  | 22 +-
>  device/ds_routines.h  | 12 ++--
>  include/device/device_types.h |  4 
>  kern/ipc_mig.c|  6 +++---
>  kern/ipc_mig.h|  6 +++---
>  6 files changed, 31 insertions(+), 23 deletions(-)
> 
> diff --git a/device/device_emul.h b/device/device_emul.h
> index 957bd505..683fc802 100644
> --- a/device/device_emul.h
> +++ b/device/device_emul.h
> @@ -56,9 +56,9 @@ struct device_emulation_ops
> vm_size_t, ipc_port_t *, boolean_t);
>void (*no_senders) (mach_no_senders_notification_t *);
>io_return_t (*write_trap) (void *, dev_mode_t,
> -  recnum_t, vm_offset_t, vm_size_t);
> +  rpc_recnum_t, rpc_vm_offset_t, rpc_vm_size_t);
>io_return_t (*writev_trap) (void *, dev_mode_t,
> -   recnum_t, io_buf_vec_t *, vm_size_t);
> +   rpc_recnum_t, rpc_io_buf_vec_t *, rpc_vm_size_t);
>  };
>  
>  #endif /* _I386AT_DEVICE_EMUL_H_ */
> diff --git a/device/ds_routines.c b/device/ds_routines.c
> index 11589d63..07cfd85b 100644
> --- a/device/ds_routines.c
> +++ b/device/ds_routines.c
> @@ -412,7 +412,7 @@ ds_notify (mach_msg_header_t *msg)
>  
>  io_return_t
>  ds_device_write_trap (device_t dev, dev_mode_t mode,
> -   recnum_t recnum, vm_offset_t data, vm_size_t count)
> +   rpc_recnum_t recnum, rpc_vm_offset_t data, rpc_vm_size_t 
> count)
>  {
>/* Refuse if device is dead or not completely open.  */
>if (dev == DEVICE_NULL)
> @@ -427,7 +427,7 @@ ds_device_write_trap (device_t dev, dev_mode_t mode,
>  
>  io_return_t
>  ds_device_writev_trap (device_t dev, dev_mode_t mode,
> -recnum_t recnum, io_buf_vec_t *iovec, vm_size_t count)
> +rpc_recnum_t recnum, rpc_io_buf_vec_t *iovec, 
> rpc_vm_size_t count)
>  {
>/* Refuse if device is dead or not completely open.  */
>if (dev == DEVICE_NULL)
> @@ -1713,7 +1713,7 @@ ds_trap_write_done(const io_req_t ior)
>   */
>  static io_return_t
>  device_write_trap (mach_device_t device, dev_mode_t mode,
> -recnum_t recnum, vm_offset_t data, vm_size_t data_count)
> +rpc_recnum_t recnum, rpc_vm_offset_t data, rpc_vm_size_t 
> data_count)
>  {
>   io_req_t ior;
>   io_return_t result;
> @@ -1752,7 +1752,7 @@ device_write_trap (mach_device_t device, dev_mode_t 
> mode,
>* Copy the data from user space.
>*/
>   if (data_count > 0)
> - copyin((void *)data, ior->io_data, data_count);
> + copyin((void*)(vm_offset_t)data, ior->io_data, data_count);
>  
>   /*
>* The ior keeps an extra reference for the device.
> @@ -1781,7 +1781,7 @@ device_write_trap (mach_device_t device, dev_mode_t 
> mode,
>  
>  static io_return_t
>  device_writev_trap (mach_device_t device, dev_mode_t mode,
> - recnum_t recnum, io_buf_vec_t *iovec, vm_size_t iocount)
> + rpc_recnum_t recnum, rpc_io_buf_vec_t *iovec, rpc_vm_size_t 
> iocount)
>  {
>   io_req_t ior;
>   io_return_t result;
> @@ -1799,11 +1799,15 @@ device_writev_trap (mach_device_t device, dev_mode_t 
> mode,
>*/
>   if (iocount > 16)
>   return KERN_INVALID_VALUE; /* lame */
> - copyin(iovec,
> -stack_iovec,
> -iocount * sizeof(io_buf_vec_t));
> - for (data_count = 0, i = 0; i < iocount; i++)
> +
> + for (data_count = 0, i=0; i + rpc_io_buf_vec_t riov;
> + if (copyin(iovec + i, , sizeof(riov)))
> + return KERN_INVALID_ARGUMENT;
> + stack_iovec[i].data = riov.data;
> + stack_iovec[i].count = riov.count;
>   data_count += stack_iovec[i].count;
> + }
>  
>   /*
>* Get a buffer to hold the ioreq.
> diff --git a/device/ds_routines.h b/device/ds_routines.h
> index c0543cbc..48d85dd0 100644
> --- a/device/ds_routines.h
> +++ b/device/ds_routines.h
> @@ -72,15 +72,15 @@ extern void io_done_thread(void) __attribute__ 
> ((noreturn));
>  io_return_t ds_device_write_trap(
>   device_tdev,
>   dev_mode_t  mode,
> - recnum_trecnum,
> - vm_offset_t data,
> - vm_size_t   count);
> + rpc_recnum_trecnum,
> + rpc_vm_offset_t data,
> + rpc_vm_size_t   count);
>  
>  io_return_t ds_device_writev_trap(
>   device_tdev,
>   

Re: [PATCH 3/7] update syscall signature with rpc_vm_* and mach_port_name_t

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:53 +0100, a ecrit:
> * include/mach/mach_types.h: use mach port names
> * kern/ipc_mig.c:  update vm types and use copyin/copyout helpers
> * kern/ipc_mig.h: Likewise
> 
> Signed-off-by: Luca Dariz 
> ---
>  include/mach/mach_traps.h | 18 -
>  kern/ipc_mig.c| 41 +--
>  kern/ipc_mig.h| 30 ++--
>  3 files changed, 41 insertions(+), 48 deletions(-)
> 
> diff --git a/include/mach/mach_traps.h b/include/mach/mach_traps.h
> index 0433707a..2a87f62a 100644
> --- a/include/mach/mach_traps.h
> +++ b/include/mach/mach_traps.h
> @@ -35,19 +35,9 @@
>  
>  #include 
>  
> -mach_port_t  mach_reply_port
> - (void);
> -
> -mach_port_t  mach_thread_self
> - (void);
> -
> -#ifdef   __386BSD__
> -#undef mach_task_self
> -#endif
> -mach_port_t  mach_task_self
> - (void);
> -
> -mach_port_t  mach_host_self
> - (void);
> +mach_port_name_t mach_reply_port (void);
> +mach_port_name_t mach_thread_self (void);
> +mach_port_name_t mach_task_self (void);
> +mach_port_name_t mach_host_self (void);
>  
>  #endif   /* _MACH_MACH_TRAPS_H_ */
> diff --git a/kern/ipc_mig.c b/kern/ipc_mig.c
> index a9e3f53b..afda1016 100644
> --- a/kern/ipc_mig.c
> +++ b/kern/ipc_mig.c
> @@ -29,6 +29,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -576,12 +577,12 @@ port_name_to_space(mach_port_name_t name)
>  kern_return_t
>  syscall_vm_map(
>   mach_port_name_ttarget_map,
> - vm_offset_t *address,
> - vm_size_t   size,
> - vm_offset_t mask,
> + rpc_vm_offset_t *address,
> + rpc_vm_size_t   size,
> + rpc_vm_offset_t mask,
>   boolean_t   anywhere,
>   mach_port_name_tmemory_object,
> - vm_offset_t offset,
> + rpc_vm_offset_t offset,
>   boolean_t   copy,
>   vm_prot_t   cur_protection,
>   vm_prot_t   max_protection,
> @@ -607,12 +608,12 @@ syscall_vm_map(
>   } else
>   port = (ipc_port_t) memory_object;
>  
> - copyin(address, , sizeof(vm_offset_t));
> + copyin_address(address, );
>   result = vm_map(map, , size, mask, anywhere,
>   port, offset, copy,
>   cur_protection, max_protection, inheritance);
>   if (result == KERN_SUCCESS)
> - copyout(, address, sizeof(vm_offset_t));
> + copyout_address(, address);
>   if (IP_VALID(port))
>   ipc_port_release_send(port);
>   vm_map_deallocate(map);
> @@ -621,9 +622,9 @@ syscall_vm_map(
>  }
>  
>  kern_return_t syscall_vm_allocate(
> - mach_port_name_ttarget_map,
> - vm_offset_t *address,
> - vm_size_t   size,
> + mach_port_name_ttarget_map,
> + rpc_vm_offset_t *address,
> + rpc_vm_size_t   size,
>   boolean_t   anywhere)
>  {
>   vm_map_tmap;
> @@ -634,19 +635,19 @@ kern_return_t syscall_vm_allocate(
>   if (map == VM_MAP_NULL)
>   return MACH_SEND_INTERRUPTED;
>  
> - copyin(address, , sizeof(vm_offset_t));
> + copyin_address(address, );
>   result = vm_allocate(map, , size, anywhere);
>   if (result == KERN_SUCCESS)
> - copyout(, address, sizeof(vm_offset_t));
> + copyout_address(, address);
>   vm_map_deallocate(map);
>  
>   return result;
>  }
>  
>  kern_return_t syscall_vm_deallocate(
> - mach_port_name_ttarget_map,
> - vm_offset_t start,
> - vm_size_t   size)
> + mach_port_name_ttarget_map,
> + rpc_vm_offset_t start,
> + rpc_vm_size_t   size)
>  {
>   vm_map_tmap;
>   kern_return_t   result;
> @@ -682,7 +683,7 @@ kern_return_t syscall_task_create(
>   (void) ipc_kmsg_copyout_object(current_space(),
>  (ipc_object_t) port,
>  MACH_MSG_TYPE_PORT_SEND, );
> - copyout(, child_task, sizeof(mach_port_name_t));
> + copyout_port(, child_task);
>   }
>   task_deallocate(t);
>  
> @@ -767,7 +768,9 @@ syscall_mach_port_allocate(
>  
>   kr = mach_port_allocate(space, right, );
>   if (kr == KERN_SUCCESS)
> - copyout(, namep, sizeof(mach_port_name_t));
> + {
> + copyout_port(, namep);
> + }
>   is_release(space);
>  
>   return kr;
> @@ -873,8 +876,8 @@ syscall_device_write_request(mach_port_name_t 
> device_name,
>mach_port_name_t   reply_name,
>dev_mode_t mode,
>recnum_t   recnum,
> -  vm_offset_t  

Re: [PATCH 2/7] x86_64: expand and shrink messages in copy{in, out}msg routines

2023-01-17 Thread Samuel Thibault
Applied except a little thing, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:52 +0100, a ecrit:
> +static inline int copyin_address(const rpc_vm_offset_t *uaddr, vm_offset_t 
> *kaddr)
> +{
> +#ifdef __x86_64
> +  return copyin_32to64(uaddr, kaddr);
> +#else /* __x86_64__ */
> +  return copyin(uaddr, kaddr, sizeof(*uaddr));
> +#endif /* __x86_64__ */
> +}
> +
> +static inline int copyout_address(const vm_offset_t *kaddr, rpc_vm_offset_t 
> *uaddr)
> +{
> +#ifdef __x86_64
> +  return copyout_64to32(kaddr, uaddr);
> +#else /* __x86_64__ */
> +  return copyout(kaddr, uaddr, sizeof(*kaddr));
> +#endif /* __x86_64__ */
> +}

These were to be USER32 rather than __86_64, to properly handle the case
of 64-on-64.

Samuel



Re: [PATCH 1/7] add msg_user_header_t for user-side msg structure

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Luca Dariz, le lun. 16 janv. 2023 11:58:51 +0100, a ecrit:
> * include/mach/message.h: use mach_msg_user_header_t only in KERNEL,
>   and define it as mach_msh_header_t for user space
> * ipc/ipc_kmsg.c: use mach_msg_user_header_t where appropriate
> * ipc/ipc_kmsg.h: Likewise
> * ipc/mach_msg.c: Likewise
> * ipc/mach_msg.h: Likewise
> * kern/thread.h: Likewise
> ---
>  include/mach/message.h | 17 -
>  ipc/ipc_kmsg.c |  6 +++---
>  ipc/ipc_kmsg.h |  4 ++--
>  ipc/mach_msg.c | 10 +-
>  ipc/mach_msg.h |  4 ++--
>  kern/thread.h  |  2 +-
>  6 files changed, 29 insertions(+), 14 deletions(-)
> 
> diff --git a/include/mach/message.h b/include/mach/message.h
> index 798b47b4..c3081e66 100644
> --- a/include/mach/message.h
> +++ b/include/mach/message.h
> @@ -132,6 +132,7 @@ typedef   unsigned int mach_msg_size_t;
>  typedef natural_t mach_msg_seqno_t;
>  typedef integer_t mach_msg_id_t;
>  
> +/* full header structure, may have different size in user/kernel spaces */
>  typedef  struct mach_msg_header {
>  mach_msg_bits_t  msgh_bits;
>  mach_msg_size_t  msgh_size;
> @@ -144,6 +145,20 @@ typedef  struct mach_msg_header {
>  mach_msg_id_tmsgh_id;
>  } mach_msg_header_t;
>  
> +#ifdef KERNEL
> +/* user-side header format, needed in the kernel */
> +typedef  struct {
> +mach_msg_bits_t  msgh_bits;
> +mach_msg_size_t  msgh_size;
> +mach_port_name_t msgh_remote_port;
> +mach_port_name_t msgh_local_port;
> +mach_port_seqno_tmsgh_seqno;
> +mach_msg_id_tmsgh_id;
> +} mach_msg_user_header_t;
> +#else
> +typedef mach_msg_header_t mach_msg_user_header_t;
> +#endif
> +
>  /*
>   *  There is no fixed upper bound to the size of Mach messages.
>   */
> @@ -389,7 +404,7 @@ typedef kern_return_t mach_msg_return_t;
>  
>  extern mach_msg_return_t
>  mach_msg_trap
> -   (mach_msg_header_t *msg,
> +   (mach_msg_user_header_t *msg,
>  mach_msg_option_t option,
>  mach_msg_size_t send_size,
>  mach_msg_size_t rcv_size,
> diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
> index 62e138c7..d00c67d4 100644
> --- a/ipc/ipc_kmsg.c
> +++ b/ipc/ipc_kmsg.c
> @@ -499,13 +499,13 @@ ipc_kmsg_free(ipc_kmsg_t kmsg)
>  
>  mach_msg_return_t
>  ipc_kmsg_get(
> - mach_msg_header_t   *msg,
> + mach_msg_user_header_t  *msg,
>   mach_msg_size_t size,
>   ipc_kmsg_t  *kmsgp)
>  {
>   ipc_kmsg_t kmsg;
>  
> - if ((size < sizeof(mach_msg_header_t)) || (size & 3))
> + if ((size < sizeof(mach_msg_user_header_t)) || (size & 3))
>   return MACH_SEND_MSG_TOO_SMALL;
>  
>   if (size <= IKM_SAVED_MSG_SIZE) {
> @@ -587,7 +587,7 @@ ipc_kmsg_get_from_kernel(
>  
>  mach_msg_return_t
>  ipc_kmsg_put(
> - mach_msg_header_t   *msg,
> + mach_msg_user_header_t  *msg,
>   ipc_kmsg_t  kmsg,
>   mach_msg_size_t size)
>  {
> diff --git a/ipc/ipc_kmsg.h b/ipc/ipc_kmsg.h
> index ffda9b5e..16df31f5 100644
> --- a/ipc/ipc_kmsg.h
> +++ b/ipc/ipc_kmsg.h
> @@ -242,13 +242,13 @@ extern void
>  ipc_kmsg_free(ipc_kmsg_t);
>  
>  extern mach_msg_return_t
> -ipc_kmsg_get(mach_msg_header_t *, mach_msg_size_t, ipc_kmsg_t *);
> +ipc_kmsg_get(mach_msg_user_header_t *, mach_msg_size_t, ipc_kmsg_t *);
>  
>  extern mach_msg_return_t
>  ipc_kmsg_get_from_kernel(mach_msg_header_t *, mach_msg_size_t, ipc_kmsg_t *);
>  
>  extern mach_msg_return_t
> -ipc_kmsg_put(mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t);
> +ipc_kmsg_put(mach_msg_user_header_t *, ipc_kmsg_t, mach_msg_size_t);
>  
>  extern void
>  ipc_kmsg_put_to_kernel(mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t);
> diff --git a/ipc/mach_msg.c b/ipc/mach_msg.c
> index f15164a3..221ea975 100644
> --- a/ipc/mach_msg.c
> +++ b/ipc/mach_msg.c
> @@ -89,7 +89,7 @@
>  
>  mach_msg_return_t
>  mach_msg_send(
> - mach_msg_header_t   *msg,
> + mach_msg_user_header_t  *msg,
>   mach_msg_option_t   option,
>   mach_msg_size_t send_size,
>   mach_msg_timeout_t  time_out,
> @@ -171,7 +171,7 @@ mach_msg_send(
>  
>  mach_msg_return_t
>  mach_msg_receive(
> - mach_msg_header_t   *msg,
> + mach_msg_user_header_t  *msg,
>   mach_msg_option_t   option,
>   mach_msg_size_t rcv_size,
>   mach_port_name_trcv_name,
> @@ -286,7 +286,7 @@ mach_msg_receive_continue(void)
>   ipc_thread_t self = current_thread();
>   ipc_space_t space = current_space();
>   vm_map_t map = current_map();
> - mach_msg_header_t *msg = self->ith_msg;
> + mach_msg_user_header_t *msg = self->ith_msg;
>   mach_msg_option_t option = self->ith_option;
>   mach_msg_size_t rcv_size = self->ith_rcv_size;
>   mach_msg_timeout_t time_out = self->ith_timeout;
> @@ -380,7 +380,7 @@ mach_msg_receive_continue(void)
>  
>  mach_msg_return_t
>  mach_msg_trap(
> - mach_msg_header_t   *msg,
> + mach_msg_user_header_t  

Re: [PATCH] Add kern/mach.h and kern/gnumach.h to define rpc prototypes

2023-01-17 Thread Samuel Thibault
Flavio Cruz, le mar. 17 janv. 2023 00:11:49 -0500, a ecrit:
> +kern_return_t
> +register_new_task_notification(
> + const host_t host,
> + ipc_port_t notification);

Err, but aren't these declared in the generated gnumach.server.h?

And similarly for function declarations added in
566c227636481b246d928772ebeaacbc7c37145b

Create kern/mach4.h and kern/mach_host.h and define the RPC prototypes for 
mach4.defs and mach_host.defs.

Samuel



Re: [PATCH] Delete x86 string functions

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le mar. 17 janv. 2023 00:11:16 -0500, a ecrit:
> The i386 functions are not used and the more portable versions in 
> kern/strings.c
> are faster (1-4x faster in synthetic benchmarks compiled with -O2 on my 
> x86_64 box).
> ---
>  i386/i386/strings.c | 54 -
>  1 file changed, 54 deletions(-)
> 
> diff --git a/i386/i386/strings.c b/i386/i386/strings.c
> index 84a3bc16..f1752de2 100644
> --- a/i386/i386/strings.c
> +++ b/i386/i386/strings.c
> @@ -94,57 +94,3 @@ memcmp(const void *s1, const void *s2, size_t n)
>  return (int)c1 - (int)c2;
>  }
>  #endif /* ARCH_STRING_MEMCMP */
> -
> -#ifdef ARCH_STRING_STRLEN
> -size_t
> -strlen(const char *s)
> -{
> -size_t n;
> -
> -n = (size_t)-1;
> -asm volatile("repne scasb"
> - : "+D" (s), "+c" (n)
> - : "a" (0)
> - : "memory");
> -return ~n - 1;
> -}
> -#endif /* ARCH_STRING_STRLEN */
> -
> -#ifdef ARCH_STRING_STRCPY
> -char *
> -strcpy(char *dest, const char *src)
> -{
> -char *orig_dest;
> -
> -orig_dest = dest;
> -asm volatile("1:\n"
> - "lodsb\n"
> - "stosb\n"
> - "testb %%al, %%al\n"
> - "jnz 1b\n"
> - : "+D" (dest), "+S" (src)
> - : : "al", "memory");
> -return orig_dest;
> -}
> -#endif /* ARCH_STRING_STRCPY */
> -
> -#ifdef ARCH_STRING_STRCMP
> -int
> -strcmp(const char *s1, const char *s2)
> -{
> -unsigned char c1, c2;
> -
> -asm volatile("1:\n"
> - "lodsb\n"
> - "scasb\n"
> - "jne 1f\n"
> - "testb %%al, %%al\n"
> - "jnz 1b\n"
> - "1:\n"
> - : "+D" (s1), "+S" (s2)
> - : : "al", "memory");
> -c1 = *(((const unsigned char *)s1) - 1);
> -c2 = *(((const unsigned char *)s2) - 1);
> -return (int)c1 - (int)c2;
> -}
> -#endif /* ARCH_STRING_STRCMP */
> -- 
> 2.39.0
> 
> 

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



Re: [PATCH] Delete util/putchar.{c,h} and util/puts.c

2023-01-17 Thread Samuel Thibault
Applied, thanks!

Flavio Cruz, le mar. 17 janv. 2023 00:09:45 -0500, a ecrit:
> Those functions are unused.
> ---
>  Makefrag.am|  3 ---
>  util/putchar.c | 32 
>  util/putchar.h | 32 
>  util/puts.c| 40 
>  4 files changed, 107 deletions(-)
>  delete mode 100644 util/putchar.c
>  delete mode 100644 util/putchar.h
>  delete mode 100644 util/puts.c
> 
> diff --git a/Makefrag.am b/Makefrag.am
> index 9da44d55..60aeffe0 100644
> --- a/Makefrag.am
> +++ b/Makefrag.am
> @@ -240,9 +240,6 @@ EXTRA_DIST += \
>  #
>  
>  libkernel_a_SOURCES += \
> - util/putchar.c \
> - util/putchar.h \
> - util/puts.c \
>   util/atoi.c \
>   util/atoi.h \
>   util/byteorder.h \
> diff --git a/util/putchar.c b/util/putchar.c
> deleted file mode 100644
> index 76c013ed..
> --- a/util/putchar.c
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -/* 
> - * Copyright (c) 1995 The University of Utah and
> - * the Computer Systems Laboratory at the University of Utah (CSL).
> - * All rights reserved.
> - *
> - * Permission to use, copy, modify and distribute this software is hereby
> - * granted provided that (1) source code retains these copyright, permission,
> - * and disclaimer notices, and (2) redistributions including binaries
> - * reproduce the notices in supporting documentation, and (3) all advertising
> - * materials mentioning features or use of this software display the 
> following
> - * acknowledgement: ``This product includes software developed by the
> - * Computer Systems Laboratory at the University of Utah.''
> - *
> - * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
> - * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
> - * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS 
> SOFTWARE.
> - *
> - * CSL requests users of this software to return to csl-d...@cs.utah.edu any
> - * improvements that they make and grant CSL redistribution rights.
> - *
> - *  Author: Bryan Ford, University of Utah CSL
> - */
> -
> -#include 
> -#include 
> -
> -int putchar(int c)
> -{
> - cnputc(c);
> - return c;
> -}
> -
> diff --git a/util/putchar.h b/util/putchar.h
> deleted file mode 100644
> index 2e65bd56..
> --- a/util/putchar.h
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -/*
> - * Copyright (C) 2008 Free Software Foundation, Inc.
> - *
> - * 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 2, 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, write to the Free Software
> - * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
> - *
> - *  Author: Barry deFreese.
> - */
> -/*
> - * Simple putchar implementation header.
> - *
> - */
> -
> -#ifndef _PUTCHAR_H_
> -#define _PUTCHAR_H_
> -
> -#include 
> -
> -extern int putchar(int c);
> -
> -#endif /* _PUTCHAR_H_ */
> diff --git a/util/puts.c b/util/puts.c
> deleted file mode 100644
> index 0bd72e98..
> --- a/util/puts.c
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -/* 
> - * Copyright (c) 1995 The University of Utah and
> - * the Computer Systems Laboratory at the University of Utah (CSL).
> - * All rights reserved.
> - *
> - * Permission to use, copy, modify and distribute this software is hereby
> - * granted provided that (1) source code retains these copyright, permission,
> - * and disclaimer notices, and (2) redistributions including binaries
> - * reproduce the notices in supporting documentation, and (3) all advertising
> - * materials mentioning features or use of this software display the 
> following
> - * acknowledgement: ``This product includes software developed by the
> - * Computer Systems Laboratory at the University of Utah.''
> - *
> - * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
> - * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
> - * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS 
> SOFTWARE.
> - *
> - * CSL requests users of this software to return to csl-d...@cs.utah.edu any
> - * improvements that they make and grant CSL redistribution rights.
> - *
> - *  Author: Bryan Ford, University of Utah CSL
> - */
> -
> -#include 
> -#include 
> -
> -/* Simple puts() implementation that just uses putchar().
> -   Note that our libc's printf() is implemented
> -   in terms of only puts() and putchar(), so that's all we need.  */
> -int puts(const char *s)
> -{
> -

Re: [PATCH] Fix some compiler warnings

2023-01-17 Thread Samuel Thibault
Hello,

Svante Signell, le mar. 17 janv. 2023 13:15:27 +0100, a ecrit:
> --- hurd-git/ext2fs/ext2fs.c  2022-12-08 15:05:29.80800 +0100
> +++ hurd-git/ext2fs/ext2fs.c  2022-12-08 19:11:12.60400 +0100
> @@ -232,7 +232,7 @@
>if (store->size < SBLOCK_OFFS + SBLOCK_SIZE)
>  ext2_panic ("device too small for superblock (%Ld bytes)", store->size);
>if (store->log2_blocks_per_page < 0)
> -ext2_panic ("device block size (%zu) greater than page size (%lu)",
> +ext2_panic ("device block size (%zu) greater than page size (%u)",
>   store->block_size, vm_page_size);

But conversely when we'll build it in 64bit, vm_page_size (actually
uintptr_t) will be an unsigned long.

This needs to be fixed the *proper* way: either use the PRIuPTR macro,
or cast the value into unsigned long.

Samuel



Re: [PATCH] Add libraries to Makefiles.

2023-01-17 Thread Samuel Thibault
Hello,

Svante Signell, le mar. 17 janv. 2023 13:20:46 +0100, a ecrit:
> The attached patch adds libraries needed when cross-building Hurd. Most
> of them arise when enabling zlib with --with-libz.

But none of these directories are actually using libz, so it doesn't
make sense to make them use -lz.

Are you sure that your cross-toolchain supports linking shared
libraries?

Samuel



[PATCH] Add libraries to Makefiles.

2023-01-17 Thread Svante Signell
Hi,

The attached patch adds libraries needed when cross-building Hurd. Most
of them arise when enabling zlib with --with-libz.

Applies nicely to hurd-0.9.git20221224 and latest git.

Thanks!

--- hurd/boot/Makefile	2022-11-30 11:14:21.08400 +0100
+++ hurd/boot/Makefile	2022-12-02 15:31:09.73600 +0100
@@ -28,6 +28,6 @@
 MIGSFLAGS=-imacros $(srcdir)/mig-mutate.h -DHURD_DEFAULT_PAYLOAD_TO_PORT=1
 io-MIGSFLAGS=-DREPLY_PORTS -DHURD_DEFAULT_PAYLOAD_TO_PORT=1
 HURDLIBS = store shouldbeinlibc ihash
-LDLIBS += -lpthread
+LDLIBS += -lpthread $(and $(HAVE_LIBZ),-lz)
 
 include ../Makeconf
--- hurd/storeio/Makefile	2022-11-30 11:14:21.18800 +0100
+++ hurd/storeio/Makefile	2022-11-30 12:27:44.26800 +0100
@@ -24,6 +24,6 @@
 
 OBJS = $(SRCS:.c=.o)
 HURDLIBS = trivfs pager fshelp iohelp store ports ihash shouldbeinlibc
-LDLIBS = -lpthread
+LDLIBS = -lpthread $(and $(HAVE_LIBZ),-lz)
 
 include ../Makeconf
--- hurd/sutils/Makefile	2022-11-30 11:14:21.19200 +0100
+++ hurd/sutils/Makefile	2022-12-02 15:51:54.06400 +0100
@@ -29,6 +29,7 @@
 
 OBJS = $(progs:=.o)
 HURDLIBS = store shouldbeinlibc
+LDLIBS += $(and $(HAVE_LIBZ),-lz)
 
 include ../Makeconf
 
--- hurd/tmpfs/Makefile	2022-11-30 11:14:21.19200 +0100
+++ hurd/tmpfs/Makefile	2022-11-30 12:18:05.20400 +0100
@@ -24,6 +24,6 @@
 OBJS = $(SRCS:.c=.o) default_pagerUser.o
 # XXX The shared libdiskfs requires libstore even though we don't use it here.
 HURDLIBS = diskfs pager iohelp fshelp store ports ihash shouldbeinlibc
-LDLIBS = -lpthread
+LDLIBS = -lpthread $(and $(HAVE_LIBZ),-lz)
 
 include ../Makeconf
--- hurd/utils/Makefile	2022-11-30 11:14:21.19600 +0100
+++ hurd/utils/Makefile	2022-12-02 15:40:57.58400 +0100
@@ -35,7 +35,7 @@
 
 OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
 HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
-LDLIBS += -lpthread
+LDLIBS += -lpthread $(and $(HAVE_LIBZ),-lz)
 login-LDLIBS = -lutil $(and $(HAVE_LIBCRYPT),-lcrypt)
 addauth-LDLIBS = $(and $(HAVE_LIBCRYPT),-lcrypt)
 setauth-LDLIBS = $(and $(HAVE_LIBCRYPT),-lcrypt)
--- hurd-git/mach-defpager/Makefile	2022-12-03 16:44:52.84800 +0100
+++ hurd-git/mach-defpager/Makefile	2022-12-08 21:27:32.33600 +0100
@@ -30,7 +30,7 @@
 	   default_pager_replyUser.o
 
 HURDLIBS:= ihash shouldbeinlibc
-LDLIBS:= -lpthread
+LDLIBS:= -lpthread -lhurduser
 
 include ../Makeconf
 
--- hurd/trans/Makefile	2019-12-18 19:29:43.94000 +0100
+++ hurd/trans/Makefile	2019-12-22 00:37:06.65600 +0100
@@ -62,7 +62,7 @@
 ifeq ($(HAVE_LIBGCRYPT),yes)
  SRCS += random.c
  targets += random
- random-LDLIBS = -lgcrypt
+ random-LDLIBS = -lgcrypt -lgpg-error
  random: startup_notifyServer.o mach_debugUser.o ../libtrivfs/libtrivfs.a
 endif
 


[PATCH] Fix some compiler warnings

2023-01-17 Thread Svante Signell
Hi,

The attached patch fixes some format warnings as well as an implicit
declaration of ‘startup_essential_task’ in mach-defpager/main.c.

Applies nicely to hurd-0.9.git20221224 and latest git.

Thanks!
--- hurd-git/ext2fs/ext2fs.c	2022-12-08 15:05:29.80800 +0100
+++ hurd-git/ext2fs/ext2fs.c	2022-12-08 19:11:12.60400 +0100
@@ -232,7 +232,7 @@
   if (store->size < SBLOCK_OFFS + SBLOCK_SIZE)
 ext2_panic ("device too small for superblock (%Ld bytes)", store->size);
   if (store->log2_blocks_per_page < 0)
-ext2_panic ("device block size (%zu) greater than page size (%lu)",
+ext2_panic ("device block size (%zu) greater than page size (%u)",
 		store->block_size, vm_page_size);
 
   /* Map the entire disk. */
--- hurd-git/ext2fs/dir.c	2022-12-03 16:44:52.78000 +0100
+++ hurd-git/ext2fs/dir.c	2022-12-09 11:35:05.29600 +0100
@@ -415,7 +415,7 @@
 	  || EXT2_DIR_REC_LEN (entry->name_len) > le16toh (entry->rec_len)
 	  || memchr (entry->name, '\0', entry->name_len))
 	{
-	  ext2_warning ("bad directory entry: inode: %Ld offset: %lu",
+	  ext2_warning ("bad directory entry: inode: %Ld offset: %u",
 			dp->cache_id,
 			currentoff - blockaddr + idx * DIRBLKSIZ);
 	  return ENOENT;
--- hurd-git/libpager/data-request.c	2022-12-08 15:05:29.81200 +0100
+++ hurd-git/libpager/data-request.c	2022-12-09 11:23:20.41200 +0100
@@ -49,7 +49,7 @@
 }
   if (length != __vm_page_size)
 {
-  printf ("incg data request: bad length size %lu\n", length);
+  printf ("incg data request: bad length size %u\n", length);
   goto release_out;
 }
   if (offset % __vm_page_size)
--- hurd-git/libpager/data-return.c	2022-12-08 15:05:29.81200 +0100
+++ hurd-git/libpager/data-return.c	2022-12-09 11:24:56.80400 +0100
@@ -60,7 +60,7 @@
 }
   if (length % __vm_page_size)
 {
-  printf ("incg data return: bad length size %lu\n", length);
+  printf ("incg data return: bad length size %u\n", length);
   goto release_out;
 }
   if (offset % __vm_page_size)
--- hurd-git/libpager/data-unlock.c	2022-12-08 15:05:29.81200 +0100
+++ hurd-git/libpager/data-unlock.c	2022-12-09 11:26:07.95600 +0100
@@ -58,7 +58,7 @@
 }
   if (length != __vm_page_size)
 {
-  printf ("incg data unlock: bad length size %lu\n", length);
+  printf ("incg data unlock: bad length size %u\n", length);
   goto out;
 }
 
--- hurd-git/ext2fs/pager.c	2022-12-08 15:05:29.81200 +0100
+++ hurd-git/ext2fs/pager.c	2022-12-08 19:23:39.85600 +0100
@@ -642,7 +642,7 @@
   if (err == ENOSPC)
 	ext2_warning ("This filesystem is out of space.");
   else if (err)
-	ext2_warning ("inode=%Ld, page=0x%lx: %s",
+	ext2_warning ("inode=%Ld, page=0x%x: %s",
 		  node->cache_id, page, strerror (err));
 
   return err;
@@ -905,7 +905,7 @@
 disk_cache_init (void)
 {
   if (block_size != vm_page_size)
-ext2_panic ("Block size %u != vm_page_size %lu",
+ext2_panic ("Block size %u != vm_page_size %u",
 		block_size, vm_page_size);
 
   pthread_mutex_init (_cache_lock, NULL);
--- hurd-git/mach-defpager/main.c	2022-12-04 14:53:41.23200 +0100
+++ hurd-git/mach-defpager/main.c	2022-12-09 11:53:44.37200 +0100
@@ -43,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 /* XXX */