Commit Graph

146 Commits

Author SHA1 Message Date
Andreas Kling
6f4c380d95 AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
2019-12-09 17:51:21 +01:00
Andrew Kaster
e09a02ad3f SystemMonitor: Show thread name instead of process name
Add the thread name to CThreadStatistics and display it in the
system monitor's process model instead of the process name.
2019-12-08 14:09:29 +01:00
Andreas Kling
5d4ee0f58a LibIPC: Move IPC client/server connection templates to LibIPC
Move over the CoreIPC::Server and CoreIPC::Client namespace stuff
into LibIPC where it will soon becomes LibIPC-style things.
2019-12-02 11:11:05 +01:00
Andreas Kling
272d65e3e2 WindowServer: Port to the new IPC system
This patch introduces code generation for the WindowServer IPC with
its clients. The client/server endpoints are defined by the two .ipc
files in Servers/WindowServer/: WindowServer.ipc and WindowClient.ipc

It now becomes significantly easier to add features and capabilities
to WindowServer since you don't have to know nearly as much about all
the intricate paths that IPC messages take between LibGUI and WSWindow.

The new system also uses significantly less IPC bandwidth since we're
now doing packed serialization instead of passing fixed-sized structs
of ~600 bytes for each message.

Some repaint coalescing optimizations are lost in this conversion and
we'll need to look at how to implement those in the new world.

The old CoreIPC::Client::Connection and CoreIPC::Server::Connection
classes are removed by this patch and replaced by use of ConnectionNG,
which will be renamed eventually.

Goodbye, old WindowServer IPC. You served us well :^)
2019-12-02 11:11:05 +01:00
Andreas Kling
5a45376180 Kernel+SystemMonitor: Log amounts of I/O per thread
This patch adds these I/O counters to each thread:

- (Inode) file read bytes
- (Inode) file write bytes
- Unix socket read bytes
- Unix socket write bytes
- IPv4 socket read bytes
- IPv4 socket write bytes

These are then exposed in /proc/all and seen in SystemMonitor.
2019-12-01 17:40:27 +01:00
Andreas Kling
2ece61fa1f LibCore: Improve logging of errors in safe_syscall() somewhat 2019-12-01 16:47:28 +01:00
Andreas Kling
5b8cf2ee23 Kernel: Make syscall counters and page fault counters per-thread
Now that we show individual threads in SystemMonitor and "top",
it's also very nice to have individual counters for the threads. :^)
2019-11-26 21:37:38 +01:00
Andreas Kling
712ae73581 Kernel: Expose per-thread information in /proc/all
Previously it was not possible to see what each thread in a process was
up to, or how much CPU it was consuming. This patch fixes that.

SystemMonitor and "top" now show threads instead of just processes.
"ps" is gonna need some more fixing, but it at least builds for now.

Fixes #66.
2019-11-26 21:37:30 +01:00
Sergey Bugaev
c9e21b2bcc SystemServer+LibCore: Implement socket takeover
SystemServer can now create sockets on behalf of services before spawning any
of them, and pass the open socket fd as fd 3. CLocalServer gains a method to
complete the takeover and listen on the passed fd.

This is not used by any services at the moment.
2019-11-26 19:58:25 +01:00
Sergey Bugaev
2f9be662ef LibCore: Assert instead of crashing in CEventLoop::current() 2019-11-26 19:58:25 +01:00
Andreas Kling
aa49419173 LibCore: Make CFile::open() truncate when opening something "WriteOnly"
Unless we're also opening to append (and/or if the file is required to
be a new file), CFile::open(WriteOnly) will now truncate the file.
2019-11-26 14:32:59 +01:00
Andreas Kling
35c26a06fc LibCore: Move puff() from LibDraw to LibCore
Since it's used both by CGzip and PNGLoader, it seems most appropriate
to keep this in LibCore.
2019-11-23 23:43:37 +01:00
Andreas Kling
20c957ef61 LibCore: Have CNetworkJob protect itself during the on_finish callback
Otherwise, the callback may trigger the destruction of the CNetworkJob
and make it difficult to continue execution correctly.
2019-11-23 21:42:02 +01:00
Andreas Kling
630d5b3ffd LibIPC+AudioServer: Allow unsolicited server-to-client IPC messages
Client-side connection objects must now provide both client and server
endpoint types. When a message is received from the server side, we try
to decode it using both endpoint types and then send it to the right
place for handling.

