[PATCH gnumach] Define rpc_vm_size_array_t and rpc_vm_offset_array_t

2023-01-30 Thread Flavio Cruz
When generating stubs, Mig will will take the vm_size_array_t and define the
input request struct using rpc_vm_size_t since the size is variable. This will 
turn cause a mismatch
between types (vm_size_t* vs rpc_vm_size_t*). We could also ask Mig to produce
a prototype by using rpc_vm_size_t*, however we would need to change the 
implementation
of the RPC to use rpc_* types anyway since we want to avoid another allocation
of the array.
---
 i386/include/mach/i386/vm_types.h |  3 +++
 include/mach/mach4.defs   |  8 +---
 vm/memory_object_proxy.c  |  6 +++---
 vm/memory_object_proxy.h  |  8 
 vm/vm_map.c   | 13 +++--
 5 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/i386/include/mach/i386/vm_types.h 
b/i386/include/mach/i386/vm_types.h
index 663f920a..bd07ef26 100644
--- a/i386/include/mach/i386/vm_types.h
+++ b/i386/include/mach/i386/vm_types.h
@@ -158,6 +158,9 @@ typedef long_integer_t rpc_long_integer_t;
 #define convert_long_natural_to_user convert_vm_to_user
 #define convert_long_natural_from_user convert_vm_from_user
 
+typedefrpc_vm_size_t * rpc_vm_size_array_t;
+typedefrpc_vm_offset_t *   rpc_vm_offset_array_t;
+
 #endif /* __ASSEMBLER__ */
 
 /*
diff --git a/include/mach/mach4.defs b/include/mach/mach4.defs
index 53cca7d3..d63d6f77 100644
--- a/include/mach/mach4.defs
+++ b/include/mach/mach4.defs
@@ -108,14 +108,16 @@ skip  /* pc_sampling reserved 4*/;
protection MAX_PROTECTION and return it in *PORT.  */
 type vm_offset_array_t = array[*:1024] of vm_offset_t;
 type vm_size_array_t = array[*:1024] of vm_size_t;
+type rpc_vm_size_array_t = array[*:1024] of rpc_vm_size_t;
+type rpc_vm_offset_array_t = array[*:1024] of rpc_vm_offset_t;
 routine memory_object_create_proxy(
task: ipc_space_t;
max_protection  : vm_prot_t;
object  : memory_object_array_t =
  array[*:1024] of mach_port_send_t;
-   offset  : vm_offset_array_t;
-   start   : vm_offset_array_t;
-   len : vm_size_array_t;
+   offset  : rpc_vm_offset_array_t;
+   start   : rpc_vm_offset_array_t;
+   len : rpc_vm_size_array_t;
out proxy   : mach_port_t);
 
 /* Gets a proxy to the region that ADDRESS belongs to, starting at the region
diff --git a/vm/memory_object_proxy.c b/vm/memory_object_proxy.c
index 46a57932..0f1e75e5 100644
--- a/vm/memory_object_proxy.c
+++ b/vm/memory_object_proxy.c
@@ -133,9 +133,9 @@ memory_object_proxy_notify (mach_msg_header_t *msg)
 kern_return_t
 memory_object_create_proxy (ipc_space_t space, vm_prot_t max_protection,
ipc_port_t *object, natural_t object_count,
-   vm_offset_t *offset, natural_t offset_count,
-   vm_offset_t *start, natural_t start_count,
-   vm_size_t *len, natural_t len_count,
+   rpc_vm_offset_t *offset, natural_t offset_count,
+   rpc_vm_offset_t *start, natural_t start_count,
+   rpc_vm_size_t *len, natural_t len_count,
ipc_port_t *port)
 {
   memory_object_proxy_t proxy;
diff --git a/vm/memory_object_proxy.h b/vm/memory_object_proxy.h
index 97f20b36..8b3f2025 100644
--- a/vm/memory_object_proxy.h
+++ b/vm/memory_object_proxy.h
@@ -36,12 +36,4 @@ extern kern_return_t memory_object_proxy_lookup (ipc_port_t 
port,
  vm_offset_t *start,
  vm_offset_t *len);
 
-extern kern_return_t
-memory_object_create_proxy (ipc_space_t space, vm_prot_t max_protection,
-   ipc_port_t *object, natural_t object_count,
-   vm_offset_t *offset, natural_t offset_count,
-   vm_offset_t *start, natural_t start_count,
-   vm_size_t *len, natural_t len_count,
-   ipc_port_t *port);
-
 #endif /* _VM_MEMORY_OBJECT_PROXY_H_ */
