Commit graph

318 commits

Author SHA1 Message Date
macarc bffdc056a2 Kernel: Ensure KeyEvent::key sent to Userspace respects keyboard layout
Before, only KeyEvent::code_point took the user's keyboard layout
into consideration, while KeyEvent::key was hardcoded QWERTY. This
affected, among other things, Vim Emulation.

Now, KeyEvent::key respects the user's keyboard layout, so will be the
same as KeyEvent::code_point for visible (alphanumeric + symbol) keys.

Co-Authored-By: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
2021-11-26 11:19:36 -08:00
Ben Wiederhake 33079c8ab9 Kernel+UE+LibC: Remove unused dbgputch syscall
Everything uses the dbgputstr syscall anyway, so there is no need to
keep supporting it.
2021-11-24 22:56:39 +01:00
Andreas Kling daef7e2c71 Kernel+LibC: Fix misspelled "VERTICAL" in framebuffer ioctls 2021-11-21 20:22:48 +01:00
Itamar 38ddf301f6 Kernel+LibC: Fix ptrace for 64-bit
This makes the types used in the PT_PEEK and PT_POKE actions
suitable for 64-bit platforms as well.
2021-11-20 21:22:24 +00:00
Andreas Kling 32aa37d5dc Kernel+LibC: Add msync() system call
This allows userspace to trigger a full (FIXME) flush of a shared file
mapping to disk. We iterate over all the mapped pages in the VMObject
and write them out to the underlying inode, one by one. This is rather
naive, and there's lots of room for improvement.

Note that shared file mappings are currently not possible since mmap()
returns ENOTSUP for PROT_WRITE+MAP_SHARED. That restriction will be
removed in a subsequent commit. :^)
2021-11-17 19:34:15 +01:00
Andreas Kling 79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Idan Horowitz a8bd78e634 LibC: Include sys/uio.h in sys/socket.h for struct iovec 2021-10-28 11:24:36 +02:00
Idan Horowitz 2882a90dec Kernel: Add the IFF_* SIOCGIFFLAGS flag macros 2021-10-28 11:24:36 +02:00
Idan Horowitz adc9939a7b Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockopt 2021-10-28 11:24:36 +02:00
Idan Horowitz c45b1e1983 LibC: Add IPPROTO_ICMPV6 macro 2021-10-28 11:24:36 +02:00
Filiph Sandström c6247fe414 Everywhere: Rename back-click to backward-click
This matches the current forward-click terminology.
2021-10-27 22:05:58 +03:00
Liav A 8554952690 Kernel + WindowServer: Re-define the interface to framebuffer devices
We create a base class called GenericFramebufferDevice, which defines
all the virtual functions that must be implemented by a
FramebufferDevice. Then, we make the VirtIO FramebufferDevice and other
FramebufferDevice implementations inherit from it.
The most important consequence of rearranging the classes is that we now
have one IOCTL method, so all drivers should be committed to not
override the IOCTL method or make their own IOCTLs of FramebufferDevice.
All graphical IOCTLs are known to all FramebufferDevices, and it's up to
the specific implementation whether to support them or discard them (so
we require extensive usage of KResult and KResultOr, together with
virtual characteristic functions).
As a result, the interface is much cleaner and understandable to read.
2021-10-27 07:57:44 +03:00
Rodrigo Tobar e1093c3403 Kernel: Implement pread syscall
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-13 16:10:50 +02:00
Nico Weber 5a951d6258 Kernel: Fix a few typos 2021-10-01 00:51:49 +01:00
Jelle Raaijmakers 9a6283c524 Kernel: Define PT_READ_I and PT_READ_D
Looking at how these two constants are commonly used in other systems,
we should be able to mimic their behavior using our PT_PEEK constant.

For example, see:
https://man.netbsd.org/NetBSD-6.0.1/i386/ptrace.2
2021-09-23 18:51:21 +02:00
Brian Gianforcaro 07b314e843 Kernel+LibC: Pack SC_stat_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro be15bd3c86 Kernel+LibC: Pack SC_mount_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro dcb327a83b Kernel+LibC: Pack SC_setsockopt_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro 9956607283 Kernel+LibC: Pack SC_accept4_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro b45ca5d56e Kernel+LibC: Pack SC_inode_watcher_add_watch_params struct better
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Liav A 8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
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-12 11:52:16 +02:00
TheFightingCatfish a81b21c1a7 Kernel+LibC: Implement fsync 2021-09-12 11:24:02 +02:00
Liav A 04ba31b8c5 Kernel+Userland: Remove loadable kernel moduless
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-11 19:05:00 +02:00
Linus Groh f646d49ac1 Kernel: Add _SC_HOST_NAME_MAX 2021-09-11 00:28:39 +02:00
Rodrigo Tobar a0ac5c5fc2 Kernel: Define INADDR_BROADCAST constant
This is required by some programs, notably python's socket module, which
fails to compile without this definition.
2021-09-09 11:33:45 +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 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 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
Andreas Kling 4226b662cd Kernel+Userland: Remove global futexes
We only ever use private futexes, so it doesn't make sense to carry
around all the complexity required for global (cross-process) futexes.
2021-08-17 01:21:47 +02:00
Itamar f3aa87c436 Kernel: Make makedev()/minor()/major() static
This was originally done in 7274037 and for some reason reverted in
740140a.

