summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
2021-10-13Kernel: Implement pread syscallRodrigo Tobar
The OpenFileDescription class already offers the necessary functionlity, so implementing this was only a matter of following the structure for `read` while handling the additional `offset` argument.
2021-10-13Kernel: Factor out common code from read/readv syscallsRodrigo Tobar
Having these bits of code factored out not only prevents duplication now, but will also allow us to implement pread without repeating ourselves (too much).
2021-10-11Kernel: Correctly interpret ioctl's FIONBIO user valueRodrigo Tobar
Values in `ioctl` are given through a pointer, but ioctl's FIONBIO implementation was interpreting this pointer as an integer directly. This meant that programs using `ioctl` to set a file descriptor in blocking mode met with incorrect behavior: they passed a non-null pointer pointing to a value of 0, but the kernel interpreted the pointer as a non-zero integer, thus making the file non-blocking. This commit fixes this behavior by reading the value from the userspace pointer and using that to set the non-blocking flag on the file descriptor. This bug was found while trying to run the openssl tool on serenity, which used `ioctl` to ensure newly-created sockets are in blocking mode.
2021-10-08Kernel: Fix -Wunreachable-code warnings from clangNico Weber
2021-10-02Kernel: Access MemoryManager static functions staticallyBrian Gianforcaro
SonarCloud flagged this "Code Smell", where we are accessing these static methods as if they are instance methods. While it is technically possible, it is very confusing to read when you realize they are static functions.
2021-10-01Kernel: Fix a few typosNico Weber
2021-09-23Kernel: Allow PROT_NONE in mmap and mprotect for stack regionsEric Seifert
To allow for userspace guard pages (ruby uses this). Redundant since serenity creates them automatically, but should be allowed anyway.
2021-09-21Kernel: Use AK::Variant default initialization where appropriateBen Wiederhake
2021-09-19Kernel: Add support for O_NONBLOCK in pipe syscallEric Seifert
While working on a port, I saw a pipe creation fail due to missing nonblock support in pipe syscall.
2021-09-16Kernel: Allow calling sys$waitid on traced, non-child processesItamar
Previously, attempting to call sys$waitid on non-child processes returned ECHILD. That prevented debugging non-child processes by attaching to them during runtime (as opposed to forking and debugging the child, which is what was previously supported). We now allow calling sys$waitid on a any process that is being traced by us, even if it's not our child.
2021-09-16Kernel: Only instantiate main_program_metadata in the scope it's neededBrian Gianforcaro
pvs-studio flagged this as a potential perf optimization.
2021-09-15Kernel: Use move semantics in sys$sendfd()Andreas Kling
Avoid an unnecessary NonnullRefPtr<OpenFileDescription> copy.
2021-09-12Kernel+Userland: Introduce a new way to reboot and poweroff the machineLiav A
This change removes the halt and reboot syscalls, and create a new mechanism to change the power state of the machine. Instead of how power state was changed until now, put a SysFS node as writable only for the superuser, that with a defined value, can result in either reboot or poweroff. In the future, a power group can be assigned to this node (which will be the GroupID responsible for power management). This opens an opportunity to permit to shutdown/reboot without superuser permissions, so in the future, a userspace daemon can take control of this node to perform power management operations without superuser permissions, if we enforce different UserID/GroupID on that node.
2021-09-12Kernel: Move ACPI and BIOS code into the new Firmware directoryLiav A
This will somwhat help unify them also under the same SysFS directory in the commit. Also, it feels much more like this change reflects the reality that both ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-12Kernel+LibC: Implement fsyncTheFightingCatfish
2021-09-11Kernel+Userland: Remove loadable kernel modulessLiav A
These interfaces are broken for about 9 months, maybe longer than that. At this point, this is just a dead code nobody tests or tries to use, so let's remove it instead of keeping a stale code just for the sake of keeping it and hoping someone will fix it. To better justify this, I read that OpenBSD removed loadable kernel modules in 5.7 release (2014), mainly for the same reason we do - nobody used it so they had no good reason to maintain it. Still, OpenBSD had LKMs being effectively working, which is not the current state in our project for a long time. An arguably better approach to minimize the Kernel image size is to allow dropping drivers and features while compiling a new image.
2021-09-11Kernel: Add _SC_HOST_NAME_MAXLinus Groh
2021-09-09Kernel: Use KString all the way in sys$execve()Andreas Kling
This patch converts all the usage of AK::String around sys$execve() to using KString instead, allowing us to catch and propagate OOM errors. It also required changing the kernel CommandLine helper class to return a vector of KString for the userspace init program arguments.
2021-09-08Kernel: Add KBuffer::bytes() and use itAndreas Kling
(Instead of hand-wrapping { data(), size() } in a bunch of places.)
2021-09-08Kernel: Rename DevFS => DevTmpFSLiav A
The current implementation of DevFS resembles the linux devtmpfs, and not the traditional DevFS, so let's rename it to better represent the direction of the development in regard to this filesystem. The abbreviation for DevTmpFS is still "dev", because it doesn't add value as a commandline option to make it longer. In quick summary - DevFS in unix OSes is simply a static filesystem, so device nodes are generated and removed by the kernel code. DevTmpFS is a "modern reinvention" of the DevFS, so it is much more like a TmpFS in the sense that not only it's stored entirely in RAM, but the userland is responsible to add and remove devices nodes as it sees fit, and no kernel code is directly being involved to keep the filesystem in sync.
2021-09-07Kernel: Remove KBuffer::try_copy() in favor of try_create_with_bytes()Andreas Kling
These were already equivalent, so let's only have one of them.
2021-09-07Kernel: Convert KBuffer::copy() => KBuffer::try_copy()Andreas Kling
This was a weird KBuffer API that assumed failure was impossible. This patch converts it to a modern KResultOr<NonnullOwnPtr<KBuffer>> API and updates the two clients to the new style.
2021-09-07Kernel: Make KBuffer::try_create_with_bytes() return KResultOrAndreas Kling
2021-09-07Kernel: Use KResultOr and TRY() for FIFOAndreas Kling
2021-09-07Kernel: Rename file_description(fd) => open_file_description(fd)Andreas Kling
To go with the class rename.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Kernel: Convert much of sys$execve() to using KStringAndreas Kling
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-07LibELF: Use StringView to carry temporary strings in auxiliary vectorAndreas Kling
Let's not force clients to provide a String.
2021-09-07Kernel: Avoid unnecessary String allocation in sys$statvfs()Andreas Kling
2021-09-07Kernel: Store process names as KStringAndreas Kling
2021-09-07Kernel: Add a comment explaining an alternate path in Process::exec()Andreas Kling
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-07Kernel: Fix file description leak in sys$execve()Andreas Kling
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-07Kernel: Don't seek the program executable description in sys$execve()Andreas Kling
The dynamic loader doesn't care if the kernel has moved the file cursor around before it gains control.
2021-09-07Kernel: Hoist allocation of main program FD in sys$execve()Andreas Kling
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-07Kernel: Reorganize ELF loading so it can use TRY()Andreas Kling
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-07Kernel: Make copy_time_from_user() helpers use KResultOr<Time>Andreas Kling
...and use TRY() for smooth error propagation everywhere.
2021-09-06Kernel: Use TRY() in sys$module_load() and sys$module_unload()Andreas Kling
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
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-06Kernel: Rename ProcessPagingScope => ScopedAddressSpaceSwitcherAndreas Kling
2021-09-06Kernel: Improve API names for switching address spacesAndreas Kling
- enter_space => enter_address_space - enter_process_paging_scope => enter_process_address_space
2021-09-06Kernel: Allocate signal trampoline before committing to a sys$execve()Andreas Kling
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-06Kernel: Use TRY() more in sys$execve()Andreas Kling
I just keep finding more and more places to make use of this. :^)
2021-09-06Kernel: Use TRY() in find_elf_interpreter_for_executable()Andreas Kling
2021-09-06Kernel: Improve find_elf_interpreter_for_executable() parameter namesAndreas Kling
2021-09-06Kernel: Don't turn I/O errors during sys$execve() into ENOEXECAndreas Kling
Instead, just propagate whatever the real error was.
2021-09-06Kernel: Improve arguments retrieval error propagation in sys$execve()Andreas Kling
Instead of turning any arguments related error into an EFAULT, we now propagate the innermost error during arguments retrieval.
2021-09-06Kernel: Use KResultOr and TRY() for {Shared,Private}InodeVMObjectAndreas Kling
2021-09-06Kernel: Make Memory::Region::map() return KResultAndreas Kling
..and use TRY() at the call sites to propagate errors. :^)
2021-09-06Kernel: Make Threads always have a nameAndreas Kling
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-06Kernel: Improvements to Custody absolute path serializationAndreas Kling
- 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