Commit Graph

5997 Commits

Author SHA1 Message Date
Andreas Kling
ed5d04b0ea Kernel: Use KResultOr and TRY() for FIFO 2021-09-07 13:58:16 +02:00
Andreas Kling
631b8e90cd Kernel: Use KResultOr and TRY() for MasterPTY 2021-09-07 13:58:16 +02:00
Andreas Kling
01993d0af3 Kernel: Make DoubleBuffer::try() return KResultOr
This tidies up error propagation in a number of places.
2021-09-07 13:53:14 +02:00
Andreas Kling
213b8868af Kernel: Rename file_description(fd) => open_file_description(fd)
To go with the class rename.
2021-09-07 13:53:14 +02:00
Andreas Kling
4a9c18afb9 Kernel: Rename FileDescription => OpenFileDescription
Dr. POSIX really calls these "open file description", not just
"file description", so let's call them exactly that. :^)
2021-09-07 13:53:14 +02:00
Andreas Kling
dbd639a2d8 Kernel: Convert much of sys$execve() to using KString
Make use of the new FileDescription::try_serialize_absolute_path() to
avoid String in favor of KString throughout much of sys$execve() and
its helpers.
2021-09-07 13:53:14 +02:00
Andreas Kling
226383f45b LibELF: Use StringView to carry temporary strings in auxiliary vector
Let's not force clients to provide a String.
2021-09-07 13:53:14 +02:00
Andreas Kling
cae20d2aa9 Kernel: Add FileDescription::try_serialize_absolute_path()
Unlike FileDescription::absolute_path(), this knows that failures can
happen and will propagate them to the caller.
2021-09-07 13:53:14 +02:00
Andreas Kling
a27c6f5226 Kernel: Avoid unnecessary String allocation in sys$statvfs() 2021-09-07 13:53:14 +02:00
Andreas Kling
6ad427993a Everywhere: Behaviour => Behavior 2021-09-07 13:53:14 +02:00
Andreas Kling
55b0b06897 Kernel: Store process names as KString 2021-09-07 13:53:14 +02:00
Andreas Kling
db2e67fd53 Kernel: Tidy up ProcessProcFSTraits construction a bit more
Let the constructor take a Process& instead of a WeakPtr<Process> and
avoid a bunch of WeakPtr copying.
2021-09-07 13:53:14 +02:00
Andreas Kling
b481132418 Kernel: Make UserOrKernelBuffer return KResult from read/write/memset
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-07 13:53:14 +02:00
Liav A
7bf8844499 Kernel/PCI: Turn on memory access by default
This will allow the Kernel to utilize memory access to the PCI
configuration space if such method is available.
2021-09-07 13:47:37 +02:00
Liav A
25ea7461a0 Kernel/PCI: Simplify the entire subsystem
A couple of things were changed:
1. Semantic changes - PCI segments are now called PCI domains, to better
match what they are really. It's also the name that Linux gave, and it
seems that Wikipedia also uses this name.
We also remove PCI::ChangeableAddress, because it was used in the past
but now it's no longer being used.
2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as
they made a bunch of unnecessary complexity. Instead, Windowed access is
removed entirely (this was tested, but never was benchmarked), so we are
left with IO access and memory access options. The memory access option
is essentially mapping the PCI bus (from the chosen PCI domain), to
virtual memory as-is. This means that unless needed, at any time, there
is only one PCI bus being mapped, and this is changed if access to
another PCI bus in the same PCI domain is needed. For now, we don't
support mapping of different PCI buses from different PCI domains at the
same time, because basically it's still a non-issue for most machines
out there.
2. OOM-safety is increased, especially when constructing the Access
object. It means that we pre-allocating any needed resources, and we try
to find PCI domains (if requested to initialize memory access) after we
attempt to construct the Access object, so it's possible to fail at this
point "gracefully".
3. All PCI API functions are now separated into a different header file,
which means only "clients" of the PCI subsystem API will need to include
that header file.
4. Functional changes - we only allow now to enumerate the bus after
a hardware scan. This means that the old method "enumerate_hardware"
is removed, so, when initializing an Access object, the initializing
function must call rescan on it to force it to find devices. This makes
it possible to fail rescan, and also to defer it after construction from
both OOM-safety terms and hotplug capabilities.
2021-09-07 13:47:37 +02:00
Brian Gianforcaro
d1378339f6 Kernel: Avoid string creation for simple string comparison 2021-09-07 13:16:01 +02:00
Brian Gianforcaro
abc523a5ab Kernel: Specify a lock rank for s_mm_lock 2021-09-07 13:16:01 +02:00
Brian Gianforcaro
88c27fc38e Kernel: Specify a lock rank for Thread::m_lock 2021-09-07 13:16:01 +02:00
Brian Gianforcaro
f6b1517426 Kernel/Locking: Add lock rank tracking to Spinlock/RecursiveSpinlock 2021-09-07 13:16:01 +02:00
Brian Gianforcaro
066b0590ec Kernel/Locking: Add lock rank tracking per thread to find deadlocks
This change adds a static lock hierarchy / ranking to the Kernel with
the goal of reducing / finding deadlocks when running with SMP enabled.

We have seen quite a few lock ordering deadlocks (locks taken in a
different order, on two different code paths). As we properly annotate
locks in the system, then these facilities will find these locking
protocol violations automatically

The `LockRank` enum documents the various locks in the system and their
rank. The implementation guarantees that a thread holding one or more
locks of a lower rank cannot acquire an additional lock with rank that
is greater or equal to any of the currently held locks.
2021-09-07 13:16:01 +02:00
Brian Gianforcaro
0718afa773 Kernel: Track when a thread is in the middle of crashing
There are certain checks that we should skip if the system is crashing.
The system can avoid stack overflow during crash, or even triple
faulting while while handling issues that can causes recursive panics
or aborts.
2021-09-07 13:16:01 +02:00
Andreas Kling
fe2e25edad Kernel: Add a comment explaining an alternate path in Process::exec()
I had to look at this for a moment before I realized that sys$execve()
and the spawning of /bin/SystemServer at boot are taking two different
paths out of exec().