This avoids "multiple definitions" link errors and fixes the libuv port.
2021-08-16 23:26:52 +02:00
Andreas Kling 1b739a72c2 Kernel+Userland: Remove chroot functionality
We are not using this for anything and it's just been sitting there
gathering dust for well over a year, so let's stop carrying all this
complexity around for no good reason.
2021-08-15 12:44:35 +02:00
Kenneth Myhra cb10c62327 LibC: Add SOCK_RDM and SOCK_SEQPACKET to socket.h 2021-08-14 22:32:00 +01:00
Kenneth Myhra 3875e8bd4b LibC: Add IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP to netin/in.h 2021-08-14 22:32:00 +01:00
Andreas Kling e1273a8ff7 Kernel+LibC: Share definitions for sys/statvfs.h 2021-08-14 19:58:11 +02:00
Andreas Kling dfd78b75d8 Kernel+LibC: Share definitions for sched.h 2021-08-14 19:58:11 +02:00
Andreas Kling c9a5d83ccc Kernel+LibC: Share definitions for sys/uio.h 2021-08-14 19:58:11 +02:00
Andreas Kling 37e98a55b7 Kernel+LibC: Share definitions for sys/ptrace.h 2021-08-14 19:58:11 +02:00
Andreas Kling 6b6eca0631 Kernel+LibC: Share definitions for sys/time.h 2021-08-14 19:58:11 +02:00
Andreas Kling 35b52338bb Kernel+LibC: Share definitions for sys/times.h 2021-08-14 19:58:11 +02:00
Andreas Kling 808ce594db Kernel+LibC: Share definitions for stdio.h 2021-08-14 19:58:11 +02:00
Andreas Kling 9c2212a60a Kernel+LibC: Share definitions for unistd.h 2021-08-14 19:58:11 +02:00
Andreas Kling d33b43276c Kernel+LibC: Share definitions for poll.h 2021-08-14 19:58:11 +02:00
Andreas Kling d794ed1de7 Kernel+LibC: Share definitions for utsname.h 2021-08-14 19:58:11 +02:00
Andreas Kling c65a735d71 Kernel+LibC: Share definitions for dirent.h 2021-08-14 19:58:11 +02:00
Andreas Kling 77c2c0f620 Kernel+LibC: Share definitions for serenity.h 2021-08-14 19:58:11 +02:00
Andreas Kling 6f78377864 Kernel+LibC: Share definitions for sys/wait.h 2021-08-14 19:58:11 +02:00
Andreas Kling 661bd992b0 Kernel+LibC: Share definitions for net/{if,if_arp,route}.h 2021-08-14 19:58:11 +02:00
Andreas Kling ff50122dc5 Kernel+LibC: Share definitions for futex.h 2021-08-14 19:58:11 +02:00
Andreas Kling 6fd7212476 Kernel+LibC: Share definitions for signal.h 2021-08-14 19:58:11 +02:00
Andreas Kling 9dc1350177 Kernel+LibC: Share definitions for netinet/in.h 2021-08-14 19:58:11 +02:00
Andreas Kling b92e6b02e5 Kernel+LibC: Share definitions for sys/socket.h and sys/un.h 2021-08-14 19:58:11 +02:00
Andreas Kling d277cdfd4c Kernel+LibC: Share definitions for termios.h 2021-08-14 19:58:11 +02:00
Andreas Kling a8d1c2dde9 Kernel+LibC: Share definitions for sys/mman.h 2021-08-14 19:58:11 +02:00
Andreas Kling 0a78056453 Kernel+LibC: Share definitions for time.h and sys/stat.h 2021-08-14 19:58:11 +02:00
Andreas Kling 740140a661 Kernel+LibC: Share definitions in fcntl.h and sys/types.h
This patch begins the work of sharing types and macros between Kernel
and LibC instead of duplicating them via the kludge in UnixTypes.h.

The basic idea is that the Kernel vends various POSIX headers via
Kernel/API/POSIX/ and LibC simply #include's them to get the macros.
2021-08-14 19:58:11 +02:00
Andreas Kling 4657c79143 Kernel+LibC: Add sys$perf_register_string()
This syscall allows userspace to register a keyed string that appears in
a new "strings" JSON object in profile output.

