* [RFC PATCH 0/9] More x86_64-gnu glibc work
@ 2023-02-18 20:37 Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
` (8 more replies)
0 siblings, 9 replies; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, 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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new ()
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:32 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
` (7 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, Sergey Bugaev
This is going to be done differently on x86_64.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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 *) &ts, &tssize))
- return error;
- assert (tssize == MACHINE_THREAD_STATE_COUNT);
-
- _hurd_tls_new (thread, &ts, tcb);
-
- error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
- (natural_t *) &ts, 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) &state,
+ &state_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, &sel, 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,
+ state_count);
}
/* Global scope switch support. */
--
2.39.2
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 2/9] hurd: Use proper integer types
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:33 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
` (6 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, 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 <bugaevc@gmail.com>
---
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, &flags,
&pi, &pisize,
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, &ifc.ifc_buf, &len);
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, &data, &len);
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,
- &data, &dirp->__size,
+ &data, &data_size,
dirp->__entry_ptr,
-1, 0, &nentries)))
{
@@ -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 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
/* We've emptied out our buffer. Refill it. */
char *data = dirp->__data;
+ mach_msg_type_number_t data_size = dirp->__size;
int nentries;
if (err = HURD_FD_PORT_USE (dirp->__fd,
__dir_readdir (port,
- &data, &dirp->__size,
+ &data, &data_size,
dirp->__entry_ptr,
-1, 0, &nentries)))
{
@@ -58,6 +59,7 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
break;
}
+ dirp->__size = data_size;
/* DATA now corresponds to entry index DIRP->__entry_ptr. */
dirp->__entry_data = dirp->__entry_ptr;
--
2.39.2
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 3/9] hurd: Fix xattr function return type
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:34 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
` (5 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, Sergey Bugaev
They all return int, not size_t.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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 <hurd/xattr.h>
#include <hurd/fd.h>
-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 <hurd/xattr.h>
#include <fcntl.h>
-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 <hurd/xattr.h>
#include <fcntl.h>
-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 <hurd.h>
#include <hurd/xattr.h>
-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 <hurd.h>
#include <hurd/xattr.h>
-ssize_t
+int
setxattr (const char *path, const char *name, const void *value, size_t size,
int flags)
{
--
2.39.2
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 4/9] hurd: Make timer_t pointer-sized
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (2 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:35 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Sergey Bugaev
` (4 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, Sergey Bugaev
This ensures that a timer_t value can be cast to struct timer_node *
and back.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 5/9] hurd: Simplify init-first.c a bit
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (3 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:45 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
` (3 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, 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 <bugaevc@gmail.com>
---
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) = &call_init1;
+ *ret_address = &call_init1;
/* Force USERCODE into %eax and &init1 into %ecx, which are not
restored by function return. */
asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1));
@@ -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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 6/9] mach: Use PAGE_SIZE
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (4 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-19 23:47 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
` (2 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, 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 <bugaevc@gmail.com>
---
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 <mach.h>
#include <mach/mig_support.h>
+#include <mach/vm_param.h>
#include <unistd.h>
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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (5 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-20 0:01 ` Samuel Thibault
2023-02-20 17:27 ` Noah Goldstein
2023-02-18 20:37 ` [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
8 siblings, 2 replies; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, Sergey Bugaev
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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 *) &argc);
+ init (&argc);
}
/* 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" (&doinit1));
+# 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" (&doinit1));
+# endif
/* NOTREACHED */
}
--
2.39.2
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (6 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
8 siblings, 0 replies; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, 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 @@
#define i386_V86_ASSIST_STATE 4
#define i386_REGS_SEGS_STATE 5
#define i386_DEBUG_STATE 6
+#define i386_FSGS_BASE_STATE 7
/*
* This structure is used for both
@@ -179,4 +180,11 @@ struct i386_debug_state {
#define i386_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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
` (7 preceding siblings ...)
2023-02-18 20:37 ` [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state Sergey Bugaev
@ 2023-02-18 20:37 ` Sergey Bugaev
2023-02-20 0:30 ` Samuel Thibault
8 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-18 20:37 UTC (permalink / raw)
To: bug-hurd, libc-alpha; +Cc: Flávio Cruz, Sergey Bugaev
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
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 00000000..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
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _X86_64_TLS_H
+#define _X86_64_TLS_H
+
+
+/* Some things really need not be machine-dependent. */
+#include <sysdeps/mach/hurd/tls.h>
+
+
+#ifndef __ASSEMBLER__
+# include <dl-dtv.h>
+# include <mach/machine/thread_status.h>
+# include <errno.h>
+# include <assert.h>
+
+/* 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 (tcbhead_t, member))
+# define THREAD_SETMEM(descr, member, value) \
+ (*(__typeof (descr->member) __seg_fs *) offsetof (tcbhead_t, member) = value)
+
+# else
+
+# define THREAD_SELF \
+ ({ tcbhead_t *__tcb; \
+ asm ("movq %%fs:%c1,%0" : "=r" (__tcb) \
+ : "i" (offsetof (tcbhead_t, tcb))); \
+ __tcb; })
+
+/* Read member of the thread descriptor directly. */
+# define THREAD_GETMEM(descr, member) \
+ ({ __typeof (descr->member) __value; \
+ _Static_assert (sizeof (__value) == 1 \
+ || sizeof (__value) == 4 \
+ || sizeof (__value) == 8, \
+ "size of per-thread data"); \
+ if (sizeof (__value) == 1) \
+ asm volatile ("movb %%fs:%P2,%b0" \
+ : "=q" (__value) \
+ : "0" (0), "i" (offsetof (tcbhead_t, member))); \
+ else if (sizeof (__value) == 4) \
+ asm volatile ("movl %%fs:%P1,%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (tcbhead_t, member))); \
+ else /* 8 */ \
+ asm volatile ("movq %%fs:%P1,%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (tcbhead_t, member))); \
+ __value; })
+
+/* Write member of the thread descriptor directly. */
+# define THREAD_SETMEM(descr, member, value) \
+ ({ \
+ _Static_assert (sizeof (descr->member) == 1 \
+ || sizeof (descr->member) == 4 \
+ || sizeof (descr->member) == 8, \
+ "size of per-thread data"); \
+ if (sizeof (descr->member) == 1) \
+ asm volatile ("movb %b0,%%fs:%P1" : \
+ : "iq" (value), \
+ "i" (offsetof (tcbhead_t, member))); \
+ else if (sizeof (descr->member) == 4) \
+ asm volatile ("movl %0,%%fs:%P1" : \
+ : "ir" (value), \
+ "i" (offsetof (tcbhead_t, member))); \
+ else /* 8 */ \
+ asm volatile ("movq %0,%%fs:%P1" : \
+ : "ir" (value), \
+ "i" (offsetof (tcbhead_t, member))); \
+ })
+# endif /* __GNUC_PREREQ (6, 0) */
+
+/* Return the TCB address of a thread given its state.
+ Note: this is expensive. */
+static inline tcbhead_t * __attribute__ ((unused))
+THREAD_TCB (thread_t thread,
+ const void *all_state __attribute__ ((unused)))
+{
+ error_t err;
+ /* Fetch the target thread's state. */
+ struct i386_fsgs_base_state state;
+ mach_msg_type_number_t state_count = i386_FSGS_BASE_STATE_COUNT;
+ err = __thread_get_state (thread, i386_FSGS_BASE_STATE,
+ (thread_state_t) &state,
+ &state_count);
+ assert_perror (err);
+ assert (state_count == i386_FSGS_BASE_STATE_COUNT);
+ return (tcbhead_t *) state.fs_base;
+}
+
+/* Set the stack guard field in TCB head. */
+# define THREAD_SET_STACK_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, stack_guard, value)
+# define THREAD_COPY_STACK_GUARD(descr) \
+ ((descr)->stack_guard \
+ = THREAD_GETMEM (THREAD_SELF, stack_guard))
+
+/* Set the pointer guard field in the TCB head. */
+# define THREAD_SET_POINTER_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, pointer_guard, value)
+# define THREAD_COPY_POINTER_GUARD(descr) \
+ ((descr)->pointer_guard \
+ = THREAD_GETMEM (THREAD_SELF, pointer_guard))
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtvp) THREAD_SETMEM (THREAD_SELF, dtv, dtvp)
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() THREAD_GETMEM (THREAD_SELF, dtv)
+
+/* Set up TLS in the new thread of a fork child, copying from the original. */
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_fork (thread_t child, thread_t orig,
+ void *machine_state __attribute__ ((unused)))
+{
+ error_t err;
+ struct i386_fsgs_base_state state;
+ mach_msg_type_number_t state_count = i386_FSGS_BASE_STATE_COUNT;
+ err = __thread_get_state (orig, i386_FSGS_BASE_STATE,
+ (thread_state_t) &state,
+ &state_count);
+ if (err)
+ return err;
+ assert (state_count == i386_FSGS_BASE_STATE_COUNT);
+
+ return __thread_set_state (child, i386_FSGS_BASE_STATE,
+ (thread_state_t) &state,
+ state_count);
+}
+
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_new (thread_t child, tcbhead_t *tcb)
+{
+ struct i386_fsgs_base_state state;
+
+ tcb->tcb = tcb;
+ tcb->self = child;
+
+ /* Install the TCB address into FS base. */
+ state.fs_base = (uintptr_t) tcb;
+ state.gs_base = 0;
+ return __thread_set_state (child, i386_FSGS_BASE_STATE,
+ (thread_state_t) &state,
+ i386_FSGS_BASE_STATE_COUNT);
+}
+
+static inline bool __attribute__ ((unused))
+_hurd_tls_init (tcbhead_t *tcb)
+{
+ error_t err;
+ thread_t self = __mach_thread_self ();
+
+ /* We always at least start the sigthread anyway. */
+ tcb->multiple_threads = 1;
+
+ err = _hurd_tls_new (self, tcb);
+ __mach_port_deallocate (__mach_task_self (), self);
+ __libc_tls_initialized = 1;
+ return err == 0;
+}
+
+
+/* Global scope switch support. */
+# define THREAD_GSCOPE_FLAG_UNUSED 0
+# define THREAD_GSCOPE_FLAG_USED 1
+# define THREAD_GSCOPE_FLAG_WAIT 2
+
+# define THREAD_GSCOPE_SET_FLAG() \
+ THREAD_SETMEM (THREAD_SELF, gscope_flag, THREAD_GSCOPE_FLAG_USED)
+
+# define THREAD_GSCOPE_RESET_FLAG() \
+ ({ \
+ int __flag; \
+ asm volatile ("xchgl %0, %%fs:%P1" \
+ : "=r" (__flag) \
+ : "i" (offsetof (tcbhead_t, gscope_flag)), \
+ "0" (THREAD_GSCOPE_FLAG_UNUSED)); \
+ if (__flag == THREAD_GSCOPE_FLAG_WAIT) \
+ lll_wake (THREAD_SELF->gscope_flag, LLL_PRIVATE); \
+ })
+
+
+
+#endif /* __ASSEMBLER__ */
+#endif /* x86_64/tls.h */
diff --git a/sysdeps/mach/x86_64/thread_state.h b/sysdeps/mach/x86_64/thread_state.h
new file mode 100644
index 00000000..d8c8889f
--- /dev/null
+++ b/sysdeps/mach/x86_64/thread_state.h
@@ -0,0 +1,51 @@
+/* Mach thread state definitions for machine-independent code. x86_64 version.
+ Copyright (C) 1994-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
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _MACH_X86_64_THREAD_STATE_H
+#define _MACH_X86_64_THREAD_STATE_H 1
+
+#include <mach/machine/thread_status.h>
+
+#define MACHINE_NEW_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_COUNT i386_THREAD_STATE_COUNT
+
+#define machine_thread_state i386_thread_state
+
+#define PC rip
+#define SP ursp
+#define SYSRETURN rax
+
+#define MACHINE_THREAD_STATE_FIX_NEW(ts) do { \
+ asm ("mov %%cs, %w0" : "=q" ((ts)->cs)); \
+ asm ("mov %%ds, %w0" : "=q" ((ts)->ds)); \
+ asm ("mov %%es, %w0" : "=q" ((ts)->es)); \
+ asm ("mov %%fs, %w0" : "=q" ((ts)->fs)); \
+ asm ("mov %%gs, %w0" : "=q" ((ts)->gs)); \
+} while(0)
+
+struct machine_thread_all_state
+ {
+ int set; /* Mask of bits (1 << FLAVOR). */
+ struct i386_thread_state basic;
+ struct i386_float_state fpu;
+ };
+
+#include <sysdeps/mach/thread_state.h>
+
+#endif /* mach/x86_64/thread_state.h */
diff --git a/sysdeps/x86_64/htl/bits/pthreadtypes-arch.h b/sysdeps/x86_64/htl/bits/pthreadtypes-arch.h
new file mode 100644
index 00000000..1d402cc6
--- /dev/null
+++ b/sysdeps/x86_64/htl/bits/pthreadtypes-arch.h
@@ -0,0 +1,36 @@
+/* Machine-specific pthread type layouts. Hurd x86_64 version.
+ Copyright (C) 2002-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
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _BITS_PTHREADTYPES_ARCH_H
+#define _BITS_PTHREADTYPES_ARCH_H 1
+
+#define __SIZEOF_PTHREAD_MUTEX_T 32
+#define __SIZEOF_PTHREAD_ATTR_T 48
+#define __SIZEOF_PTHREAD_RWLOCK_T 48
+#define __SIZEOF_PTHREAD_BARRIER_T 40
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 16
+#define __SIZEOF_PTHREAD_COND_T 40
+#define __SIZEOF_PTHREAD_CONDATTR_T 8
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 4
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#define __SIZEOF_PTHREAD_ONCE_T 8
+
+#define __LOCK_ALIGNMENT
+#define __ONCE_ALIGNMENT
+
+#endif /* bits/pthreadtypes.h */
diff --git a/sysdeps/x86_64/htl/pt-machdep.h b/sysdeps/x86_64/htl/pt-machdep.h
new file mode 100644
index 00000000..2e2846fa
--- /dev/null
+++ b/sysdeps/x86_64/htl/pt-machdep.h
@@ -0,0 +1,28 @@
+/* Machine dependent pthreads internal defenitions. x86_64 version.
+ Copyright (C) 2000-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
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _PT_MACHDEP_H
+#define _PT_MACHDEP_H 1
+
+struct pthread_mcontext
+{
+ void *pc;
+ void *sp;
+};
+
+#endif /* pt-machdep.h */
--
2.39.2
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new ()
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
@ 2023-02-19 23:32 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:32 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:09 +0300, a ecrit:
> This is going to be done differently on x86_64.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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 *) &ts, &tssize))
> - return error;
> - assert (tssize == MACHINE_THREAD_STATE_COUNT);
> -
> - _hurd_tls_new (thread, &ts, tcb);
> -
> - error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
> - (natural_t *) &ts, 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) &state,
> + &state_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, &sel, 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,
> + state_count);
> }
>
> /* Global scope switch support. */
> --
> 2.39.2
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 2/9] hurd: Use proper integer types
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
@ 2023-02-19 23:33 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:33 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:10 +0300, a ecrit:
> Fix a few more cases of build errors caused by mismatched types. This is a
> continuation of f4315054b46d5e58b44a709a51943fb73f846afb.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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, &flags,
> &pi, &pisize,
> 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, &ifc.ifc_buf, &len);
> 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, &data, &len);
> 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,
> - &data, &dirp->__size,
> + &data, &data_size,
> dirp->__entry_ptr,
> -1, 0, &nentries)))
> {
> @@ -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 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
> /* We've emptied out our buffer. Refill it. */
>
> char *data = dirp->__data;
> + mach_msg_type_number_t data_size = dirp->__size;
> int nentries;
>
> if (err = HURD_FD_PORT_USE (dirp->__fd,
> __dir_readdir (port,
> - &data, &dirp->__size,
> + &data, &data_size,
> dirp->__entry_ptr,
> -1, 0, &nentries)))
> {
> @@ -58,6 +59,7 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
> break;
> }
>
> + dirp->__size = data_size;
> /* DATA now corresponds to entry index DIRP->__entry_ptr. */
> dirp->__entry_data = dirp->__entry_ptr;
>
> --
> 2.39.2
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 3/9] hurd: Fix xattr function return type
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
@ 2023-02-19 23:34 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:34 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:11 +0300, a ecrit:
> They all return int, not size_t.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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 <hurd/xattr.h>
> #include <hurd/fd.h>
>
> -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 <hurd/xattr.h>
> #include <fcntl.h>
>
> -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 <hurd/xattr.h>
> #include <fcntl.h>
>
> -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 <hurd.h>
> #include <hurd/xattr.h>
>
> -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 <hurd.h>
> #include <hurd/xattr.h>
>
> -ssize_t
> +int
> setxattr (const char *path, const char *name, const void *value, size_t size,
> int flags)
> {
> --
> 2.39.2
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 4/9] hurd: Make timer_t pointer-sized
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
@ 2023-02-19 23:35 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:35 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:12 +0300, a ecrit:
> This ensures that a timer_t value can be cast to struct timer_node *
> and back.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 5/9] hurd: Simplify init-first.c a bit
2023-02-18 20:37 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Sergey Bugaev
@ 2023-02-19 23:45 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:45 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:13 +0300, a ecrit:
> And make it a bit more 64-bit ready. This is in preparation to moving this
> file into x86/
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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) = &call_init1;
> + *ret_address = &call_init1;
> /* Force USERCODE into %eax and &init1 into %ecx, which are not
> restored by function return. */
> asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1));
> @@ -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
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 6/9] mach: Use PAGE_SIZE
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
@ 2023-02-19 23:47 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-19 23:47 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Applied, thanks!
Sergey Bugaev, le sam. 18 févr. 2023 23:37:14 +0300, a ecrit:
> 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 <bugaevc@gmail.com>
> ---
> 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 <mach.h>
> #include <mach/mig_support.h>
> +#include <mach/vm_param.h>
> #include <unistd.h>
>
> 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
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
@ 2023-02-20 0:01 ` Samuel Thibault
2023-02-20 16:16 ` Sergey Bugaev
2023-02-20 17:27 ` Noah Goldstein
1 sibling, 1 reply; 22+ messages in thread
From: Samuel Thibault @ 2023-02-20 0:01 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Sergey Bugaev, le sam. 18 févr. 2023 23:37:15 +0300, a ecrit:
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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 *) &argc);
> + init (&argc);
That won't work on x86_64: there, arguments are passed mostly through
registers, so &argc won't actually give you the address of arguments on
the stack. This can probably be checked on linux x86_64 to make sure how
arguments are passed.
> }
>
> /* 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" (&doinit1));
> +# 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" (&doinit1));
> +# endif
> /* NOTREACHED */
> }
>
> --
> 2.39.2
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
@ 2023-02-20 0:30 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-20 0:30 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Sergey Bugaev, le sam. 18 févr. 2023 23:37:17 +0300, a ecrit:
> diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h
> new file mode 100644
> index 00000000..644dcb1a
> --- /dev/null
> +++ b/sysdeps/mach/hurd/x86_64/tls.h
> @@ -0,0 +1,257 @@
> +# define TCB_ALIGNMENT 64
Please copy the comment about the penalty of non-64-aligned accesses.
> +# 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 (tcbhead_t, member))
> +# define THREAD_SETMEM(descr, member, value) \
> + (*(__typeof (descr->member) __seg_fs *) offsetof (tcbhead_t, member) = value)
> +
> +# else
I'd say don't bother keeping the non-gcc-6 case, since x86_64-gnu got
added to gcc only recently.
> +/* Set the stack guard field in TCB head. */
> +# define THREAD_SET_STACK_GUARD(value) \
> + THREAD_SETMEM (THREAD_SELF, stack_guard, value)
> +# define THREAD_COPY_STACK_GUARD(descr) \
> + ((descr)->stack_guard \
> + = THREAD_GETMEM (THREAD_SELF, stack_guard))
> +
> +/* Set the pointer guard field in the TCB head. */
> +# define THREAD_SET_POINTER_GUARD(value) \
> + THREAD_SETMEM (THREAD_SELF, pointer_guard, value)
> +# define THREAD_COPY_POINTER_GUARD(descr) \
> + ((descr)->pointer_guard \
> + = THREAD_GETMEM (THREAD_SELF, pointer_guard))
> +
> +/* Install new dtv for current thread. */
> +# define INSTALL_NEW_DTV(dtvp) THREAD_SETMEM (THREAD_SELF, dtv, dtvp)
> +
> +/* Return the address of the dtv for the current thread. */
> +# define THREAD_DTV() THREAD_GETMEM (THREAD_SELF, dtv)
Please keep #define order coherent with i386/tls.h
> diff --git a/sysdeps/x86_64/htl/pt-machdep.h b/sysdeps/x86_64/htl/pt-machdep.h
> new file mode 100644
> index 00000000..2e2846fa
> --- /dev/null
> +++ b/sysdeps/x86_64/htl/pt-machdep.h
I don't think this is needed since we already have sysdeps/x86/htl/pt-machdep.h
?
Samuel
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-20 0:01 ` Samuel Thibault
@ 2023-02-20 16:16 ` Sergey Bugaev
2023-02-20 17:10 ` Sergey Bugaev
0 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-20 16:16 UTC (permalink / raw)
To: Samuel Thibault; +Cc: bug-hurd, libc-alpha, Flávio Cruz
On Mon, Feb 20, 2023 at 3:01 AM Samuel Thibault <samuel.thibault@gnu.org> wrote:
> That won't work on x86_64: there, arguments are passed mostly through
> registers, so &argc won't actually give you the address of arguments on
> the stack.
Right, good point.
I wish I had a better understanding of just what's going on in this
file. Maybe a lot of the hacks can be rewritten in a nicer way. For
instance, do we really need to hijack the return addresses and jump to
init1 in this weird way, only to enable it to access argc/arg0? Since
we know where they are on our stack (__builtin_frame_address (0) + 2
or something like that), can't we just pass it a pointer?
Let me actually try just that...
Sergey
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-20 16:16 ` Sergey Bugaev
@ 2023-02-20 17:10 ` Sergey Bugaev
2023-02-20 17:31 ` Samuel Thibault
0 siblings, 1 reply; 22+ messages in thread
From: Sergey Bugaev @ 2023-02-20 17:10 UTC (permalink / raw)
To: Samuel Thibault; +Cc: bug-hurd, libc-alpha, Flávio Cruz
> I wish I had a better understanding of just what's going on in this
> file. Maybe a lot of the hacks can be rewritten in a nicer way. For
> instance, do we really need to hijack the return addresses and jump to
> init1 in this weird way, only to enable it to access argc/arg0? Since
> we know where they are on our stack (__builtin_frame_address (0) + 2
> or something like that), can't we just pass it a pointer?
>
> Let me actually try just that...
Eh, no, let's start even earlier than that. Please correct me if I
(inevitably) get things wrong.
_dl_init_first is Hurd-specific. It is called from the assembly code
in dl-machine.h, specifically there's a RTLD_START_SPECIAL_INIT macro
that's defined to call _dl_init_first on the Hurd, and to nothing
otherwise. This RTLD_START_SPECIAL_INIT is used ("invoked") in
i386/dl-machine.h, s390/s390-{32,64}/dl-machine.h, ia64/dl-machine.h,
and alpha/dl-machine.h (but notably not in x86_64/dl-machine.h). In
all cases, it's emphasized that "The special initializer gets called
with the stack just as the application's entry point will see it; it
can switch stacks if it moves these contents over."
But I conclude that:
- s390-gnu, ia64-gnu, and alpha-gnu ports are nonexistent, nor are
they realistically ever going to happen, so we can ignore them
completely
- the implementation does not seem to actually switch stacks (in fact,
I have removed the unused switch_stacks function in the last commit)
-- so the "gets called with the stack just as the application's entry
point will see it" property may not be important anymore?
The only thing it really needs, it seems, is a pointer to
argc/argv/envp & Hurd data block *somewhere*. It does not have to be
on the stack (though where else would it be), or immediately preceding
its call frame -- all that really matters is that there's a pointer.
So my thinking goes, why don't we just hook into _dl_start, which
already has this very pointer? And in fact, _dl_start calls
_dl_sysdep_start, for which there is already a Hurd version. Can't we
just call our logic from there, and not worry about the stack layout
and overwriting return addresses?
That would work for the SHARED case; we also need to do something for
the static case. In that case, we are invoked by static-start.S; do I
understand it right that the argc/argv/whatever is still located
on-stack even on x86_64 in this case, and not passed in registers
according to the calling convention? Then again, we should be able to
just use __builtin_frame_address (0) + 2 and avoid most of the hacks?
Please tell me if this makes any sense.
Sergey
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
2023-02-20 0:01 ` Samuel Thibault
@ 2023-02-20 17:27 ` Noah Goldstein
1 sibling, 0 replies; 22+ messages in thread
From: Noah Goldstein @ 2023-02-20 17:27 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
On Sat, Feb 18, 2023 at 2:40 PM Sergey Bugaev via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> 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 *) &argc);
> + init (&argc);
> }
>
> /* 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. */
Unless you are intentionally preserving flags, `xorl %%ebp, %%ebp` is
better way to
zero a register.
> + "jmp *%1" : : "r" (data), "r" (&doinit1));
> +# 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" (&doinit1));
> +# endif
> /* NOTREACHED */
> }
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64
2023-02-20 17:10 ` Sergey Bugaev
@ 2023-02-20 17:31 ` Samuel Thibault
0 siblings, 0 replies; 22+ messages in thread
From: Samuel Thibault @ 2023-02-20 17:31 UTC (permalink / raw)
To: Sergey Bugaev; +Cc: bug-hurd, libc-alpha, Flávio Cruz
Sergey Bugaev, le lun. 20 févr. 2023 20:10:29 +0300, a ecrit:
> - the implementation does not seem to actually switch stacks (in fact,
> I have removed the unused switch_stacks function in the last commit)
> -- so the "gets called with the stack just as the application's entry
> point will see it" property may not be important anymore?
That's possible, yes.
> So my thinking goes, why don't we just hook into _dl_start, which
> already has this very pointer? And in fact, _dl_start calls
> _dl_sysdep_start, for which there is already a Hurd version. Can't we
> just call our logic from there, and not worry about the stack layout
> and overwriting return addresses?
Possibly, yes.
> That would work for the SHARED case; we also need to do something for
> the static case. In that case, we are invoked by static-start.S; do I
> understand it right that the argc/argv/whatever is still located
> on-stack even on x86_64 in this case, and not passed in registers
> according to the calling convention?
I don't know. But you can check on Linux, we'll probably want to use the
same ABI.
Samuel
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2023-02-20 17:31 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 20:37 [RFC PATCH 0/9] More x86_64-gnu glibc work Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Sergey Bugaev
2023-02-19 23:32 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 2/9] hurd: Use proper integer types Sergey Bugaev
2023-02-19 23:33 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 3/9] hurd: Fix xattr function return type Sergey Bugaev
2023-02-19 23:34 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 4/9] hurd: Make timer_t pointer-sized Sergey Bugaev
2023-02-19 23:35 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 5/9] hurd: Simplify init-first.c a bit Sergey Bugaev
2023-02-19 23:45 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 6/9] mach: Use PAGE_SIZE Sergey Bugaev
2023-02-19 23:47 ` Samuel Thibault
2023-02-18 20:37 ` [RFC PATCH 7/9] hurd: Generalize init-first.c to support x86_64 Sergey Bugaev
2023-02-20 0:01 ` Samuel Thibault
2023-02-20 16:16 ` Sergey Bugaev
2023-02-20 17:10 ` Sergey Bugaev
2023-02-20 17:31 ` Samuel Thibault
2023-02-20 17:27 ` Noah Goldstein
2023-02-18 20:37 ` [RFC PATCH 8/9 gnumach] Add i386_fsgs_base_state Sergey Bugaev
2023-02-18 20:37 ` [RFC PATCH 9/9] hurd, htl: Add some more x86_64-specific code Sergey Bugaev
2023-02-20 0:30 ` Samuel Thibault
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).