Add a comment to help the next person looking at it. :^)
2021-09-07 01:34:26 +02:00
Andreas Kling
5d06ab6531 Kernel: Fix file description leak in sys$execve()
Before this patch, we were leaking a ref on the open file description
used for the interpreter (the dynamic loader) in sys$execve().

This surfaced when adapting the syscall to use TRY(), since we were now
correctly transferring ownership of the interpreter to Process::exec()
and no longer holding on to a local copy of it (in `elf_result`).

Fixing the leak uncovered another problem. The interpreter description
would now get destroyed when returning from do_exec(), which led to a
kernel panic when attempting to acquire a mutex.

This happens because we're in a particularly delicate state when
returning from do_exec(). Everything is primed for the upcoming context
switch into the new executable image, and trying to block the thread
at this point will panic the kernel.

We fix this by destroying the interpreter description earlier in
do_exec(), at the point where we no longer need it.
2021-09-07 01:18:02 +02:00
Andreas Kling
e226400dd8 Kernel: Don't seek the program executable description in sys$execve()
The dynamic loader doesn't care if the kernel has moved the file
cursor around before it gains control.
2021-09-07 01:18:02 +02:00
Andreas Kling
f4624e4ee1 Kernel: Hoist allocation of main program FD in sys$execve()
When executing a dynamically linked program, we need to pass the main
program executable via a file descriptor to the dynamic loader.

Before this patch, we were allocating an FD for this purpose long after
it was safe to do anything fallible. If we were unable to allocate an
FD we would simply panic the kernel(!)

We now hoist the allocation so it can fail before we've committed to
a new executable.
2021-09-07 01:18:02 +02:00
Andreas Kling
b141bfe53b Kernel: Reorganize ELF loading so it can use TRY()
Due to the use of ELF::Image::for_each_program_header(), we were
previously unable to use TRY() in the ELF loading code (since the return
statement inside TRY() would only return from the iteration callback.)
2021-09-07 01:18:02 +02:00
Andreas Kling
4b4e1d1c90 Kernel: Remove redundant [[nodiscard]] on KResult return values
Both KResult and KResultOr are [[nodiscard]] at the class level,
so there's no need to have functions return `[[nodiscard]] KResult`.
2021-09-07 01:18:02 +02:00
Andreas Kling
e6929835d2 Kernel: Make copy_time_from_user() helpers use KResultOr<Time>
...and use TRY() for smooth error propagation everywhere.
2021-09-07 01:18:02 +02:00
Nico Weber
62bc238ac3 Kernel: Let aarch64 port call into C++
Put all but the first core into a loop, make room for some stack,
and call init().
2021-09-06 21:57:59 +01:00
Andreas Kling
2641a068dc Kernel: Don't try to allocate ProcessProcFSTraits in Process constructor 2021-09-06 20:38:56 +02:00
Andreas Kling
1c543598f1 Kernel: Use TRY() in ProcessProcFSTraits::to_inode() 2021-09-06 20:34:54 +02:00
Andreas Kling
bdb697f6de Kernel: Use TRY() in MemoryDevice::mmap() 2021-09-06 20:33:45 +02:00
Andreas Kling
d6fe5e1e5b Kernel/KCOV: Use TRY() in KCOVInstance::buffer_allocate() 2021-09-06 20:33:35 +02:00
Andreas Kling
0d44cdb7a2 Kernel: Wrap two VirtualFileSystem directory traversals in TRY() 2021-09-06 20:30:18 +02:00
Andreas Kling
1101994fad Kernel: Wrap ISO9660FS directory traversal in TRY() 2021-09-06 20:28:40 +02:00
Andreas Kling
a2bf8244fe Kernel: Use TRY() once more in LocalSocket::try_create_connected_pair() 2021-09-06 20:26:03 +02:00
Andreas Kling
704a2bfad5 Kernel: Use TRY() in TmpFSInode::write_bytes() 2021-09-06 20:24:38 +02:00
Andreas Kling
274d535d0e Kernel: Use TRY() in sys$module_load() and sys$module_unload() 2021-09-06 20:23:08 +02:00
Andreas Kling
56a2594de7 Kernel: Make KString factories return KResultOr + use TRY() everywhere
There are a number of places that don't have an error propagation path
right now, so I've added FIXME's about that.
2021-09-06 19:25:36 +02:00
Andreas Kling
69b9b2888c Kernel: Don't allocate so much when generating coredumps
Instead of creating a bunch of ByteBuffers and concatenating them to
generate the "notes" segment, we now simply create a KBufferBuilder
and tell each of the notes generator helpers to write into the builder.

This allows the code to flow more naturally, with some bonus additional
error propagation. :^)
2021-09-06 18:56:51 +02:00
Andreas Kling
9db8a14264 Kernel: Make SysFS and ProcFS generator functions return KResult
This allows us to propagate a whole bunch of KBufferBuilder errors.
2021-09-06 18:56:51 +02:00
Andreas Kling
2065ced8f6 Kernel: Make KBufferBuilder::append() & friends return KResult
This allows callers to react to a failed append (due to OOM.)
2021-09-06 18:56:51 +02:00
Andreas Kling
60eea6940f Kernel: Tidy up Coredump construction
- Use KResultOr and TRY to propagate errors
- Return more specific errors now that they have a path out from here
2021-09-06 18:56:51 +02:00
Andreas Kling
c11c0fe453 Kernel: Use TRY() in Coredump 2021-09-06 18:56:51 +02:00
Andreas Kling
f16b9a691f Kernel: Rename ProcessPagingScope => ScopedAddressSpaceSwitcher 2021-09-06 18:56:51 +02:00
Andreas Kling
cd8d52e6ae Kernel: Improve API names for switching address spaces
- enter_space => enter_address_space
- enter_process_paging_scope => enter_process_address_space
2021-09-06 18:56:51 +02:00
Andreas Kling
298cd57fe7 Kernel: Allocate signal trampoline before committing to a sys$execve()
Once we commit to a new executable image in sys$execve(), we can no
longer return with an error to whoever called us from userspace.
We must make sure to surface any potential errors before that point.

