Commit Graph

1021 Commits

Author SHA1 Message Date
Andreas Kling
bcc6ddfb6b Kernel: Let PageDirectory own the associated RangeAllocator.
Since we transition to a new PageDirectory on exec(), we need a matching
RangeAllocator to go with the new directory. Instead of juggling this in
Process and MemoryManager, simply attach the RangeAllocator to the
PageDirectory instead.

Fixes #61.
2019-05-20 04:46:29 +02:00
Andreas Kling
5023464d95 LocalSocket: Make send() and sendto() work, too. 2019-05-20 03:59:30 +02:00
Andreas Kling
668bfaa2af LocalSocket: Bump internal buffer sizes to 16KB.
This gives us some leeway for WindowServer to queue up a bunch of messages
for one of its clients. Longer-term we should improve DoubleBuffer to be
able to grow dynamically in a way that gets billed to some reasonable place.
2019-05-20 03:57:25 +02:00
Andreas Kling
b3a1671f1a Kernel: Add support for recv() with MSG_DONTWAIT.
Passing this flag to recv() temporarily puts the file descriptor into
non-blocking mode.

Also implement LocalSocket::recv() as a simple forwarding to read().
2019-05-20 03:47:02 +02:00
Andreas Kling
85d2e85912 LocalSocket: Fix mismatch between can_write() and write() logic.
can_write() was saying yes in situations where write() would overflow the
internal buffer. This patch adds a has_attached_peer() helper to make it
easier to understand what's going on in these functions.
2019-05-20 02:54:52 +02:00
Robin Burchell
a8864dc590 Kernel: Report EAGAIN from read() on a non-blocking socket if the buffer is empty
This is not EOF, and never should have been so -- can trip up other code
when porting.

Also updates LibGUI and WindowServer which both relied on the old
behaviour (and didn't work without changes). There may be others, but I
didn't run into them with a quick inspection.
2019-05-20 01:31:28 +02:00
Andreas Kling
212a263f0a Kernel+LibC: Implement getsockname() syscall. 2019-05-19 19:55:27 +02:00
Andreas Kling
189b342e6f LibC: Add mmap_with_name() that names the allocation immediately.
This allows us to skip the separate call to set_mmap_name() in code that
we control, e.g malloc() and GraphicsBitmap.
2019-05-19 15:54:56 +02:00
Andreas Kling
5f26f83451 IDEDiskDevice: Add sysctl variable for turning DMA on/off. 2019-05-19 15:54:33 +02:00
Robin Burchell
d8b74c8c86 Kernel: Check can_write for blocking write
This way the socket write buffer sizes are respected, and things that
exceed them get sent EAGAIN.
2019-05-19 14:13:49 +02:00
Robin Burchell
635eb20289 Kernel: Add the ability to debug poll/select independently of read/write 2019-05-19 14:13:49 +02:00
Andreas Kling
c7d8aa6969 IDEDiskDevice: Support reading multiple sectors at a time with DMA.
This is another sizable improvement to GCC compile times.
2019-05-19 04:40:30 +02:00
Andreas Kling
ed79116e94 IDEDiskDevice: Use wait_for_irq() when waiting for DMA transfers.
Also make sure we return any device errors to caller.
2019-05-19 03:56:06 +02:00
Andreas Kling
c818773983 IDEDiskDevice: Add support for DMA reads.
I've only tested this with the PIIX3 chipset QEMU emulates, but it works
pretty well here. GCC compile times are cut roughly in half :^)
2019-05-19 03:46:50 +02:00
Andreas Kling
1fd90b09f8 Kernel: Remove an unused ELFLoader member. 2019-05-19 02:03:56 +02:00
Andreas Kling
853597200e Kernel: Remove relocation-related code since it's not used by the kernel.
If/when we need this in the future, we can bring it back. Right now it's
just sitting there making the ELF code look huge when it's not.
2019-05-19 01:14:32 +02:00
Andreas Kling
75866438b5 Kernel: Don't page in entire file immediately on mmap().
If we just don't do anything, the page fault handler will load the file
incrementally as-needed instead. :^)
2019-05-18 22:30:55 +02:00
Andreas Kling
959c8f287c FileDescriptor: It's actually okay to seek past the end of a file. :^) 2019-05-18 21:54:31 +02:00
Andreas Kling
7900da9667 Kernel: Make sure we never put the colonel thread in the runnable list.
This would cause it to get scheduled unnecessarily.
2019-05-18 20:28:04 +02:00
Andreas Kling
64a4f3df69 Kernel: Add a Thread::set_thread_list() helper to keep logic in one place. 2019-05-18 20:28:04 +02:00
Andreas Kling
8c7d5abdc4 Kernel: Refactor thread scheduling a bit, breaking it into multiple lists.
There are now two thread lists, one for runnable threads and one for non-
runnable threads. Thread::set_state() is responsible for moving threads
between the lists.

Each thread also has a back-pointer to the list it's currently in.
2019-05-18 20:28:04 +02:00
Robin Burchell
99dd60611f Kernel: Fix select with a 0 timeout
select essentially has 3 modes (which is presumably why we're finding it
so hard to get this right in a reliable way :)).

1. NULL timeout -- no timeout on blocking
2. non-NULL timeout that is not zero'd -- timeout on blocking
3. non-NULL but zero timeout -- no blocking at all (immediate poll)

For cases 1 and 2, we want to block the thread. We have a timeout set
only for case 2, though.

