Commit Graph

3202 Commits

Author SHA1 Message Date
Tom
0fab0ee96a Kernel: Rename Process::is_ring0/3 to Process::is_kernel/user_process
Since "rings" typically refer to code execution and user processes
can also execute in ring 0, rename these functions to more accurately
describe what they mean: kernel processes and user processes.
2020-09-10 19:57:15 +02:00
Tom
19ffd9d677 Kernel: Fix detecting in what ring a crash happened
The ring is determined based on the CS register. This fixes crashes
being handled as ring 3 crashes even though EIP/CS clearly showed
that the crash happened in the kernel.
2020-09-10 19:57:15 +02:00
Avery
06218a4074 IPv4: Truncate raw socket reads past buffer length
In addition to being the proper POSIX etiquette, it seems like a bad idea
for issues like the one seen in #3428 to result in a kernel crash. This patch
replaces the current behavior of failing on insufficient buffer size to truncating
SOCK_RAW messages to the buffer size. This will have to change if/when MSG_PEEK
is implemented, but for now this behavior is more compliant and logical than
just bailing.
2020-09-10 12:03:56 +02:00
Andreas Kling
f8e59addf7 Kernel+LibC+UE: Introduce SIGINFO (generated with ^T)
This signal is ignored by default, but can be caught to implement state
reporting a la BSD. :^)
2020-09-09 21:10:23 +02:00
Tom
678bbd29ca Kernel: Fix heap expansion loop
By being a bit too greedy and only allocating how much we need for
the failing allocation, we can end up in an infinite loop trying
to expand the heap further. That's because there are other allocations
(e.g. logging, vmobjects, regions, ...) that happen before we finally
retry the failed allocation request.

Also fix allocating in page size increments, which lead to an assertion
when the heap had to grow more than the 1 MiB backup.
2020-09-09 20:14:30 +02:00
Tom
efe2b75017 Kernel: Optimize single physical page allocation and randomize returns
Rather than trying to find a contiguous set of bits of size 1, just
find one single available bit using a hint.

Also, try to randomize returned physical pages a bit by placing them
into a 256 entry queue rather than making them available immediately.
Then, once the queue is filled, pick a random one, make it available
again and use that slot for the latest page to be returned.
2020-09-09 13:02:14 +02:00
Tom
92bfe40954 Kernel: Keep signal state in sync
In c3d231616c we added the atomic variable
m_have_any_unmasked_pending_signals tracking the state of pending signals.
Add helper functions that automatically update this variable as needed.
2020-09-09 12:43:56 +02:00
asynts
70dd97c46e AK: Remove FixedArray class. 2020-09-08 14:01:21 +02:00
asynts
ec1080b18a Refactor: Replace usages of FixedArray with Vector. 2020-09-08 14:01:21 +02:00
asynts
9c83d6ff46 Refactor: Replace usages of FixedArray with Array. 2020-09-08 14:01:21 +02:00
Tom
c3d231616c Kernel: Fix crash when delivering signal to barely created thread
We need to wait until a thread is fully set up and ready for running
before attempting to deliver a signal. Otherwise we may not have a
user stack yet.

Also, remove the Skip0SchedulerPasses and Skip1SchedulerPass thread
states that we don't really need anymore with software context switching.

Fixes the kernel crash reported in #3419
2020-09-07 16:49:19 +02:00
Nico Weber
e8131f503d Kernel: Let TimeManagement keep epoch time as timespec
Previously, it was kept as just a time_t and the sub-second
offset was inferred from the monotonic clock. This means that
sub-second time adjustments were ignored.

Now that `ntpquery -s` can pass in a time with sub-second
precision, it makes sense to keep time at that granularity
in the kernel.