This patch moves signal trampoline allocation before the commit.
A number of other things remain to be moved.
2021-09-06 18:56:51 +02:00
Andreas Kling
6863d015ec Kernel: Use TRY() more in sys$execve()
I just keep finding more and more places to make use of this. :^)
2021-09-06 18:56:51 +02:00
Andreas Kling
009ea5013d Kernel: Use TRY() in find_elf_interpreter_for_executable() 2021-09-06 18:56:51 +02:00
Andreas Kling
511ebffd94 Kernel: Improve find_elf_interpreter_for_executable() parameter names 2021-09-06 18:56:51 +02:00
Andreas Kling
645e29a88b Kernel: Don't turn I/O errors during sys$execve() into ENOEXEC
Instead, just propagate whatever the real error was.
2021-09-06 13:06:05 +02:00
Andreas Kling
84addef10f Kernel: Improve arguments retrieval error propagation in sys$execve()
Instead of turning any arguments related error into an EFAULT, we now
propagate the innermost error during arguments retrieval.
2021-09-06 13:06:05 +02:00
Andreas Kling
6e3381ac32 Kernel: Use KResultOr and TRY() for {Shared,Private}InodeVMObject 2021-09-06 13:06:05 +02:00
Andreas Kling
e3a716ceff Kernel: Make Memory::Region::map() return KResult
..and use TRY() at the call sites to propagate errors. :^)
2021-09-06 13:06:05 +02:00
Andreas Kling
7981422500 Kernel: Make Threads always have a name
We previously allowed Thread to exist in a state where its m_name was
null, and had to work around that in various places.

This patch removes that possibility and forces those who would create a
thread (or change the name of one) to provide a NonnullOwnPtr<KString>
with the name.
2021-09-06 13:06:05 +02:00
Andreas Kling
cda2b9e71c Kernel: Improvements to Custody absolute path serialization
- Renamed try_create_absolute_path() => try_serialize_absolute_path()
- Use KResultOr and TRY() to propagate errors
- Don't call this when it's only for debug logging
2021-09-06 13:06:05 +02:00
Andreas Kling
f173f73f10 Kernel/USB: Use TRY() and adopt_nonnull_own_or_enomem() some more 2021-09-06 13:06:05 +02:00
Andreas Kling
e3b063581e Kernel: Use TRY() in sys$alarm() 2021-09-06 13:06:05 +02:00
Andreas Kling
b083b165a7 Kernel/Ext2FS: Wrap calls to traverse_as_directory() in TRY()
Nothing says we can't TRY() a multi-line function call. :^)
2021-09-06 13:06:05 +02:00
Andreas Kling
18dbafec85 Kernel: Use TRY() more in Plan9FS 2021-09-06 13:06:05 +02:00
Andreas Kling
d34f2b643e Kernel: Tidy up Plan9FS construction a bit 2021-09-06 13:06:05 +02:00
Andreas Kling
36725228fa Kernel: Tidy up Ext2FS construction a bit 2021-09-06 13:06:05 +02:00
Andreas Kling
47bfbe343b Kernel: Tidy up SysFS construction
- Use KResultOr and TRY() to propagate errors
- Check for OOM errors
- Move allocation out of constructors

There's still a lot more to do here, as SysFS is still quite brittle
in the face of memory pressure.
2021-09-06 13:06:05 +02:00
Andreas Kling
788b91a65c Kernel: Tidy up DevFS construction and handle OOM errorso
- Use KResultOr and TRY() to propagate errors
- Check for OOM
- Move allocations out of the DevFS constructor
2021-09-06 13:06:05 +02:00
Andreas Kling
efe4e230ee Kernel: Tidy up DevPtsFS construction and handle OOM errors
- Use KResultOr and TRY() to propagate errors
- Check for OOM when creating new inodes
2021-09-06 13:06:05 +02:00
Andreas Kling
f2512071f2 Kernel: Use TRY() in sys$getrandom() 2021-09-06 02:36:21 +02:00
Andreas Kling
a8516681b7 Kernel: Tidy up TmpFS and TmpFSInode construction
- Use KResultOr<NonnullRefPtr<T>>
- Propagate errors
- Use TRY() at call sites
2021-09-06 02:36:21 +02:00
Andreas Kling
398f8e7c96 Kernel: Use TRY() more in process-specific ProcFS code 2021-09-06 02:14:22 +02:00
Andreas Kling
f4a6b60570 Kernel: Use TRY() in Graphics::VirtIOGPU::FrameBufferDevice 2021-09-06 02:11:46 +02:00
Andreas Kling
17a12c8a30 Kernel: Use TRY() in FramebufferDevice 2021-09-06 02:10:01 +02:00
Andreas Kling
7a8061ba0c Kernel: Use TRY() in ISO9660FileSystem 2021-09-06 02:06:49 +02:00
Andreas Kling
a994f11f10 Kernel: Make AddressSpace::add_region() return KResultOr<Region*>
This allows us to use TRY() in a few places.
2021-09-06 02:02:06 +02:00
Andreas Kling
062cc804e7 Kernel: Use TRY() some more in Memory::AddressSpace 2021-09-06 01:59:30 +02:00
Andreas Kling
75564b4a5f Kernel: Make kernel region allocators return KResultOr<NOP<Region>>
This expands the reach of error propagation greatly throughout the
kernel. Sadly, it also exposes the fact that we're allocating (and
doing other fallible things) in constructors all over the place.