This will be used to add custom strings to profile signposts. :^)
2021-08-12 00:03:39 +02:00
Andreas Kling b7dae4f90e Kernel: Add CLOCK_MONOTONIC_COARSE to the kernel time page
This allows clock_gettime(CLOCK_MONOTONIC_COARSE) without syscalls.
Core::EventLoop takes advantage of this automatically. :^)
2021-08-10 21:51:05 +02:00
Andreas Kling aaead6f332 Kernel: Only expose CLOCK_REALTIME_COARSE via the kernel time page
Non-COARSE clock sources may probably still require a syscall.
2021-08-10 21:51:05 +02:00
Andreas Kling fdfc66db61 Kernel+LibC: Allow clock_gettime() to run without syscalls
This patch adds a vDSO-like mechanism for exposing the current time as
an array of per-clock-source timestamps.

LibC's clock_gettime() calls sys$map_time_page() to map the kernel's
"time page" into the process address space (at a random address, ofc.)
This is only done on first call, and from then on the timestamps are
fetched from the time page.

This first patch only adds support for CLOCK_REALTIME, but eventually
we should be able to support all clock sources this way and get rid of
sys$clock_gettime() in the kernel entirely. :^)

Accesses are synchronized using two atomic integers that are incremented
at the start and finish of the kernel's time page update cycle.
2021-08-10 19:21:16 +02:00
Andreas Kling 595ed59eb7 Kernel: Alphabetize the syscall list 2021-08-10 13:01:39 +02:00
Andreas Kling fa64ab26a4 Kernel+UserspaceEmulator: Remove unused sys$gettimeofday()
Now that LibC uses clock_gettime() to implement gettimeofday(), we can
get rid of this entire syscall. :^)
2021-08-10 13:01:39 +02:00
Idan Horowitz 9d21c79671 Kernel: Disable big process lock for sys$sync
This syscall doesn't touch any intra-process shared resources and only
calls VirtualFileSystem::sync, which is self-locking.
2021-08-07 15:30:26 +02:00
Idan Horowitz ad419a669d Kernel: Disable big process lock for sys$sysconf
This syscall only reads constant kernel globals, and as such does not
need to hold the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz efeb01e35f Kernel: Disable big process lock for sys$get_stack_bounds
This syscall only reads from the shared m_space field, but that field
is only over written to by Process::attach_resources, before the
process was initialized (aka, before syscalls can happen), by
Process::finalize which is only called after all the process' threads
have exited (aka, syscalls can not happen anymore), and by
Process::do_exec which calls all other syscall-capable threads before
doing so. Space's find_region_containing already holds its own lock,
and as such there's no need to hold the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz d40038a04f Kernel: Disable big process lock for sys$gettimeofday
This syscall doesn't touch any intra-process shared resources and only
accesses the time via the atomic TimeManagement::now so there's no need
to hold the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz 3ba2449058 Kernel: Disable big process lock for sys$clock_nanosleep
This syscall doesn't touch any intra-process shared resources and only
accesses the time via the atomic TimeManagement::current_time so there's
no need to hold the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz fbd848e6eb Kernel: Disable big process lock for sys$clock_gettime()
This syscall doesn't touch any intra-process shared resources and
reads the time via the atomic TimeManagement::current_time, so it
doesn't need to hold any lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz 1a08694dfc Kernel: Disable big process lock for sys$getkeymap
This syscall only reads non process-related global values, and as such
doesn't need to hold the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz 48325e2959 Kernel: Disable big process lock for sys$getrandom
This syscall doesn't touch any intra-process shared resources and
already holds the global kernel RNG lock so there's no reason to hold
the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz b1f4f6ee15 Kernel: Disable big process lock for sys$dbgputch
This syscall doesn't touch any intra-process shared resources and
already holds the global logging lock so there's no reason to hold
the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz c7ad4c6c32 Kernel: Disable big process lock for sys$dbgputstr
This syscall doesn't touch any intra-process shared resources and
already holds the global logging lock so there's no reason to hold
the big lock.
2021-08-06 23:36:12 +02:00
Idan Horowitz 00818b8447 Kernel: Disable big process lock for sys$dump_backtrace()
This syscall only dumps the current thread's backtrace and as such
doesn't touch any shared intra-process resources.
2021-08-06 23:36:12 +02:00
Idan Horowitz da0b7d1737 Kernel: Disable big process lock for sys$beep()
The PCSpeaker is global and not locked anyways, so there's no need for
mutual exclusion between threads in the same process.
2021-08-06 23:36:12 +02:00
Andreas Kling af46f2214c Kernel: Make a bunch of "char const* to_string()" return StringView 2021-08-06 00:37:47 +02:00
Andreas Kling deff554096 Kernel+LibSystem: Add a 4th syscall argument
Let's allow passing 4 function arguments to a syscall. The 4th argument
goes into ESI or RSI.
2021-07-25 14:08:50 +02:00
Brian Gianforcaro 8f01a8b741 Kernel: Disable big process lock for sys$yield() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 5c10fb4007 Kernel: Disable big process lock for sys$gettid()
This syscall reads a read only value from the current thread, and hence
has no need for the big process lock.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 638598b15d Kernel: Disable big process lock for sys$getpid() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro bfd4635274 Kernel: Disable big process lock for sys$uname() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 10ce896d4f Kernel: Disable big process lock in sys$gethostname() sys$sethostname() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 9201a06027 Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIRED
Before we start disabling acquisition of the big process lock for
specific syscalls, make sure to document and assert that all the
lock is held during all syscalls.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro af543328ea Kernel: Instrument syscalls with their process big lock requirements
Currently all syscalls run under the Process:m_big_lock, which is an
obvious bottleneck. Long term we would like to remove the big lock and
replace it with the required fine grained locking.