After this, `ntpquery -s` immediately followed by `ntpquery` shows
an offset of 0.02s (that is, on the order of network roundtrip time)
instead of up to 0.75s previously.
2020-09-07 11:22:48 +02:00
Andreas Kling
4527d9852a Kernel: Track time-of-last-write in SlavePTY and report it as mtime 2020-09-06 18:48:24 +02:00
Andreas Kling
48a0b76a77 Kernel: Make File weakable
This will be useful for some things. This also removes the need for
TCPSocket to be special about this.
2020-09-06 18:46:46 +02:00
Andreas Kling
22831033d0 Kernel: Virtualize the File::stat() operation
Instead of FileDescriptor branching on the type of File it's wrapping,
add a File::stat() function that can be overridden to provide custom
behavior for the stat syscalls.
2020-09-06 18:31:51 +02:00
Andreas Kling
5444cabd39 Kernel: Rename FileDescription::fstat() => stat() 2020-09-06 18:17:07 +02:00
Andreas Kling
c14de7da99 Kernel: Remove bogus FIXME in TTY::write()
Failure to send SIGTTOU to the current process is not something that
should cause write() to fail with -ESRCH.
2020-09-06 18:13:04 +02:00
Andreas Kling
802f541184 Kernel/USB: Disable autodetection of UHCI controllers for now
Until this thing becomes stable, let's not bother everyone with it.
2020-09-05 15:42:54 +02:00
Andreas Kling
3f36903201 Kernel/USB: Start the UHCI controller after resetting it 2020-09-05 15:42:54 +02:00
Andreas Kling
02b3cb8123 Kernel: Add a missing "#pragma once" 2020-09-04 23:51:50 +02:00
Andreas Kling
eb74f62201 Kernel/USB: Add a simple UHCIController::stop()
This stops the controller and waits for it to complete.
2020-09-04 21:21:46 +02:00
Andreas Kling
1254447bd7 Kernel/USB: Add some constants for the USBCMD and USBSTS bits 2020-09-04 21:21:46 +02:00
Andreas Kling
e834c24eea Kernel/USB: Start fleshing out a basic UHCI controller driver :^)
Let's see if we can talk to some USB devices. We will now detect
a UHCI controller if present on the PCI bus.
2020-09-04 21:21:41 +02:00
Andreas Kling
2e01f1f9b9 Kernel: Add PCI::get_programming_interface(PCI::Address)
This returns the programming interface at a given PCI address.
This is sometimes referred to as "prog-if" on other systems.
2020-09-03 21:02:47 +02:00
Tom
bf268a0185 Kernel: Handle committing pages in regions more gracefully
Sometimes a physical underlying page may be there, but we may be
unable to allocate a page table that may be needed to map it. Bubble
up such mapping errors so that they can be handled more appropriately.
2020-09-02 00:35:56 +02:00
Tom
1ece93c805 Kernel: Use removed memory as backup if backup hasn't been allocated
It may be impossible to allocate more backup memory after expanding
the heap if memory is running low. In that case we wouldn't allocate
backup memory until trying to expand the heap again. But we also
wouldn't take advantage of using removed memory as backup, which means
that no backup memory would be available when the heap needs to grow
again, causing subsequent expansion to fail because there is no
backup memory.
2020-09-02 00:35:56 +02:00
Tom
ee51b28edd Kernel: Prevent recursive expansion or removing memory while expanding it
The process of expanding memory requires allocations and deallocations
on the heap itself. So, while we're trying to expand the heap, don't
remove memory just because we might briefly not need it. Also prevent
recursive expansion attempts.
2020-09-02 00:35:56 +02:00
Tom
83ddf3d850 Kernel: Fix memory purge clobbering mapped page directory in ensure_pte
If allocating a page table triggers purging memory, we need to call
quickmap_pd again to make sure the underlying physical page is
remapped to the correct one. This is needed because purging itself
may trigger calls to ensure_pte as well.

Fixes #3370
2020-09-01 22:08:43 +02:00
Tom
30d36a3ad1 Kernel: Remove assertion from Region::commit
We should be able to gracefully fail a commit in low-memory situations.
2020-09-01 22:08:43 +02:00
Tom
eb1cc5d665 Kernel: Only remap regions if memory was purged from them 2020-09-01 22:08:43 +02:00
Andreas Kling
171868e4f7 Kernel: Preserve internal state in cloned PurgeableVMObjects
When cloning a purgeable memory region (which happens on fork),
we need to preserve the "was purged" and "volatile" state of the
original region, or they will always appear as non-volatile and
unpurged regions in the child process.

Fixes #3374.
2020-09-01 17:45:28 +02:00
Andreas Kling
e002cbb06b Build: Add some -Wno-unknown-warning-option flags to CXXFLAGS
Patch from Anonymous.
2020-09-01 12:00:53 +02:00
Luke
8a2fd0e436 Kernel: Fix Processor::features_string() stopping too early and detect more features
The exit condition for the loop was sizeof(m_features) * 8,
which was 32. Presumably this was supposed to mean 32 bits, but it
actually made it stop as soon as it reached the 6th bit.