This patch doesn't attempt to address that of course. That's work for
our future selves.
2021-09-06 01:55:27 +02:00
Andreas Kling
cb71a73708 Kernel/USB: Tidy up UHCIDescriptorPool construction
- Use KResultOr<NonnullRefPtr<UHCIDescriptorPool<T>>
- Make the constructor private
- Use TRY() at call sites
2021-09-06 01:55:27 +02:00
Andreas Kling
91fe6b6552 Kernel/KCOV: Bring closer to typical SerenityOS coding style
- Remove a bunch of redundant `this->`
- Make class data members private and provide accessors instead
2021-09-06 01:55:27 +02:00
Andreas Kling
79fbad6df9 Kernel/USB: Tidy up USB::Transfer construction 2021-09-06 01:55:27 +02:00
Andreas Kling
f4a9a0d561 Kernel: Make VirtualRangeAllocator return KResultOr<VirtualRange>
This achieves two things:
- The allocator can report more specific errors
- Callers can (and now do) use TRY() :^)
2021-09-06 01:55:27 +02:00
Andreas Kling
21f7932ae2 Kernel: Use TRY() and adopt_nonnull_ref_or_enomem() in AnonymousVMObject 2021-09-06 01:55:27 +02:00
Andreas Kling
52cbbe1dc5 Kernel: Actually share committed CoW pages
Due to a double-move mistake, we were always clearing the shared
committed CoW pages in the parent when forking.
2021-09-06 01:55:27 +02:00
Andreas Kling
2f790cf78f Kernel: Make MM.commit_user_physical_pages() return KResultOr
..and use TRY() at call sites. :^)
2021-09-06 01:55:27 +02:00
Andreas Kling
98dc08fe56 Kernel: Use KResultOr better in ProcessGroup construction
This allows us to use TRY() more.
2021-09-06 01:55:27 +02:00
Andreas Kling
540d62d3b2 Kernel: Simplify WatchDescription::create() 2021-09-06 01:55:27 +02:00
Andreas Kling
5e2bae700d Kernel: Use TRY() in PTYMultiplexer::open() 2021-09-06 01:55:27 +02:00
Andreas Kling
4d961387c1 Kernel: Use TRY() some more in USB::Hub 2021-09-06 01:55:27 +02:00
Andreas Kling
8ceff65161 Kernel: Use TRY() some more in FileDescription 2021-09-06 01:55:27 +02:00
Andreas Kling
5516592748 Kernel: Use TRY() in BlockBasedFileSystem 2021-09-06 01:55:27 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
Brian Gianforcaro
bb58a4d943 Kernel: Make all Spinlocks use u8 for storage, remove template
The default template argument is only used in one place, and it
looks like it was probably just an oversight. The rest of the Kernel
code all uses u8 as the type. So lets make that the default and remove
the unused template argument, as there doesn't seem to be a reason to
allow the size to be customizable.
2021-09-05 20:46:02 +02:00
Brian Gianforcaro
472454cded Kernel: Switch static_asserts of a type size to AK::AssertSize
This will provide better debug ability when the size comparison fails.
2021-09-05 20:08:57 +02:00
Andreas Kling
100b3835f0 Kernel: Use TRY() in DevFSLinkInode::write_bytes() 2021-09-05 19:02:57 +02:00
Andreas Kling
667a39df6b Kernel: Use TRY() in ProcFS 2021-09-05 19:01:38 +02:00
Andreas Kling
caaeae9607 Kernel: Make FileSystem::get_inode() return KResultOr<NRP<Inode>>
This allows for natural error propagation in a bunch of new places.
2021-09-05 18:55:55 +02:00
Andreas Kling
12d9a6c1fa Kernel: Use TRY() in sys$waitid() 2021-09-05 18:42:32 +02:00
Andreas Kling
c076d765c4 Kernel: Simplify sys$inode_watcher_remove_watch() a little bit 2021-09-05 18:41:28 +02:00
Andreas Kling
d912bfdf38 Kernel: Use TRY() in sys$create_inode_watcher() and friends 2021-09-05 18:41:01 +02:00
Andreas Kling
a9204510a4 Kernel: Make file description lookup return KResultOr
Instead of checking it at every call site (to generate EBADF), we make
file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>.

This allows us to wrap all the calls in TRY(). :^)

