about summary refs log tree commit diff
path: root/sysdeps/mach
Commit message (Collapse)AuthorAgeFilesLines
...
* hurd: Implement sigreturn for x86_64Sergey Bugaev2023-05-011-0/+162
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429201822.2605207-2-bugaevc@gmail.com>
* hurd: Make _exit work during early boot-upSergey Bugaev2023-04-291-2/+3
| | | | | | | | | | | | | | | | | | If any of the early boot-up tasks calls exit () or returns from main (), terminate it properly instead of crashing on trying to dereference _hurd_ports and getting forcibly terminated by the kernel. We sadly cannot make the __USEPORT macro do the check for _hurd_ports being unset, because it evaluates to the value of the expression provided as the second argument, and that can be of any type; so there is no single suitable fallback value for the macro to evaluate to in case _hurd_ports is unset. Instead, each use site that wants to care for this case will have to do its own checking. Checked on x86_64-gnu. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-4-bugaevc@gmail.com>
* Fix Hurd getcwd build with GCC >= 13Joseph Myers2023-04-271-2/+3
| | | | | | | | | | | | | | | | | | | | | The build of glibc for i686-gnu has been failing for a while with GCC mainline / GCC 13: ../sysdeps/mach/hurd/getcwd.c: In function '__hurd_canonicalize_directory_name_internal': ../sysdeps/mach/hurd/getcwd.c:242:48: error: pointer 'file_name' may be used after 'realloc' [-Werror=use-after-free] 242 | file_namep = &buf[file_namep - file_name + size / 2]; | ~~~~~~~~~~~^~~~~~~~~~~ ../sysdeps/mach/hurd/getcwd.c:236:25: note: call to 'realloc' here 236 | buf = realloc (file_name, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~ Fix by doing the subtraction before the reallocation. Tested with build-many-glibcs.py for i686-gnu. [samuel.thibault@ens-lyon.rg: Removed mention of this being a bug] Message-Id: <18587337-7815-4056-ebd0-724df262d591@codesourcery.com>
* Regenerate sysdeps/mach/hurd/bits/errno.hJoseph Myers2023-04-261-0/+19
| | | | | This file was out of date, as shown by build-many-glibcs.py runs resulting in a modified source directory.
* hurd: Do not take any flag from the CMSG_DATASamuel Thibault2023-04-251-1/+3
| | | | | | As fixed in 0822e3552a78 ("hurd: Don't pass FD_CLOEXEC in CMSG_DATA"), senders currently don't have any flag to pass. We shouldn't blindly take random flags that senders could be erroneously giving us.
* hurd: Implement MSG_CMSG_CLOEXECSergey Bugaev2023-04-242-2/+7
| | | | | | | | | | | | | | | This is a new flag that can be passed to recvmsg () to make it atomically set the CLOEXEC flag on all the file descriptors received using the SCM_RIGHTS mechanism. This is useful for all the same reasons that the other XXX_CLOEXEC flags are useful: namely, it provides atomicity with respect to another thread of the same process calling (fork and then) exec at the same time. This flag is already supported on Linux and FreeBSD. The flag's value, 0x40000, is choosen to match FreeBSD's. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230423160548.126576-2-bugaevc@gmail.com>
* hurd: Don't pass FD_CLOEXEC in CMSG_DATASamuel Thibault2023-04-241-2/+2
| | | | | | | | | | | | | | | | | | | The flags are used by _hurd_intern_fd, which takes O_* flags, not FD_*. Also, it is of no concern to the receiving process whether or not the sender process wants to close its copy of sent file descriptor upon exec, and it should not influence whether or not the received file descriptor gets the FD_CLOEXEC flag set in the receiving process. The latter should in fact be dependent on the MSG_CMSG_CLOEXEC flag being passed to the recvmsg () call, which is going to be implemented in the following commit. Fixes 344e755248ce02c0f8d095d11cc49e340703d926 "hurd: Support sending file descriptors over Unix sockets" Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Implement prefer_map_32bit_exec tunableSergey Bugaev2023-04-242-0/+11
| | | | | | | This makes the prefer_map_32bit_exec tunable no longer Linux-specific. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230423215526.346009-4-bugaevc@gmail.com>
* hurd: Don't attempt to deallocate MACH_PORT_DEADSergey Bugaev2023-04-242-4/+4
| | | | | | | ...in some more places. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230423215526.346009-2-bugaevc@gmail.com>
* hurd: Only deallocate addrport when it's validSergey Bugaev2023-04-245-6/+10
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230423160548.126576-3-bugaevc@gmail.com>
* hurd: Implement MAP_32BITSergey Bugaev2023-04-243-7/+12
| | | | | | | | | | | | | | | | | | | | This is a flag that can be passed to mmap () to request that the mapping being established should be located in the lower 2 GB area of the address space, so only the lower 31 (not 32) bits can be set in its address, and the address can be represented as a 32-bit integer without truncating it. This flag is intended to be compatible with Linux, FreeBSD, and Darwin flags of the same name. Out of those systems, it appears Linux and FreeBSD take MAP_32BIT to mean "map 31 bit", whereas Darwin allows the 32nd bit to be set in the address as well. The Hurd follows Linux and FreeBSD behavior. Unlike on those systems, on the Hurd MAP_32BIT is defined on all supported architectures (which currently are only i386 and x86_64). Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230423215526.346009-1-bugaevc@gmail.com>
* hurd: Don't migrate reply port into __init1_tcbheadSergey Bugaev2023-04-213-17/+19
| | | | | | | | | | | | | | | Properly differentiate between setting up the real TLS with TLS_INIT_TP, and setting up the early TLS (__init1_tcbhead) in static builds. In the latter case, don't yet migrate the reply port into the TCB, and don't yet set __libc_tls_initialized to 1. This also lets us move the __init1_desc assignment inside _hurd_tls_init (). Fixes cd019ddd892e182277fadd6aedccc57fa3923c8d "hurd: Don't leak __hurd_reply_port0" Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Make dl-sysdep's open () cope with O_IGNORE_CTTYSergey Bugaev2023-04-201-2/+2
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230419160207.65988-6-bugaevc@gmail.com>
* hurd: Microoptimize sigreturnSergey Bugaev2023-04-181-3/+9
| | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Fix restoring reply port in sigreturnSergey Bugaev2023-04-171-12/+23
| | | | | | | | | We must not use the user's reply port (scp->sc_reply_port) for any of our own RPCs, otherwise various things break. So, use MACH_PORT_DEAD as a reply port when destroying our reply port, and make sure to do this after _hurd_sigstate_unlock (), which may do a gsync_wake () RPC. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Only check for TLS initialization inside rtld or in static buildsSergey Bugaev2023-04-146-33/+83
| | | | | | | | | | | | | | | | | | | | | When glibc is built as a shared library, TLS is always initialized by the call of TLS_INIT_TP () macro made inside the dynamic loader, prior to running the main program (see dl-call_tls_init_tp.h). We can take advantage of this: we know for sure that __LIBC_NO_TLS () will evaluate to 0 in all other cases, so let the compiler know that explicitly too. Also, only define _hurd_tls_init () and TLS_INIT_TP () under the same conditions (either !SHARED or inside rtld), to statically assert that this is the case. Other than a microoptimization, this also helps with avoiding awkward sharing of the __libc_tls_initialized variable between ld.so and libc.so that we would have to do otherwise -- we know for sure that no sharing is required, simply because __libc_tls_initialized would always be set to true inside libc.so. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-25-bugaevc@gmail.com>
* hurd: Remove __hurd_local_reply_portSergey Bugaev2023-04-143-14/+60
| | | | | | | | | | | | | | | | | | Now that the signal code no longer accesses it, the only real user of it was mig-reply.c, so move the logic for managing the port there. If we're in SHARED and outside of rtld, we know that __LIBC_NO_TLS () always evaluates to 0, and a TLS reply port will always be used, not __hurd_reply_port0. Still, the compiler does not see that __hurd_reply_port0 is never used due to its address being taken. To deal with this, explicitly compile out __hurd_reply_port0 when we know we won't use it. Also, instead of accessing the port via THREAD_SELF->reply_port, this uses THREAD_GETMEM and THREAD_SETMEM directly, avoiding possible miscompilations. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Mark two tests as unsupportedSamuel Thibault2023-04-131-0/+10
| | | | They make the whole testsuite hang/crash.
* hurd: Restore destroying receive rights on sigreturnSamuel Thibault2023-04-131-2/+2
| | | | | Just subtracting a ref is making signal/tst-signal signal/tst-raise signal/tst-minsigstksz-5 htl/tst-raise1 fail.
* Revert "hurd: Only check for TLS initialization inside rtld or in static builds"Samuel Thibault2023-04-116-83/+33
| | | | | | | | This reverts commit b37899d34d2190ef4b454283188f22519f096048. Apparently we load libc.so (and thus start using its functions) before calling TLS_INIT_TP, so libc.so functions should not actually assume that TLS is always set up.
* hurd: Don't leak __hurd_reply_port0Sergey Bugaev2023-04-112-1/+13
| | | | | | | | | | | | | Previously, once we set up TLS, we would implicitly switch from using __hurd_reply_port0 to reply_port inside the TCB, leaving the former unused. But we never deallocated it, so it got leaked. Instead, migrate the port into the new TCB's reply_port slot. This avoids both the port leak and an extra syscall to create a new reply port for the TCB. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-28-bugaevc@gmail.com>
* hurd: Improve reply port handling when exiting signal handlersSergey Bugaev2023-04-101-16/+5
| | | | | | | | | | | | | | | | | If we're doing signals, that means we've already got the signal thread running, and that implies TLS having been set up. So we know that __hurd_local_reply_port will resolve to THREAD_SELF->reply_port, and can access that directly using the THREAD_GETMEM and THREAD_SETMEM macros. This avoids potential miscompilations, and should also be a tiny bit faster. Also, use mach_port_mod_refs () and not mach_port_destroy () to destroy the receive right. mach_port_destroy () should *never* be used on mach_task_self (); this can easily lead to port use-after-free vulnerabilities if the task has any other references to the same port. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-26-bugaevc@gmail.com>
* hurd: Only check for TLS initialization inside rtld or in static buildsSergey Bugaev2023-04-106-34/+85
| | | | | | | | | | | | | | | | | | | | | When glibc is built as a shared library, TLS is always initialized by the call of TLS_INIT_TP () macro made inside the dynamic loader, prior to running the main program (see dl-call_tls_init_tp.h). We can take advantage of this: we know for sure that __LIBC_NO_TLS () will evaluate to 0 in all other cases, so let the compiler know that explicitly too. Also, only define _hurd_tls_init () and TLS_INIT_TP () under the same conditions (either !SHARED or inside rtld), to statically assert that this is the case. Other than a microoptimization, this also helps with avoiding awkward sharing of the __libc_tls_initialized variable between ld.so and libc.so that we would have to do otherwise -- we know for sure that no sharing is required, simply because __libc_tls_initialized would always be set to true inside libc.so. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-25-bugaevc@gmail.com>
* hurd: Port trampoline.c to x86_64Sergey Bugaev2023-04-101-7/+151
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230403115621.258636-3-bugaevc@gmail.com>
* hurd: Do not declare local variables volatileSergey Bugaev2023-04-101-2/+2
| | | | | | | | | | | | | | These are just regular local variables that are not accessed in any funny ways, not even though a pointer. There's absolutely no reason to declare them volatile. It only ends up hurting the quality of the generated machine code. If anything, it would make sense to decalre sigsp as *pointing* to volatile memory (volatile void *sigsp), but evidently that's not needed either. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230403115621.258636-2-bugaevc@gmail.com>
* hurd: Implement x86_64/intr-msg.hSergey Bugaev2023-04-101-0/+119
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-18-bugaevc@gmail.com>
* hurd: Add sys/ucontext.h and sigcontext.h for x86_64Sergey Bugaev2023-04-102-0/+169
| | | | | | | This is based on the Linux port's version, but laid out to match Mach's struct i386_thread_state, much like the i386 version does. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Stop depending on the default_pager stubs provided by gnumachFlavio Cruz2023-04-102-4/+2
| | | | | | The hurd source tree already provides the same stubs and they are only needed there. Message-Id: <ZDN3rDdjMowtUWf7@jupiter.tail36e24.ts.net>
* htl: move pthread_self info libc.Guy-Fleury Iteriteka2023-04-052-2/+2
| | | | | Signed-off-by: Guy-Fleury Iteriteka <gfleury@disroot.org> Message-Id: <20230318095826.1125734-4-gfleury@disroot.org>
* htl: move ___pthread_self into libc.Guy-Fleury Iteriteka2023-04-053-2/+25
| | | | | | | | | | | sysdeps/mach/hurd/htl/pt-pthread_self.c: New file. htl/Makefile: .. Add it to libc routine. sysdeps/mach/hurd/htl/pt-sysdep.c(__pthread_self): Remove it. sysdeps/mach/hurd/htl/pt-sysdep.h(__pthread_self): Add hidden propertie. htl/Versions(__pthread_self) Version it as private symbol. Signed-off-by: Guy-Fleury Iteriteka <gfleury@disroot.org> Message-Id: <20230318095826.1125734-3-gfleury@disroot.org>
* hurd: Add vm_param.h for x86_64Sergey Bugaev2023-04-031-0/+24
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-30-bugaevc@gmail.com>
* hurd: Implement _hurd_longjmp_thread_state for x86_64Sergey Bugaev2023-04-031-0/+41
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-29-bugaevc@gmail.com>
* htl: Implement thread_set_pcsptp for x86_64Sergey Bugaev2023-04-031-0/+73
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-23-bugaevc@gmail.com>
* hurd: Move a couple of signal-related files to x86Sergey Bugaev2023-04-032-0/+0
| | | | | | | These do not need any changes to be used on x86_64. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-20-bugaevc@gmail.com>
* hurd: Use uintptr_t for register values in trampoline.cSergey Bugaev2023-04-031-7/+6
| | | | | | | | | | | | This is more correct, if only because these fields are defined as having the type unsigned int in the Mach headers, so casting them to a signed int and then back is suboptimal. Also, remove an extra reassignment of uesp -- this is another remnant of the ecx kludge. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-16-bugaevc@gmail.com>
* hurd: Move rtld-strncpy-c.c out of mach/hurd/Sergey Bugaev2023-04-031-1/+0
| | | | | | | | There's nothing Mach- or Hurd-specific about it; any port that ends up with rtld pulling in strncpy will need this. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-15-bugaevc@gmail.com>
* hurd: More 64-bit integer casting fixesSergey Bugaev2023-04-032-4/+4
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-13-bugaevc@gmail.com>
* mach, hurd: Drop __libc_lock_self0Sergey Bugaev2023-04-033-8/+3
| | | | | | | | | | | This was used for the value of libc-lock's owner when TLS is not yet set up, so THREAD_SELF can not be used. Since the value need not be anything specific -- it just has to be non-NULL -- we can just use a plain constant, such as (void *) 1, for this. This avoids accessing the symbol through GOT, and exporting it from libc.so in the first place. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-12-bugaevc@gmail.com>
* hurd: Remove __hurd_threadvar_stack_{offset,mask}Sergey Bugaev2023-04-034-26/+2
| | | | | | | | | | | Noone is or should be using __hurd_threadvar_stack_{offset,mask}, we have proper TLS now. These two remaining variables are never set to anything other than zero, so any code that would try to use them as described would just dereference a zero pointer and crash. So remove them entirely. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-6-bugaevc@gmail.com>
* libio: Do not autogenerate stdio_lim.hAdhemerval Zanella Netto2023-03-271-0/+28
| | | | | | | | | | | | | Instead define the required fields in system dependend files. The only system dependent definition is FILENAME_MAX, which should match POSIX PATH_MAX, and it is obtained from either kernel UAPI or mach headers. Currently set pre-defined value from current kernels. It avoids a circular dependendy when including stdio.h in gen-as-const-headers files. Checked on x86_64-linux-gnu and i686-linux-gnu Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Move libc_freeres_ptrs and libc_subfreeres to hidden/weak functionsAdhemerval Zanella Netto2023-03-271-1/+0
| | | | | | | | | | | | | | | | | | | | They are both used by __libc_freeres to free all library malloc allocated resources to help tooling like mtrace or valgrind with memory leak tracking. The current scheme uses assembly markers and linker script entries to consolidate the free routine function pointers in the RELRO segment and to be freed buffers in BSS. This patch changes it to use specific free functions for libc_freeres_ptrs buffers and call the function pointer array directly with call_function_static_weak. It allows the removal of both the internal macros and the linker script sections. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* C2x scanf binary constant handlingJoseph Myers2023-03-021-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | C2x adds binary integer constants starting with 0b or 0B, and supports those constants for the %i scanf format (in addition to the %b format, which isn't yet implemented for scanf in glibc). Implement that scanf support for glibc. As with the strtol support, this is incompatible with previous C standard versions, in that such an input string starting with 0b or 0B was previously required to be parsed as 0 (with the rest of the input potentially matching subsequent parts of the scanf format string). Thus this patch adds 12 new __isoc23_* functions per long double format (12, 24 or 36 depending on how many long double formats the glibc configuration supports), with appropriate header redirection support (generally very closely following that for the __isoc99_* scanf functions - note that __GLIBC_USE (DEPRECATED_SCANF) takes precedence over __GLIBC_USE (C2X_STRTOL), so the case of GNU extensions to C89 continues to get old-style GNU %a and does not get this new feature). The function names would remain as __isoc23_* even if C2x ends up published in 2024 rather than 2023. When scanf %b support is added, I think it will be appropriate for all versions of scanf to follow C2x rules for inputs to the %b format (given that there are no compatibility concerns for a new format). Tested for x86_64 (full glibc testsuite). The first version was also tested for powerpc (32-bit) and powerpc64le (stdio-common/ and wcsmbs/ tests), and with build-many-glibcs.py.
* hurd: Remove the ecx kludgeSergey Bugaev2023-03-022-43/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "We don't need it any more" The INTR_MSG_TRAP macro in intr-msg.h used to play little trick with the stack pointer: it would temporarily save the "real" stack pointer into ecx, while setting esp to point to just before the message buffer, and then invoke the mach_msg trap. This way, INTR_MSG_TRAP reused the on-stack arguments laid out for the containing call of _hurd_intr_rpc_mach_msg (), passing them to the mach_msg trap directly. This, however, required special support in hurdsig.c and trampoline.c, since they now had to recognize when a thread is inside the piece of code where esp doesn't point to the real tip of the stack, and handle this situation specially. Commit 1d20f33ff4fb634310f27493b7b87d0b20f4a0b0 has removed the actual temporary change of esp by actually re-pushing mach_msg arguments onto the stack, and popping them back at end. It did not, however, deal with the rest of "the ecx kludge" code in other files, resulting in potential crashes if a signal arrives in the middle of pushing arguments onto the stack. Fix that by removing "the ecx kludge". Instead, when we want a thread to skip the RPC, but cannot make just make it jump to after the trap since it's not done adjusting the stack yet, set the SYSRETURN register to MACH_SEND_INTERRUPTED (as we do anyway), and rely on the thread itself for detecting this case and skipping the RPC. This simplifies things somewhat and paves the way for a future x86_64 port of this code. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230301162355.426887-1-bugaevc@gmail.com>
* hurd: Implement TLS for x86_64Sergey Bugaev2023-02-272-1/+228
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230221211932.296459-4-bugaevc@gmail.com>
* htl: Make pthread_mutex_t pointer-alignedSergey Bugaev2023-02-271-5/+8
| | | | | | | | This is for future-proofing. On i386, it is 4-byte aligned anyway, but on x86_64, we want it 8-byte aligned, not 4-byte aligned. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230214173722.428140-4-bugaevc@gmail.com>
* hurd: Generalize init-first.c to support x86_64Sergey Bugaev2023-02-241-0/+6
| | | | | Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230223151436.49180-2-bugaevc@gmail.com>
* hurd: Simplify init-first.c furtherSergey Bugaev2023-02-244-140/+68
| | | | | | | | This drops all of the return address rewriting kludges. The only remaining hack is the jump out of a call stack while adjusting the stack pointer. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
* hurd: Mark some audit tests as unsupportedSamuel Thibault2023-02-241-0/+10
| | | | They hang the testsuite.
* htl: Mark select loop test as unsupportedSamuel Thibault2023-02-241-0/+6
| | | | It overflows pflocal and doesn't manage to terminate.
* hurd: Mark RLIMIT_AS tests as unsupportedSamuel Thibault2023-02-241-0/+11
| | | | Otherwise they put the system on its knees.