Commit graph

394 commits

Author SHA1 Message Date
Liav A 8142f7b196 Kernel: Mark sys$get_dir_entries as not needing the big lock
After examination of all overriden Inode::traverse_as_directory methods
it seems like proper locking is already existing everywhere, so there's
no need to take the big process lock anymore, as there's no access to
shared process structures anyway.
2023-05-27 10:58:58 +02:00
Liav A 46ef2f8e20 Kernel: Mark sys$fork as not needing the big lock
All shared structures are already protected by "atomic" spinlocks for
those structures, so there's no need to take the big process lock.
2023-05-27 10:58:58 +02:00
Liav A 0be79f9bc2 Kernel: Mark sys$umount as not needing the big lock
All accesses to the mount table are already serialized by the actual
spinlock of that table.
2023-05-27 10:58:58 +02:00
Liav A 0bbd9040ef Kernel+Userland: Split bind-mounting and re-mounting from mount syscall
These 2 are an actual separate types of syscalls, so let's stop using
special flags for bind mounting or re-mounting and instead let userspace
calling directly for this kind of actions.
2023-05-17 23:39:15 -06:00
Tim Schumacher d78bed2ffe Kernel: Alias _SC_PAGE_SIZE to _SC_PAGESIZE
Both of those are specified by POSIX.
2023-05-17 08:54:55 +02:00
Liav A 8289759f1d Kernel: Allow configuring a Jail to not impose PID isolation restriction
This is quite useful for userspace applications that can't cope with the
restriction, but it's still useful to impose other non-configurable
restrictions by using jails.
2023-04-24 12:15:29 +02:00
Daniel Bertalan d205814da6 Kernel+LibC: Implement pthread_create for AArch64
Instead of storing x86_64 register names in `SC_create_thread_params`,
let the Kernel figure out how to pass the parameters to
`pthread_create_helper`.
2023-04-23 14:30:59 +02:00
Arda Cinar 38dc54317c Kernel/Net: Implement SIOCGIFINDEX and SIOCGIFNAME for sockets
These ioctls exist on Linux and can be used to implement libc functions
if_indextoname and if_nametoindex (without needing to parse any JSON).
2023-04-14 12:29:03 +01:00
Liav A cbf78975f1 Kernel: Add the futimens syscall
We have a problem with the original utimensat syscall because when we
do call LibC futimens function, internally we provide an empty path,
and the Kernel get_syscall_path_argument method will detect this as an
invalid path.

This happens to spit an error for example in the touch utility, so if a
user is running "touch non_existing_file", it will create that file, but
the user will still see an error coming from LibC futimens function.

This new syscall gets an open file description and it provides the same
functionality as utimensat, on the specified open file description.
The new syscall will be used later by LibC to properly implement LibC
futimens function so the situation described with relation to the
"touch" utility could be fixed.
2023-04-10 10:21:28 +02:00
Liav A bfffe88de5 Kernel/HID: Untie the PS2 protocol, i8042 hardware and generic devices
For a very long time, the kernel had only support for basic PS/2 devices
such as the PS2 AT keyboard and regular PS2 mouse (with a scroll wheel).

To adapt to this, we had very simple abstractions in place, essentially,
the PS2 devices were registered as IRQ handlers (IRQ 1 and 12), and when
an interrupt was triggered, we simply had to tell the I8042Controller to
fetch a byte for us, then send it back to the appropriate device for
further processing and queueing of either a key event, or a mouse packet
so userspace can do something meaningful about it.

When we added the VMWare mouse integration feature it was easily adapted
to this paradigm, requiring small changes across the handling code for
these devices.

This patch is a major cleanup for any future advancements in the HID
subsystem.
It ensures we do things in a much more sane manner:
- We stop using LockRefPtrs. Currently, after the initialization of the
  i8042 controller, we never have to change RefPtrs in that class, as we
  simply don't support PS2 hotplugging currently.
  Also, we remove the unnecessary getters for keyboard and mouse devices
  which also returned a LockRefPtr.
- There's a clear separation between PS2 devices and the actual device
  nodes that normally exist in /dev. PS2 devices are not polled, because
  when the user uses these devices, they will trigger an IRQ which when
  is handled, could produce either a MousePacket or KeyEvent, depending
  on the device state.
  The separation is crucial for buses that are polled, for example - USB
  is a polled bus and will not generate an IRQ for HID devices.