The only place that got a little bit messier from this is sys$mount(),
and there's a whole bunch of things there in need of cleanup.
2021-09-05 18:36:13 +02:00
Andreas Kling
2d2ea05c97 Kernel: Use TRY() in sys$sethostname() 2021-09-05 18:22:18 +02:00
Andreas Kling
963f847579 Kernel: Use TRY() in sys$mount() 2021-09-05 18:20:57 +02:00
Andreas Kling
3580c5a72e Kernel: Use TRY() in sys$umount() 2021-09-05 18:18:23 +02:00
Andreas Kling
76f2596ce8 Kernel: Use TRY() in sys$set_process_name() 2021-09-05 18:17:06 +02:00
Andreas Kling
53aa01384d Kernel: Use TRY() in sys$set_coredump_metadata() 2021-09-05 18:15:42 +02:00
Andreas Kling
bfe4c84541 Kernel: Use TRY() in sys$create_thread() 2021-09-05 18:15:05 +02:00
Andreas Kling
257fa80312 Kernel: Use TRY() in sys$set_thread_name() 2021-09-05 18:15:05 +02:00
Andreas Kling
afc5bbd56b Kernel: Use TRY() in sys$write() 2021-09-05 18:15:05 +02:00
Andreas Kling
17933b193a Kernel: Use TRY() in sys$perf_register_string() 2021-09-05 18:15:05 +02:00
Andreas Kling
77b7a44691 Kernel: Use TRY() in sys$recvfd() 2021-09-05 18:15:05 +02:00
Andreas Kling
ea911bc125 Kernel: Use TRY() in sys$pledge() 2021-09-05 18:15:05 +02:00
Andreas Kling
95e74d1776 Kernel: Use TRY() even more in sys$mmap() and friends :^) 2021-09-05 18:15:05 +02:00
Andreas Kling
cf2c04eb13 Kernel: Use TRY() in sys$dbgputstr() 2021-09-05 18:15:05 +02:00
Andreas Kling
6dddd500bf Kernel: Use TRY() in sys$map_time_page() 2021-09-05 18:15:05 +02:00
Andreas Kling
d53c60fd9f Kernel: Use TRY() in sys$setkeymap() 2021-09-05 18:15:05 +02:00
Andreas Kling
1f475f7bbc Kernel: Use TRY() in sys$realpath() 2021-09-05 18:15:05 +02:00
Andreas Kling
4ea3dc77f0 Kernel: Use TRY() in sys$statvfs() 2021-09-05 18:15:05 +02:00
Andreas Kling
7efa742a39 Kernel: Use TRY() in sys$stat() 2021-09-05 17:58:08 +02:00
Andreas Kling
de2c1bc5c3 Kernel: Use TRY() in sys$unlink() 2021-09-05 17:56:40 +02:00
Andreas Kling
4e4b7c272c Kernel: Use TRY() in sys$readlink() 2021-09-05 17:55:43 +02:00
Andreas Kling
e0cf9152ca Kernel: Use TRY() in sys$rmdir() 2021-09-05 17:54:33 +02:00
Andreas Kling
780737de7a Kernel: Use TRY() in sys$rename() 2021-09-05 17:53:59 +02:00
Andreas Kling
c5d046c23a Kernel: Use TRY() in sys$utime() 2021-09-05 17:53:28 +02:00
Andreas Kling
789db813d3 Kernel: Use copy_typed_from_user<T> for fetching syscall parameters 2021-09-05 17:51:37 +02:00
Andreas Kling
d7e5768763 Kernel: Add copy_typed_from_userspace<T>(Userspace<T const*>)
This allows easy retrieval of typed POD values from userspace with
implicit error propagation.
2021-09-05 17:50:34 +02:00
Andreas Kling
48a0b31c47 Kernel: Make copy_{from,to}_user() return KResult and use TRY()
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05 17:38:37 +02:00
Andreas Kling
9903f5c6ef Kernel: Use TRY() in sys$read() and sys$readv() 2021-09-05 16:25:40 +02:00
Andreas Kling
c1e18befe8 Kernel: Reorder sys$pipe() to fail more nicely
Try to do both FD allocations up front instead of interleaved between
assigning them to the descriptor table. This prevents us from failing
in the middle of setting up the pipes.
2021-09-05 16:25:40 +02:00
Andreas Kling
4483110990 Kernel: Use TRY() in sys$open() 2021-09-05 16:25:40 +02:00
Andreas Kling
b01e4b171d Kernel: Use TRY() in sys$mknod() 2021-09-05 16:25:40 +02:00
Andreas Kling
2658ab4a80 Kernel: Use TRY() in sys$mkdir() 2021-09-05 16:25:40 +02:00
Andreas Kling
e899ea459c Kernel: Use TRY() in sys$lseek() 2021-09-05 16:25:40 +02:00
Andreas Kling
f605cd04b6 Kernel: Use TRY() in sys$fork()
There's a lot of work to do on improving error propagation in the
fork system call. This just scratches the surface.
2021-09-05 16:25:40 +02:00
Andreas Kling
29bafec43b Kernel: Use is_error() in sys$fcntl() 2021-09-05 16:25:40 +02:00
Andreas Kling
c767e20f91 Kernel: Use TRY() in sys$chown() 2021-09-05 16:25:40 +02:00
Andreas Kling
24e8ad5ade Kernel: Use TRY() in sys$chmod() 2021-09-05 16:25:40 +02:00
Andreas Kling
3631ebe963 Kernel: Use TRY() in AnonymousVMObject 2021-09-05 16:25:40 +02:00
Andreas Kling
abb43468dc Kernel: Use TRY() in FileDescription::attach() 2021-09-05 16:25:40 +02:00
Andreas Kling
aa4d5817af Kernel: Use TRY() in sys$ptrace() 2021-09-05 16:25:40 +02:00
Andreas Kling
b2950c67ea Kernel: Use TRY() in Inode 2021-09-05 16:25:40 +02:00
Andreas Kling
f20d1f0cc6 Kernel: Use TRY() in Region 2021-09-05 16:25:40 +02:00
Andreas Kling
c9a20bcd87 Kernel: Use TRY() in the SoundBlaster16 driver 2021-09-05 16:25:40 +02:00
Andreas Kling
4a2b0f6bec Kernel: Use TRY() in sys$access() 2021-09-05 16:25:40 +02:00
Andreas Kling
c1c774da91 Kernel: Use TRY() in FIFO 2021-09-05 16:25:40 +02:00
Andreas Kling
cad78f5904 Kernel: Use TRY() in InodeFile 2021-09-05 16:25:40 +02:00
Andreas Kling
29a9f80ecf Kernel/USB: Use TRY() in the various USB classes 2021-09-05 16:25:40 +02:00
Andreas Kling
f8fba5f017 Kernel: Use TRY() in sys$socket() and friends 2021-09-05 16:25:40 +02:00
Andreas Kling
8714c550b4 Kernel: Use TRY() in TCPSocket 2021-09-05 16:25:40 +02:00
Andreas Kling
4b7575fabd Kernel: Unbreak x86_64 build (PageDirectory) 2021-09-05 15:38:57 +02:00
Andreas Kling
865eb54f75 Kernel/Ext2FS: Use TRY() in the Ext2FS
This class was just *full* of great opportunities for TRY(). :^)
2021-09-05 15:30:15 +02:00
Andreas Kling
83fed5b2de Kernel: Tidy up Memory::AddressSpace construction
- Return KResultOr<T> in places
- Propagate errors
- Use TRY()
2021-09-05 15:13:20 +02:00
Andreas Kling
0cf65cf7ec Kernel: Use TRY() even more in VirtualFileSystem
Allowing TRY() with KResult unlocked a whole lot more opportunities.
2021-09-05 14:55:51 +02:00
Andreas Kling
e1af24eac8 Kernel: Make KResult usable with TRY() as well
This patch adds release_error() and release_value() to KResult, making
it usable with TRY().