To facilitate this goal we need a way of gradually decomposing the big
lock into the all of the required fine grained locks. This commit
introduces instrumentation to the syscall table, allowing the big lock
requirement to be toggled on/off per syscall.

Eventually when we are finished, no syscall will required the big lock,
and we'll be able to remove all of this instrumentation.
2021-07-20 03:21:14 +02:00
Ali Mohammad Pur e37f9fa7db LibPthread+Kernel: Add pthread_kill() and the thread_kill syscall 2021-07-09 15:36:50 +02:00
Edwin Hoksberg 99328e1038 Kernel+KeyboardSettings: Remove numlock syscall and implement ioctl 2021-07-07 10:44:20 +02:00
Andreas Kling 565796ae4e Kernel+LibC: Remove sys$donate()
This was an old SerenityOS-specific syscall for donating the remainder
of the calling thread's time-slice to another thread within the same
process.

Now that Threading::Lock uses a pthread_mutex_t internally, we no
longer need this syscall, which allows us to get rid of a surprising
amount of unnecessary scheduler logic. :^)
2021-07-05 23:30:15 +02:00
ForLoveOfCats ce6658acc1 KeyboardSettings+Kernel: Setting to enable Num Lock on login 2021-07-05 06:19:59 +02:00
Tom 6e792553f2 WindowServer: Query driver for framebuffer offset
Depending on the driver, the second buffer may not be located right
after the first, e.g. it may be page aligned. This removes this
assumption and queries the driver for the appropriate offset.
2021-07-04 23:59:17 +02:00
Tom fdae117600 WindowServer: Implement support for combined buffer flipping + flushing
Some devices may require DMA transfers to flush the updated buffer
areas prior to flipping. For those devices we track the areas that
require flushing prior to the next flip. For devices that do not
support flipping, but require flushing, we'll simply flush after
updating the front buffer.

This also adds a small optimization that skips these steps entirely for
a screen that doesn't have any updates that need to be rendered.
2021-07-04 23:59:17 +02:00
Gunnar Beutner 16b9a2d2e1 Kernel+LibPthread: Add support for usermode threads on x86_64 2021-07-01 17:22:22 +02:00
Gunnar Beutner 93c741018e Kernel+LibPthread: Remove m_ prefix for public members 2021-07-01 17:22:22 +02:00
Tom 38af4c29e6 WindowServer: Coalesce flushing buffers into one ioctl() call
We regularily need to flush many rectangles, so instead of making many
expensive ioctl() calls to the framebuffer driver, collect the
rectangles and only make one call. And if we have too many rectangles
then it may be cheaper to just update the entire region, in which case
we simply convert them all into a union and just flush that one
rectangle instead.
2021-06-27 09:46:27 +02:00
Sahan Fernando 974e996d33 Userland: Add FB_FLUSH ioctl for fbdev 2021-06-25 19:26:30 +02:00
Justin 1c3badede3 Kernel: Add statvfs & fstatvfs Syscalls
These syscalls fill a statvfs struct with various data
about the mount on the VFS.
2021-05-19 21:33:29 +02:00
Gunnar Beutner 89956cb0d6 Kernel+Userspace: Implement the accept4() system call
Unlike accept() the new accept4() system call lets the caller specify
flags for the newly accepted socket file descriptor, such as
SOCK_CLOEXEC and SOCK_NONBLOCK.
2021-05-17 13:32:19 +02:00
Mart G e7310ba45a Kernel+LibC: Add fstatat
The function fstatat can do the same thing as the stat and lstat
functions. However, it can be passed the file descriptor of a directory
which will be used when as the starting point for relative paths. This
is contrary to stat and lstat which use the current working directory as
the starting for relative paths.
2021-05-14 23:32:10 +02:00
sin-ack fe5ca6ca27 Kernel: Implement multi-watch InodeWatcher :^)
This patch modifies InodeWatcher to switch to a one watcher, multiple
watches architecture.  The following changes have been made:

