aboutsummaryrefslogtreecommitdiff
path: root/hurd
AgeCommit message (Collapse)AuthorFilesLines
2024-07-30x86_64 hurd: ensure we have a large enough buffer to receive exception_raise ↵Flavio Cruz1-1/+8
requests. Message-ID: <gtxd6s4s7fi7hdrlb7zayq3akij7x6jqawwq3zfl3v4nqspulo@euucuzeonrl6>
2024-07-13hurd: Fix restoring message to be retriedSamuel Thibault1-1/+4
save_data stores the start of the original message to be retried, overwritten by the EINTR reply. In 64b builds the overwrite is however rounded up to the 64b pointer size, so we have to save more than just the 32b err. Thanks a lot to Luca Dariz for the investigation!
2024-06-10hurd: Fix getxattr/listxattr returning ERANGESamuel Thibault1-4/+21
The manpage says that when the passed size is zero, they should set the expected size and return 0. ERANGE shall be returned only when the non-zero passed size is not large enough.
2024-06-10hurd: Fix setxattr return value on replacingSamuel Thibault1-4/+3
When XATTR_REPLACE is set we shall succeed when the value already exists, and fail with ENODATA otherwise, instead of the converse.
2024-06-10hurd: Fix getxattr("gnu.translator") returning ENODATASamuel Thibault1-1/+10
When no translator is set, __file_get_translator would return EINVAL which is a confusing value. Better check for a passive translation before getting the value.
2024-04-30hurd: Stop mapping AT_NO_AUTOMOUNT to O_NOTRANSSergey Bugaev1-2/+0
While AT_NO_AUTOMOUNT is similar in function to the Hurd's O_NOTRANS, there are significant enough differences in semantics: 1. AT_NO_AUTOMOUNT has no effect on already established mounts, whereas O_NOTRANS causes the lookup to ignore both passive and active translators. A better approximation of the AT_NO_AUTOMOUNT behavior would be to honor active translators, but avoid starting passive ones; like what the file_name_lookup_carefully () routine from sutils/clookup.c in the Hurd source tree does. 2. On GNU/Hurd, translators are used much more pervasively than mounts on "traditional" Unix systems: among other things, translators underlie features like symlinks, device nodes, and sockets. And while on a "traditional" Unix system, the mountpoint and the root of the mounted tree may look similar enough for many purposes (they're both directories, for one thing), the Hurd allows for any combination of the two node types, and indeed it is common to have e.g. a device node "mounted" on top of a regular file node on the underlying filesystem. Ignoring the translator and stat'ing the underlying node is therefore likely to return very different results from what you'd get if you stat the translator's root node. In practice, mapping AT_NO_AUTOMOUNT to O_NOTRANS was breaking GNU Coreutils, including stat(1) and ls(1): $ stat /dev/hd0s1 File: /dev/hd0s1 Size: 0 Blocks: 8 IO Block: 8192 regular empty file Device: 0,8 Inode: 32866 Links: 1 This was also breaking GNOME's glib, where a g_local_file_stat () call that is supposed to stat () a file through a symlink uses AT_NO_AUTOMOUNT, which gets mapped to O_NOTRANS, which then causes the stat () call to stat symlink itself like lstat () would, rather then the file it points to, which is what the logic expects to happen. This reverts most of 13710e7e6af6c8965cc9a63a0660cb4ce1966557 "hurd: Add support for AT_NO_AUTOMOUNT". Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-03-23hurd: Stop relying on VM_MAX_ADDRESSSergey Bugaev1-4/+4
We'd like to avoid committing to a specific size of virtual address space (i.e. the value of VM_AARCH64_T0SZ) on AArch64. While the current version of GNU Mach still exports VM_MAX_ADDRESS for compatibility, we should try to avoid relying on it when we can. This piece of logic in _hurdsig_getenv () doesn't actually care about the size of user- accessible virtual address space, it just wants to preempt faults on any addresses starting from the value of the P pointer and above. So, use (unsigned long int) -1 instead of VM_MAX_ADDRESS. While at it, change the casts to (unsigned long int) and not just (long int), since the type of struct hurd_signal_preemptor.{first,last} is unsigned long int. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-ID: <20240323173301.151066-3-bugaevc@gmail.com>
2024-03-23hurd: Move internal functions to internal headerSergey Bugaev1-87/+0
Move _hurd_self_sigstate (), _hurd_critical_section_lock (), and _hurd_critical_section_unlock () inline implementations (that were already guarded by #if defined _LIBC) to the internal version of the header. While at it, add <tls.h> to the includes, and use __LIBC_NO_TLS () unconditionally. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-ID: <20240323173301.151066-2-bugaevc@gmail.com>
2024-02-25hurd: Reformat Makefile.Carlos O'Donell1-42/+129
Reflow and sort Makefile. Code generation changes present due to link order changes. No regressions on x86_64 and i686. Tested with build-many-glibcs.py for x86_64-gnu.
2024-01-03hurd: Declare _hurd_intr_rpc_msg* with protected visibilitySergey Bugaev1-3/+3
These symbols are internal and never exported; make sure the compiler realizes that when compiling hurdsig.c and does not try to emit GOT reads. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-01-03hurd: Add some missing includesSergey Bugaev1-1/+1
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert89-89/+89
2023-12-17Update code to handle the new ABI for sending inlined port rights.Flavio Cruz1-2/+24
For i686, this change is no op but for x86_64 it forces all inlined port rights to be 8 bytes long.
2023-12-03Revert "Update code to handle the new ABI for sending inlined port rights."Samuel Thibault1-24/+2
This reverts commit 7e23b3c2c008e0b9b5da055e675d40cc27bb10ef.
2023-12-03Revert "hurd: Fix build"Samuel Thibault1-1/+1
This reverts commit 7096914dd8ff2dfd1d8cba3577b72838f5e4c2bd.
2023-12-03hurd: Fix buildSamuel Thibault1-1/+1
7e23b3c2c008 ("Update code to handle the new ABI for sending inlined port rights.") was missing a cast. Fixes 7e23b3c2c008e0b9b5da055e675d40cc27bb10ef
2023-12-03Update code to handle the new ABI for sending inlined port rights.Flavio Cruz1-2/+24
For i686, this change is no op but for x86_64 it forces all inlined port rights to be 8 bytes long. Message-ID: <20231124213041.952886-2-flaviocruz@gmail.com>
2023-11-21hurd: fix restarting reauth_dtable on signalSamuel Thibault1-12/+23
While inside the critical section, RPCs would not be restarted, so we have to handle EINTR errors.
2023-11-20hurd: Prevent the final file_exec_paths call from signalsSamuel Thibault1-0/+12
Otherwise if the exec server started thrashing the old task, we won't be able to restart the exec. This notably fixes building ghc.
2023-11-19Remove untyped mach RPC code.Flavio Cruz2-73/+0
Existing MiG does not support untyped messages and the Hurd will continue to use typed messages for the foreseeable future. Message-ID: <ZVmYX6j4pYNUfqn4@jupiter.tail36e24.ts.net>
2023-11-19_hurd_intr_rpc_mach_msg: handle message iteration correctly.Flavio Cruz1-12/+12
The `ty` pointer is only set at the end of the loop so that `msgtl_header.msgt_inline` and `msgtl_header.msgt_deallocate` remain valid. Also, when deallocating memory, we use the length from the message directly rather than hard coding mach_port_t since we want to deallocate any kind of OOL data. Message-ID: <ZVlGVD6eEN-dXsOr@jupiter.tail36e24.ts.net>
2023-11-14hurd: Make _hurd_intr_rpc_mach_msg avoid returning MACH_SEND_INTERRUPTEDSamuel Thibault1-0/+6
When the given options do not include MACH_SEND_INTERRUPT, _hurd_intr_rpc_mach_msg (aka mach_msg) is not supposed to return MACH_SEND_INTERRUPTED. In such a case we thus have to retry sending the message. This was observed to fix various occurrences of spurious "(ipc/send) interrupted" errors when running haskell programs.
2023-09-05hurd: Avoid including thread_state.h in installed headerSamuel Thibault1-2/+1
thread_state.h is not actually installed. It was only needed for struct machine_thread_all_state, which we can just declare, actually.
2023-08-15hurd: Add prototype for and thus fix _hurdsig_abort_rpcs callSamuel Thibault2-10/+7
This was actually not a problem since NULL was getting passed.
2023-08-03hurd: Do not include full <stdarg.h> in <hurd.h>Florian Weimer1-2/+2
This fixes a hurd/check-installed-headers-c failure with -std=c89 #define _FORTIFY_SOURCE 1: In file included from ../hurd/hurd.h:354, from ../sysdeps/hurd/include/hurd.h:2, from /tmp/cih_test_9IaUwa.c:10: /home/bmg/install/compilers/i686-gnu/lib/gcc/i686-glibc-gnu/13.2.1/include/stdarg.h:54:34: error: "__STDC_VERSION__" is not defined, evaluates to 0 [-Werror=undef] 54 | #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L \ | ^~~~~~~~~~~~~~~~ /home/bmg/install/compilers/i686-gnu/lib/gcc/i686-glibc-gnu/13.2.1/include/stdarg.h:55:8: error: "__cplusplus" is not defined, evaluates to 0 [-Werror=undef] 55 | || __cplusplus + 0 >= 201103L | ^~~~~~~~~~~ cc1: all warnings being treated as errors Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2023-06-02Fix all the remaining misspellings -- BZ 25337Paul Pluzhnikov5-5/+5
2023-05-22Fix build for hurd/thread-self.c for i386.Flavio Cruz1-0/+1
We need to include hurd.h for libc_hidden_proto (__hurd_thread_self), introduced in b44c1e12524b ("hurd: Fix using interposable hurd_thread_self") This the error log: In file included from <command-line>: ./../include/libc-symbols.h:472:33: error: '__EI___hurd_thread_self' aliased to undefined symbol '__GI___hurd_thread_self' 472 | extern thread __typeof (name) __EI_##name \ | ^~~~~ ./../include/libc-symbols.h:468:3: note: in expansion of macro '__hidden_ver2' 468 | __hidden_ver2 (, local, internal, name) | ^~~~~~~~~~~~~ ./../include/libc-symbols.h:476:41: note: in expansion of macro '__hidden_ver1' 476 | # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); | ^~~~~~~~~~~~~ ./../include/libc-symbols.h:557:32: note: in expansion of macro 'hidden_def' 557 | # define libc_hidden_def(name) hidden_def (name) | ^~~~~~~~~~ thread-self.c:27:1: note: in expansion of macro 'libc_hidden_def' 27 | libc_hidden_def (__hurd_thread_self) | ^~~~~~~~~~~~~~~ Message-Id: <ZGr6wj2UOxg3F0qH@jupiter.tail36e24.ts.net>
2023-05-20hurd: Use __hurd_fail () instead of assigning errnoSergey Bugaev5-36/+14
The __hurd_fail () inline function is the dedicated, idiomatic way of reporting errors in the Hurd part of glibc. Not only is it more concise than '{ errno = err; return -1; }', it is since commit 6639cc10029e24e06b34e169712b21c31b8cf213 "hurd: Mark error functions as __COLD" marked with the cold attribute, telling the compiler that this codepath is unlikely to be executed. In one case, use __hurd_dfail () over the plain __hurd_fail (). Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230520115531.3911877-1-bugaevc@gmail.com>
2023-05-19hurd: Fix using interposable hurd_thread_selfSergey Bugaev2-1/+5
Create a private hidden __hurd_thread_self alias, and use that one. Fixes 2f8ecb58a59eb82c43214d000842d99644a662d1 "hurd: Fix x86_64 _hurd_tls_fork" and c7fcce38c83a2bb665ef5dc4981bf20c7e586123 "hurd: Make sure to not use tcb->self" Reported-by: Joseph Myers <joseph@codesourcery.com> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-05-17hurd: Use __mach_setup_thread_call ()Sergey Bugaev1-4/+6
...instead of mach_setup_thread (), which is unsuitable for setting up function calls. Checked on x86_64-gnu: the signal thread no longer crashes upon trying to process a message. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230517191436.73636-6-bugaevc@gmail.com>
2023-05-17hurd: Use MACHINE_THREAD_STATE_SETUP_CALLSergey Bugaev1-2/+2
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230517191436.73636-4-bugaevc@gmail.com>
2023-05-06Update hurd/hurdselect.c to be more portable.Flavio Cruz2-21/+15
Summary of changes: - Use BAD_TYPECHECK to perform type checking in a cleaner way. BAD_TYPECHECK is moved into sysdeps/mach/rpc.h to avoid duplication. - Remove assertions for mach_msg_type_t since those won't work for x86_64. - Update message structs to use mach_msg_type_t directly. - Use designated initializers. Message-Id: <ZFa+roan3ioo0ONM@jupiter.tail36e24.ts.net>
2023-05-05Update hurd/intr-msg.c to be more portableFlavio Cruz1-13/+21
Summary of the changes: - Introduce BAD_TYPECHECK from MiG to make it simpler to do type checking. - Replace int type with mach_msg_type_t. This assumes that mach_msg_type_t is always the same size as int which is not true for x86_64. - Calculate the size and align using PTR_ALIGN_UP, which is a bit cleaner and similar to what we do elsewhere. - Define mach_msg_type_t to check using designated initializers. Message-Id: <ZFMvrIkvoCSxqB/C@jupiter.tail36e24.ts.net>
2023-05-01hurd: Replace reply port with a dead name on failed interruptionSergey Bugaev2-3/+13
If we're trying to interrupt an interruptible RPC, but the server fails to respond to our __interrupt_operation () call, we instead destroy the reply port we were expecting the reply to the RPC on. Instead of deallocating the name completely, replace it with a dead name, so the name won't get reused for some other right, and deallocate it in _hurd_intr_rpc_mach_msg once we return from the signal handler. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429201822.2605207-4-bugaevc@gmail.com>
2023-04-29hurd: Mark error functions as __COLDSergey Bugaev2-5/+5
This should hopefully hint the compiler that they are unlikely to be called. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131223.2507236-2-bugaevc@gmail.com>
2023-04-29hurd: Fix FS_RETRY_MAGICAL "machtype" handlingSergey Bugaev1-7/+4
We need to set file_name, not update retryname. This is what the other branches do. Before this change, any attempt to access such a file would segfault due to file_name being unset: $ settrans -ac /tmp/my-machtype /hurd/magic machtype $ cat /tmp/my-machtype Segmentation fault Checked on i686-gnu. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-7-bugaevc@gmail.com>
2023-04-29hurd: Respect existing FD_CLOEXEC in S_msg_set_fdSergey Bugaev1-1/+7
If the process has set the close-on-exec flag for the file descriptor, it expects the file descriptor to get closed on exec, even if we replace what the file descriptor refers to. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-6-bugaevc@gmail.com>
2023-04-29hurd: Don't leak the auth port in msg* RPCsSergey Bugaev1-9/+58
The leak can be easily reproduced (and observed) using the portinfo tool: $ portinfo -v $$ | grep task 36: send task(1577)(self) (refs: 127) $ portinfo -v $$ | grep task 36: send task(1577)(self) (refs: 253) $ portinfo -v $$ | grep task 36: send task(1577)(self) (refs: 379) $ portinfo -v $$ | grep task 36: send task(1577)(self) (refs: 505) $ portinfo -v $$ | grep task 36: send task(1577)(self) (refs: 631) Checked on i686-gnu. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-5-bugaevc@gmail.com>
2023-04-29hurd: Mark various conditions as unlikelySergey Bugaev2-7/+7
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-3-bugaevc@gmail.com>
2023-04-29hurd: Move libc_hidden_def's aroundSergey Bugaev1-4/+5
Each libc_hidden_def should be placed immediately next to its function, not in some random unrelated place. No functional change. Fixes: 653d74f12abea144219af00400ed1f1ac5dfa79f "hurd: Global signal disposition" Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-2-bugaevc@gmail.com>
2023-04-29hurd: Simplify _hurd_critical_section_lock a bitSergey Bugaev1-13/+6
This block of code was doing exactly what _hurd_self_sigstate does; so just call that and let it do its job. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230429131354.2507443-1-bugaevc@gmail.com>
2023-04-18hurd: Avoid leaking task & thread portsSergey Bugaev1-0/+6
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-04-18hurd: Simplify _S_catch_exception_raiseSergey Bugaev1-7/+1
_hurd_thread_sigstate () already handles finding an existing sigstate before allocating a new one, so just use that. Bonus: this will only lock the _hurd_siglock once. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-04-17hurd: Run init_pids () before init_dtable ()Sergey Bugaev1-9/+9
Much as the comment says, things on _hurd_subinit assume that _hurd_pid is already initialized by the time _hurd_subinit is run, so _hurd_proc_subinit has to run before it. Specifically, init_dtable () calls _hurd_port2fd (), which uses _hurd_pid and _hurd_pgrp to set up ctty handling. With _hurd_subinit running before _hurd_proc_subinit, ctty setup was broken: 13<--33(pid1255)->term_getctty () = 0 4<--39(pid1255) task16(pid1255)->mach_port_deallocate (pn{ 10}) = 0 13<--33(pid1255)->term_open_ctty (0 0) = 0x40000016 (Invalid argument) Fix this by running the _hurd_proc_subinit hook in the correct place -- just after _hurd_portarray is set up (so the proc server port is available in its usual place) and just before running _hurd_subinit. Fixes 1ccbb9258eed0f667edf459a28ba23a805549b36 ("hurd: Notify the proc server later during initialization"). Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-04-17hurd: Avoid extra ctty RPCs in init_dtable ()Sergey Bugaev1-7/+39
It is common to have (some of) stdin, stdout and stderr point to the very same port. We were making the ctty RPCs that _hurd_port2fd () does for each one of them separately: 1. term_getctty () 2. mach_port_deallocate () 3. term_open_ctty () Instead, let's detect this case and duplicate the ctty port we already have. This means we do 1 RPC instead of 3 (and create a single protid on the server side) if the file is our ctty, and no RPCs instead of 1 if it's not. A clear win! Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-04-14hurd: Remove __hurd_local_reply_portSergey Bugaev1-7/+0
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>
2023-04-10hurd: Improve reply port handling when exiting signal handlersSergey Bugaev1-13/+11
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>
2023-04-10hurd: Do not declare local variables volatileSergey Bugaev1-1/+1
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>
2023-04-03hurd: Microoptimize _hurd_self_sigstate ()Sergey Bugaev1-3/+5
When THREAD_GETMEM is defined with inline assembly, the compiler may not optimize away the two reads of _hurd_sigstate. Help it out a little bit by only reading it once. This also makes for a slightly cleaner code. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-32-bugaevc@gmail.com>
2023-04-03hurd: Fix _hurd_setup_sighandler () signatureSergey Bugaev1-5/+5
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230319151017.531737-10-bugaevc@gmail.com>