summaryrefslogtreecommitdiff
path: root/libports
AgeCommit message (Collapse)Author
2023-12-17Update server handlers to return kern_return_error to fix ↵Flavio Cruz
-Werror=enum-int-mismatch warnings MiG expects those to return kern_return_t. Message-ID: <ZXqbbXpVqQAwd2qv@jupiter.tail36e24.ts.net>
2023-11-26libports: Make sure we don't leak current RPCs listsSamuel Thibault
2023-11-26libports: Force threads to wake up periodicallySamuel Thibault
Quiescence support in port-deref-deferred.c assumes that all threads will sooner or later go through a quiescent state (because it finished processing a message). But that is not true: proc doesn't set a thread timeout, and thus some threads can stay indefinitely stuck in receiving messages. And thus the deferred dereferencing used by ports_destroy_right never gets achieved. This accumulation can be seen by running: while true ; do echo $(echo -n $(echo a)) > /dev/null ; done while running vminfo 4 | wc -l in parallel. Making threads get out of mach_msg at least periodically allows unstucking quiescence generations.
2023-11-26libports: Add more assertionSamuel Thibault
flip_generations needs to make sure it is not throwing away a list of objects to be released.
2023-05-10Style tweaksSergey Bugaev
Message-Id: <20230508213136.608575-42-bugaevc@gmail.com>
2023-05-10libports: Port to x86_64Sergey Bugaev
Message-Id: <20230508213136.608575-3-bugaevc@gmail.com>
2023-05-04Use designated initializers when building mach_msg_type_tFlavio Cruz
Message-Id: <ZFLcIs0iwiC9kQDf@jupiter.tail36e24.ts.net>
2023-05-02Use uintptr_t for message payloads.Flavio Cruz
A follow up to 92fad38a043b75ed6b435b3efa574ede91dbe9ee in gnumach. Message-Id: <ZFCNasf9bJ9qj+CG@jupiter.tail36e24.ts.net>
2023-04-08Further modernize Hurd code by enforcing strict prototypes and no implicit ↵Flavio Cruz
function declarations. Most of the changes land in one of these buckets: * Removed unused declarations. * Used (void) to represent no parameters instead of () which means an undeterminate number of parameters. * Included missing header files whenever necessary (stdlib.h, sys/mman.h, etc) * Typedefed function pointers to be able to fully declare the parameter types. * Added declarations of library functions that are used elsewhere (example is libps/ps.h). * Made functions static whenever they are only used in that file. * Forwarded declarations of some methods that were made static. Message-Id: <ZDD1o7/tVYeZew+G@jupiter.tail36e24.ts.net>
2023-04-03Modernize code by removing use of old style definitions.Flavio Cruz
Also add -Werror=old-style-definition to enforce new code. Message-Id: <ZBZ+8xf7GHy2RT/h@jupiter.tail36e24.ts.net>
2022-08-10libports: Only accept dead-name notifications on notify_portSergey Bugaev
Since this port is never given out to anyone but the kernel, our clients can't spoof a dead-name notification this way.
2022-08-10libports: Return EOPNOTSUPP when appropriateSergey Bugaev
We do not impement most of the mach_notify_* () routines. Explicitly return an error code so that our caller knows to properly deallocate all resources the messages may carry.
2022-08-10libports: Add ports_request_dead_name_notification ()Sergey Bugaev
This significantly cuts down the boilerplate of requesting dead-name notifications.
2022-08-10libports: Request notifications to the notify_portSergey Bugaev
2022-08-10libports: Create a notify_port in each bucketSergey Bugaev
This notify port will be used to request & receive Mach notifications. While it is present in the bucket much like any other port, it is not counted in ports_count_bucket () and is not exposed to the user callback in ports_bucket_iterate ().
2022-08-10libports: Treat no-senders notifications as a hintSergey Bugaev
No-senders notifications are directed to the port that no longer has any senders left. Since any client can easily spoof such a notification, we have to treat the notification as just a hint and verify whether there are, in fact, any senders, and only call ports_no_senders () if there actually are none left.
2020-12-01Drop spurious changeSamuel Thibault
2020-11-30hurd_types: Add const_string_t typeSamuel Thibault
This will allow to relieve constraints in callers, e.g. dir_lookup("") would otherwise produce a warning with gcc-11 since char[1024] would mean that dir_lookup would read all 1024 characters while it is not. * hurd/hurd_types.h (const_string_t): New type.
2020-11-11Remove remnants of cthreadsSamuel Thibault
* doc/hurd.texi: Index pthread.h instead of cthreads.h * libports/Makefile (SRCS): Drop stubs.c. * libports/stubs.c: Remove file. * mach-defpager/default_pager.c (default_pager): Drop disabled cthreads calls. * pfinet/kmem_cache.c: Fix comment. * proc/stubs.c: Fix comments.
2018-10-08libports: Fix typoSamuel Thibault
2017-08-23Drop the register qualifier.Justus Winter
* console/display.c: Drop 'register'. * eth-multiplexer/dev_stat.c: Likewise. * libbpf/bpf_impl.c: Likewise. * libbpf/queue.c: Likewise. * libports/manage-multithread.c: Likewise. * libports/manage-one-thread.c: Likewise.
2017-08-05Use our own variant of 'assert' and 'assert_perror'.Justus Winter
Our variants print stack traces on failures. This will make locating errors much easier.
2017-03-04Avoid ports_interrupt_rpcs cancel itselfSamuel Thibault
While this does not hurt immediately, callers of ports_interrupt_rpcs would themselves get canceled at the next cancelation point. * libports/interrupt-rpcs.c (ports_interrupt_rpcs): Do not call cancel ourself.
2017-01-02Fix libports dependenciesSamuel Thibault
Due to refcount.h usage. * libports/Makefile (HURDLIBS): Add shouldbeinlibc.
2016-11-27libports: fix using ports.h in C++Samuel Thibault
class is a reserved keyword, event when imported inside extern "C" { } * libports/ports.h (port_info) [__cplusplus]: Rename `class' field to `port_class'. (ports_create_port, ports_create_port_noinstall, ports_import_port, ports_lookup_port, ports_lookup_payload, ports_count_class, ports_enable_class, ports_class_iterate, _ports_bucket_class_iterate, ports_inhibit_class_rpcs, ports_resume_class_rpcs): Rename `class' parameter to `port_class'. [!__cplusplus] (ports_lookup_payload, ports_payload_get_name): Do not define extern inlines.
2016-10-15Avoid warnings if increasing a threads priority fails.Justus Winter
* libports/manage-multithread.c (adjust_priorities): Avoid displaying error messages if we do not have the privileged processor set port by treating this error condition like EPERM. * proc/main.c (increase_priority, main): Likewise.
2016-02-23libports: preserve the complex message flagJustus Winter
* libports/manage-multithread.c (internal_demuxer): Preserve all message flags when we store the objects address as payload in the message. * libports/manage-one-thread.c (internal_demuxer): Likewise.
2015-09-22libports: remove unused variablesJustus Winter
* libports/inhibit-all-rpcs.c (ports_inhibit_all_rpcs): Remove unused variable `bucket'. * libports/inhibit-class-rpcs.c (ports_inhibit_class_rpcs): Remove unused variables `pi' and `rpc'.
2015-09-10Install port-deref-deferred.h header for ports.hJames Clarke
* libports/Makefile (installhdrs): Add port-deref-deferred.h for ports.h
2015-08-14libports: clarify why we emulate protected payloadsJustus Winter
The Hurd uses protected payloads to improve the receiver lookup on the server side to the point that we no longer do a hash table lookup in the dispatch code. If the kernel does not support protected payloads, we degrade gracefully, do one lookup in libports' dispatching code, and emulate the protected payload feature to still save one hash table lookup in the intrans function. * libports/manage-multithread.c (ports_manage_port_operations_multithread): Add comment. * libports/manage-one-thread.c (ports_manage_port_operations_one_thread): Likewise.
2015-04-07libports: use protected payloads to optimize the object lookupJustus Winter
* NEWS: Mention protected payloads. * libports/Makefile (SRCS): Add `port-deref-deferred.c'. * libports/create-internal.c (_ports_create_port_internal): Set the protected payload to the objects address. * libports/import-port.c (ports_import_port): Likewise. * libports/reallocate-from-external.c (ports_reallocate_from_external): Likewise. * libports/reallocate-port.c (ports_reallocate_port): Likewise. * libports/transfer-right.c (ports_transfer_right): Likewise. * libports/manage-multithread.c (ports_manage_port_operations_multithread): Use the protected payload for the object lookup if provided. Add thread pool management calls. * libports/manage-one-thread.c (ports_manage_port_operations_one_thread): Likewise. * libports/destroy-right.c (ports_destroy_right): Defer the dereferencing of outstanding send rights to avoid a port_info use-after-free. * libports/port-deref-deferred.c: New file. * libports/port-deref-deferred.h: Likewise. * libports/ports.h (struct port_bucket): New field `threadpool'. (ports_lookup_payload): Check `port_right'.
2015-02-17libports: avoid acquiring global lock in message dispatchJustus Winter
* libports/interrupt-operation.c (ports_S_interrupt_operation): Update `cancel_threshold' using atomic operations. * libports/manage-multithread.c (internal_demuxer): Avoid taking the lock. * libports/ports.h (struct port_info): Mention that one needs atomic operations to access `cancel_threshold'.
2015-01-17libports: silence pointless error messageJustus Winter
* libports/manage-multithread.c (adjust_priority): Silence pointless error message.
2014-12-07libports: add a payload-aware intrans functionJustus Winter
* libports/mig-decls.h (begin_using_port_info_payload): New function. * libports/mig-mutate.h: Add mutator.
2014-12-07libports: add `ports_lookup_payload' and `ports_payload_get_name'Justus Winter
These two functions map payloads to objects and port names. The former can be used like `ports_lookup_port' to look up objects, the latter to map payloads to port names if the server function expects a `mach_port_t'. * libports/ports.h: Add function ports_payload_get_name. * libports/lookup-payload.c: New file. * libports/ports.h (ports_lookup_payload): Add declaration. * libports/Makefile (SRCS): Add lookup-payload.c.
2014-11-03Use a mere weak attribute instead of a weak aliasSamuel Thibault
We don't need to call the original function, so a weak attribute is enough. * libports/dead-name.c (ports_dead_name): Remove weak alias. (__ports_dead_name): Rename back to ports_dead_name, but add weak attribute.
2014-11-02Fix dead name notification in static binariesSamuel Thibault
When linking statically, the libports definition would come before the libdiskfs definition, defeating the purpose of the ports_dead_name callback. * libports/dead-name.c (ports_dead_name): Rename into __ports_dead_name. (ports_dead_name): Add weak alias for __ports_dead_name.
2014-10-05libports: lock-less reference counting for port_info objectsJustus Winter
* libports/ports.h (struct port_info): Use the new type. * libports/lookup-port.c: No need to lock _ports_lock anymore. * libports/bucket-iterate.c: Likewise. * libports/complete-deallocate.c: Check if someone reacquired a reference through a hash table lookup. * libports/create-internal.c: Use the new reference counting primitives. * libports/get-right.c: Likewise. * libports/import-port.c: Likewise. * libports/port-deref-weak.c: Likewise. * libports/port-deref.c: Likewise. * libports/port-ref-weak.c: Likewise. * libports/port-ref.c: Likewise. * libports/reallocate-from-external.c: Likewise. * libports/transfer-right.c: Likewise. * utils/rpctrace.c: Likewise.
2014-09-29libports: use a global hash table for the lookupsJustus Winter
Previously, libports used a hash table per port bucket. This makes looking up a port difficult if one does not know the port bucket, as one has to iterate over all buckets and do a hash table lookup each. Having to iterate over the buckets makes it necessary to keep a list of all buckets, which has to be updated and protected by a lock as well. Also, the current code in _ports_bucket_class_iterate iterates over the hash table associated with the bucket given. When ports_class_iterate calls this common function, it obtains a reference to the bucket from one of the ports in the given class. This will not work if a class contains ports in different port buckets. This limitation is not documented as far as I can see. Again, having to maintain this list has its cost and requires serialization. Use a global hash table for lookups instead. Keep the per-bucket hash tables for efficient iteration over buckets. Furthermore, serialize access to all hash tables using a separate lock. Remove the linked lists of all buckets and all ports in a class. * libports/bucket-iterate.c (ports_bucket_iterate): Acquire _ports_htable_lock. Also, generalize ports_bucket_iterate so that it takes a pointer to a hash table as first argument. (ports_bucket_iterate): Ajust call to former function accordingly. * libports/class-iterate.c (ports_class_iterate): Just call the generalized _ports_bucket_class_iterate with the global hash table as argument. * libports/ports.h (struct port_info): Remove the port class links. (struct port_bucket): Remove the hash table, and the all buckets link. (_ports_all_buckets): Remove declaration. (_ports_htable): New global hash table. (_ports_htable_lock): Protected by this lock. * libports/claim-right.c: Adjust accordingly. * libports/complete-deallocate.c: Likewise. * libports/create-bucket.c: Likewise. * libports/create-class.c: Likewise. * libports/create-internal.c: Likewise. * libports/destroy-right.c: Likewise. * libports/import-port.c: Likewise. * libports/lookup-port.c: Likewise. * libports/reallocate-from-external.c: Likewise. * libports/reallocate-port.c: Likewise. * libports/transfer-right.c: Likewise. * libports/inhibit-all-rpcs.c: Iterate over the hash table. * libports/inhibit-bucket-rpcs.c: Likewise, but filter using bucket. * libports/inhibit-class-rpcs.c: Likewise, but filter using class. * libports/init.c (_ports_htable): Initialize. (_ports_htable_lock): Likewise.
2014-06-18libports: avoid realloc(3) corner caseJustus Winter
If the size argument is 0, realloc may either return NULL, or return a pointer that is only valid for use with free(3). In either case, the memory is freed. So if realloc would return NULL (it does not on GNU), the current code would double free p. Found using the Clang Static Analyzer. * libports/bucket-iterate.c (_ports_bucket_class_iterate): Avoid calling realloc if no ports were matched.
2014-05-05libports: unlock _ports_lock on malloc failureJustus Winter
* libports/bucket-iterate.c (_ports_bucket_class_iterate): Unlock _ports_lock on malloc failure.
2014-04-29libports: reduce malloc overhead in _ports_bucket_class_iterateJustus Winter
_ports_bucket_class_iterate creates a snapshot of the buckets hash table. This is done so that the lock protecting the hash table can be released while we iterate over the snapshot. Formerly, a linked list was used to store the snapshot. As the maximal number of items is known, using an array is much simpler. _ports_bucket_class_iterate implements both ports_bucket_iterate and ports_class_iterate. For this change might make ports_class_iterate less efficient memory-wise if the number of ports belonging to the class is low with respect to the number of ports in the bucket. If this happens, we allocate too much. Alleviate this by releasing unused memory. On the other hand, the array representation is more compact. Furthermore a survey of the Hurd code revealed that ports_class_iterate is rarely used, while ports_bucket_iterate is used more often, most prominently in paging code. * libports/bucket-iterate.c (_ports_bucket_class_iterate): Use an array instead of a linked list.
2014-04-29libports: work around bugs in server terminationJustus Winter
Some servers use ports_manage_port_operations_one_thread to process requests and terminate when it returns. Since many of them don't detach before shutting down, a client may receive an error if its request arrived while the server is shutting down. Prevent those spurious errors by forcing ports_manage_port_operations_one_thread not to return. This is the same change as 235491231bdd1fd93507c835767503f047e10b91 introduced for ports_manage_port_operations_multithread. * libports/manage-one-thread.c (ports_manage_port_operations_one_thread): Force timeout to 0.
2014-04-09libports: fix receiver lookupJustus Winter
* libports/interrupt-operation.c (ports_S_interrupt_operation): Fix receiver lookup. * libports/mig-mutate.h: Add mutators. * libports/ports.h: Remove superfluous declarations.
2014-04-06libports: fix notify_port_t receiver lookupsJustus Winter
* libports/Makefile (MIGSFLAGS): Include mig-mutate.h. * libports/mig-decls.h: New file. * libports/mig-mutate.h: Likewise. * libports/notify-dead-name.c: Fix receiver lookups. * libports/notify-no-senders.c: Likewise. * libports/notify-msg-accepted.c: Adjust function declaration. * libports/notify-port-deleted.c: Likewise. * libports/notify-port-destroyed.c: Likewise. * libports/notify-send-once.c: Likewise. * libports/ports.h: Likewise. * proc/Makefile (MIGSFLAGS): Include mig-mutate.h, move PROCESS mutators... * proc/mig-mutate.h: ... into a new file, add NOTIFY mutators. * proc/notify.c: Fix receiver lookups, adjust function declarations. * term/devio.c (ports_do_mach_notify_send_once): Adjust accordingly.
2014-02-22libports: work around bugs in server terminationRichard Braun
Most servers use ports_manage_port_operations_multithread to process requests and terminate when it returns. Since many of them don't detach before shutting down, a client may receive an error if its request arrived while the server is shutting down. Prevent those spurious errors by forcing ports_manage_port_operations_multithread not to return. * libports/manage-multithread.c (ports_manage_port_operations_multithread): Force global_timeout to 0.
2013-12-28libports: remove the threadvars stack size hackRichard Braun
Setting the stack size should now correctly be supported by libpthread. * libports/manage-multithread.c (__pthread_stack_default_size): Remove global variable.
2013-11-30libports: another right leak fixRichard Braun
* libports/manage-multithread.c (adjust_priority): Deallocate host right before returning.
2013-11-28libports: improve error reporting in adjust_priorityJustus Winter
By using error instead of perror, the warning can be proprely attributed to the process. * libports/manage-multithread.c (adjust_priority): Use error instead of perror to print the warning.
2013-11-28libports: improve error handling in ports_transfer_rightJustus Winter
* libports/transfer-right.c (ports_transfer_right): Improve error handling.