- The watch_file syscall is removed, and in its place the
  create_iwatcher, iwatcher_add_watch and iwatcher_remove_watch calls
  have been added.
- InodeWatcher now holds multiple WatchDescriptions for each file that
  is being watched.
- The InodeWatcher file descriptor can be read from to receive events on
  all watched files.

Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-12 22:38:20 +02:00
Jesse Buhagiar 60cdbc9397 Kernel/LibC: Implement setreuid 2021-04-30 11:35:17 +02:00
Gunnar Beutner aa792062cb Kernel+LibC: Implement the socketpair() syscall 2021-04-28 14:19:45 +02:00
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Brian Gianforcaro 4ed682aebc Kernel: Add a syscall to clear the profiling buffer
While profiling all processes the profile buffer lives forever.
Once you have copied the profile to disk, there's no need to keep it
in memory. This syscall surfaces the ability to clear that buffer.
2021-04-19 18:30:37 +02:00
Gunnar Beutner f033416893 Kernel+LibC: Clean up how assertions work in the kernel and LibC
This also brings LibC's abort() function closer to the spec.
2021-04-18 11:11:15 +02:00
Jean-Baptiste Boric 7a079f7780 LibC+Kernel: Switch off_t to 64 bits 2021-03-17 23:22:42 +01:00
Andreas Kling 38f11cc1ba Everywhere: Rename "logo" key to "super" key
This seems to be the most common way to refer to this key, so let's
call it what people actually call it.
2021-03-11 18:55:16 +01:00
Andreas Kling 84725ef3a5 Kernel+UserspaceEmulator: Add sys$emuctl() system call
This returns ENOSYS if you are running in the real kernel, and some
other result if you are running in UserspaceEmulator.

There are other ways we could check if we're inside an emulator, but
it seemed easier to just ask. :^)
2021-03-09 08:58:26 +01:00
Ben Wiederhake add94aebfa Kernel: Don't trust user-supplied bool in sys$stat
Found by fuzz-syscalls. Can be reproduced by running this in the Shell:
    $ syscall stat [ Desktop 7 buf 2 ]

Fixes #5316.
2021-03-03 11:03:03 +01:00
Andreas Kling 8f70528f30 Kernel: Take some baby steps towards x86_64
Make more of the kernel compile in 64-bit mode, and make some things
pointer-size-agnostic (by using FlatPtr.)

There's a lot of work to do here before the kernel will even compile.
2021-02-25 16:27:12 +01:00
Jean-Baptiste Boric 0d22ec9d32 Kernel: Handle 'Menu' key on PS/2 keyboard 2021-02-15 19:37:14 +01:00
AnotherTest a3a7ab83c4 Kernel+LibC: Implement readv
We already had writev, so let's just add readv too.
2021-02-15 17:32:56 +01:00
Andreas Kling e87eac9273 Userland: Add LibSystem and funnel all syscalls through it
This achieves two things:

- Programs can now intentionally perform arbitrary syscalls by calling
  syscall(). This allows us to work on things like syscall fuzzing.

- It restricts the ability of userspace to make syscalls to a single
  4KB page of code. In order to call the kernel directly, an attacker
  must now locate this page and call through it.
2021-02-05 12:23:39 +01:00
Andreas Kling 823186031d Kernel: Add a way to specify which memory regions can make syscalls
This patch adds sys$msyscall() which is loosely based on an OpenBSD
mechanism for preventing syscalls from non-blessed memory regions.

It works similarly to pledge and unveil, you can call it as many
times as you like, and when you're finished, you call it with a null
pointer and it will stop accepting new regions from then on.

If a syscall later happens and doesn't originate from one of the
previously blessed regions, the kernel will simply crash the process.
2021-02-02 20:13:44 +01:00
Ben Wiederhake a2c21a55e1 Kernel+LibKeyboard: Enable querying the current keymap 2021-02-01 09:54:32 +01:00
Tom 1d621ab172 Kernel: Some futex improvements
This adds support for FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET,
FUTEX_REQUEUE, and FUTEX_CMP_REQUEUE, as well well as global and private
futex and absolute/relative timeouts against the appropriate clock. This
also changes the implementation so that kernel resources are only used when
a thread is blocked on a futex.

Global futexes are implemented as offsets in VMObjects, so that different
processes can share a futex against the same VMObject despite potentially
being mapped at different virtual addresses.
2021-01-17 20:30:31 +01:00
Andreas Kling bf0719092f Kernel+Userland: Remove shared buffers (shbufs)
All users of this mechanism have been switched to anonymous files and
passing file descriptors with sendfd()/recvfd().

