Commit Graph

3646 Commits

Author SHA1 Message Date
Andreas Kling
5096eaa845 AK: Add a FixedArray<T> container
This is a simple array wrapper that knows its size. It has begin/end
so you can use range-for. It also has a resize() that reallocates.
2019-08-07 20:05:36 +02:00
Andreas Kling
6bdb81ad87 Kernel: Split VMObject into two classes: Anonymous- and InodeVMObject
InodeVMObject is a VMObject with an underlying Inode in the filesystem.
AnonymousVMObject has no Inode.

I'm happy that InodeVMObject::inode() can now return Inode& instead of
VMObject::inode() return Inode*. :^)
2019-08-07 18:09:32 +02:00
Andreas Kling
cb2d572a14 Kernel: Remove "allow CPU caching" flag on VMObject
This wasn't really thought-through, I was just trying anything to see
if it would make WindowServer faster. This doesn't seem to make much of
a difference either way, so let's just not do it for now.

It's easy to bring back if we think we need it in the future.
2019-08-07 16:34:00 +02:00
Andreas Kling
3364da388f Kernel: Remove VMObject names
The VMObject name was always either the owning region's name, or the
absolute path of the underlying inode.

We can reconstitute this information if wanted, no need to keep copies
of these strings around.
2019-08-07 16:14:08 +02:00
Andreas Kling
5487f81b5d Vector: Use memcpy when dynamically growing Vectors of trivial types 2019-08-07 15:35:23 +02:00
Andreas Kling
6da6ca64d2 Vector: Use TypedTransfer in more parts of Vector
Make more Vector-of-trivial-type operations go fast :^)
2019-08-07 15:25:34 +02:00
Andreas Kling
e8e85f5457 Vector: Use memcmp for comparing two vectors with trivial elements 2019-08-07 15:05:10 +02:00
Andreas Kling
6d97caf124 JsonParser: Scan ahead to find the first special char in quoted strings
This allows us to take advantage of the now-optimized (to do memmove())
Vector::append(const T*, int count) for collecting these strings.

This is a ~15% speedup on the load_4chan_catalog benchmark.
2019-08-07 11:57:51 +02:00
Andreas Kling
b48b6c0caa Vector: Use memmove() for moving trivial types around more
This can definitely be improved with better trivial type detection and
by using the TypedTransfer template in more places.

It's a bit annoying that we can't get <type_traits> in Vector.h since
it's included in the toolchain compilation before we have libstdc++.
2019-08-07 11:55:20 +02:00
Andreas Kling
bebe7c4cff DiskDevice: Add missing override and remove unnecessary class_name()
This class needs to be fixed up to not hide the read()/write() virtuals
at some point.
2019-08-07 07:21:28 +02:00
Andreas Kling
60c25228ee AK: Fix -Wconsumed warnings in Optional move-ctor and move-assign
Our protocol says we have to call has_value() before release_value().
The code was already safe, but the compiler had no way of knowing that.
2019-08-07 07:17:52 +02:00
Andreas Kling
0f7eece141 Meta: Make Serenity run on Bochs once again
It's now possible to run Serenity inside Bochs by executing "./run b"
Note that it only works with a GRUB image (i.e ./build-image-grub.sh)
2019-08-06 21:09:24 +02:00
Andreas Kling
2abfab2892 ELFLoader: Remove an uninteresting debug log message
This is showing up at the boundary between kernel and userspace stack
frames in backtraces, and looks silly.
2019-08-06 20:49:36 +02:00
Andreas Kling
f083031a27 Kernel: Add KBufferBuilder, similar to StringBuilder but for KBuffer
This class works by eagerly allocating 1MB of virtual memory but only
adding physical pages on demand. In other words, when you append to it,
its memory usage will increase by 1 page whenever you append across a
page boundary (4KB.)
2019-08-06 20:04:12 +02:00
Andreas Kling
83fdad25ed Kernel: For signal-killed threads, dump backtrace from finalizer thread
Instead of dumping the dying thread's backtrace in the signal handling
code, wait until we're finalizing the thread. Since signalling happens
during scheduling, the less work we do there the better.

Basically the less that happens during a scheduler pass the better. :^)
2019-08-06 19:45:08 +02:00
Conrad Pankoff
73c998dbfc Kernel: Refactor TCP/IP stack
This has several significant changes to the networking stack.

* Significant refactoring of the TCP state machine. Right now it's
  probably more fragile than it used to be, but handles quite a lot
  more of the handshake process.
* `TCPSocket` holds a `NetworkAdapter*`, assigned during `connect()` or
  `bind()`, whichever comes first.
* `listen()` is now virtual in `Socket` and intended to be implemented
  in its child classes