diff --git a/vm/vm_map.c b/vm/vm_map.c
index bea84a4d..23c4c296 100644
--- a/vm/vm_map.c
+++ b/vm/vm_map.c
@@ -4804,7 +4804,8 @@ vm_region_create_proxy (task_t task, vm_address_t address,
   kern_return_t ret;
   vm_map_entry_t entry, tmp_entry;
   vm_object_t object;
-  vm_offset_t offset, start;
+  rpc_vm_offset_t rpc_offset, rpc_start;
+  rpc_vm_size_t rpc_len = (rpc_vm_size_t) len;
   ipc_port_t pager;
 
   if (task == TASK_NULL)
@@ -4840,16 +4841,16 @@ vm_region_create_proxy (task_t task, vm_address_t 
address,
   pager = ipc_port_copy_send(object->pager);
   vm_object_unlock(object);
 
-  start = (address - entry->vme_start) + entry->offset;
-  offset = 0;
+  rpc_start = (address - entry->vme_start) + entry->offset;
+  rpc_offset = 0;
 
  

Re: [PATCH] Use $(CC) instead of gcc to avoid relying on the host gcc.

2023-01-30 Thread Flávio Cruz
On Mon, Jan 30, 2023 at 6:51 PM Guillem Jover  wrote:

> On Mon, 2023-01-30 at 12:43:09 +0300, Sergey Bugaev wrote:
> > it would be nicer if you explicitly specified what source tree this
> > patch is for, for instance: [PATCH glibc] or [PATCH gnumach] instead
> > of just [PATCH]. (There is the --subject-prefix option in git
> > format-patch for this.)
>
> Right, and in case this is not obvious, you can configure it
> permanently per repo with something like:
>
>   $ git config format.subjectprefix "PATCH gnumach"
>

Thanks Guillem and Sergey! I ended up with a git alias to format patches
with the subject prefix as [PATCH ]:

git config --global alias.format-patch-repo '!git format-patch
--subject-prefix="PATCH $(basename $(git rev-parse --show-toplevel))"'


> Thanks,
> Guillem
>


Re: [PATCH] Use $(CC) instead of gcc to avoid relying on the host gcc.

2023-01-30 Thread Guillem Jover
On Mon, 2023-01-30 at 12:43:09 +0300, Sergey Bugaev wrote:
> it would be nicer if you explicitly specified what source tree this
> patch is for, for instance: [PATCH glibc] or [PATCH gnumach] instead
> of just [PATCH]. (There is the --subject-prefix option in git
> format-patch for this.)

Right, and in case this is not obvious, you can configure it
permanently per repo with something like:

  $ git config format.subjectprefix "PATCH gnumach"

Thanks,
Guillem



Out of order building

2023-01-30 Thread Ryan Raymond
I think I found a resolvable issue. Still looking into it though.
Apparently some things which depend on libstrore/libstore.so are built
before it. The solution is to run make libstore and then continue. If this
fixes it I'd like to make this the default behavior.
What think?


Re: [PATCH] Use $(CC) instead of gcc to avoid relying on the host gcc.

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

Flavio Cruz, le lun. 30 janv. 2023 02:26:59 -0500, a ecrit:
> ---
>  Makefile.am | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 10d030b8..e31a875d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -41,7 +41,7 @@ AM_LDFLAGS =
>  # Compilation flags
>  #
>  
> -GCC_INSTALL = $(shell LANG=C gcc -print-search-dirs | sed -n -e 's/install: 
> \(.*\)/\1/p')
> +GCC_INSTALL = $(shell LANG=C $(CC) -print-search-dirs | sed -n -e 
> 's/install: \(.*\)/\1/p')
>  AM_CPPFLAGS += \
>   -imacros config.h -I $(GCC_INSTALL)/include
>  
> -- 
> 2.39.0
> 
> 

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



Re: [PATCH] Include i386asm.h using i386/i386/i386.asm.h

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

Flavio Cruz, le lun. 30 janv. 2023 02:22:14 -0500, a ecrit:
> If we 1) build for x86_64 and 2) build in a separate directory, we will not 
> have
> -Ii386 (-Ix86_64 instead) hence this file won't be found since it is 
> autogenerated.
> ---
>  i386/i386at/int_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/i386/i386at/int_init.c b/i386/i386at/int_init.c
> index 964ce1bb..1d264004 100644
> --- a/i386/i386at/int_init.c
> +++ b/i386/i386at/int_init.c
> @@ -24,7 +24,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  
>  /* defined in locore.S */
>  extern vm_offset_t int_entry_table[];
> -- 
> 2.39.0
> 
> 

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



Re: [PATCH] Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd

2023-01-30 Thread Thomas Schwinge
Hi!

On 2023-01-27T21:15:01-0500, Flávio Cruz  wrote:
> Not sure what happened, but here's the patch as an attachment. Thanks for
> your patience.

Thanks, that worked.  Without any changes now pushed to master branch in
commit 5f8950b403f6351f125d8281d2e7430a43e7d125
"Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd",
see attached.

I'll watch how x86_64 GNU/Hurd develops!  :-)


Grüße
 Thomas


> On Fri, Jan 27, 2023 at 4:16 PM Thomas Schwinge 
> wrote:
>
>> Hi Flavio!
>>
>> Sorry to bother you one last time (hopefully):
>>
>> On 2023-01-27T01:49:25-0500, Flavio Cruz  wrote:
>> > On Thu, Jan 26, 2023 at 09:34:16AM +0100, Thomas Schwinge wrote:
>> >>As you don't have FSF Copyright Assignment on file for GCC (as far as I
>> >>can tell), are you either going to get that, or re-submit this patch with
>> >>DCO ('Signed-off-by:' tag), ?
>> >
>> > Yes, I think I have it for Hurd related projects
>>
>> Yes.
>>
>> > but not GCC. Added Signed-off-by.
>>
>> ACK, thanks.
>>
>> > Revisted patch is inlined below. Also added the ChangeLog details.
>>
>> Thanks!
>>
>> If I 'git am' that one, I get:
>>
>> warning: Patch sent with format=flowed; space at the end of lines might 
>> be lost.
>> Applying: Add support for x86_64-*-gnu-* targets to build x86_64 
>> gnumach/hurd
>> error: corrupt patch at line 180
>> Patch failed at 0001 Add support for x86_64-*-gnu-* targets to build 
>> x86_64 gnumach/hurd
>> [...]
>>
>> That's due to:
>>
>> Content-Type: text/plain; charset="iso-8859-1"; format=flowed
>>
>> Is it easy for you to re-send that "differently"?  (Or, just attach the
>> file generated by 'git format-patch'.)  If that's inconvenient, then I'll
>> fix it up manually, no worries.
>>
>>
>> Grüße
>>  Thomas


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
>From 5f8950b403f6351f125d8281d2e7430a43e7d125 Mon Sep 17 00:00:00 2001
From: Flavio Cruz 
Date: Thu, 26 Jan 2023 22:45:27 -0500
Subject: [PATCH] Add support for x86_64-*-gnu-* targets to build x86_64
 gnumach/hurd