- There's a clear separation in roles of each structure. The PS2 devices
  which are attached to a I8042Controller object are managing the device
  state, while the generic MouseDevice and KeyboardDevice manage all
  related tasks of a CharacterDevice, as well as interpreting scan code
  events and mouse relative/absolute coordinates.
2023-04-09 18:11:37 +02:00
Idan Horowitz 3f89a1b131 Kernel: Mark sys$msync as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 1dae6a2e4a Kernel: Mark sys$mremap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz db10f201c8 Kernel: Mark sys$munmap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz d1082a00b7 Kernel: Mark sys$set_mmap_name as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 2f79d0e8b9 Kernel: Mark sys$mprotect as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 3697214166 Kernel: Mark sys$mmap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 0b14081ae1 Kernel: Mark sys$map_time_page as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 0e564240a6 Kernel: Mark sys$madvise as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Andreas Kling e219662ce0 Kernel: Mark sys$setpgid as not needing the big lock
This function is already serialized by access to process protected data.
2023-04-05 11:37:27 +02:00
Andreas Kling f764b8b113 Kernel: Mark sys$setsid as not needing the big lock
This function is now serialized by access to the process group list,
and to the current process's protected data.
2023-04-05 11:37:27 +02:00
Andreas Kling ca1f8cac66 Kernel: Mark sys$faccessat as not needing the big lock 2023-04-05 11:37:27 +02:00
Andreas Kling bd46397e1f Kernel: Mark inode watcher syscalls as not needing the big lock
These syscalls are already protected by existing locking mechanisms,
including the mutex inside InodeWatcher.
2023-04-04 10:33:42 +02:00
Andreas Kling 08d79c757a Kernel: Mark sys$killpg as not needing the big lock
Same as sys$kill, nothing here that isn't already protected by existing
locks.
2023-04-04 10:33:42 +02:00
Andreas Kling e71b84228e Kernel: Mark sys$kill as not needing the big lock
This syscall sends a signal to other threads or itself. This mechanism
is already guarded by locking mechanisms, and widely used within the
kernel without help from the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 46ab245e74 Kernel: Mark sys$getrusage as not needing the big lock
Same deal as sys$times, nothing here that needs locking at the moment.
2023-04-04 10:33:42 +02:00
Andreas Kling 5bc7882b68 Kernel: Make sys$times not use the big lock
...and also make the Process tick counters clock_t instead of u32.
It seems harmless to get interrupted in the middle of reading these
counters and reporting slightly fewer ticks in some category.
2023-04-04 10:33:42 +02:00
Andreas Kling b98f537f11 Kernel+Userland: Make some of the POSIX types larger
Expand the following types from 32-bit to 64-bit:
- blkcnt_t
- blksize_t
- dev_t
- nlink_t
- suseconds_t
- clock_t

This matches their size on other 64-bit systems.
2023-04-04 10:33:42 +02:00
Andreas Kling d8bb32117e Kernel: Mark sys$umask as not needing the big lock
The body of this syscall is already serialized by calling
with_mutable_protected_data().
2023-04-04 10:33:42 +02:00
Andreas Kling 6c02c493f1 Kernel: Mark sys$sigtimedwait as not needing the big lock
Yet another syscall that only messes with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling f0b5c585f2 Kernel: Mark sys$sigpending as not needing the big lock
Another one that only touches the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling e9fe0ecbae Kernel: Mark sys$sigprocmask as not needing the big lock
Another one that only messes with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling d1fae8b09c Kernel: Mark sys$sigsuspend as not needing the big lock
This syscall is only concerned with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling 374f4aeab9 Kernel: Mark sys$sigreturn as not needing the big lock
This syscall is only concerned with the current thread (except in the
case of a pledge violation, when it will add some details about that
to the process coredump metadata. That stuff is already serialized.)
2023-04-04 10:33:42 +02:00
Andreas Kling a7212a7488 Kernel: Mark sys$open as not needing the big lock
All the individual sub-operations of this syscall are protected by their
own locking mechanisms, so it should be okay to get it off the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 41f5598516 Kernel: Make sys$getsid not require the big lock
Reorganize the code slightly to avoid creating a TOCTOU bug, then mark
the syscall as not needing the big lock anymore.
2023-04-04 10:33:42 +02:00
Andreas Kling 1382439267 Kernel: Mark sys$getpgrp as not needing the big lock
Access to the process's process group is already serialized by
SpinlockProtected.
2023-04-04 10:33:42 +02:00
Andreas Kling 2ddd69260c Kernel: Mark sys$getpgid as not needing the big lock
Access to the process's process group is already serialized by
SpinlockProtected.
2023-04-04 10:33:42 +02:00
Andreas Kling 775e6d6865 Kernel: Mark sys$fcntl as not needing the big lock
This syscall operates on the file descriptor table, and on individual
open file descriptions. Both of those are already protected by scoped
locking mechanisms.
2023-04-04 10:33:42 +02:00
Andreas Kling 6132193bd4 Kernel: Make sys$disown not require the big lock
This syscall had a TOCTOU where it checked the peer's PPID before
locking the protected data (where the PPID is stored).