Shbufs got us where we are today, but it's time we say good-bye to them
and welcome a much more idiomatic replacement. :^)
2021-01-17 09:07:32 +01:00
Andreas Kling 05dbfe9ab6 Kernel: Remove sys$shbuf_seal() and userland wrappers
There are no remaining users of this syscall so let it go. :^)
2021-01-17 00:18:01 +01:00
Andreas Kling b818cf898e Kernel+Userland: Remove sys$shbuf_allow_all() and userland wrappers
Nobody is using globally shared shbufs anymore, so let's remove them.
2021-01-16 22:43:03 +01:00
Ben Wiederhake 2a8baf9582 Kernel: Remove unused 'ImmutableBufferArgument' 2021-01-16 22:40:53 +01:00
Andreas Kling 01c2480eb3 Kernel+LibC+WindowServer: Remove unused thread/process boost mechanism
The priority boosting mechanism has been broken for a very long time.
Let's remove it from the codebase and we can bring it back the day
someone feels like implementing it in a working way. :^)
2021-01-16 14:52:04 +01:00
Andreas Kling 43109f9614 Kernel: Remove unused syscall sys$minherit()
This is no longer used. We can bring it back the day we need it.
2021-01-16 14:52:04 +01:00
Andreas Kling de31e82f97 Kernel: Remove sys$shbuf_set_volatile() and userland wrappers
There are no remaining users of this syscall so let's remove it! :^)
2021-01-16 14:52:04 +01:00
Andreas Kling fb4993f067 Kernel: Add anonymous files, created with sys$anon_create()
This patch adds a new AnonymousFile class which is a File backed by
an AnonymousVMObject that can only be mmap'ed and nothing else, really.

I'm hoping that this can become a replacement for shbufs. :^)
2021-01-15 13:56:47 +01:00
Davide Carella ca9e0a70f5 Syscall: Changed 'setkeymap' to take also the Shift+AltGr map. 2021-01-06 09:32:08 +01:00
Andreas Kling d991658794 Kernel+LibC: Tidy up assertion failures with a dedicated syscall
This patch adds sys$abort() which immediately crashes the process with
SIGABRT. This makes assertion backtraces a lot nicer by removing all
the gunk that otherwise happens between __assertion_failed() and
actually crashing from the SIGABRT.
2021-01-04 21:57:30 +01:00
Linus Groh bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
Linus Groh 91332515a6 Kernel: Add sys$set_coredump_metadata() syscall
This can be used by applications to store information (key/value pairs)
likely useful for debugging, which will then be embedded in the coredump.
2020-12-30 16:28:27 +01:00
Andreas Kling 30dbe9c78a Kernel+LibC: Add a very limited sys$mremap() implementation
This syscall can currently only remap a shared file-backed mapping into
a private file-backed mapping.
2020-12-29 02:20:43 +01:00
Andreas Kling 0e2b7f9c9a Kernel: Remove the per-process icon_id and sys$set_process_icon()
This was a goofy kernel API where you could assign an icon_id (int) to
a process which referred to a global shbuf with a 16x16 icon bitmap
inside it.

Instead of this, programs that want to display a process icon now
retrieve it from the process executable instead.
2020-12-27 01:16:56 +01:00
Andreas Kling 82f86e35d6 Kernel+LibC: Introduce a "dumpable" flag for processes
This new flag controls two things:
- Whether the kernel will generate core dumps for the process
- Whether the EUID:EGID should own the process's files in /proc

Processes are automatically made non-dumpable when their EUID or EGID is
changed, either via syscalls that specifically modify those ID's, or via
sys$execve(), when a set-uid or set-gid program is executed.

A process can change its own dumpable flag at any time by calling the
new sys$prctl(PR_SET_DUMPABLE) syscall.

Fixes #4504.
2020-12-25 19:35:55 +01:00
Itamar 345abc3132 Kernel: Move InodeWatcher::Event into Kernel/API/InodeWatcherEvent
This allows userspace code to parse these events.
2020-12-14 23:05:53 +01:00
Itamar 9ca1a0731f Kernel: Support TLS allocation from userspace
This adds an allocate_tls syscall through which a userspace process
can request the allocation of a TLS region with a given size.

This will be used by the dynamic loader to allocate TLS for the main
executable & its libraries.
2020-12-14 23:05:53 +01:00
Nico Weber 323e727a4c Kernel+LibC: Add adjtime(2)
Most systems (Linux, OpenBSD) adjust 0.5 ms per second, or 0.5 us per
1 ms tick. That is, the clock is sped up or slowed down by at most
0.05%.  This means adjusting the clock by 1 s takes 2000 s, and the
clock an be adjusted by at most 1.8 s per hour.

FreeBSD adjusts 5 ms per second if the remaining time adjustment is
>= 1 s (0.5%) , else it adjusts by 0.5 ms as well. This allows adjusting
by (almost) 18 s per hour.