* `listen()` no longer works without `bind()` - this is a bit of a
  regression, but listening sockets didn't work at all before, so it's
  not possible to observe the regression.
* A file is exposed at `/proc/net_tcp`, which is a JSON document listing
  the current TCP sockets with a bit of metadata.
* There's an `ETHERNET_VERY_DEBUG` flag for dumping packet's content out
  to `kprintf`. It is, indeed, _very debug_.
2019-08-06 16:21:17 +02:00
Andreas Kling
c973a51a23 Kernel: Make KBuffer lazily populated
KBuffers are now zero-filled on demand instead of up front. This means
that you can create a huge KBuffer and it will only take up VM, not
physical pages (until you access them.)
2019-08-06 15:06:31 +02:00
Andreas Kling
a0bb592b4f Kernel: Allow zero-fill page faults on kernel-only pages
We were short-circuiting the page fault handler a little too eagerly
for page-not-present faults in kernel memory.
If the current page directory already has up-to-date mapps for kernel
memory, allow it to progress to checking for zero-fill conditions.

This will enable us to have lazily populated kernel regions.
2019-08-06 15:06:31 +02:00
Conrad Pankoff
da615e46cd LibCore: Initialise m_port as zero in CSocketAddress 2019-08-06 15:06:20 +02:00
Conrad Pankoff
6f75d96689 Launcher: Add ChanViewer to default config 2019-08-06 15:05:56 +02:00
Sergey Bugaev
9de48cd81a Terminal: Fix trying to free() a stack variable
GWindow::~GWindow() deletes the main widget, assuming it was
allocated with new; this is what all other applications do,
so heap-allocate the terminal widget as well even though it's
not necessary in this case.
2019-08-06 11:59:14 +02:00
Andreas Kling
2ad963d261 Kernel: Add mapping from page directory base (PDB) to PageDirectory
This allows the page fault code to find the owning PageDirectory and
corresponding process for faulting regions.

The mapping is implemented as a global hash map right now, which is
definitely not optimal. We can come up with something better when it
becomes necessary.
2019-08-06 11:30:26 +02:00
Andreas Kling
8d07bce12a Kernel: Break region_from_vaddr() into {user,kernel}_region_from_vaddr
Sometimes you're only interested in either user OR kernel regions but
not both. Let's break this into two functions so the caller can choose
what he's interested in.
2019-08-06 10:33:22 +02:00
Andreas Kling
e27e1b3fb2 Kernel: Add LogStream operator<< for VirtualAddress 2019-08-06 10:28:46 +02:00
Andreas Kling
945f8eb22a Kernel: Don't treat read faults like CoW exceptions
I'm not sure why we would have a non-readable CoW region, but I suppose
we could, so let's not Copy-on-Read in those cases.
2019-08-06 09:39:39 +02:00
Andreas Kling
af4cf01560 Kernel: Clean up the page fault handling code a bit
Not using "else" after "return" unnests the code and makes it easier to
follow. Also use an enum for the two different page fault types.
2019-08-06 09:33:35 +02:00
Andreas Kling
f58b0c245d KBuffer: Add set_size() and LogStream operator<<
It will be useful to be able to set the "public" size of a KBuffer.
It can still have a different amount of memory allocated internally.
2019-08-06 07:31:52 +02:00
Andreas Kling
da6c8fe3f8 Kernel: On kernel NP fault, always copy into *active* page directory
If we were using a ProcessPagingScope to temporarily go into another
process's page tables, things would fall apart when hitting a kernel
NP fault, since we'd clone the kernel page directory entry into the
*currently active process's* page directory rather than cloning it
into the *currently active* page directory.
2019-08-06 07:28:35 +02:00
Andreas Kling
2d7a993db3 SynthFS: Remove unused create_text_file() feature
We don't need to support static text files in SynthFS, it's better to
always use generators for everything.
2019-08-05 22:37:50 +02:00
Andreas Kling
151e6a1818 AK: Fix leak in Optional(Optional&&)
We were *copying* the other Optional's value and then marking it as not
having a value. This prevented us from ever destroying the original.
2019-08-05 22:27:47 +02:00
Andreas Kling
9553ecfe01 AK: Optional::operator=(Optional&&) should clear movee's has_value bit
We were forgetting to clear m_has_value in the Optional being moved
from when using operator=(Optional&&).
2019-08-05 21:47:36 +02:00
Andreas Kling
cd08c8e1bf ChanViewer: Add a status bar to show loading status
Also update the window title with the current board after loading. :^)
2019-08-05 18:54:44 +02:00
Andreas Kling
fdcaf2d2b5 GComboBox: Make set_only_allow_values_from_model() actually take effect 2019-08-05 18:52:29 +02:00
Andreas Kling
7a63277115 ChanViewer: Fetch the list of boards and allow switching the board
We put the list of boards in a combo box and allow the user to switch
boards that way. :^)
2019-08-05 18:43:36 +02:00
Andreas Kling
6311a617be GComboBox: Include the selected index with the on_change notification
This will be useful for clients that need to fetch additional data from
the model on selection change.
2019-08-05 18:42:51 +02:00
Andreas Kling
ffff150435 LibGUI: Allow specifying the model column for GListView and GComboBox
These widgets can only display a single column from the underlying data
model, and it was previously hard-coded to use column 0. Now you can
use any column you like.
2019-08-05 18:32:04 +02:00
Andreas Kling
7c0f9ea2b9 GComboBox: Constrain the list popup window height to the desktop rect
This looks much better than allowing it to extend past the bottom of
the screen. :^)
2019-08-05 18:31:13 +02:00
Andreas Kling
f2fbb90dae Meta: Add some recently-added features to the list 2019-08-05 16:26:39 +02:00
Sergey Bugaev
211b51dab7 CEventLoop: Create the wake pipe with O_CLOEXEC
This ensures the pipe fds don't leak into child processes.
This manifested as the Shell (and all processes started
from the shell) having two mysterious FIFOs open. This
was happening because of the Terminal, which the shell
was spawned form, leaking its CEventLoop wake pipe fds.
2019-08-05 16:04:31 +02:00
Sergey Bugaev
9c3b1ca0c6 Kernel+LibC: Support passing O_CLOEXEC to pipe()
In the userspace, this mimics the Linux pipe2() syscall;
in the kernel, the Process::sys$pipe() now always accepts
a flags argument, the no-argument pipe() syscall is now a
userspace wrapper over pipe2().
2019-08-05 16:04:31 +02:00
Sergey Bugaev
55d7810fab AK: Do not keep an open FD in MmappedFile
We only need an open FD while establishing the mapping,
and can close it immediately after mmap() call.
2019-08-05 16:04:31 +02:00
Andreas Kling
837b476283 Lagom: Disable building the IPC client/server apps for now
This is not gonna work right until we also build IPCCompiler.
2019-08-05 14:03:15 +02:00
Andreas Kling
4e70c1fc0a SynthFS: Oops, fix build. 2019-08-05 12:56:31 +02:00
Conrad Pankoff
ed66f1d6d4 LibCore: Add CTCPServer
This is pretty much a find/replace copy of CLocalServer, and some
modifications to CTCPSocket and CSocketAddress to support it.
2019-08-05 12:53:07 +02:00
Andreas Kling
79e22acb22 Kernel: Use KBuffers for ProcFS and SynthFS
Instead of generating ByteBuffers and keeping those lying around, have
these filesystems generate KBuffers instead. These are way less spooky
to leave around for a while.