Tested by building a toolchain and compiling gnumach for x86_64 [1].
This is the basic version without unwind support which I think is only
required to implement exceptions.

[1]
https://github.com/flavioc/cross-hurd/blob/master/bootstrap-kernel.sh.

gcc/ChangeLog:
	* config.gcc: Recognize x86_64-*-gnu* targets and include
	i386/gnu64.h.
	* config/i386/gnu64.h: Define configuration for new target
	including ld.so location.

libgcc/ChangeLog:
	* config.host: Recognize x86_64-*-gnu* targets.
	* config/i386/gnu-unwind.h: Update to handle __x86_64__ with a
	TODO for now.

Signed-off-by: Flavio Cruz 
---
 gcc/config.gcc  |  5 -
 gcc/config/i386/gnu64.h | 40 +
 libgcc/config.host  |  8 ++-
 libgcc/config/i386/gnu-unwind.h | 10 +
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/i386/gnu64.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 744b46fb3b0..f0958e1c959 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1971,7 +1971,7 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]8
 		;;
 	esac
 	;;
-x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
+x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-gnu*)
 	tm_file="${tm_file} i386/unix.h i386/att.h elfos.h gnu-user.h glibc-stdint.h \
 		 i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h"
 	case ${target} in
@@ -1982,6 +1982,9 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
 	x86_64-*-kfreebsd*-gnu)
 		tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h"
 		;;
