public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@gnu.org>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org,
	"Flávio Cruz" <flaviocruz@gmail.com>
Subject: Re: [RFC PATCH glibc 11/12] hurd, htl: Add some x86_64-specific code
Date: Sun, 12 Feb 2023 17:36:07 +0100	[thread overview]
Message-ID: <20230212163607.47dynpr5rpbohrhe@begin> (raw)
In-Reply-To: <CAN9u=Hf-HqYVaw-Z=hXypzsU6hPRycEK-A7+ch2aRBr7306tbw@mail.gmail.com>

Sergey Bugaev, le dim. 12 févr. 2023 19:25:11 +0300, a ecrit:
> On Sun, Feb 12, 2023 at 7:11 PM Samuel Thibault <samuel.thibault@gnu.org> wrote:
> > Sergey Bugaev, le dim. 12 févr. 2023 14:10:42 +0300, a ecrit:
> > > We should not need a getter routine, because one can simply inspect the target
> > > thread's state (unless, again, I misunderstand things horribly).
> >
> > For 16bit fs/gs values we could read them from userland yes. But for
> > fs/gs base, the FSGSBASE instruction is not available on all 64bit
> > processors. And ATM in THREAD_TCB we want to be able to get the base of
> > another thread.
> 
> What I've meant is:
> 
> __thread_get_state (whatever_thread, &state);
> uintptr_t its_fs_base = state->fs_base;
> 
> You can't really do the same to *write* [fg]s_base, because doing
> thread_set_state on your own thread is bound to end badly.

? Well, sure, just like setting fs/gs through thread state was not done
for i386.

I don't see where you're aiming. Getting fs/gs from __thread_get_state
won't actually give you the base, you'll just read something like 0.

> > > diff --git a/sysdeps/mach/hurd/x86_64/static-start.S b/sysdeps/mach/hurd/x86_64/static-start.S
> > > new file mode 100644
> > > index 00000000..982d3d52
> > > --- /dev/null
> > > +++ b/sysdeps/mach/hurd/x86_64/static-start.S
> > > @@ -0,0 +1,27 @@
> > > +/* 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;
> >
> > ? Isn't that rather feature_1 ?
> 
> sysdeps/mach/hurd/i386/tls.h has 'int private_futex;', which is where
> I stole this from. A quick grep confirms that it's never used,

Yes, this was just to align on the nptl tls.h. But apparently that got
renamed and hurd's tls wasn't updated.

> so we might rename both to feature_1, or maybe another instance of
> __glibc_padding.

Better stay coherent with the nptl version.

> > > +/* 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");
> >
> > Indeed. Could you perhaps also add them to the i386 tls.h?
> 
> > > +/* 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)
> >
> > While at it, try to make the i386 version use that too?
> 
> Yeah, I have not ported the improvements back to the 32-bit version;
> maybe I should.

Better always keep things as coherent as possible. Otherwise another you
will later wonder why in the hell we have differences between the two
versions.

> Another cool one is doing fs/gs-relative access using
> GCC's __seg_fs/__seg_gs when supported.

Yes, that's nice indeed!

Samuel

  reply	other threads:[~2023-02-12 16:36 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-12 11:10 [RFC PATCH 0/12] Towards glibc on x86_64-gnu Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 1/12] hurd: Refactor readlinkat() Sergey Bugaev
2023-02-12 14:49   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 2/12] hurd: Use mach_msg_type_number_t where appropriate Sergey Bugaev
2023-02-12 14:52   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 3/12] mach, hurd: Cast through uintptr_t Sergey Bugaev
2023-02-12 14:55   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 4/12] hurd: Fix xattr error value Sergey Bugaev
2023-02-12 14:56   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 5/12] htl: Fix semaphore reference Sergey Bugaev
2023-02-12 14:57   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH hurd 6/12] hurd: Fix modes_t and speeds_t types on 64-bit Sergey Bugaev
2023-02-12 15:00   ` Samuel Thibault
2023-02-12 15:15     ` Sergey Bugaev
2023-02-12 15:22       ` Samuel Thibault
2023-02-12 16:13         ` Sergey Bugaev
2023-02-12 16:30           ` Samuel Thibault
2023-02-12 19:03           ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH mig 7/12] Drop -undef -ansi from cpp flags Sergey Bugaev
2023-02-12 15:01   ` Samuel Thibault
2023-02-12 18:43     ` Flávio Cruz
2023-02-12 18:44   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH mig 8/12] Set max type alignment to sizeof(long) Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 9/12] mach: Look for mach_i386.defs on x86_64 too Sergey Bugaev
2023-02-12 15:07   ` Samuel Thibault
2023-02-12 15:38     ` Sergey Bugaev
2023-02-12 15:46       ` Samuel Thibault
2023-02-12 16:01         ` Sergey Bugaev
2023-02-16 20:22   ` Joseph Myers
2023-02-12 11:10 ` [RFC PATCH glibc 10/12] hurd: Set up the basic tree for x86_64-gnu Sergey Bugaev
2023-02-12 15:15   ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 11/12] hurd, htl: Add some x86_64-specific code Sergey Bugaev
2023-02-12 16:11   ` Samuel Thibault
2023-02-12 16:25     ` Sergey Bugaev
2023-02-12 16:36       ` Samuel Thibault [this message]
2023-02-12 16:40         ` Florian Weimer
2023-02-12 16:46           ` Samuel Thibault
2023-02-12 19:29             ` Florian Weimer
2023-02-12 19:37               ` Samuel Thibault
2023-02-12 16:51         ` Sergey Bugaev
2023-02-12 17:02           ` Samuel Thibault
2023-02-12 17:06             ` Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 12/12] C11 thrd: Downgrade the default alignment of mtx_t Sergey Bugaev
2023-02-12 15:18   ` Samuel Thibault
2023-02-12 15:52     ` Sergey Bugaev
2023-02-12 16:29       ` Samuel Thibault
2023-02-12 16:12 ` [RFC PATCH 0/12] Towards glibc on x86_64-gnu Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230212163607.47dynpr5rpbohrhe@begin \
    --to=samuel.thibault@gnu.org \
    --cc=bug-hurd@gnu.org \
    --cc=bugaevc@gmail.com \
    --cc=flaviocruz@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).