<div dir="ltr">This is similar to our private process environment. Based on this proposal,<div>what do folks think? Would this work for RTEMS?</div><div><br></div><div>--joel<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <strong class="gmail_sendername" dir="auto">Florian Weimer</strong> <span dir="auto"><<a href="mailto:fweimer@redhat.com">fweimer@redhat.com</a>></span><br>Date: Mon, Oct 24, 2022 at 11:42 AM<br>Subject: [libc-coord] Per-thread file system attributes<br>To: <<a href="mailto:libc-coord@lists.openwall.com">libc-coord@lists.openwall.com</a>><br></div><br><br>Some userspace file servers (e.g. Samba) want to change the current<br>
directory (or chroot or umask) on individual threads, rather than<br>
affecting the entire process. In some cases, this can avoid a userspace<br>
emulation of kernel pathname resolution.<br>
<br>
On Linux, these file servers current call unshare(CLONE_FS) to achieve<br>
this effect (even without libc support), but I'd rather have a record<br>
inside libc, in case we need to open internal implementation files<br>
spontaneously.<br>
<br>
For glibc, I came up with the interfaces described below. It's slightly<br>
convoluted because file servers need even more support in this<br>
direction.<br>
<br>
Any suggestions or comments?<br>
<br>
Thanks,<br>
Florian<br>
<br>
35.2.2.3 Enabling Additional Per-Thread Properties<br>
..................................................<br>
<br>
POSIX mandates that the current directory, file system root, umask<br>
value, and the current user and group IDs are process-global properties.<br>
For example, if a thread calls the ‘chdir’ function to change to a<br>
different directory, all threads are eventually affected by this change.<br>
The GNU C Library implements an extension which allows threads to be<br>
created which do not share these properties with the rest of the<br>
process.<br>
<br>
The desired behavior is specified at the time the thread is created,<br>
using the thread attribute. The following constants are used to update<br>
the attribute:<br>
<br>
‘PTHREAD_PER_PROCESS_NP’<br>
<br>
This property in question is globally shared across the entire<br>
process. This is the default.<br>
<br>
‘PTHREAD_PER_THREAD_NP’<br>
<br>
This property in question is thread-specific.<br>
<br>
The ‘PTHREAD_PER_THREAD_NP’ flag is sticky, in the sense that all<br>
threads created by a thread created with this flag have per-thread<br>
properties, even if they are created with the matching thread attribute<br>
set to the ‘PTHREAD_PER_PROCESS_NP’ flag. If an application wants to<br>
create new threads sharing properties with the main thread, it should<br>
create a service thread early (perhaps from an ELF constructor) and<br>
create these threads using this service thread.<br>
<br>
Per-thread properties can be set and examined for an attribute using<br>
the functions below.<br>
<br>
-- Function: int pthread_attr_setperthreadfs_np (pthread_attr_t *ATTR,<br>
int SCOPE)<br>
<br>
| MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety Concepts::.<br>
<br>
Change whether the following properties related to file system<br>
access are made thread-specific when a new thread is created using<br>
the attribute ATTR:<br>
<br>
• current directory (as changed by ‘chdir’ and related<br>
functions)<br>
<br>
• file system root (as changed by ‘chroot’)<br>
<br>
• umask value (as changed by the function of the same name)<br>
<br>
This function returns zero on success. SCOPE must be one of the<br>
constants ‘PTHREAD_PER_PROCESS_NP’ or ‘PTHREAD_PER_THREAD_NP’,<br>
otherwise the function returns ‘EINVAL’.<br>
<br>
If SCOPE is ‘PTHREAD_PER_THREAD_NP’, the attribute will cause the<br>
properties listed above to be specific to the thread. The initial<br>
values of these properties are copied from the creating thread, at<br>
thread creation time.<br>
<br>
If a thread that has been created with the ‘PTHREAD_PER_THREAD_NP’<br>
flag creates further threads, these threads are implicitly created<br>
with the ‘PTHREAD_PER_THREAD_NP’ flag, ignoring the value of this<br>
thread creation attribute.<br>
<br>
This function is a GNU extension and specific to Linux.<br>
<br>
-- Function: int pthread_attr_getperthreadfs_np (pthread_attr_t<br>
*restrict ATTR, int *restrict SCOPE)<br>
<br>
| MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety Concepts::.<br>
<br>
Obtain the per-thread status of the file system properties in ATTR<br>
and store it in the location SCOPE.<br>
<br>
This function is a GNU extension and specific to Linux.<br>
<br>
</div></div></div>