+	x86_64-*-gnu*)
+		tm_file="${tm_file} gnu.h i386/gnu64.h"
+		;;
 	esac
 	tmake_file="${tmake_file} i386/t-linux64"
 	x86_multilibs="${with_multilib_list}"
diff --git a/gcc/config/i386/gnu64.h b/gcc/config/i386/gnu64.h
new file mode 100644
index 000..a411f0e802a
--- /dev/null
+++ b/gcc/config/i386/gnu64.h
@@ -0,0 +1,40 @@
+/* Configuration for an x86_64 running GNU with ELF as the target machine.  */
+
+/*
+Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC.  If not, see .
+*/
+
+#define 

[PATCH v2 3/3] hurd: Implement SHM_ANON

2023-01-30 Thread Sergey Bugaev
This adds a special SHM_ANON value that can be passed into shm_open ()
in place of a name. When called in this way, shm_open () will create a
new anonymous shared memory file. The file will be created in the same
way that other shared memory files are created (i.e., under /dev/shm/),
except that it is not given a name and therefore cannot be reached from
the file system, nor by other calls to shm_open (). This is accomplished
by utilizing O_TMPFILE.

This is intended to be compatible with FreeBSD's API of the same name.

Signed-off-by: Sergey Bugaev 
---
 posix/shm-directory.c | 25 +
 rt/shm_open.c |  5 +
 sysdeps/mach/hurd/bits/mman_ext.h | 25 +
 3 files changed, 51 insertions(+), 4 deletions(-)
 create mode 100644 sysdeps/mach/hurd/bits/mman_ext.h

diff --git a/posix/shm-directory.c b/posix/shm-directory.c
index 47e2355d..86d9fd8e 100644
--- a/posix/shm-directory.c
+++ b/posix/shm-directory.c
@@ -23,17 +23,34 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 int
 __shm_get_name (struct shmdir_name *result, const char *name, bool sem_prefix)
 {
+  struct alloc_buffer buffer;
+  size_t namelen;
+
+  buffer = alloc_buffer_create (result->name, sizeof (result->name));
+  alloc_buffer_copy_bytes (, SHMDIR, strlen (SHMDIR));
+
+#if defined (SHM_ANON) && defined (O_TMPFILE)
+  if (name == SHM_ANON)
+{
+  /* For SHM_ANON, we want shm_open () to pass O_TMPFILE to open (),
+ with SHMDIR itself as the path.  So, leave it at that.  */
+  alloc_buffer_add_byte (, 0);
+  if (alloc_buffer_has_failed ())
+return -1;
+  return 0;
+}
+#endif
+
   while (name[0] == '/')
 ++name;
-  size_t namelen = strlen (name);
+  namelen = strlen (name);
 
-  struct alloc_buffer buffer
-= alloc_buffer_create (result->name, sizeof (result->name));
-  alloc_buffer_copy_bytes (, SHMDIR, strlen (SHMDIR));
   if (sem_prefix)
 alloc_buffer_copy_bytes (, "sem.", strlen ("sem."));
   alloc_buffer_copy_bytes (, name, namelen + 1);
diff --git a/rt/shm_open.c b/rt/shm_open.c
index 48970bbc..6c1f4d60 100644
--- a/rt/shm_open.c
+++ b/rt/shm_open.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Open shared memory object.  */
 int
@@ -36,6 +37,10 @@ __shm_open (const char *name, int oflag, mode_t mode)
 }
 
   oflag |= O_NOFOLLOW | O_CLOEXEC;
