Commit Graph

44 Commits

Author SHA1 Message Date
Andrew Kaster
5e1d678bae Ladybird+Userland: Remove use of unnecessary fd passing socket concept
Now that LibIPC is using SCM_RIGHTS properly, we can go back to only
having one socket laying around when needing to transfer fds to peers.
2024-04-19 16:38:55 -04:00
Andrew Kaster
cb87725ec8 LibIPC+LibWeb: Transfer IPC::Files using sendmsg/recvmsg directly
This refactor eliminates the need for a second "fd passing socket" on
Lagom, as it uses SCM_RIGHTS in the expected fashion, to send fds along
with the data of our Unix socket message.
2024-04-19 16:38:55 -04:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Andreas Kling
21db2b7b90 Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling
359d6e7b0b Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-06 23:46:35 +01:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
a96339b72b LibCore: Move Stream-based sockets into the Core namespace 2023-02-13 00:50:07 +00:00
Ben Wiederhake
6b7ce19161 Everywhere: Remove unused includes of LibC/stdlib.h
These instances were detected by searching for files that include
stdlib.h, but don't match the regex:

\\b(_abort|abort|abs|aligned_alloc|arc4random|arc4random_buf|arc4random_
uniform|atexit|atof|atoi|atol|atoll|bsearch|calloc|clearenv|div|div_t|ex
it|_Exit|EXIT_FAILURE|EXIT_SUCCESS|free|getenv|getprogname|grantpt|labs|
ldiv|ldiv_t|llabs|lldiv|lldiv_t|malloc|malloc_good_size|malloc_size|mble
n|mbstowcs|mbtowc|mkdtemp|mkstemp|mkstemps|mktemp|posix_memalign|posix_o
penpt|ptsname|ptsname_r|putenv|qsort|qsort_r|rand|RAND_MAX|random|reallo
c|realpath|secure_getenv|serenity_dump_malloc_stats|serenity_setenv|sete
nv|setprogname|srand|srandom|strtod|strtof|strtol|strtold|strtoll|strtou
l|strtoull|system|unlockpt|unsetenv|wcstombs|wctomb)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use anything from the stdlib.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Timothy Flynn
765c5b416f IPCCompiler+LibIPC: Generate message decoders with better TRY semantics
Instead of a bunch of manual error checking and returning a null OwnPtr,
we can propagate the errors up and return NonnullOwnPtr on success.
2022-12-26 09:36:16 +01:00
kleines Filmröllchen
7669441282 LibIPC: Add deferred invoker getter 2022-12-15 00:21:00 -07:00
Andreas Kling
b5681992e1 LibIPC: Allow overriding the use of deferred_invoke()
This will allow Ladybird to use IPC::Connection without having an
actively running Core::EventLoop.

The abstraction here is not great, and we should think of something
nicer, but we have to start somewhere.
2022-10-06 09:51:04 +02:00
Andreas Kling
ece1b7422f LibIPC: Allow giving Connection a separate socket for FD passing
Our IPC protocol currently relies on the behavior of recvfd() and
sendfd() on SerenityOS, which provide an out-of-band queue that can be
accessed independently of the in-band data stream.

To make LibIPC usable on other platforms, this patch adds a mechanism
where IPC::Connection can be given a dedicated socket for FD passing.
This gives us the same behavior as the syscalls on SerenityOS, without
having to change the protocol implementation.
2022-10-06 09:51:04 +02:00
Jelle Raaijmakers
a39c38840e LibIPC: Make noise when shutting down because of an error
Previously, an IPC connection error could shut down the entire process
without giving a hint as to what's wrong. Now, we report that error to
the debug console.
2022-06-10 16:35:05 +01:00
Lenny Maiorani
dcdc62323d Libraries: Use default constructors/destructors in LibIPC
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00
sin-ack
2e1bbcb0fa LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServer
This change unfortunately cannot be atomically made without a single
commit changing everything.

Most of the important changes are in LibIPC/Connection.cpp,
LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp.

The notable changes are:
- IPCCompiler now generates the decode and decode_message functions such
  that they take a Core::Stream::LocalSocket instead of the socket fd.
- IPC::Decoder now uses the receive_fd method of LocalSocket instead of
  doing system calls directly on the fd.
- IPC::ConnectionBase and related classes now use the Stream API
  functions.
- IPC::ServerConnection no longer constructs the socket itself; instead,
  a convenience macro, IPC_CLIENT_CONNECTION, is used in place of
  C_OBJECT and will generate a static try_create factory function for
  the ServerConnection subclass. The subclass is now responsible for
  passing the socket constructed in this function to its
  ServerConnection base; the socket is passed as the first argument to
  the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before
  any other arguments.
- The functionality regarding taking over sockets from SystemServer has
  been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket
  implementation of this functionality hasn't been deleted due to my
  intention of removing this class in the near future and to reduce
  noise on this (already quite noisy) PR.
2022-01-15 13:29:48 +03:30
Andreas Kling
8d76eb773f LibIPC: Make IPC::Connection::post_message() return ErrorOr 2021-11-28 23:14:18 +01:00
Andreas Kling
2c70c479ab LibIPC: Replace Result<T, E> use with ErrorOr<T> 2021-11-08 00:35:27 +01:00
Andreas Kling
99a33c9a67 Revert "LibIPC: Use a zero-delay timer for message processing"
This reverts commit 3bed7d5a5e.