Note that release_value() returns void, since there is no value inside
a KResult.
2021-09-05 14:50:52 +02:00
Andreas Kling
71187d865e Kernel: Tidy up VirtualFileSystem::mount_root() a little bit
- Return KResult instead of bool
- Use TRY()
2021-09-05 14:46:44 +02:00
Andreas Kling
b0f2acbd91 Kernel: Use TRY() in FileDescription 2021-09-05 14:43:51 +02:00
Andreas Kling
f2f5df793a Kernel: Use TRY() in sys$chdir() 2021-09-05 14:41:13 +02:00
Andreas Kling
5ba10c6017 Kernel: Use TRY() in Memory::AddressSpace 2021-09-05 14:40:18 +02:00
Andreas Kling
8cd4879946 Kernel: Use TRY() in sys$link() and sys$symlink() 2021-09-05 14:38:28 +02:00
Andreas Kling
c902b3cb0d Kernel: Use TRY() in sys$anon_create() 2021-09-05 14:36:40 +02:00
Andreas Kling
4012099338 Kernel: Tidy up AnonymousFile construction a bit
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-05 14:33:25 +02:00
Andreas Kling
9a1fdb523f Kernel: Use TRY() in sys$unveil() 2021-09-05 14:30:08 +02:00
Andreas Kling
36efecf3c3 Kernel: Use try in sys$mmap() and friends :^) 2021-09-05 14:27:41 +02:00
Andreas Kling
6bf901b414 Kernel: Use TRY() in sys$execve()
There are more opportunities to use TRY() here, but it will require
improvements to error propagation first.
2021-09-05 14:20:03 +02:00
Andreas Kling
982991d92d Kernel: Use TRY() in IPv4Socket 2021-09-05 14:16:08 +02:00
Andreas Kling
d65fbdc44d Kernel: Use TRY() in Thread 2021-09-05 14:08:12 +02:00
Andreas Kling
ae885b188f Kernel: Use TRY() when creating first thread in a new process 2021-09-05 14:08:12 +02:00
Andreas Kling
2ab8fd89fc Kernel: Simplify Process::get_syscall_path_argument() 2021-09-05 14:08:12 +02:00
Andreas Kling
f30eae7e7a Kernel: Use TRY() in some Process functions 2021-09-05 14:08:12 +02:00
Andreas Kling
81d3f823f7 Kernel: Use TRY() in LocalSocket 2021-09-05 14:08:12 +02:00
Andreas Kling
a5e71debef Kernel: Use TRY() in VirtualFileSystem 2021-09-05 14:08:12 +02:00
Andreas Kling
e1da3b1841 Kernel: Make KResult pull in the TRY macro 2021-09-05 14:08:12 +02:00
Andreas Kling
fd44336ef8 Kernel: Add KResultOr::release_error()
This is just for symmetry with AK::Result, so that we can use them
interchangeably in generic code.
2021-09-05 13:29:06 +02:00
sin-ack
566c5d1e99 AK+Kernel: Move KResult.h to Kernel/API for userspace access
This commit moves the KResult and KResultOr objects to Kernel/API to
signify that they may now be freely used by userspace code at points
where a syscall-related error result is to be expected. It also exposes
KResult and KResultOr to the global namespace to make it nicer to use
for userspace code.
2021-09-05 12:54:48 +02:00
Brian Gianforcaro
3d12d0f408 Kernel: Declare syscall handlers with "using" instead of "typedef"
Also use bit_cast to avoid -Wcast-function-type warning.
2021-09-05 09:48:43 +01:00
Brian Gianforcaro
9d1b27263f Kernel: Declare type aliases with "using" instead of "typedef"
This is the idiomatic way to declare type aliases in modern C++.
Flagged by Sonar Cloud as a "Code Smell", but I happen to agree
with this particular one. :^)
2021-09-05 09:48:43 +01:00
Andreas Kling
7463eb52e8 Kernel: Improve names in the ARP table thread blocker
More instances of functions named "unblock()" that don't actually
unblock in all cases being renamed to something more precise.
2021-09-05 01:10:56 +02:00
Andreas Kling
e851a77346 Kernel: Rename FileBlocker::unblock() => unblock_if_conditions_are_met()
Since this may not actually unblock, the old name was very confusing.
2021-09-05 01:10:56 +02:00
Andreas Kling
68a6d4c30a Kernel: Tidy up InodeWatcher construction
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-05 01:10:56 +02:00
Andreas Kling
393229e2aa Kernel: Remove UserOrKernelBuffer::copy_into_string()
All former users of this API have been converted to use KString. :^)
2021-09-05 01:10:56 +02:00
Andreas Kling
211c1c087d Kernel/Plan9FS: Use KString instead of String in one place 2021-09-05 01:10:56 +02:00
Andreas Kling
9d736772bd Kernel/Ext2FS: Remove a String allocation in debug logging
We were creating a temporary String just to log the target when writing
a symlink directly into inline storage.
2021-09-05 01:10:55 +02:00
Andreas Kling
7d8e036e26 Kernel: Tidy up UDPSocket creation a bit
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-04 23:11:04 +02:00
Andreas Kling
648c768d81 Kernel: Tidy up TCPSocket creation a bit
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-04 23:11:04 +02:00
Andreas Kling
ac85fdeb1c Kernel: Handle ProcessGroup allocation failures better
- Rename create* => try_create*
- Don't null out existing process group on allocation failure
2021-09-04 23:11:04 +02:00
Andreas Kling
12f820eb08 Kernel: Make Process::try_create() propagate errors better 2021-09-04 23:11:04 +02:00
Andreas Kling
3b995c6d01 Kernel: Tidy up Process::try_create_user_process()
This function is currently only ever used to create the init process
(SystemServer). It had a few idiosyncratic things about it that this
patch cleans up:

- Errors were returned in an int& out-param.
- It had a path for non-0 process PIDs which was never taken.
2021-09-04 23:11:04 +02:00
Andreas Kling
ba1a6ca971 Kernel: Move pledge verification into Process member functions
REQUIRE_PROMISE and REQUIRE_NO_PROMISES were macros for some reason,
and used all over the place.

This patch adds require_promise(Pledge) and require_no_promises()
to Process and makes the macros call these on the current process
instead of inlining code everywhere.
2021-09-04 23:11:04 +02:00
Andreas Kling
5d5a3708c4 Kernel: Rename Thread::clone() => try_clone() and propagate errors 2021-09-04 23:11:04 +02:00
Andreas Kling
cfc1a628d5 Kernel: Add missing error check after Process::try_create()
As the name now suggests, this API can fail. :^)
2021-09-04 23:11:04 +02:00
Andreas Kling
5e2e17c38c Kernel: Rename Process::create() => try_create() 2021-09-04 23:11:03 +02:00
Tom
8a258edfd6 Kernel: Add x2APIC support
This allows addressing all cores on more modern processors. For now,
we still have a hardcoded limit of 64 due to s_processors being a
static array.
2021-09-04 22:22:58 +02:00
Tom
123087e235 Kernel: Allow specifying ecx with CPUID
Some CPUID functions (e.g. 0xb) require input values in ecx.
2021-09-04 22:22:58 +02:00
Liav A
e606ff3751 Kernel/VirtIO: Determine VirtIO device class also with the PCI device ID
According to the VirtIO 1.0 specification:
"Non-transitional devices SHOULD have a PCI Device ID in the range
0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID
of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem
Device ID of 0x40 or higher."