+#if defined (SHM_ANON) && defined (O_TMPFILE)
+  if (name == SHM_ANON)
+oflag |= O_TMPFILE;
+#endif
 
   int fd = __open64_nocancel (dirname.name, oflag, mode);
   if (fd == -1 && __glibc_unlikely (errno == EISDIR))
diff --git a/sysdeps/mach/hurd/bits/mman_ext.h 
b/sysdeps/mach/hurd/bits/mman_ext.h
new file mode 100644
index ..f022826e
--- /dev/null
+++ b/sysdeps/mach/hurd/bits/mman_ext.h
@@ -0,0 +1,25 @@
+/* System-specific extensions of , Hurd version.
+   Copyright (C) 2022 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 _SYS_MMAN_H
+# error "Never include  directly; use  instead."
+#endif
+
+#ifdef __USE_GNU
+# define SHM_ANON  ((const char *) 1)
+#endif /* __USE_GNU  */
-- 
2.39.1




[PATCH v2 2/3] hurd: Implement O_TMPFILE

2023-01-30 Thread Sergey Bugaev
This is a flag that causes open () to create a new, unnamed file in the
same filesystem as the given directory. The file descriptor can be
simply used in the creating process as a temporary file, or shared with
children processes via fork (), or sent over a Unix socket. The file can
be left anonymous, in which case it will be deleted from the backing
file system once all copies of the file descriptor are closed, or given
a permanent name with a linkat () call, such as the following:

int fd = open ("/tmp", O_TMPFILE | O_RDWR, 0700);
/* Do something with the file... */
linkat (fd, "", AT_FDCWD, "/tmp/filename", AT_EMPTY_PATH);

In between creating the file and linking it to the file system, it is
possible to set the file content, mode, ownership, author, and other
attributes, so that the file visibly appears in the file system (perhaps
replacing another file) atomically, with all of its attributes already
set up.

The Hurd support for O_TMPFILE directly exposes the dir_mkfile RPC to
user programs. Previously, dir_mkfile was used by glibc internally, in
particular for implementing tmpfile (), but not exposed to user programs
through a Unix-level API.

O_TMPFILE was initially introduced by Linux. This implementation is
intended to be compatible with the Linux implementation, except that the
O_EXCL flag is not given the special meaning when used together with
O_TMPFILE, unlike on Linux.

Signed-off-by: Sergey Bugaev 
---
 hurd/lookup-at.c   | 21 +
 sysdeps/mach/hurd/bits/fcntl.h |  4 
 2 files changed, 25 insertions(+)

diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c
index 25dab5a1..88c83779 100644
--- a/hurd/lookup-at.c
+++ b/hurd/lookup-at.c
@@ -29,6 +29,7 @@ __file_name_lookup_at (int fd, int at_flags,
   error_t err;
   file_t result;
   int empty = at_flags & AT_EMPTY_PATH;
+  int orig_flags;
 
   at_flags &= ~AT_EMPTY_PATH;
 
@@ -53,6 +54,10 @@ __file_name_lookup_at (int fd, int at_flags,
   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
 }
 
+  orig_flags = flags;
+  if (flags & O_TMPFILE)
+flags = O_DIRECTORY;
+
   if (fd == AT_FDCWD || file_name[0] == '/')
 {
   err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0,
@@ -90,6 +95,22 @@ __file_name_lookup_at (int fd, int at_flags,
 }
 }
 
+  if (orig_flags & O_TMPFILE)
+{
+  /* What we have looked up is not the file itself, but actually
+ the directory to create the file in.  Do that now.  */
+  file_t dir = result;
+
+  err = __dir_mkfile (dir, orig_flags & ~(O_TMPFILE | O_DIRECTORY),
+  mode, );
+  __mach_port_deallocate (__mach_task_self (), dir);
+  if (err)
+{
+  __hurd_fail (err);
+  return MACH_PORT_NULL;
+}
+}
+
   return result;
 }
 
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
index 970f79b8..c24a819e 100644
--- a/sysdeps/mach/hurd/bits/fcntl.h
+++ b/sysdeps/mach/hurd/bits/fcntl.h
@@ -123,6 +123,10 @@
 # define O_CLOEXEC 0x0040 /* Set FD_CLOEXEC.  */
 #endif
 
