summaryrefslogtreecommitdiff
path: root/Kernel/Process.h
AgeCommit message (Collapse)Author
2020-02-26Kernel: Allow process with multiple threads to call exec and exitCristian-Bogdan SIRB
This allows a process wich has more than 1 thread to call exec, even from a thread. This kills all the other threads, but it won't wait for them to finish, just makes sure that they are not in a running/runable state. In the case where a thread does exec, the new program PID will be the thread TID, to keep the PID == TID in the new process. This introduces a new function inside the Process class, kill_threads_except_self which is called on exit() too (exit with multiple threads wasn't properly working either). Inside the Lock class, there is the need for a new function, clear_waiters, which removes all the waiters from the Process::big_lock. This is needed since after a exit/exec, there should be no other threads waiting for this lock, the threads should be simply killed. Only queued threads should wait for this lock at this point, since blocked threads are handled in set_should_die.
2020-02-24Kernel: Fix some formatting goofs in Process.hAndreas Kling
2020-02-24Kernel: Make Region weakable and use WeakPtr<Region> instead of Region*Andreas Kling
This turns use-after-free bugs into null pointer dereferences instead.
2020-02-18Kernel: Use a FixedArray for a process's extra GIDsAndreas Kling
There's not really enough of these to justify using a HashTable.
2020-02-17Kernel: Replace "current" with Thread::current and Process::currentAndreas Kling
Suggested by Sergey. The currently running Thread and Process are now Thread::current and Process::current respectively. :^)
2020-02-17Kernel: Allow multiple inspectors of a process (in /proc)Andreas Kling
Replace Process::m_being_inspected with an inspector reference count. This prevents an assertion from firing when inspecting the same process in /proc from multiple processes at the same time. It was trivially reproducible by opening multiple FileManagers.
2020-02-16Kernel+LibC: Allow sys$mmap() callers to specify address alignmentAndreas Kling
This is exposed via the non-standard serenity_mmap() call in userspace.
2020-02-16Kernel: Remove Process inheriting from WeakableAndreas Kling
This mechanism wasn't actually used to create any WeakPtr<Process>. Such pointers would be pretty hard to work with anyway, due to the multi-step destruction ritual of Process.
2020-02-16Kernel: More header dependency reduction workAndreas Kling
2020-02-16Kernel: Reduce header dependencies of Process and ThreadAndreas Kling
2020-02-16Kernel: Add forward declaration headerAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-16Kernel: Rename RegisterDump => RegisterStateAndreas Kling
2020-02-10Kernel+LibC: Merge sys$stat() and sys$lstat()Andreas Kling
There is now only one sys$stat() instead of two separate syscalls.
2020-02-08Net: Add a basic sys$shutdown() implementationAndreas Kling
Calling shutdown prevents further reads and/or writes on a socket. We should do a few more things based on the type of socket, but this initial implementation just puts the basic mechanism in place. Work towards #428.
2020-02-05Kernel+LibC: Add sys$waitid(), and make sys$waitpid() wrap itSergey Bugaev
sys$waitid() takes an explicit description of whether it's waiting for a single process with the given PID, all of the children, a group, etc., and returns its info as a siginfo_t. It also doesn't automatically imply WEXITED, which clears up the confusion in the kernel.
2020-02-02Kernel: Start working on a syscall for logging performance eventsAndreas Kling
This patch introduces sys$perf_event() with two event types: - PERF_EVENT_MALLOC - PERF_EVENT_FREE After the first call to sys$perf_event(), a process will begin keeping these events in a buffer. When the process dies, that buffer will be written out to "perfcore" in the current directory unless that filename is already taken. This is probably not the best way to do this, but it's a start and will make it possible to start doing memory allocation profiling. :^)
2020-01-30Kernel: Address validation helpers should take size_t, not ssize_tAndreas Kling
2020-01-27Kernel: Remove SmapDisablers in sys$getsockname() and sys$getpeername()Andreas Kling
Instead use the user/kernel copy helpers to only copy the minimum stuff needed from to/from userspace. Based on work started by Brian Gianforcaro.
2020-01-21Kernel: Rename UnveilState to VeilStateAndreas Kling
2020-01-21Kernel: Tidy up debug logging a little bitAndreas Kling
When using dbg() in the kernel, the output is automatically prefixed with [Process(PID:TID)]. This makes it a lot easier to understand which thread is generating the output. This patch also cleans up some common logging messages and removes the now-unnecessary "dbg() << *current << ..." pattern.
2020-01-20Kernel: Add a basic implementation of unveil()Andreas Kling
This syscall is a complement to pledge() and adds the same sort of incremental relinquishing of capabilities for filesystem access. The first call to unveil() will "drop a veil" on the process, and from now on, only unveiled parts of the filesystem are visible to it. Each call to unveil() specifies a path to either a directory or a file along with permissions for that path. The permissions are a combination of the following: - r: Read access (like the "rpath" promise) - w: Write access (like the "wpath" promise) - x: Execute access - c: Create/remove access (like the "cpath" promise) Attempts to open a path that has not been unveiled with fail with ENOENT. If the unveiled path lacks sufficient permissions, it will fail with EACCES. Like pledge(), subsequent calls to unveil() with the same path can only remove permissions, not add them. Once you call unveil(nullptr, nullptr), the veil is locked, and it's no longer possible to unveil any more paths for the process, ever. This concept comes from OpenBSD, and their implementation does various things differently, I'm sure. This is just a first implementation for SerenityOS, and we'll keep improving on it as we go. :^)
2020-01-19Kernel: Add a 1-deep cache to Process::region_from_range()Andreas Kling
This simple cache gets hit over 70% of the time on "g++ Process.cpp" and shaves ~3% off the runtime.
2020-01-19Kernel: Add a Process::add_region() helperAndreas Kling
This is a private helper for adding a Region to Process::m_regions. It's just for convenience since it's a bit cumbersome to do this.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-17Kernel+LibC: Unify sys$open() and sys$openat()Sergey Bugaev
The syscall is now called sys$open(), but it behaves like the old sys$openat(). In userspace, open_with_path_length() is made a wrapper over openat_with_path_length().
2020-01-17Kernel: Add "accept" pledge promise for accepting incoming connectionsAndreas Kling
This patch adds a new "accept" promise that allows you to call accept() on an already listening socket. This lets programs set up a socket for for listening and then dropping "inet" and/or "unix" so that only incoming (and existing) connections are allowed from that point on. No new outgoing connections or listening server sockets can be created. In addition to accept() it also allows getsockopt() with SOL_SOCKET and SO_PEERCRED, which is used to find the PID/UID/GID of the socket peer. This is used by our IPC library when creating shared buffers that should only be accessible to a specific peer process. This allows us to drop "unix" in WindowServer and LookupServer. :^) It also makes the debugging/introspection RPC sockets in CEventLoop based programs work again.
2020-01-13Kernel: Tighten up exec/do_exec and allow for PT_INTERP iterpretersAndrew Kaster
This patch changes how exec() figures out which program image to actually load. Previously, we opened the path to our main executable in find_shebang_interpreter_for_executable, read the first page (or less, if the file was smaller) and then decided whether to recurse with the interpreter instead. We then then re-opened the main executable in do_exec. However, since we now want to parse the ELF header and Program Headers of an elf image before even doing any memory region work, we can change the way this whole process works. We open the file and read (up to) the first page in exec() itself, then pass just the page and the amount read to find_shebang_interpreter_for_executable. Since we now have that page and the FileDescription for the main executable handy, we can do a few things. First, validate the ELF header and ELF program headers for any shenanigans. ELF32 Little Endian i386 only, please. Second, we can grab the PT_INTERP interpreter from any ET_DYN files, and open that guy right away if it exists. Finally, we can pass the main executable's and optionally the PT_INTERP interpreter's file descriptions down to do_exec and not have to feel guilty about opening the file twice. In do_exec, we now have a choice. Are we going to load the main executable, or the interpreter? We could load both, but it'll be way easier for the inital pass on the RTLD if we only load the interpreter. Then it can load the main executable itself like any old shared object, just, the one with main in it :). Later on we can load both of them into memory and the RTLD can relocate itself before trying to do anything. The way it's written now the RTLD will get dibs on its requested virtual addresses being the actual virtual addresses.
2020-01-13Kernel: Combine validate and copy of user mode pointers (#1069)Brian Gianforcaro
Right now there is a significant amount of boiler plate code required to validate user mode parameters in syscalls. In an attempt to reduce this a bit, introduce validate_read_and_copy_typed which combines the usermode address check and does the copy internally if the validation passes. This cleans up a little bit of code from a significant amount of syscalls.
2020-01-12Kernel: Don't forget to copy & destroy root_directory_for_procfsSergey Bugaev
Also, rename it to root_directory_relative_to_global_root.
2020-01-12Kernel+LibC: Allow passing mount flags to chroot()Sergey Bugaev
Since a chroot is in many ways similar to a separate root mount, we can also apply mount flags to it as if it was an actual mount. These flags will apply whenever the chrooted process accesses its root directory, but not when other processes access this same directory for the outside. Since it's common to chdir("/") immediately after chrooting (so that files accessed through the current directory inherit the same mount flags), this effectively allows one to apply additional limitations to a process confined inside a chroot. To this effect, sys$chroot() gains a mount_flags argument (exposed as chroot_with_mount_flags() in userspace) which can be set to all the same values as the flags argument for sys$mount(), and additionally to -1 to keep the flags set for that file system. Note that passing 0 as mount_flags will unset any flags that may have been set for the file system, not keep them.
2020-01-12Kernel: Add "video" pledge for accessing framebuffer devicesAndreas Kling
WindowServer becomes the only user.
2020-01-11ping: Use pledge()Andreas Kling
2020-01-11Kernel: Use the Syscall string and buffer types moreAndreas Kling
While I was updating syscalls to stop passing null-terminated strings, I added some helpful struct types: - StringArgument { const char*; size_t; } - ImmutableBuffer<Data, Size> { const Data*; Size; } - MutableBuffer<Data, Size> { Data*; Size; } The Process class has some convenience functions for validating and optionally extracting the contents from these structs: - get_syscall_path_argument(StringArgument) - validate_and_copy_string_from_user(StringArgument) - validate(ImmutableBuffer) - validate(MutableBuffer) There's still so much code around this and I'm wondering if we should generate most of it instead. Possible nice little project.
2020-01-11Kernel: Remove validate_read_str() as nothing uses it anymore :^)Andreas Kling
2020-01-11Kernel: Pass a parameter struct to mount()Andreas Kling
This was the last remaining syscall that took a null-terminated string and figured out how long it was by walking it in kernelspace *shudder*.
2020-01-11Kernel: Pass a parameter struct to rename()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to symlink()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to mknod()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to chown()Andreas Kling
2020-01-10Kernel: Expose a process's filesystem root as a /proc/PID/root symlinkAndreas Kling
In order to preserve the absolute path of the process root, we save the custody used by chroot() before stripping it to become the new "/". There's probably a better way to do this.
2020-01-10Kernel: Add a basic chroot() syscall :^)Andreas Kling
The chroot() syscall now allows the superuser to isolate a process into a specific subtree of the filesystem. This is not strictly permanent, as it is also possible for a superuser to break *out* of a chroot, but it is a useful mechanism for isolating unprivileged processes. The VFS now uses the current process's root_directory() as the root for path resolution purposes. The root directory is stored as an uncached Custody in the Process object.
2020-01-10Kernel: Pass characters+length to link()Andreas Kling
2020-01-10Kernel: Pass characters+length to readlink()Andreas Kling
Note that I'm developing some helper types in the Syscall namespace as I go here. Once I settle on some nice types, I will convert all the other syscalls to use them as well.
2020-01-10Kernel: Enable SMAP protection during the execve() syscallAndreas Kling
The userspace execve() wrapper now measures all the strings and puts them in a neat and tidy structure on the stack. This way we know exactly how much to copy in the kernel, and we don't have to use the SMAP-violating validate_read_str(). :^)
2020-01-10Kernel+LibELF: Enable SMAP protection during non-syscall exec()Andreas Kling
When loading a new executable, we now map the ELF image in kernel-only memory and parse it there. Then we use copy_to_user() when initializing writable regions with data from the executable. Note that the exec() syscall still disables SMAP protection and will require additional work. This patch only affects kernel-originated process spawns.
2020-01-09Kernel: Removed an unused global variableAndreas Kling
2020-01-09Kernel: Take path+length in the unlink() and umount() syscallsAndreas Kling
2020-01-08Kernel: Remove unused syscall for setting the signal maskAndreas Kling
2020-01-07Kernel: Take const Process& in InodeMetadata::may_{read,write,execute}Andreas Kling