This now makes it possible for AudioServer to send unsolicited messages
to its clients. This opens up a ton of possibilities :^)
2019-11-23 16:50:21 +01:00
Andreas Kling
0ddde627b1 Lagom: Fix build 2019-11-19 11:14:26 +01:00
Andreas Kling
37329f829b LibCore: Add CConfigFile::open() for opening an arbitrary INI file 2019-11-11 13:13:08 +01:00
Marcel Schneider
a353d16ff4 LibCore: Rename class Gzip -> CGZip 2019-11-10 12:52:23 +01:00
Marcel Schneider
c40935e79f LibCore: Add Content-Encoding handling to CHttpJob 2019-11-10 12:52:23 +01:00
Marcel Schneider
4fe5503b17 LibCore: Add a gzip implementation 2019-11-10 12:52:23 +01:00
Andreas Kling
d3558b6137 LibCore+LibGUI: Allow inserting a CObject/GWidget before another
When adding a widget to a parent, you don't always want to append it to
the set of existing children, but instead insert it before one of them.

This patch makes that possible by adding CObject::insert_child_before()
which also produces a ChildAdded event with an additional before_child
pointer. This pointer is then used by GWidget to make sure that any
layout present maintains the correct order. (Without doing that, newly
added children would still be appended into the layout order, despite
having a different widget sibling order.)
2019-11-05 20:41:27 +01:00
Andreas Kling
43a6c70c2a LibCore: Make CTCPServer's local address/port getters return Optionals 2019-11-04 13:07:41 +01:00
Andreas Kling
50d937152a LibCore: Constify CTCPServer's local_address() and local_port() 2019-11-04 12:49:48 +01:00
Conrad Pankoff
fbe8569412 LibCore: Add local_{address,port} functions to CTCPServer 2019-11-04 12:49:15 +01:00
Andreas Kling
ea4e02ed86 LibCore: Flush outgoing IPC messages before trying to send a new one
This ensures that messages are sent in order.
2019-11-04 10:52:01 +01:00
Andreas Kling
53cfed7c8b LibCore: Put a limit on how many unsent messages an IPC server queues
This patch adds a limit of 200 unsent messages per client. If a client
does not handle its incoming messages and we manage to queue up 200
messages for it, we'll now disconnect that client. :^)
2019-11-03 12:40:57 +01:00
Andreas Kling
31c1b8ec3e LibCore: Have IPC server connections queue up unsendable messages
If an IPC client is giving us EAGAIN when trying to send him a message,
we now queue up the messages inside the CoreIPCServer::Connection and
will retry flushing them on next post/receive.

This prevents WindowServer from freezing up when one of its clients is
not taking care of its incoming messages.
2019-11-03 12:36:35 +01:00
George Pickering
704f48d7f3 POSIX compliance: (most) shell scripts converted to generic shell
Ports/.port_include.sh, Toolchain/BuildIt.sh, Toolchain/UseIt.sh
have been left largely untouched due to use of Bash-exclusive
functions and variables such as $BASH_SOURCE, pushd and popd.
2019-11-03 09:26:22 +01:00
Andreas Kling
f37cf5ea4a LibCore: Only wait 10ms between IPC connection retries instead of 1 sec
This makes startup feel way faster in case the WindowServer is not yet
available when we try connecting to it from Taskbar, Terminal, etc.
2019-10-31 16:28:30 +01:00
Brandon Scott
5311f8fae1 LibCore: Added unquit() method to CEventLoop.
Added an unquit() method to CEventLoop allowing you to cancel a
pending exit request.
2019-10-25 15:29:19 +02:00
Andreas Kling
74bba649c3 LibCore: Make CFile::open() assert that the filename is non-null 2019-10-21 18:45:27 +02:00
Andreas Kling
43a9843938 LibCore: Put HTTP debug spam behind FOO_DEBUG macros 2019-10-15 19:51:02 +02:00
Andreas Kling
7dbc13ac88 LibCore: Don't crash in IPC client/server on EAGAIN
Instead, just sched_yield() and try again. This makes the WindowServer
not fall apart whenever clients take a bit too long to respond.

Fixes #656.
2019-10-14 21:49:33 +02:00
Andreas Kling
3fdc595e0c LibCore: CHttpJob::start() should fail asynchronously
Clients are expected to have a chance to set up an on_finish callback
before we finish or fail.
2019-10-08 19:32:34 +02:00
Andreas Kling
35138437ef Kernel+SystemMonitor: Add fault counters
This patch adds three separate per-process fault counters:

- Inode faults

    An inode fault happens when we've memory-mapped a file from disk
    and we end up having to load 1 page (4KB) of the file into memory.

- Zero faults

    Memory returned by mmap() is lazily zeroed out. Every time we have
    to zero out 1 page, we count a zero fault.