+#ifdef __USE_GNU
+# define O_TMPFILE 0x0080 /* Make a new unnamed file.  */
+#endif
+
 
 /* Controlling terminal flags.  These are understood only by `open',
and are not preserved once the file has been opened.  */
-- 
2.39.1




[PATCH v2 1/3] hurd: Consolidate file_name_lookup implementation

2023-01-30 Thread Sergey Bugaev
Instead of __file_name_lookup_at delegating to __file_name_lookup
in simple cases, make __file_name_lookup_at deal with both cases, and
have __file_name_lookup simply wrap __file_name_lookup_at.

Signed-off-by: Sergey Bugaev 
---
 hurd/hurdlookup.c | 10 ++
 hurd/lookup-at.c  | 51 ---
 2 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c
index 49eac443..3cfe444f 100644
--- a/hurd/hurdlookup.c
+++ b/hurd/hurdlookup.c
@@ -16,6 +16,7 @@
.  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -220,14 +221,7 @@ weak_alias (__hurd_directory_name_split, 
hurd_directory_name_split)
 file_t
 __file_name_lookup (const char *file_name, int flags, mode_t mode)
 {
-  error_t err;
-  file_t result;
-
-  err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0,
-file_name, flags, mode & ~_hurd_umask,
-);
-
-  return err ? (__hurd_fail (err), MACH_PORT_NULL) : result;
+  return __file_name_lookup_at (AT_FDCWD, 0, file_name, flags, mode);
 }
 weak_alias (__file_name_lookup, file_name_lookup)
 
diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c
index 6f30a067..25dab5a1 100644
--- a/hurd/lookup-at.c
+++ b/hurd/lookup-at.c
@@ -36,9 +36,6 @@ __file_name_lookup_at (int fd, int at_flags,
   if (err)
 return (__hurd_fail (err), MACH_PORT_NULL);
 
-  if (fd == AT_FDCWD || file_name[0] == '/')
-return __file_name_lookup (file_name, flags, mode);
-
   if (empty != 0 && file_name[0] == '\0')
 {
   enum retry_type doretry;
@@ -56,22 +53,44 @@ __file_name_lookup_at (int fd, int at_flags,
   return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
 }
 
-  file_t startdir;
-  error_t use_init_port (int which, error_t (*operate) (mach_port_t))
+  if (fd == AT_FDCWD || file_name[0] == '/')
 {
-  return (which == INIT_PORT_CWDIR ? (*operate) (startdir)
- : _hurd_ports_use (which, operate));
+  err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0,
+ file_name, flags, mode & ~_hurd_umask,
+ );
+  if (err)
+{
+  __hurd_fail (err);
+  return MACH_PORT_NULL;
+}
+}
+  else
+{
+  file_t startdir;
+  /* We need to look the file up relative to the given directory (and
+ not our cwd).  For this to work, we supply our own wrapper for
+ _hurd_ports_use, which replaces cwd with our startdir.  */
+  error_t use_init_port (int which, error_t (*operate) (mach_port_t))
+{
+  return (which == INIT_PORT_CWDIR ? (*operate) (startdir)
+ : _hurd_ports_use (which, operate));
+}
+
+  err = HURD_DPORT_USE (fd, (startdir = port,
+ __hurd_file_name_lookup (_init_port,
+  &__getdport, NULL,
+  file_name,
+  flags,
+  mode & ~_hurd_umask,
+  )));
+  if (err)
+{
+  __hurd_dfail (fd, err);
+  return MACH_PORT_NULL;
+}
 }
 
-  err = HURD_DPORT_USE (fd, (startdir = port,
-__hurd_file_name_lookup (_init_port,
- &__getdport, NULL,
- file_name,
- flags,
- mode & ~_hurd_umask,
- )));
-
-  return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
+  return result;
 }
 
 file_t