It also says that:
"Transitional devices MUST have a PCI Revision ID of 0. Transitional
devices MUST have the PCI Subsystem Device ID matching the Virtio
Device ID, as indicated in section 5. Transitional devices MUST have the
Transitional PCI Device ID in the range 0x1000 to 0x103f."

So, for legacy devices, we know that revision ID in the PCI header won't
be 1, so we probe for PCI_SUBSYSTEM_ID value.
Instead of using the subsystem device ID, we can probe the DEVICE_ID
value directly in case it's not a legacy device.
This should cover all possibilities for identifying VirtIO devices, both
per the specification of 0.9.5, and future revisions from 1.0 onwards.
2021-09-04 20:53:26 +02:00
Liav A
ed6c1f53af Kernel/VirtIO: Defer initialization of device out of the constructor
This ensures we safely handle interrupts (which can call virtual
functions), so they don't happen in the constructor - this pattern can
lead to a crash, if we are still in the constructor context because
not all methods are available for usage (some are pure virtual,
so it's possible to call __cxa_pure_virtual).

Also, under some conditions like adding a PCI device via PCI-passthrough
mechanism in QEMU, it became exposed to the eye that the code asserts on
RNG::handle_device_config_change(). That device has no configuration but
if the hypervisor still misbehaves and tries to configure it, we should
simply return false to indicate nothing happened.
2021-09-04 16:36:02 +02:00
Liav A
e490c17bde Kernel/SysFS: Ensure data stability when reading from Inodes
Like with the ProcFS, description data can change at anytime, so it's
wise to ensure that when the userland reads from an Inode, data is
consistent unless the userland indicated it wants to refresh the data
(by seeking to offset 0, or re-attaching the Inode).
Otherwise, if the data changes in the middle of the reading, it can
cause silent corruption in output which can lead to random crashes.
2021-09-04 16:33:56 +02:00
Liav A
f2ba44cbdf Kernel/DevFS: Remove unnecessary include 2021-09-04 16:19:12 +02:00
Liav A
d189cb6a24 Kernel/Devices: Remove unnecessary virtual method
The is_disk_device method is not being overrided by any class or called
by anyone, so let's just remove it.
2021-09-04 16:19:12 +02:00
Andreas Kling
74ce098d58 Kernel: Delete the rvalue-ref qualified version of KResultOr::value()
This makes calling value() on a temporary KResultOr be a compile-time
error. This exposed a number of missing error checks (fixed in the
preceding commits.)
2021-09-04 13:08:37 +02:00
Andreas Kling
d065de1fcf Kernel: Add missing error check when opening TTY for a new process 2021-09-04 13:08:37 +02:00
Andreas Kling
4b3bc3805b Kernel: Add missing error check when opening root file system 2021-09-04 13:08:37 +02:00
Andreas Kling
b02eb8224c Kernel/VirtIO: Add two missing error checks in VirtIO::ConsolePort 2021-09-04 13:08:37 +02:00
Daniel Bertalan
d7b6cc6421 Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other
pointer in the constructors and move assignment operators. This meant
that some operations that would require explicit casting on raw pointers
were done implicitly, such as:
- downcasting a base class to a derived class (e.g. `Kernel::Inode` =>
  `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp),
- casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>`
  in LibIMAP/Client.cpp)

This, of course, allows gross violations of the type system, and makes
the need to type-check less obvious before downcasting. Luckily, while
adding the `static_ptr_cast`s, only two truly incorrect usages were
found; in the other instances, our casts just needed to be made
explicit.
2021-09-03 23:20:23 +02:00
brapru
bad23e3f8c Kernel: Convert Routing to east-const style 2021-09-03 23:18:50 +02:00
Luke Wilde
01af7d1ae1 Kernel: Don't use {:p} when printing out invalid userspace stack pointer
`userspace_esp` is a virtual address and thus using `{:p}` on it is
invalid and will cause an assertion failure.

I ran into this while testing #9772.
2021-09-03 11:46:40 +02:00
Andreas Kling
8a89698ea4 Kernel/VirtIO: Stop leaking VirtIO::ConsolePort objects 2021-09-03 02:36:09 +02:00
Andreas Kling
eaf88cc78a AK: Rename create<T> => make_ref_counted<T>
And also try_create<T> => try_make_ref_counted<T>.

A global "create" was a bit much. The new name matches make<T> better,
which we've used for making single-owner objects since forever.
2021-09-03 02:36:09 +02:00
Brian Gianforcaro
c0341215de Kernel: Use = default for empty destructors 2021-09-01 18:06:14 +02:00
Brian Gianforcaro
afa0fb55b0 Kernel: Don't cast to NetworkOrdered<u16>* from random data
NetworkOrdered is a non trivial type, and it's undefined behavior to
cast a random pointer to it and then pretend it's that type.

Instead just call AK::convert_between_host_and_network_endian on the
individual u16*. This suppresses static analysis warnings.

I don't think there was a "bug" in the previous code, it worked, but
it was very brittle.
2021-09-01 18:06:14 +02:00
Brian Gianforcaro
668c429900 Kernel: Convert UserOrKernelBuffer callbacks to use AK::Bytes 2021-09-01 18:06:14 +02:00
Brian Gianforcaro
f3baa5d8c9 Kernel: Convert random bytes interface to use AK::Bytes 2021-09-01 18:06:14 +02:00
Brian Gianforcaro
0678ac265c Kernel: Pass InodeMetadata by reference in TmpFSInode::create
This struct is non-trivially large, it makes sense to pass it by
reference instead of by value in the factory method.

Found by Sonar Cloud.
2021-09-01 18:06:14 +02:00
Andrew Kaster
fcdd7aa990 Kernel: Only unlock Mutex once in execve when PT_TRACE_ME is enabled
Fixes a regression introduced in 70518e6. Fixes #9704.
2021-09-01 13:36:26 +02:00
Peter Elliott
33d7fdca28 Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
Liav A
8e90a4fd1c Kernel/VirtIO: Don't expose constructors as public method
This leads to a bad pattern where anyone could create an RNG or a
Console object. Instead, let's just use the common pattern of a static
method to instantiate a new object and return it wrapped by a
NonnullRefPtr.
2021-08-31 16:51:13 +02:00
Liav A
01ae614727 Kernel/VirtIO: Remove redundant VirtIO word from filenames
Now that all related VirtIO classes are in the VirtIO namespace, let's
just remove the redundant VirtIO word from filenames.
2021-08-31 16:51:13 +02:00
Liav A
e418740645 Kernel/VirtIO: Move everything into the VirtIO namespace
Before of this change, many specific classes to VirtIO were in the
Kernel namespace, which polluted it.
Everything should be more organized now, but there's still room for
improvement later.
2021-08-31 16:51:13 +02:00
Liav A
9a03c00f45 Kernel/VirtIO: Remove the m_class_name member
This class member was used only to determine the device type when
printing messages to the debug log. Instead, remove this class member,
and add a quick way to find the device type according to how the VirtIO
specification says to do that.

This simplifies construction of VirtIODevices a bit, because now the
constructor doesn't need to ask for a String identified with the device
type.
2021-08-31 16:51:13 +02:00
Liav A
5a0aa66b73 Kernel/PCI: Fix offset error of the PCI_SUBSYSTEM values
Apparently both PCI_SUBSYSTEM_ID and PCI_SUBSYSTEM_VENDOR_ID offsets
should be swapped from one to another to be correct.
2021-08-31 16:51:13 +02:00
Liav A
b596af363c Kernel/VirtIO: Make RNG device to not be a CharacterDevice
This class as a CharacterDevice really was not useful, because you
couldn't even read from it.
Also, the random number generator interface should be the /dev/random,
so any other interface to get random numbers is generally not a good
idea.
Instead, let's keep this functionality as an entropy source for random
numbers generation, but without exposing a device node.
2021-08-31 16:51:13 +02:00
Andreas Kling
5046a1fe38 Kernel: Ignore zero-sized PT_LOAD headers when loading ELF images 2021-08-31 16:46:16 +02:00
Jesse Buhagiar
59eab8148d Kernel/Userland: Expose usb device address and use it in lsusb
We now expose the `USBDevice`'s address in the SysFS object. This means
that device addresses are no longer determined by the name of the file
in the `/bus/usb/` directory. This was an incorrect way of determining
device address, as a standard PC can have multiple USB controllers
(and hence multiple buses) that can have overlapping device IDs.
2021-08-31 16:38:49 +02:00
Owen Smith
22ec21bd61 Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()
Invoking sendmsg on a listening socket triggers this assertion as
sendto calls has_attached_peer before checking the result of
send_buffer_for.
2021-08-31 16:00:53 +02:00
LepkoQQ
25f76ed771 Kernel: Fix shift sometimes staying pressed after releasing the key
Previous implementation sometimes didn't release the key after pressing
and holding shift due to repeating key updates when holding keys. This
meant repeating updates would set/unset `m_both_shift_keys_pressed`
repeatedly, sometimes resulting in shift still being considered pressed
even after you released it.

Simplify left and right shift key pressed logic by tracking both key
states separately and always updating modifiers based on them.
2021-08-30 22:35:51 +02:00
Daniel Bertalan
779cf49f38 Kernel: Fix Clang not initializing s_bsp_processor correctly
Initializing the variable this way fixes a kernel panic in Clang where
the object was zero-initialized, so the `m_in_scheduler` contained the
wrong value. GCC got it right, but we're better off making this change,
as leaving uninitialized fields in constant-initialized objects can
cause other weird situations like this. Also, initializing only a single
field to a non-zero value isn't worth the cost of no longer fitting in
`.bss`.

Another two variables suffer from the same problem, even though their
values are supposed to be zero. Removing these causes the
`_GLOBAL_sub_I_` function to no longer be generated and the (not
handled) `.init_array` section to be omitted.
2021-08-30 13:20:34 +02:00
Brian Gianforcaro
f0b3aa0331 Everywhere: Pass AK::Format TypeErasedFormatParams by reference
This silences a overeager warning in sonar cloud, warning that
slicing could occur with `VariadicFormatParams` which derives from
`TypeErasedFormatParams`.

Reference:
https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPBO_k92xXUF3qWsm&open=AXuVPBO_k92xXUF3qWsm
2021-08-30 15:50:00 +04:30
Andreas Kling
5cd030568f Kernel: Unbreak the LOCK_DEBUG build
Regressed with 68bf6db673
2021-08-30 02:48:31 +02:00
Andreas Kling
68bf6db673 Kernel: Rename Spinlock::is_owned_by_current_thread()
...to is_owned_by_current_processor(). As Tom pointed out, this is
much more accurate. :^)
2021-08-29 22:19:42 +02:00
Andreas Kling
ed0e64943f Kernel: Rename Socket::lock() => Socket::mutex()
"lock" is ambiguous (verb vs noun) while "mutex" is not.
2021-08-29 22:19:42 +02:00
Andreas Kling
0b4671add7 Kernel: {Mutex,Spinlock}::own_lock() => is_locked_by_current_thread()
Rename these API's to make it more clear what they are checking.
2021-08-29 12:53:11 +02:00
Andreas Kling
d9da513959 Kernel: Move "in-scheduler" flag from SchedulerData to Processor
This avoids a race between getting the processor-specific SchedulerData
and accessing it. (Switching to a different CPU in that window means
that we're operating on the wrong SchedulerData.)

Co-authored-by: Tom <tomut@yahoo.com>
2021-08-29 12:43:39 +02:00
Andreas Kling
249d6a490d Kernel: Add read_gs_value() and write_gs_value()
Co-authored-by: Tom <tomut@yahoo.com>
2021-08-29 12:26:40 +02:00
Andreas Kling
6ae60137d7 Kernel: Use StringView instead of C strings in Mutex 2021-08-29 02:21:01 +02:00
Andreas Kling
a28cd921a1 Kernel: Add Socket::set_role() and use it everywhere
Instead of having Socket subclasses write their role into Socket::m_role
directly, add a setter to do this.
2021-08-29 02:21:01 +02:00
Andreas Kling
70b2225b3d Kernel: Store LocalSocket address as a KString internally
Just because we deal with sockaddr_un at the userspace API layer doesn't
mean we have to store an awkward C type internally. :^)
2021-08-29 02:21:01 +02:00
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