- CoW faults

    VM objects can be shared by multiple mappings that make their own
    unique copy iff they want to modify it. The typical reason here is
    memory shared between a parent and child process.
2019-10-02 14:13:49 +02:00
Andreas Kling
8f45a259fc ByteBuffer: Remove pointer() in favor of data()
We had two ways to get the data inside a ByteBuffer. That was silly.
2019-09-30 08:57:01 +02:00
Andreas Kling
a1907011b2 CSocket: Don't create the read notifier until after we've connected
This makes it so that "on_connected" always gets called first.
Since accepted sockets are connected before construction, they have
to manually set CSocket::m_connected.
2019-09-22 21:46:46 +02:00
Andreas Kling
34d0e96aec LibCore+LibGUI: Remove GEventLoop and use CEventLoop everywhere
GEventLoop was just a dummy subclass of CEventLoop anyway. The only
thing it actually did was make sure a GWindowServerConnectionw was
instantiated. We now take care of that in GApplication instead.

CEventLoop is now non-virtual and a little less confusing. :^)
2019-09-22 20:50:39 +02:00
Andreas Kling
5614cdf308 LibCore: Remove leftover debug spam in CObject::remove_child() 2019-09-22 00:42:20 +02:00
Andreas Kling
f614081b83 LibCore: Add CObject::remove_from_parent()
This is a convenient shorthand for:

    if (object.parent())
        object.parent()->remove_child(object);
2019-09-22 00:41:01 +02:00
Andreas Kling
d6abfbdc5a LibCore: Remove ObjectPtr in favor of RefPtr
Now that CObject is fully ref-counted, just use RefPtr everywhere! :^)
2019-09-22 00:31:54 +02:00
Andreas Kling
bc319d9e88 LibCore: Make CObject reference-counted
Okay, I've spent a whole day on this now, and it finally kinda works!
With this patch, CObject and all of its derived classes are reference
counted instead of tree-owned.

The previous, Qt-like model was nice and familiar, but ultimately also
outdated and difficult to reason about.

CObject-derived types should now be stored in RefPtr/NonnullRefPtr and
each class can be constructed using the forwarding construct() helper:

    auto widget = GWidget::construct(parent_widget);

Note that construct() simply forwards all arguments to an existing
constructor. It is inserted into each class by the C_OBJECT macro,
see CObject.h to understand how that works.

CObject::delete_later() disappears in this patch, as there is no longer
a single logical owner of a CObject.
2019-09-22 00:25:25 +02:00
Andreas Kling
8d550c174e LibCore: Convert CFile to ObjectPtr 2019-09-21 20:50:06 +02:00
Andreas Kling
f4b51a63ec LibCore: Remove CTimer::create() overloads in favor of construct() 2019-09-21 18:13:17 +02:00
Andreas Kling
9e00651e14 LibCore: ObjectPtr should delete the pointee when cleared
We were only deleting the pointee when the ObjectPtr was destroyed.
If the ObjectPtr is cleared before that, we should also delete the
pointee. This is not the most important class to get right, since
it will go away as soon as we're able to switch to RefPtr.
2019-09-21 18:07:46 +02:00
Andreas Kling
4d8455156e CHttpJob: Shutting down the job should actually destroy the socket
It's pretty confusing when a CObject is owned both by its parent-child
relationship, but also by an ObjectPtr member in the parent.
In those cases, we have to make sure we both unparent the child *and*
reove it from the ObjectPtr.

This will become a bit less confusing when ObjectPtr becomes RefPtr,
although still not crystal clear. I'm not sure what the solution is.
2019-09-21 18:05:34 +02:00
Andreas Kling
bdf23a3d23 LibCore: Make it possible to cancel pending CNetworkJobs
Subclasses of CNetworkJob handle this by overriding shutdown().
This patch implements it for CHttpJob by simply tearing down the
underlying socket.

We also automatically call shutdown() after the job finishes,
regardless of success or failure. :^)
2019-09-21 17:32:26 +02:00
Andreas Kling
4ea229accd LibCore: Convert CTCPServer to ObjectPtr
Also get rid of the custom CNotifier::create() in favor of construct().
2019-09-21 15:25:08 +02:00
Andreas Kling
6b347747f2 LibCore: Convert CHttpJob to ObjectPtr 2019-09-21 15:25:08 +02:00
Andreas Kling
953cb4e436 LibCore: Convert CLocalServer to ObjectPtr 2019-09-21 15:25:08 +02:00
Andreas Kling
c83da29a9d LibCore: Convert CLocalSocket to ObjectPtr 2019-09-21 15:25:08 +02:00