-- 
2.39.1




[PATCH v2 0/3] O_TMPFILE and SHM_ANON for the Hurd

2023-01-30 Thread Sergey Bugaev
Changes since v1:
- Add forgotten Signed-off-by
- Fix a typo (thanks Amos!)
- Drop the separate __O_TMPFILE definition

Re-tested on i686-gnu, still works.

Sergey Bugaev (3):
  hurd: Consolidate file_name_lookup implementation
  hurd: Implement O_TMPFILE
  hurd: Implement SHM_ANON

 hurd/hurdlookup.c | 10 +
 hurd/lookup-at.c  | 70 ---
 posix/shm-directory.c | 25 +--
 rt/shm_open.c |  5 +++
 sysdeps/mach/hurd/bits/fcntl.h|  4 ++
 sysdeps/mach/hurd/bits/mman_ext.h | 25 +++
 6 files changed, 112 insertions(+), 27 deletions(-)
 create mode 100644 sysdeps/mach/hurd/bits/mman_ext.h

-- 
2.39.1




Re: [RFC PATCH 2/3] hurd: Implement O_TMPFILE

2023-01-30 Thread Samuel Thibault
Sergey Bugaev, le lun. 30 janv. 2023 12:53:02 +0300, a ecrit:
> So should I remove this and just have
> 
> # define O_TMPFILE 0x0080 /* Make a new unnamed file.  */
> 
> ?

Yes, I believe we don't need the __ variant.

Samuel



Re: [RFC PATCH 2/3] hurd: Implement O_TMPFILE

2023-01-30 Thread Sergey Bugaev
On Mon, Jan 30, 2023 at 2:25 AM Samuel Thibault  wrote:
>
> Hello,
>
> Sergey Bugaev, le lun. 12 déc. 2022 14:46:35 +0300, a ecrit:
> > diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
> > index 17dcb384..b898a0c5 100644
> > --- a/sysdeps/mach/hurd/bits/fcntl.h
> > +++ b/sysdeps/mach/hurd/bits/fcntl.h
> > @@ -123,6 +123,11 @@
> >  # define O_CLOEXEC   0x0040 /* Set FD_CLOEXEC.  */
> >  #endif
> >
> > +#ifdef __USE_GNU
> > +# define __O_TMPFILE 0x0080 /* Make a new unnamed file.  */
> > +# define O_TMPFILE   (__O_TMPFILE | O_DIRECTORY)
> > +#endif
>
> I don't think we need the __O_TMPFILE variant, only the O_TMPFILE one?
>
> Linux uses __ variants just because it has per-arch definitions.

This was an attempt to mimic the Linux port's behavior, where it
automatically or's in O_DIRECTORY when you specify O_TMPFILE. Not that
it has any real meaning (at least for us) since my
__file_name_lookup_at () passes O_DIRECTORY automatically (instead of
any other flags) when O_TMPFILE is used. So should I remove this and
just have

# define O_TMPFILE 0x0080 /* Make a new unnamed file.  */

?

Thanks for taking a look!

Sergey



Re: [PATCH] Use $(CC) instead of gcc to avoid relying on the host gcc.

2023-01-30 Thread Sergey Bugaev
A humble meta-suggestion, if I might:

it would be nicer if you explicitly specified what source tree this
patch is for, for instance: [PATCH glibc] or [PATCH gnumach] instead
of just [PATCH]. (There is the --subject-prefix option in git
format-patch for this.)

This is typically easy to infer by looking at the file paths, e.g.
sysdeps/htl clearly points at glibc, kern/task.c is naturally GNU
Mach, rumpdisk/main.c is of course the Hurd proper. But just
Makefile.am — I don't know what this is. Is this GNU Mach, GNU MIG,
glibc, the Hurd, something else? (Actually, looking at the actual
patch, this seems to be GNU Mach.)

Thanks for your work!

Sergey