As discovered by tomuta, this caused a large increase in WindowServer
CPU usage.
2021-11-03 19:56:47 +01:00
Andreas Kling
3bed7d5a5e LibIPC: Use a zero-delay timer for message processing
This lets us avoid using Core::deferred_invoke() which is not usable
during application teardown (as there is no event loop to push the
deferred invocation onto.)

(Not that there is an event loop to fire the processing timer during
teardown *either*, but at least we can exit gracefully with pending
timers, unlike deferred invocations, which hang the process. This is an
area where more improvements are definitely needed!)
2021-10-24 01:01:01 +02:00
Andreas Kling
24642861af LibIPC: Store local endpoint magic in a ConnectionBase member
This simplifies some of the code, since it's no longer necessary for the
templated code to pass LocalEndpoint::static_magic() everywhere.
2021-10-24 01:01:01 +02:00
Andreas Kling
9a8bdf84c8 LibIPC: Move waiting for synchronous responses to ConnectionBase 2021-10-24 01:01:01 +02:00
Andreas Kling
8728d36dd0 LibIPC: Move more of IPC::Connection to ConnectionBase
This patch moves the templated message parsing code to a virtual
try_parse_messages() helper. By doing that, we can move the rest of the
socket draining code up to ConnectionBase and keep it out of line.
2021-10-24 01:01:01 +02:00
Andreas Kling
f3c4a357ea LibIPC: Move non-templated parts of IPC::Connection out of line
This patch splits IPC::Connection into Connection and ConnectionBase.
ConnectionBase moves into Connection.cpp so we don't have to inline it
for every single templated subclass.
2021-10-24 01:01:01 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
Federico Guerinoni
b2a849935b LibIPC: Pass only message size to decoder
Fixes #9015.
2021-08-11 18:28:59 +02:00
Tom
7e8a5d7323 LibIPC: Fix losing messages when connection is closed
This fixes not processing any messages read up until a connection
close is detected. We were returning from the function despite having
read some messages.
2021-07-21 01:13:45 +02:00
Gunnar Beutner
ab353fd4e1 LibIPC: Close the socket and die when the peer is closed
This will close the socket when the recv() returns 0 indicating that
the peer has shutdown, and when there are no pending bytes to be
processed.
2021-07-18 17:21:28 +02:00
Gunnar Beutner
e331ef7057 LibIPC: Add Connection::is_open()
This will allow clients to see if the IPC socket is still open.
2021-07-18 17:21:28 +02:00
Daniel Bertalan
a36c37db47 LibIPC: Remove unnecessary template<>
This fixes a Clang warning.
2021-07-08 10:11:00 +02:00
Andreas Kling
d3f298c592 LibIPC: Fix unaligned u32 access in drain_messages_from_peer()
Caught by userspace UBSAN. :^)
2021-05-24 09:04:22 +02:00
Gunnar Beutner
5bb79ea0a7 Userland: Update IPC calls to use proxies
This updates all existing code to use the auto-generated client
methods instead of post_message/send_sync.
2021-05-03 21:14:40 +02:00
Gunnar Beutner
78803ce384 Userland: Split IPC endpoints into proxies and stubs
This enables support for automatically generating client methods.
With this added the user gets code completion support for all
IPC methods which are available on a connection object.
2021-05-03 21:14:06 +02:00
Gunnar Beutner
de9b454f89 LibIPC: Make sure FDs survive when passed into a MessageBuffer 2021-05-02 13:26:07 +02:00
Gunnar Beutner
7cf2839a26 Userland: Get rid of the OwnPtr<...> boilerplate code for IPC handlers 2021-05-02 08:11:38 +02:00
Jean-Baptiste Boric
9aa44fa36c LibIPC: Add missing errno.h include 2021-04-27 23:06:16 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
e5318d51e6 LibCore: Remove the barely-used Core::safe_syscall()
This was a helper that would call a syscall repeatedly until it either
succeeded or failed with a non-EINTR error.

It was only used in two places, so I don't think we need this helper.
2021-04-21 23:49:01 +02:00
Idan Horowitz
28b8a2ec7a LibIPC: Make Connection::send_sync return a NonnullOwnPtr
Since we VERIFY that we received a response, the response pointer is
always non-null.
2021-04-20 10:10:15 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
a446cea759 LibIPC: Add Connection::send_sync_but_allow_failure()
Instead of asserting that the peer responds successfully, this API
allows for the peer to die/crash/whatever happens on the other side
while handling a synchronous request.

This will be useful when using process separation to parse untrusted
data from the web.
2021-02-20 11:37:55 +01:00
Andreas Kling
1b5be4a342 LibIPC: Stop exchanging client/server PIDs in greeting handshake
The PIDs were used for sharing shbufs between processes, but now that
we have migrated to file descriptor passing, we no longer need to know
the PID of the other side.
2021-01-31 09:29:27 +01:00
asynts
01879d27c2 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-16 11:54:35 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00