Also add detection for more SIMD CPU features.
2020-08-31 18:57:54 +02:00
Luke
8be708454c Kernel: Add more detailed debug output for E1000 {in,out}{8,16,32}
Also adds FIXME for VirtualBox.
2020-08-31 18:54:04 +02:00
Andreas Kling
57dd3b66c5 Kernel+LibC+UE: Implement sleep() via sys$clock_nanosleep()
This doesn't need to be its own syscall either. :^)
2020-08-30 13:21:24 +02:00
Andreas Kling
cc5403f77b Kernel: Remove unused variable PhysicalRegion::m_last 2020-08-30 13:13:55 +02:00
Tom
4b66692a55 Kernel: Make Heap implementation reusable, and make kmalloc expandable
Add an ExpandableHeap and switch kmalloc to use it, which allows
for the kmalloc heap to grow as needed.

In order to make heap expansion to work, we keep around a 1 MiB backup
memory region, because creating a region would require space in the
same heap. This means, the heap will grow as soon as the reported
utilization is less than 1 MiB. It will also return memory if an entire
subheap is no longer needed, although that is rarely possible.
2020-08-30 11:39:38 +02:00
Andreas Kling
f857f3ce4c Kernel+LibC+UE: Implement usleep() via sys$clock_nanosleep()
This doesn't need to be its own syscall. Thanks @BenWiederhake for
the idea. :^)
2020-08-30 10:45:51 +02:00
Luke
453affb101 Kernel: Add shutdown commands for other virtualizers
Source: https://wiki.osdev.org/Shutdown
2020-08-30 10:31:39 +02:00
Ben Wiederhake
737c9f0a14 Kernel: Explain correctness of reference to local lambda 2020-08-30 10:31:04 +02:00
Ben Wiederhake
081bb29626 Kernel: Unbreak building with extra debug macros, part 2 2020-08-30 09:43:49 +02:00
Ben Wiederhake
eac3bbdcee Kernel: Unbreak building with extra debug macros, part 1 2020-08-30 09:43:49 +02:00
Itamar
33138900de FileSystem: Convert file types to DT_* types at a later stage
A change introduced in 5e01234 made it the resposibility of each
filesystem to have the file types returned from
'traverse_as_directory' match up with the DT_* types.
However, this caused corruption of the Ext2FS file format because
the Ext2FS uses 'traverse_as_directory' internally when manipulating
 the file system. The result was a mixture between EXT2_FT_* and DT_*
file types in the internal Ext2FS structures.

Starting with this commit, the conversion from internal filesystem file
types to the user facing DT_* types happens at a later stage,
in the 'FileDescription::get_dir_entries' function which is directly
used by sys$get_dir_entries.
2020-08-29 20:54:06 +02:00
Itamar
b6c34c0521 Ext2FS: Make reported file_type values match up with those in dirent
This fixes an issue we had in the git port where git would not
recognize untracked files (for example in 'git status').
When git used readdir, the 'd_type' field in the dirent struct contained
bad values (Specifically, it contained the values defiend in
Kernel/FileSystem/ext2_fs.h instead of the ones in LibC/dirent.h).

After this fix, we can create a new git repository with 'git init', and
then stage and commit files as usual.
2020-08-28 16:06:55 +02:00
Tom
67dbb56444 Kernel: Release page tables when no longer needed
When unmapping regions, check if page tables can be freed.

This is a follow-up change for #3254.
2020-08-28 09:21:24 +02:00
Liav A
ab87d42200 Kernel: Remove the enabled concept of IRQ handlers
An IRQ handler should always be ready to respond to any IRQ.
We must remember that hardware can generate IRQs without any interaction
from our code at all. Ignoring IRQs in such cases is obviously not the
right thing to do.
2020-08-28 09:16:18 +02:00
Liav A
a431108ab6 Kernel: Add and remove explicit keyword where needed 2020-08-28 09:16:18 +02:00
Nico Weber
4dfe97f9ae Kernel: Minor tweak to now() computation
Make sure the expression is evaluated as time_t so that it does
the right thing after 2037, and factor things so that the constants
look less magical.
2020-08-26 08:52:07 +02:00
Nico Weber
c85e679e2d AK+LibCore+Kernel: Have fewer implementations of day_of_year
The JS tests pointed out that the implementation in DateTime
had an off-by-one in the month when doing the leap year check,
so this change fixes that bug.
2020-08-26 08:52:07 +02:00
Nico Weber
9b17082899 AK+LibC+Kernel: Have fewer implementations of year_to_days_in_epoch
I believe the implementation in RTC.cpp had an off-by-one
in the year passed to is_leap_year(). If that's true, then this
fixes that too.
2020-08-26 08:52:07 +02:00