After closing the race window, we can mark the syscall as not needing
the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 5759ea19fb Kernel: Mark sys$alarm as not needing the big lock
Access to Process::m_alarm_timer is serialized via SpinlockProtected,
so there's no longer need for this syscall to use the big lock.
2023-04-04 10:33:42 +02:00
Liav A d16d805d96 Kernel: Merge {get,set}_process_name syscalls to the prctl syscall
It makes much more sense to have these actions being performed via the
prctl syscall, as they both require 2 plain arguments to be passed to
the syscall layer, and in contrast to most syscalls, we don't get in
these removed syscalls an automatic representation of Userspace<T>, but
two FlatPtr(s) to perform casting on them in the prctl syscall which is
suited to what has been done in the removed syscalls.

Also, it makes sense to have these actions in the prctl syscall, because
they are strongly related to the process control concept of the prctl
syscall.
2023-03-15 20:10:48 +01:00
Andrew Kaster 6ce7257ad7 Kernel: Don't include Kernel/Arch/RegisterState from userspace
Any userspace cpp file that included <syscall.h> would end up with
a large glob of Kernel headers included, all the way down to
Kernel/Arch/x86_64/CPU.h and friends.

Only the kernel needs RegisterState, so hide it from userspace.
2023-03-13 07:23:53 +00:00
Fabian Dellwing 7c0b360881 Kernel: Add non standard value to sys$sysconf
Add `_SC_PHYS_PAGES` to sys$sysconf syscall. This value is needed
for a port I'm working on.
2023-03-11 13:06:36 +00:00
Liav A be1d7c325a Kernel: Move process coredump metadata modification to the prctl syscall 2023-03-05 16:55:08 +01:00
Liav A 6b849fc8b1 Kernel: Move TYPEDEF_* TTY macros to API/ttydefaults.h file
This allows us to get rid of an include to LibC/sys/ttydefaults.h in the
Kernel TTY implementation.

Also, move ttydefchars static const struct to another file called
Kernel/API/ttydefaultschars.h, so it could be used too in the Kernel TTY
implementation without the need to include anything from LibC.
2023-03-01 19:36:53 -07:00
Liav A 800e244ed9 Kernel+LibC: Move the FD_SETSIZE declaration to API/POSIX/select.h file 2023-03-01 19:36:53 -07:00
Liav A 8a50c967b8 Kernel: Mark sys$prctl() as not needing the big lock
This syscall has sufficient locking and therefore it doesn't need the
big lock being taken.
2023-02-25 15:21:29 +01:00
Liav A b27f88f61d Kernel+Userland: Refine preventing syscall annotations of Regions option
Instead of using a special case of the annotate_mapping syscall, let's
introduce a new prctl option to disallow further annotations of Regions
as new syscall Region(s).
2023-02-24 22:26:07 +01:00
Liav A 8f3c343b88 Kernel+Userland: Unify declarations for KCOV in Kernel/API/kcov.h 2023-02-24 20:35:45 +01:00
Liav A e7142c482a Kernel+Userland: Move prctl numbers header file to Kernel/API directory 2023-02-24 20:35:45 +01:00