Commit Graph

5565 Commits

Author SHA1 Message Date
Andreas Kling
48a1a3c0ce Kernel: Rename LocalSocket::create_connected_pair() => try_*() 2021-08-29 01:33:15 +02:00
Andreas Kling
7f96288535 Kernel: Encapsulate assignment of socket origin/acceptor credentials 2021-08-29 01:33:15 +02:00
Andreas Kling
242063866f Kernel: Rename LocalSocket factory to try_create() & tighten return type
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>>
since it cannot return any other socket type.
2021-08-29 01:25:03 +02:00
Andreas Kling
244ede561b Kernel/SysFS: Remove unnecessary mutex lockers in SysFS metadata getters
SysFS inodes have immutable metadata once created.
2021-08-29 01:09:19 +02:00
Andreas Kling
8ebf08b6c8 Kernel: Make all ProcFS and SysFS files zero-sized
There is no value in exposing particular sizes for these files.
2021-08-29 01:09:19 +02:00
Andreas Kling
b959c1bfa9 Kernel: Remove unused members in BIOSSysFSDirectory 2021-08-29 01:09:19 +02:00
Andreas Kling
ed77b6f8cb Kernel: Remove an obviously redundant check in FIFO::read() 2021-08-29 01:09:19 +02:00
Andreas Kling
4cbe348a0f Kernel/Ext2FS: Avoid temporary String allocation during inode creation
Make sure we pass the StringView we get all the way through so it never
turns into a heap-allocated String. :^)
2021-08-29 01:09:19 +02:00
Andreas Kling
4ce99e4ab7 Kernel: Use ProcessID a bit more in Socket
Store the origin and acceptor PID's as ProcessID.
2021-08-29 01:09:19 +02:00
Andreas Kling
ae197deb6b Kernel: Strongly typed user & group ID's
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`.
This made it easy to use them interchangeably. Let's not allow that.

This patch adds UserID and GroupID using the AK::DistinctNumeric
mechanism we've already been employing for pid_t/ProcessID.
2021-08-29 01:09:19 +02:00
Andreas Kling
59335bd8ea Kernel: Rename FileDescription::create() => try_create() 2021-08-29 01:09:19 +02:00
Nico Weber
585edb8cff Kernel: Omit all actual code from the kernel on aarch64 for now 2021-08-28 21:51:30 +01:00
Nico Weber
9c5e947e0e Prekernel: Make build on aarch64
Add a dummy Arch/aarch64/boot.S that for now does nothing but
let all processor cores sleep.

For now, none of the actual Prekernel code is built for aarch64.
2021-08-28 21:51:30 +01:00
Nico Weber
da785bd4bd Prekernel: Move boot.S and multiboot.S into an Arch/x86 subfolder 2021-08-28 21:51:30 +01:00
Andrew Kaster
72de228695 Kernel: Verify interrupts are disabled when interacting with Mutexes
This should help prevent deadlocks where a thread blocks on a Mutex
while interrupts are disabled, and makes it impossible for the holder of
the Mutex to make forward progress because it cannot be scheduled in.

Hide it behind a new debug macro LOCK_IN_CRITICAL_DEBUG for now, because
Ext2FS takes a series of Mutexes from the page fault handler, which
executes with interrupts disabled.
2021-08-28 20:53:38 +02:00
Andrew Kaster
4f2520674c Kernel: Don't acquire Mutex for hostname() before scheduling is enabled
There's no reason to acquire the mutex for this resource before APs are
booted, before scheduling is enabled, and before interrupts are enabled.
2021-08-28 20:53:38 +02:00
Andrew Kaster
54161bf5b4 Kernel: Acquire reference to waitee before trying to block in sys$waitid
Previously, we would try to acquire a reference to the all processes
lock or other contended resources while holding both the scheduler lock
and the thread's blocker lock. This could lead to a deadlock if we
actually have to block on those other resources.
2021-08-28 20:53:38 +02:00
Andrew Kaster
dea62fe93c Kernel: Guard the all processes list with a Spinlock rather than a Mutex
There are callers of processes().with or processes().for_each that
require interrupts to be disabled. Taking a Mutexe with interrupts
disabled is a recipe for deadlock, so convert this to a Spinlock.
2021-08-28 20:53:38 +02:00
Andrew Kaster
70518e69f4 Kernel: Unlock ptrace lock before entering a critical section in execve
While it might not be as bad to release a mutex while interrupts are
disabled as it is to acquire one, we don't want to mess with that.
2021-08-28 20:53:38 +02:00
Andrew Kaster
8e70b85215 Kernel: Don't disable interrupts in validate_inode_mmap_prot
There's no need to disable interrupts when trying to access an inode's
shared vmobject. Additionally, Inode::shared_vmobject() acquires a Mutex
which is a recipe for deadlock if acquired with interrupts disabled.
2021-08-28 20:53:38 +02:00
Nico Weber
bbad4758b2 CMake: Let Meta/serenity.sh run aarch64 make it past cmake
This adds just enough scaffolding to make cmake succeed.
The build falls over immediately.
2021-08-28 14:43:07 +01:00
kleines Filmröllchen
d0ceaa24a6 Kernel: Implement ioctl for the SB16 to change sample rate
Two new ioctl requests are used to get and set the sample rate of the
sound card. The SB16 device keeps track of the sample rate separately,
because I don't want to figure out how to read the sample rate from the
device; it's easier that way.

The soundcard write doesn't set the sample rate to 44100 Hz every time
anymore, as we want to change it externally.
2021-08-27 23:35:27 +04:30
kleines Filmröllchen
2c9afaf5ac Kernel: Modernize SB16.cpp
This was some old code that could use mostly some east-const :^)
2021-08-27 23:35:27 +04:30
Brian Gianforcaro
9acf449ced Kernel: Make VirtualAddress methods constexpr
In order to use VirtualAddresses as compile time constants in the
AddressSanitizer implementation, we need to be able to use these
methods in constexpr functions / variable initializations.
2021-08-25 12:12:59 +02:00
Brian Gianforcaro
665e848576 CMake: Remove Prekernel incompatible options instead of overriding
The pattern of having Prekernel inherit all of the build flags of the
Kernel, and then disabling some flags by adding `-fno-<flag>` options
to then disable those options doesn't work in all scenarios. For example
the ASAN flag `-fasan-shadow-offset=<offset>` has no option to disable
it once it's been passed, so in a future change where this flag is added
we need to be able to disable it cleanly.

The cleaner way is to just allow the Prekernel CMake logic to filter out
the COMPILE_OPTIONS specified for that specific target. This allows us
to remove individual options without trashing all inherited options.
2021-08-25 12:12:59 +02:00
Brian Gianforcaro
16ad297078 Kernel: Annotate Memory::Region APIs with [[nodiscard]]
This is an attempt to mitigate callers not observing the result of
map or remap.
2021-08-25 00:18:42 +02:00
Brian Gianforcaro
485f51690d Kernel: Always observe the return value of Region::map and remap
We have seen cases where the map fails, but we return the region
to the caller, causing them to page fault later on when they touch
the region.

The fix is to always observe the return code of map/remap.
2021-08-25 00:18:42 +02:00
Andreas Kling
97f5383525 Kernel: Remove confusing nested scope in Thread::block()
There was a nested scope here that didn't actually scope anything
meaningfully, so just get rid of it.
2021-08-24 16:37:28 +02:00
Andreas Kling
a22634bb59 Kernel: Use TemporaryChange to update Thread::m_in_block
Let's use an RAII helper to avoid having to update this on every path
out of block().

Note that this extends the time under `m_in_block == true` by a little
but that should be harmless.
2021-08-24 16:37:28 +02:00
Andreas Kling
0c1d41cc8a Kernel: Simplify Blockers so they don't need a "should block" flag
The `m_should_block` member variable that many of the Thread::Blocker
subclasses had was really only used to carry state from the constructor
to the immediate-unblock-without-blocking escape hatch.

This patch refactors the blockers so that we don't need to hold on
to this flag after setup_blocker(), and instead the return value from
setup_blocker() is the authority on whether the unblock conditions
are already met.
2021-08-24 16:37:28 +02:00
Andreas Kling
adbf472ca7 Kernel: Remove unused BlockTimeout::m_should_block
This was assigned but never read.
2021-08-24 16:37:28 +02:00
Andreas Kling
cfd9045891 Kernel: Remove unused Thread::Blocker::should_block() virtual
This was previously used after construction to check for early unblock
conditions that couldn't be communicated from the constructor.

Now that we've moved early unblock checks from the constructor into
setup_blocker(), we don't need should_block() anymore.
2021-08-24 16:37:28 +02:00
Andreas Kling
82c3cc4640 Kernel: Move Blocker setup out from constructors into setup_blocker()
Instead of registering with blocker sets and whatnot in the various
Blocker subclass constructors, this patch moves such initialization
to a separate setup_blocker() virtual.

setup_blocker() returns false if there's no need to actually block
the thread. This allows us to bail earlier in Thread::block().
2021-08-24 16:37:28 +02:00
Andreas Kling
b012170d69 Kernel: Don't register thread as custom data for FutexBlocker
Same deal as WaitQueueBlocker, we can get the blocked thread from
Blocker::thread() now, so there's no need to register the current
thread as custom data.
2021-08-24 01:57:11 +02:00
Andreas Kling
2c74533ba6 Kernel: Don't register thread as custom data for WaitQueueBlocker
When adding a WaitQueueBlocker to a WaitQueue, it stored the blocked
thread in the registration's custom "void* data" slot.
This was only used to print the Thread* in some debug logging.

Now that Blocker always knows its origin Thread, we can simply add
a Blocker::thread() accessor and then get the blocked Thread& from
there. No need to register custom data.
2021-08-24 01:57:11 +02:00
Andreas Kling
a58c4bbcf5 Kernel: Make Thread::Blocker::m_thread a NonnullRefPtr<Thread>
There's no harm in the blocker always knowing which thread it originated
from. It also simplifies some logic since we don't need to think about
it ever being null.
2021-08-24 01:57:11 +02:00
Andreas Kling
c351945474 Kernel: Simplify unregistering a Blocker from a BlockerSet
The BlockerSet stores its blockers along with a "void* data" that may
contain some blocker-specific context relevant to the specific blocker
registration (for example, SelectBlocker stores a pointer to the
relevant entry in an array of SelectBlocker::FDInfo structs.)

When unregistering a blocker from a set, we don't need to key the
blocker by both the Blocker* and the data. Just the Blocker* is enough,
since all registrations for that blocker need to be removed anyway as
the blocker is about to be destroyed.

So we stop passing the "void* data" to BlockerSet::remove_blocker(),
which also allows us to remove the now-unneeded Blocker::m_block_data.
2021-08-24 01:57:11 +02:00
Andreas Kling
96909f5200 Kernel: Make Thread::m_block_timer a NonnullRefPtr
Every thread has a block timer, so let's encode that in the type.
2021-08-23 18:07:58 +02:00
Andreas Kling
a8967388d3 Kernel: Remove unused ScopedLockRelease class 2021-08-23 02:17:02 +02:00
Andreas Kling
7006cb82bd Kernel: Rename Blocker::not_blocking(bool) to something more descriptive
Namely, will_unblock_immediately_without_blocking(Reason).

This virtual function is called on a blocker *before any block occurs*,
if it turns out that we don't need to block the thread after all.

This can happens for one of two reasons:

- UnblockImmediatelyReason::UnblockConditionAlreadyMet

    We don't need to block the thread because the condition for
    unblocking it is already met.

- UnblockImmediatelyReason::TimeoutInThePast

    We don't need to block the thread because a timeout was specified
    and that timeout is already in the past.

This patch does not introduce any behavior changes, it's only meant to
clarify this part of the blocking logic.
2021-08-23 02:13:04 +02:00
Andreas Kling
39474830a9 Kernel: Remove unnecessary spinlock in ~Thread::Blocker()
Instead, just VERIFY that nobody is holding the blocker's internal lock.
2021-08-23 01:45:31 +02:00
Andreas Kling
a82b5e6e50 Kernel: Remove unused WaitQueue::should_block(bool)
Nothing ever changed the state of WaitQueue::m_should_block, so this
removes the variable entirely.
2021-08-23 01:42:04 +02:00
Andreas Kling
e51a5e2d5d Kernel: Rename some BlockerSets to foo_blocker_set
Cleanup after renaming BlockCondition to BlockerSet.
2021-08-23 01:42:04 +02:00
Andreas Kling
63f9b0d0dc Kernel: Make Thread::Blocker non-copyable and non-movable 2021-08-23 01:42:04 +02:00
Liav A
aacb1f0bf4 Kernel: Rename PCI::DeviceController => PCI::Device
Now that the old PCI::Device was removed, we can complete the PCI
changes by making the PCI::DeviceController to be named PCI::Device.

Really the entire purpose and the distinction between the two was about
interrupts, but since this is no longer a problem, just rename it to
simplify things further.
2021-08-23 01:07:45 +02:00
Liav A
7b9c3439ec Kernel/PCI: Delete PCI::Device in its current form
I created this class a long time ago just to be able to quickly make a
PCI device to also represent an interrupt handler (because PCI devices
have this capability for most devices).
Then after a while I introduced the PCI::DeviceController, which is
really almost the same thing (a PCI device class that has Address member
in it), but is not tied to interrupts so it can have no interrupts, or
spawn interrupt handlers however it wants to seems fit.

However I decided it's time to say goodbye for this class for
a couple of reasons:
1. It made a whole bunch of weird patterns where you had a PCI::Device
and a PCI::DeviceController being used in the topic of implementation,
where originally, they meant to be used mutually exclusively (you
can't and really don't want to use both).
2. We can really make all the classes that inherit from PCI::Device
to inherit from IRQHandler at this point. Later on, when we have MSI
interrupts support, we can go further and untie things even more.
3. It makes it possible to simplify the VirtIO implementation to a great
extent. While this commit almost doesn't change it, future changes
can untangle some complexity in the VirtIO code.

For UHCIController, E1000NetworkAdapter, NE2000NetworkAdapter,
RTL8139NetworkAdapter, RTL8168NetworkAdapter, E1000ENetworkAdapter we
are simply making them to inherit the IRQHandler. This makes some sense,
because the first 3 devices will never support anything besides IRQs.
For the last 2, they might have MSI support, so when we start to utilize
those, we might need to untie these classes from IRQHandler and spawn
IRQHandler(s) or MSIHandler(s) as needed.

The VirtIODevice class is also a case where we currently need to use
both PCI::DeviceController and IRQHandler classes as parents, but it
could also be untied from the latter.
2021-08-23 01:07:45 +02:00
Liav A
d071ce352c Kernel/VirtIO: Make VirtIODevice constructor protected
This should be accessible only by derived classes.
2021-08-23 01:07:45 +02:00
Andreas Kling
40bc378d81 Kernel: Rename QueueBlocker => WaitQueueBlocker
This is a Thread::Blocker that blocks on a WaitQueue, so let's call it
a WaitQueueBlocker to improve clarity. :^)
2021-08-23 00:10:33 +02:00
Andreas Kling
b30081b49a Kernel: Rename BlockerSet::unblock() to something more accurate
Namely, unblock_all_blockers_whose_conditions_are_met().

The old name made it sound like things were getting unblocked no matter
what, but that's not actually the case.

What this actually does is iterate through the set of blockers,
unblocking those whose conditions are met. So give it a (very) verbose
name that errs on the side of descriptiveness.
2021-08-23 00:02:09 +02:00
Andreas Kling
6c16bedd69 Kernel: Remove unnecessary FutexQueue::did_remove()
This was only ever called immediately after FutexQueue::try_remove()
to VERIFY() that the state looks exactly like it should after returning
from try_remove().
2021-08-23 00:02:09 +02:00