Since Serenity OS can lose more than 22 s per hour (#3429), this
picks an adjustment rate up to 1% for now. This allows us to
adjust up to 36s per hour, which should be sufficient to adjust
the clock fast enough to keep up with how much time the clock
currently loses. Once we have a fancier NTP implementation that can
adjust tick rate in addition to offset, we can think about reducing
this.

adjtime is a bit old-school and most current POSIX-y OSs instead
implement adjtimex/ntp_adjtime, but a) we have to start somewhere
b) ntp_adjtime() is a fairly gnarly API. OpenBSD's adjfreq looks
like it might provide similar functionality with a nicer API. But
before worrying about all this, it's probably a good idea to get
to a place where the kernel APIs are (barely) good enough so that
we can write an ntp service, and once we have that we should write
a way to automatically evaluate how well it keeps the time adjusted,
and only then should we add improvements ot the adjustment mechanism.
2020-11-10 19:03:08 +01:00
Lenny Maiorani d1fe6a0b53
Everywhere: Redundant inline specifier on constexpr functions (#3807)
Problem:
- `constexpr` functions are decorated with the `inline` specifier
  keyword. This is redundant because `constexpr` functions are
  implicitly `inline`.
- [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr
  functions and constexpr constructors are implicitly inline (7.1.2)".

Solution:
- Remove the redundant `inline` keyword.
2020-10-20 18:08:13 +02:00
Andreas Kling 65cdac1a5b Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
Linus Groh bcfc6f0c57 Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
Ben Wiederhake 64cc3f51d0 Meta+Kernel: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Nico Weber b36a2d6686 Kernel+LibC+UserspaceEmulator: Mostly add recvmsg(), sendmsg()
The implementation only supports a single iovec for now.
Some might say having more than one iovec is the main point of
recvmsg() and sendmsg(), but I'm interested in the control message
bits.
2020-09-17 17:23:01 +02:00
Tom c8d9f1b9c9 Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps
for us, we don't really need to attempt to do this. Doing it
ourselves doesn't really work very reliably, because we'd have to
account for other processors modifying virtual memory, and we'd
have to account for e.g. pages not being able to be allocated
due to insufficient resources.

So change the copy_to/from_user (and associated helper functions)
to use the new safe_memcpy, which will return whether it succeeded
or not. The only manual validation step needed (which the CPU
can't perform for us) is making sure the pointers provided by user
mode aren't pointing to kernel mappings.

To make it easier to read/write from/to either kernel or user mode
data add the UserOrKernelBuffer helper class, which will internally
either use copy_from/to_user or directly memcpy, or pass the data
through directly using a temporary buffer on the stack.

Last but not least we need to keep syscall params trivial as we
need to copy them from/to user mode using copy_from/to_user.
2020-09-13 21:19:15 +02:00
Andreas Kling 57dd3b66c5 Kernel+LibC+UE: Implement sleep() via sys$clock_nanosleep()
This doesn't need to be its own syscall either. :^)
2020-08-30 13:21:24 +02:00
Andreas Kling f857f3ce4c Kernel+LibC+UE: Implement usleep() via sys$clock_nanosleep()
This doesn't need to be its own syscall. Thanks @BenWiederhake for
the idea. :^)
2020-08-30 10:45:51 +02:00
Brian Gianforcaro 8e97de2df9 Kernel: Use Userspace<T> for the recvfrom syscall, and Socket implementation
This fixes a bunch of unchecked kernel reads and writes, seems like they
would might exploitable :). Write of sockaddr_in size to any address you
please...
2020-08-19 21:05:28 +02:00
Brian Gianforcaro 9f9b05ba0f Kernel: Use Userspace<T> for the sendto syscall, and Socket implementation
Note that the data member is of type ImmutableBufferArgument, which has
no Userspace<T> usage. I left it alone for now, to be fixed in a future
change holistically for all usages.
2020-08-19 21:05:28 +02:00
Nico Weber 430b265cd4 AK: Rename KB, MB, GB to KiB, MiB, GiB
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
2020-08-16 16:33:28 +02:00
Andreas Kling 65f2270232 Kernel+LibC+UserspaceEmulator: Bring back sys$dup2()
This is racy in userspace and non-racy in kernelspace so let's keep
it in kernelspace.

The behavior change where CLOEXEC is preserved when dup2() is called
with (old_fd == new_fd) was good though, let's keep that.
2020-08-15 11:11:34 +02:00
Andreas Kling bf247fb45f Kernel+LibC+UserspaceEmulator: Remove sys$dup() and sys$dup2()
We can just implement these in userspace, so yay two less syscalls!
2020-08-15 01:30:22 +02:00
Ben Wiederhake 2b76f48a17 Kernel: Avoid linking errors when calling Kernel API
The compiler can't see that the definitions inside the .h file aren't meant to be
public symbols. So in a hypothetical program which uses the Kernel API, each(\!)
compilation unit that includes FB.h would define those fb_get_size_in_bytes symbols.
If that happens twice or more times, that would cause linker errors.

Since the functions are very short, inlining them seems like a good idea.

Also, using FB.h should be possible even if the containing compilation unit
doesn't already define size_t, so I added that header (stddef), too.
2020-08-12 20:40:59 +02:00
Andreas Kling 797904bafd Kernel: Forward declare struct stat in the syscall API header 2020-08-11 20:29:14 +02:00
Brian Gianforcaro 0f42463eab Kernel: Use Userspace<T> for the execve syscall 2020-08-10 12:52:15 +02:00
Ben Wiederhake bee08a4b9f Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
Brian Gianforcaro 30b2c0dc85 Kernel: Use Userspace<T> for the getsockopt syscall and Socket interface
The way getsockopt is implemented for socket types requires us to push
down Userspace<T> using into those interfaces. This change does so, and
utilizes proper copy implementations instead of the kind of haphazard
pointer dereferencing that was occurring there before.
2020-08-07 16:18:36 +02:00
Brian Gianforcaro 6920d5f423 Kernel: Use Userspace<T> for the setsockopt syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro 8fa46bcb7d Kernel: Use Userspace<T> for the getsockname syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro dc75ea9fc2 Kernel: Use Userspace<T> for the getpeername syscall 2020-08-07 16:18:36 +02:00
Valtteri Koskivuori 00a0e525e6 Kernel+LibKeyboard: Store the keymap name when setting system keymap
This way we can query the kernel to see which keymap is currently in use.
2020-08-06 17:45:06 +02:00
Brian Gianforcaro 7e6fbef8db Kernel: Partial usage of Userspace<T> for the poll syscall
This change mostly converts poll to Userspace<T> with the caveat
of the fds member of SC_poll_params. It's current usage is a bit
too gnarly for me to take on right now, this appears to need a lot
more love.

In addition to enlightening the syscall to use Userspace<T>, I've
also re-worked most of the handling to use validate_read_and_copy
instead of just directly de-referencing the user pointer. We also
appeared to be missing a re-evaluation of the fds array after the
thread block is awoken.
2020-08-06 10:22:44 +02:00
Brian Gianforcaro fa666f6897 Kernel: Use Userspace<T> for the futex syscall
Utilizie Userspace<T> for the syscall argument itself, as well
as internally in the SC_futex_params struct.

We were double validating the SC_futex_params.timeout validation,
that was removed as well.
2020-08-05 13:03:50 +02:00
Brian Gianforcaro 7490ea9449 Kernel + LibPthread: Use Userspace<T> in the create_thread syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro 74d3b202f1 Kernel: Use Userspace<T> for the waitid syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro 84035e1035 Kernel: Use Userspace<T> for the clock_nanosleep syscall 2020-08-05 09:36:53 +02:00
Andreas Kling 58feebeed2 Kernel+LibC: Tidy up sys$ttyname() and sys$ptsname()
- Remove goofy _r suffix from syscall names.
- Don't take a signed buffer size.
- Use Userspace<T>.
- Make TTY::tty_name() return a String instead of a StringView.
2020-08-04 18:17:16 +02:00
Andreas Kling 7de831efc6 Kernel+LibC: Add sys$disown() for disowning child processes
This syscall allows a parent process to disown a child process, setting
its parent PID to 0.

Unparented processes are automatically reaped by the kernel upon exit,
and no sys$waitid() is required. This will make it much nicer to do
spawn-and-forget which is common in the GUI environment.
2020-08-04 18:17:16 +02:00
Andreas Kling 83a4fbf548 Kernel: Tidy up the syscalls list by reorganizing the enumerator macro 2020-08-04 18:17:16 +02:00
Brian Gianforcaro ba4cf59d04 Kernel: Use Userspace<T> in setkeymap syscall 2020-08-02 10:56:33 +02:00
Brian Gianforcaro 1209bf82c1 Kernel: Use Userspace<T> in ptrace syscall 2020-08-02 00:29:04 +02:00
Andreas Kling 314dbc10d4 Kernel: Use Userspace<T> for sys$read() and sys$stat()
Add validation helper overloads as needed.
2020-07-31 16:28:37 +02:00
Andreas Kling b5f54d4153 Kernel+LibC: Add sys$set_process_name() for changing the process name 2020-07-27 19:10:18 +02:00
Nico Weber 4eb967b5eb LibC+Kernel: Start implementing sysconf
For now, only the non-standard _SC_NPROCESSORS_CONF and
_SC_NPROCESSORS_ONLN are implemented.

Use them to make ninja pick a better default -j value.
While here, make the ninja package script not fail if
no other port has been built yet.
2020-07-15 00:07:20 +02:00
Andreas Kling 11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00