Since FileDescription will keep a generated file buffer around until
userspace has read the whole thing, this prevents trivially exhausting
the kmalloc heap by opening many files in /proc for example.

The code responsible for generating each /proc file is not perfectly
efficient and many of them still use ByteBuffers internally but they
at least go away when we return now. :^)
2019-08-05 11:37:48 +02:00
Andreas Kling
6b6b86fbf3 Kernel: Add a little comment header about KBuffer 2019-08-05 11:11:00 +02:00
Andreas Kling
605975adb5 Kernel: Make KBuffer a value-type wrapper around a KBufferImpl
A KBuffer always contains a valid KBufferImpl. If you need a "null"
state buffer, use Optional<KBuffer>.

This makes KBuffer very easy to work with and pass around, just like
ByteBuffer before it.
2019-08-05 11:07:45 +02:00
Andreas Kling
52cfe9ebae IPv4: Remove an unnecessary copy of each outgoing IPv4 payload
There's no need for send_ipv4() to take a ByteBuffer&&, the data is
immediately cooked into a packet and transmitted. Instead, just pass
it the address+length of whatever buffer we've been using locally.

The more we can reduce the pressure on kmalloc the better. :^)
2019-08-05 10:43:22 +02:00
Andreas Kling
6347e3aa51 Net: Let Socket have read/write wrappers around sendto/recvfrom
The situations in IPv4Socket and LocalSocket were mirrors of each other
where one had implemented read/write as wrappers and the other had
sendto/recvfrom as wrappers.

Instead of this silliness, move read and write up to the Socket base.
Then mark them final, so subclasses have no choice but to implement
sendto and recvfrom.
2019-08-05 10:03:19 +02:00
Conrad Pankoff
9111d3626a Userland: Implement truncate command
This has a known bug in that you can't specify a negative size value.
This bug stems from the argument parser, and once it's fixed there,
everything should work here.
2019-08-05 08:36:28 +02:00