Case 3 should not block the thread, and does not have a timeout set.
2019-05-18 19:01:08 +02:00
Andreas Kling
d2c3749cf3 Kernel: Don't allow dump_backtrace() to call dump_backtrace().
That was not a very graceful looking loop to be stuck in.
2019-05-18 17:33:05 +02:00
Andreas Kling
316fb624f7 Kernel: Fail a bit more gracefully when we don't have userspace symbols. 2019-05-18 14:49:49 +02:00
Andreas Kling
a4e48dce77 Kernel: SharedMemory should implement mmap(). 2019-05-18 04:17:53 +02:00
Andreas Kling
237628a7a6 Kernel: Tidy up FileDescriptor members a bit. 2019-05-18 04:14:22 +02:00
Robin Burchell
123283d840 Kernel: Fix poll() with timeout 2019-05-18 04:03:28 +02:00
Andreas Kling
b33cc7f772 Kernel: Remove some RangeAllocator debug spam. 2019-05-18 03:59:16 +02:00
Andreas Kling
cdaf8cd656 Kernel: select() was transferring the readfds into the exceptfds vector.
Just a mistake I spotted while reading the code. We don't actually detect
exceptional descriptor events yet.
2019-05-18 03:09:37 +02:00
Andreas Kling
14c896ec58 Kernel: Pass ELF program header locations from multiboot to kernel.
Patch contributed by "pd"
2019-05-18 03:08:29 +02:00
Robin Burchell
ba92c07a75 Kernel: Make sure to clear FD sets when preparing for a select
NULL sets can happen, and we don't want to incorrectly return FDs which
aren't in the set too.
2019-05-18 02:57:38 +02:00
Robin Burchell
df74a9222f Kernel: Fix timeout support in select
The scheduler expects m_select_timeout to act as a deadline. That is, it
should contain the time that a task should wake at -- but we were
directly copying the time from userspace, which meant that it always
returned virtually immediately.

At the same time, fix CEventLoop to not rely on the broken select behavior
by subtracting the current time from the time of the nearest timer.
2019-05-18 02:57:38 +02:00
Andreas Kling
8f3022b5c1 NetworkTask: Don't crash on startup if there's no E1000 NIC present. 2019-05-18 00:22:08 +02:00
Robin Burchell
5babcac289 Build: Install most headers to Root (and libcore.a/libgui.a)
This makes out-of-tree linking possible. And at the same time, add a
CMakeToolchain.txt file that can be used to build arbitrary cmake-using
applications on Serenity by pointing to the CMAKE_TOOLCHAIN_FILE when
running cmake:

    -DCMAKE_TOOLCHAIN_FILE=~/code/serenity/Toolchain/CMakeToolchain.txt
2019-05-17 21:59:48 +02:00
Andreas Kling
2d98f4e28f Kernel: Make the times() syscall return something other than 0.
Based on the description I read, this syscall doesn't seem completely
reasonable, but let's at least return a number that is likely to change
between invocations in case somebody depends on that happening.
2019-05-17 20:19:29 +02:00
Andreas Kling
a182ea8c60 Kernel: After creating our GDT, make sure CS refers to the right descriptor.
This will allow us to boot from e.g GRUB which will have a different looking
GDT in effect before we start moving things around.
2019-05-17 18:52:29 +02:00
Andreas Kling
64b0b81b2a sync.sh: Use mkdir -p for everything. 2019-05-17 18:26:54 +02:00
Andreas Kling
e8ae2c952e Kernel: Put GDT and IDT in BSS rather than runtime-allocating them. 2019-05-17 18:25:50 +02:00
Andreas Kling
e0ff07bb57 Kernel: Make sure we load DS/ES/FS/GS/SS immediately after making the GDT. 2019-05-17 18:23:08 +02:00
Andreas Kling
a15857ea28 Kernel: Clear the X86 direction flag (DF) in the boot loader.
I'm not sure who is responsible for clearing this, but IIUC the C++ ABI
expects it to be clear on function entry, so just to be on the safe side..
2019-05-17 18:20:11 +02:00
Andreas Kling
45230a9544 Run QEMU with the "guest_errors" debug flag, in case we do something wrong. 2019-05-17 18:19:03 +02:00
Andreas Kling
923e587283 Kernel: GDTR and IDTR limits should be table size - 1. 2019-05-17 18:17:53 +02:00
Robin Burchell
0d77aa841a Kernel/Process: Use auto to avoid incompatible types, causing a signedness warning in the ASSERT 2019-05-17 16:06:26 +02:00
Robin Burchell
1cefb4a3b4 Kernel/RTC: Mark some intentional fallthroughs to suppress compiler warnings 2019-05-17 16:06:26 +02:00
Robin Burchell
77dfd419e9 LibCore: Move AK/ArgsParser to LibCore/CArgsParser
Also rename the classes to match LibCore naming style.
This means that it's no longer incorrectly linked into LibC and Kernel.
2019-05-17 15:49:37 +02:00
Andreas Kling
cde47089d2 Kernel: Remove some unnecessary massaging of region base/size pairs.
These will be appropriately rounded by the allocate_range(), so call sites
can stop worrying about it.
2019-05-17 04:47:06 +02:00
Andreas Kling
6957825444 Kernel: Factor out range allocation from Process::allocate_region*().
These functions were doing exactly the same thing for range allocation, so
share that code in an allocate_range() helper.

Region allocation will now also fail if range allocation fails, which means
that mmap() can actually fail without falling apart. Exciting times!
2019-05-17 04:39:22 +02:00
Andreas Kling
87b54a82c7 Kernel: Let Region keep a Range internally. 2019-05-17 04:32:08 +02:00
Andreas Kling
4a6fcfbacf Kernel: Use a RangeAllocator for kernel-only virtual space allocation too. 2019-05-17 04:02:29 +02:00
Andreas Kling
b1bb737704 Kernel: Remove Process::m_next_address.
This isn't needed now that we have RangeAllocator. :^)
2019-05-17 03:47:00 +02:00