Commit Graph

3261 Commits

Author SHA1 Message Date
Brian Gianforcaro
c8ae244ab8 Kernel: Use Userspace<T> for the shbuf_get syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
e073f2b59e Kernel: Use Userspace<T> for the get_thread_name syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
9652b0ae2b Kernel: Use Userspace<T> for the set_thread_name syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
0e20a6df0a Kernel: Use Userspace<T> for the connect syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
8bd9dbc220 Kernel: Use Userspace<T> for the accept syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
02660b5d60 Kernel: Use Userspace<T> for the bind syscall, and implementation 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
2bac7190c8 Kernel: Use Userspace<T> for the chmod syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
82bf6e8133 Kernel: Use Userspace<T> for the umount syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
317800324c Kernel: Use Userspace<T> for the unlink syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
ecfe20efd2 Kernel: Use Userspace<T> for the sigpending syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
fbb26b28b9 Kernel: Use Userspace<T> for the sigprocmask syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
431145148e Kernel: Use Userspace<T> for the fstat syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
8dd78201a4 Kernel: Use Userspace<T> for the uname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
cfedd62b5c Kernel: Use Userspace<T> for the sethostname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
1d9554f470 Kernel: Use Userspace<T> for the gethostname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
b069d757a3 Kernel: Use Userspace<T> for the clock_settime syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
1be6145fdf Kernel: Modifiy clock_settime timespec argument to const
The timeppec paramter is read only, and should be const.
2020-08-10 12:52:15 +02:00
Brian Gianforcaro
b4d04fd8d1 Kernel: Use Userspace<T> for the clock_gettime syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
48d9f3c2e6 Kernel: Use Userspace<T> for the getresgid syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
3ca18a88d7 Kernel: Use Userspace<T> for the getresuid syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
7943655838 Kernel: Use Userspace<T> for the times syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
e7728ca8fd Kernel: Use Userspace<T> for the getgroups syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
80011cd62d Kernel: Use Userspace<T> for the setgroups syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
0f42463eab Kernel: Use Userspace<T> for the execve syscall 2020-08-10 12:52:15 +02:00
Ben Wiederhake
083671ef2c Kernel: Fix PID/TID confusion in send_signal
This fixes the issue of a specific type of unkillable processes.
2020-08-10 11:51:45 +02:00
Ben Wiederhake
bee08a4b9f Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
Ben Wiederhake
7bdf54c837 Kernel: PID/PGID typing
This compiles, and fixes two bugs:
- setpgid() confusion (see previous commit)
- tcsetpgrp() now allows to set a non-empty process group even if
  the group leader has already died. This makes Serenity slightly
  more POSIX-compatible.
2020-08-10 11:51:45 +02:00
Ben Wiederhake
f5744a6f2f Kernel: PID/TID typing
This compiles, and contains exactly the same bugs as before.
The regex 'FIXME: PID/' should reveal all markers that I left behind, including:
- Incomplete conversion
- Issues or things that look fishy
- Actual bugs that will go wrong during runtime
2020-08-10 11:51:45 +02:00
Brian Gianforcaro
2eae70b097 Kernel: Mark MSIHandler as final 2020-08-10 09:57:50 +02:00
Nico Weber
0586924bbd LibELF+Lagom: Work towards getting LibELF in Lagom
Mostly -Wformat fixes, some of which pointed out real (if benign) bugs.
2020-08-09 21:12:54 +02:00
Benoît Lormeau
7b356c33cb
AK: Add a GenericLexer and extend the JsonParser with it (#2696) 2020-08-09 11:34:26 +02:00
Brian Gianforcaro
34dd8edcb3 Kernel: Decorate KResult and KResultOr<T> methods with [[nodiscard]]
This would have found my error propagation bug.
2020-08-09 00:13:39 +02:00
Brian Gianforcaro
fe64d97001 Kernel: Fix my result propagation bug @BenWiederhake spotted
In #3001 I was trying to fix result propagation issues, and
I actually just introduced another one. Luckily Ben spotted
it in the diff after it was in the tree, thanks Ben!
2020-08-09 00:13:39 +02:00
Brian Gianforcaro
35c745ca54 Kernel: Use Userspace<T> for the realpath syscall 2020-08-07 16:18:36 +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
Brian Gianforcaro
0db669a9d2 Kernel: Use Userspace<T> for the chown syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
7e7ee2ec94 Kernel: Use Userspace<T> for the mount syscall 2020-08-07 16:18:36 +02:00
Valtteri Koskivuori
471083ca3d ProcFS: Expose the current kernel keymap as /proc/keymap
Programs can now ask the kernel which keymap is in use by reading from /proc/keymap
2020-08-06 17:45:06 +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
Andreas Kling
3055f73d48 AK+Kernel+LibC: Add vdbgprintf()
This is like dbgprintf() except it takes a va_list instead of ...
2020-08-06 13:36:06 +02:00
Andreas Kling
ddab7ab693 Kernel: Store TTY's foreground process as a WeakPtr<Process>
This ensures that we don't leave a stale PGID assigned to the TTY after
the process exits, which would make PID recycling attacks possible.
2020-08-06 11:17:53 +02:00
AnotherTest
05972668d1 Kernel: Send a SIGCHLD to the parent upon suspension of a process
...that is controlling a TTY.
2020-08-06 10:35:22 +02:00
asynts
b3d1a05261 Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
This function did a const_cast internally which made the call side look
"safe". This method is removed completely and call sites are replaced
with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the
behaviour obvious.
2020-08-06 10:33:16 +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
Tom
41d2a0e9f7 Kernel: Dequeue dying threads from WaitQueue
If a thread is waiting but getting killed, we need to dequeue
the thread from the WaitQueue so that a potential wake before
finalization doesn't happen.
2020-08-06 10:02:55 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Brian Gianforcaro
f3cbb79f80 Kernel: Decorate KResult with [[nodiscard]] 2020-08-05 14:36:48 +02:00
Brian Gianforcaro
946c96dd56 Kernel: Suppress remaining unobserved KResult return codes
These are all cases where there is no clear and easy fix,
I've left FIXME bread crumbs so that these can hopefully
be fixed over time.
2020-08-05 14:36:48 +02:00
Brian Gianforcaro
d67069d922 Kernel: Propagate a few KResults properly in FileSystem subsystems
Propagating un-obsevered KResults up the stack.
2020-08-05 14:36:48 +02:00
Brian Gianforcaro
c4c6d9367d Kernel: Fix build break from missing KResult [[nodiscard]] suppressions
Missed this somehow in previous change.
2020-08-05 14:06:54 +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
ea3ee4f3f3 Kernel: Decorate KResultOr with [[nodiscard]] to catch misbehaving callers
The [[nodiscard]] decorator enables us to have the compile emit a
warning anytime the decorated type or function's return value isn't
observed. It's very useful for catching error checking bugs in systems
which use C style error handling.
2020-08-05 10:26:29 +02:00
Brian Gianforcaro
e8c9b5e870 Kernel: Make Inode::directory_entry_count errors observable.
Certain implementations of Inode::directory_entry_count were calling
functions which returned errors, but had no way of surfacing them.
Switch the return type to KResultOr<size_t> and start observing these
error paths.
2020-08-05 10:26:29 +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
337e8f98cd Kernel: Use Userspace<T> for the rename syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
c1541f4a61 Kernel: Use Userspace<T> for the mknod syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
d949b2a367 Kernel: Use Userspace<T> for the set_mmap_name syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
7449921f53 Kernel: Use Userspace<T> for the readlink syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
901dae0227 Kernel: Use Userspace<T> for the mmap 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
Brian Gianforcaro
baa070afb8 Kernel: Use Userspace<T> for the gettimeofday syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
1eeaed31c2 Kernel: Use Userspace<T> for the open syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
f3eb7db422 Kernel: Switch IPv4Socket receive queue to SinglyLinkedListWithCount<T>
Avoid walking the packet queue, instead use a linked list with a count.
2020-08-05 09:34:22 +02:00
Andreas Kling
83e32788d5 Kernel: Send SIGTTIN and SIGTTOU signals on background TTY read/write
A process that is not in the foreground process group of a TTY should
not be allowed to read/write that TTY. Instead, we now send either a
SIGTTIN (on read) or SIGTTOU (on write) signal to the process, and fail
the I/O syscall with EINTR.

Fixes #205.
2020-08-04 21:25:44 +02:00
Andreas Kling
7a3ab6c517 Kernel: Make File::write() and File::read() return KResultOr<size_t>
Instead of returning a ssize_t where negative values mean error,
we now return KResultOr<size_t> and use the error state to report
errors exclusively.
2020-08-04 18:17:16 +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
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Andreas Kling
b139fb9f38 Kernel: Use Userspace<T> in sys$link() and sys$symlink() 2020-08-03 18:40:28 +02:00
Tom
f4a5c9b6c2 Kernel: Consolidate timeout logic
Allow passing in an optional timeout to Thread::block and move
the timeout check out of Thread::Blocker. This way all Blockers
implicitly support timeouts and don't need to implement it
themselves. Do however allow them to override timeouts (e.g.
for sockets).
2020-08-03 18:23:00 +02:00
Tom
c813bb7355 Kernel: Fix a few Thread::block related races
We need to have a Thread lock to protect threading related
operations, such as Thread::m_blocker which is used in
Thread::block.

Also, if a Thread::Blocker indicates that it should be
unblocking immediately, don't actually block the Thread
and instead return immediately in Thread::block.
2020-08-03 15:59:11 +02:00
Brian Gianforcaro
cb167ea388 Kernel: Use for-each loops in unveil syscall 2020-08-03 12:54:51 +02:00
Muhammad Zahalqa
615ba0f368
AK: Fix overflow and mixed-signedness issues in binary_search() (#2961) 2020-08-02 21:10:35 +02:00
Brian Gianforcaro
2242f69cd6 Kernel: Use Userspace<T> in unveil syscall 2020-08-02 20:54:17 +02:00
Brian Gianforcaro
9db5a1b92f Kernel: Use Userspace<T> in sched_getparam syscall 2020-08-02 20:53:48 +02:00
Tom
f011c420c1 Kernel: Fix signal delivery when no syscall is made
This fixes a regression introduced by the new software context
switching where the Kernel would not deliver a signal unless the
process is making system calls. This is because the TSS no longer
updates the CS value, so the scheduler never considered delivery
as the process always appeared to be in kernel mode. With software
context switching we can just set up the signal trampoline at
any time and when the processor returns back to user mode it'll
get executed. This should fix e.g. killing programs that are
stuck in some tight loop that doesn't make any system calls and
is only pre-empted by the timer interrupt.

Fixes #2958
2020-08-02 20:50:29 +02:00
Tom
538b985487 Kernel: Remove ProcessInspectionHandle and make Process RefCounted
By making the Process class RefCounted we don't really need
ProcessInspectionHandle anymore. This also fixes some race
conditions where a Process may be deleted while still being
used by ProcFS.

Also make sure to acquire the Process' lock when accessing
regions.

Last but not least, there's no reason why a thread can't be
scheduled while being inspected, though in practice it won't
happen anyway because the scheduler lock is held at the same
time.
2020-08-02 17:15:11 +02:00
Tom
5bbf6ed46b Kernel: Fix some crashes due to missing locks
We need to hold m_lock when accessing m_regions.
2020-08-02 17:15:11 +02:00
Tom
728de56481 Kernel: Prevent recursive calls into the scheduler
Upon leaving a critical section (such as a SpinLock) we need to
check if we're already asynchronously invoking the Scheduler.
Otherwise we might end up triggering another context switch
as soon as leaving the scheduler lock.

Fixes #2883
2020-08-02 17:15:11 +02:00
Andreas Kling
a19304c9d6 Kernel: Remove a bunch of duplicate forward declarations 2020-08-02 11:01:00 +02:00
Andreas Kling
e526fa572a Kernel: Convert some more syscalls to Userspace<T>
These are really straightforward when all the helpers just work.
2020-08-02 11:01:00 +02:00
Brian Gianforcaro
2a74c59dec Kernel: Use Userspace<T> in pledge syscall 2020-08-02 10:56:43 +02:00
Brian Gianforcaro
ba4cf59d04 Kernel: Use Userspace<T> in setkeymap syscall 2020-08-02 10:56:33 +02:00
Brian Gianforcaro
10e912d68c Kernel: Use Userspace<T> in sched_setparam syscall
Note: I switched from copying the single element out of the sched_param
struct, to copy struct it self as it is identical in functionality.
This way the types match up nicer with the Userpace<T> api's and it
conforms to the conventions used in other syscalls.
2020-08-02 10:55:38 +02:00
Brian Gianforcaro
1209bf82c1 Kernel: Use Userspace<T> in ptrace syscall 2020-08-02 00:29:04 +02:00
Andreas Kling
8d4d1c7457 Kernel: Use Userspace<T> in more syscalls 2020-08-01 11:37:40 +02:00
AnotherTest
1ad51325ad Kernel+LibC: Implement 'memmem'
This commit adds an implementation of memmem, using the Bitap text
search algorithm for needles smaller than 32 bytes, and a naive loop
search for longer needles.
2020-08-01 08:39:26 +02:00
etaIneLp
586ada7a14 Kernel: Tell the bootloader to put us into graphics mode 2020-08-01 07:57:29 +02:00
Andreas Kling
628b3badfb Kernel+AK: Add and use Userspace<T>::unsafe_userspace_ptr()
Since we already have the type information in the Userspace template,
it was a bit silly to cast manually everywhere. Just add a sufficiently
scary-sounding getter for a typed pointer.

Thanks @alimpfard for pointing out that I was being silly with tossing
out the type.

In the future we may want to make this API non-public as well.
2020-07-31 20:56:48 +02:00
Itamar
5cd7159629 Kernel: Add _SC_PAGESIZE to sysconf
This unbreaks the gcc and binutils ports.
Previously, when _SC_PAGESIZE was missing, these packages opted to
use their own versions of getpagesize which made their build fail
because of conflicting definitions of the function.
2020-07-31 18:26:33 +02:00
Andreas Kling
180207062c Kernel: Use Userspace<T> in sys$utime()
And again, another helper overload.
2020-07-31 16:38:47 +02:00
Andreas Kling
62a4099581 Kernel: Use Userspace<T> in sys$getcwd() and sys$chdir()
Add more validation helper overloads as we go. :^)
2020-07-31 16:34:47 +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
d19d6a63c6 Kernel: Add missing license headers to some syscall files 2020-07-31 01:01:41 +02:00
Andreas Kling
3023a89e9b Kernel: Remove SmapDisabler in sys$setsockopt() 2020-07-31 00:29:26 +02:00
Andreas Kling
292cd53192 Kernel: Remove SmapDisabler in sys$ioctl()
Use copy_{to,from}_user() in the various File::ioctl() implementations
instead of disabling SMAP wholesale in sys$ioctl().

This patch does not port IPv4Socket::ioctl() to those API's since that
will be more involved. That function now creates a local SmapDisabler.
2020-07-31 00:17:25 +02:00
Andreas Kling
be7add690d Kernel: Rename region_from_foo() => find_region_from_foo()
Let's emphasize that these functions actually go out and find regions.
2020-07-30 23:52:28 +02:00
Andreas Kling
2e2de125e5 Kernel: Turn Process::FileDescriptionAndFlags into a proper class 2020-07-30 23:50:31 +02:00
Andreas Kling
f2a152e930 Kernel: Simplify the ScopedSpinLock template
We can just templatize the LockType here. This makes my Qt Creator
syntax highlighting work again. :^)
2020-07-30 23:43:37 +02:00
Andreas Kling
949aef4aef Kernel: Move syscall implementations out of Process.cpp
This is something I've been meaning to do for a long time, and here we
finally go. This patch moves all sys$foo functions out of Process.cpp
and into files in Kernel/Syscalls/.

It's not exactly one syscall per file (although it could be, but I got
a bit tired of the repetitive work here..)

This makes hacking on individual syscalls a lot less painful since you
don't have to rebuild nearly as much code every time. I'm also hopeful
that this makes it easier to understand individual syscalls. :^)
2020-07-30 23:40:57 +02:00
Andreas Kling
027c450d6d Kernel: Run clang-format on Scheduler.cpp 2020-07-30 21:46:06 +02:00
Luke
98bea083c4 Kernel: Make BXVGA detection actually detect VBoxVGA
I decided to play around with trying to run Serenity in VirtualBox.
It crashed WindowServer with a beautiful array of multi-color
flashing letters :^)

Skipping getting side-tracked seeing that it chose MBVGA in the
serial debug and trying to debug why it caused such a display,
I finally checked BXVGA.

While find_framebuffer_address checks for VBoxVGA, init_stage2 didn't.
Whoops!
2020-07-30 17:01:41 +02:00
Andreas Kling
a2ad0ae5fc Net: Fix IPv4 fragmentation not working for larger payloads
We were masking the fragment offset bits incorrectly in the IPv4 header
sent out with fragments. This worked up to ~32KB but after that, things
would get very confused. :^)
2020-07-28 20:33:24 +02:00
Andreas Kling
f5ac4da993 Kernel: Use AK::Span a bunch in the network adapter code 2020-07-28 20:19:22 +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
Andreas Kling
23082e528f Kernel: Support file-backed mmap() with non-zero offset
As it turns out, this works just fine and all we had to do was remove
the assertion! :^)

Fixes #2597.
2020-07-27 00:31:24 +02:00
Andreas Kling
fe6474e692 Kernel: Switch to using AK::is and AK::downcast 2020-07-26 17:51:00 +02:00
asynts
707d92db61 Refactor: Change the AK::binary_search signature to use AK::Span. 2020-07-26 16:49:06 +02:00
Ben Wiederhake
d8c8820ee9 Kernel: Allow Thread::sleep for more than 388 days
Because Thread::sleep is an internal interface, it's easy to check that there
are only few callers: Process::sys$sleep, usleep, and nanosleep are happy
with this increased size, because now they support the entire range of their
arguments (assuming small-ish values for ticks_per_second()).
SyncTask doesn't care.

Note that the old behavior wasn't "cap out at 388 days", which would have been
reasonable. Instead, the code resulted in unsigned overflow, meaning that a
very long sleep would "on average" end after about 194 days, sometimes much
quicker.
2020-07-25 20:21:25 +02:00
Ben Wiederhake
76c135ddcf Kernel: Make clock_nanosleep aware of dynamic tick length
On my system, ticks_per_second() returns 1280.
So Serenity was very fast at sleeping! :P
2020-07-25 20:21:25 +02:00
Ben Wiederhake
4a5a7b68eb Kernel: Make usleep aware of dynamic tick length
On my system, ticks_per_second() returns 1280.
So Serenity was always 20% too fast when sleeping!
2020-07-25 20:21:25 +02:00
Ben Wiederhake
b3472cb4a7 Kernel: Allow process creation during low-entropy condition
Fixes #2871.

Ignoring the 'securely generated bytes' constraint seems to
be fine for Linux, so it's probably fine for Serenity.

Note that there *might* be more bottlenecks down the road
if Serenity is started in a non-GUI way. Currently though,
loading the GUI seems to generate enough interrupts to
seed the entropy pool, even on my non-RDRAND setup. Yay! :^)
2020-07-25 12:34:30 +02:00
Peter Elliott
d01eba6fa3 Kernel: Implement FIFOs/named pipes 2020-07-19 11:46:37 +02:00
Andreas Kling
8ec8ec8b1c Kernel: Remove special-casing of sys$gettid() in syscall entry
We had a fast-path for the gettid syscall that was useful before
we started caching the thread ID in LibC. Just get rid of it. :^)
2020-07-18 00:25:02 +02:00
Florian Angermeier
c969b8390d Kernel: Make all 6 VirtualConsoles available via shortcut
Add all 6 shortcuts even if the switch between VirtualConsoles is
currently not available in the graphical console.

Also make the case statement more compact.
2020-07-17 00:36:50 +02:00
Florian Angermeier
d8fa8c5f82 Kernel: Ensure there are all VirtualConsoles properly initialized
It is possible to switch to VirtualConsoles 1 to 4 via the shortcut
ALT + [1-4]. Therefor the array of VirtualConsoles should be guaranteed
to be initialized.

Also add an constant for the maximum number of VirtualConsoles to
guarantee consistency.
2020-07-17 00:36:50 +02:00
Florian Angermeier
971a42a816 Kernel: Make the VirtualConsole index const unsigned instead of unsigned
const:
The index should not be modified in the constructor to avoid unexpected
behavior
2020-07-17 00:36:50 +02:00
Andreas Kling
396291b356 Kernel: Fix crash on cat /proc/PID/vmobjects
A Region starts at an offset into a VMObject, and if that offset is
non-zero, we need to subtract it from the VMObject page index here.

Fixes #2803.
2020-07-15 16:22:16 +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
Linus Groh
fc0ec60d82 ProcFS: JSONify /proc/cpuinfo
To be more in line with other parts of Serenity's procfs, the
"key: value" format of /proc/cpuinfo was replaced with JSON, namely
an array of objects (one for each core).

The available keys remain the same, though "features" has been changed
from a space-separated string to an array of strings.
2020-07-11 23:16:16 +02:00
Peter Elliott
7a27fa3df8 LibC: Implement tcflush(3) 2020-07-11 11:33:33 +02:00
Tom
b02d33bd63 Kernel: Fix some flaws that caused crashes or hangs during boot
We need to halt the BSP briefly until all APs are ready for the
first context switch, but we can't hold the same spinlock by all
of them while doing so. So, while the APs are waiting on each other
they need to release the scheduler lock, and then once signaled
re-acquire it. Should solve some timing dependent hangs or crashes,
most easily observed using qemu with kvm disabled.
2020-07-09 23:24:55 +02:00
Tom
6df87b51f7
Kernel: Protect Inode list with SpinLock (#2748)
Fixes crashes when a context switch happens in the middle
of modifying it, or when another thread on another processor
modifies it at the same time.
2020-07-09 21:51:58 +02:00
Tom
ce5ae83963 Kernel: Detect syscall/sysenter support 2020-07-08 23:47:36 +02:00
Tom
419703a1f2 Kernel: Fix checking BlockResult
We now have BlockResult::WokeNormally and BlockResult::NotBlocked,
both of which indicate no error. We can no longer just check for
BlockResult::WokeNormally and assume anything else must be an
interruption.
2020-07-07 15:46:58 +02:00
Andrew Kaster
f96b827990 Kernel+LibELF: Expose ELF Auxiliary Vector to Userspace
The AT_* entries are placed after the environment variables, so that
they can be found by iterating until the end of the envp array, and then
going even further beyond :^)
2020-07-07 10:38:54 +02:00
Tom
06d50f64b0 Kernel: Aggregate TLB flush requests for Regions for SMP
Rather than sending one TLB flush request for each page,
aggregate them so that we're not spamming the other
processors with FlushTLB IPIs.
2020-07-06 22:39:06 +02:00
Tom
655f4daeb1 Kernel: Minor MM optimization for SMP
MemoryManager::quickmap_pd and MemoryManager::quickmap_pt can only
be called by one processor at the time anyway, since anything using
these must have the MM lock held. So, no need to inform the other
CPUs to flush their TLBs, we can just flush our own.
2020-07-06 17:17:24 +02:00
Tom
bc107d0b33 Kernel: Add SMP IPI support
We can now properly initialize all processors without
crashing by sending SMP IPI messages to synchronize memory
between processors.

We now initialize the APs once we have the scheduler running.
This is so that we can process IPI messages from the other
cores.

Also rework interrupt handling a bit so that it's more of a
1:1 mapping. We need to allocate non-sharable interrupts for
IPIs.

This also fixes the occasional hang/crash because all
CPUs now synchronize memory with each other.
2020-07-06 17:07:44 +02:00
Andreas Kling
e83c36d053 Kernel: Tidy up SpinLock and related classes a little bit 2020-07-06 11:36:07 +02:00
Andreas Kling
163c9d5f8f Kernel: Thread::wait_on() must always leave interrupts enabled on exit
The short-circuit path added for waiting on a queue that already had a
pending wake was able to return with interrupts disabled, which breaks
the API contract of wait_on() always returning with IF=1.

Fix this by adding a way to override the restored IF in ScopedCritical.
2020-07-06 11:33:32 +02:00
Andreas Kling
3e0020e67d Kernel: Tidy up the ScopedCritical class a little bit 2020-07-06 11:33:32 +02:00
Tom
9725bda63e Kernel: Enhance WaitQueue to remember pending wakes
If WaitQueue::wake_all, WaitQueue::wake_one, or WaitQueue::wake_n
is called but nobody is currently waiting, we should remember that
fact and prevent someone from waiting after such a request. This
solves a race condition where the Finalizer thread is notified
to finalize a thread, but it is not (yet) waiting on this queue.

Fixes #2693
2020-07-06 10:00:24 +02:00
Tom
2a82a25fec Kernel: Various context switch fixes
These changes solve a number of problems with the software
context swithcing:

* The scheduler lock really should be held throughout context switches
* Transitioning from the initial (idle) thread to another needs to
  hold the scheduler lock
* Transitioning from a dying thread to another also needs to hold
  the scheduler lock
* Dying threads cannot necessarily be finalized if they haven't
  switched out of it yet, so flag them as active while a processor
  is running it (the Running state may be switched to Dying while
  it still is actually running)
2020-07-06 10:00:24 +02:00
Tom
49f5069b76 Kernel: Add a SpinLock to the WaitQueue
We need to be able to prevent a WaitQueue from being
modified by another CPU. So, add a SpinLock to it.

Because this pushes some other class over the 64 byte
limit, we also need to add another 128-byte bucket to
the slab allocator.
2020-07-06 10:00:24 +02:00
Tom
788b2d64c6 Kernel: Require a reason to be passed to Thread::wait_on
The Lock class still permits no reason, but for everything else
require a reason to be passed to Thread::wait_on. This makes it
easier to diagnose why a Thread is in Queued state.
2020-07-06 10:00:24 +02:00
Sergey Bugaev
a8489967a3 Kernel: Add Plan9FS :^)
This is an (incomplete, and not very stable) implementation of the client side
of the 9P protocol.
2020-07-05 12:26:27 +02:00
Sergey Bugaev
187b785a05 Kernel: Split BlockBasedFileSystem off FileBackedFileSystem
FileBackedFileSystem is one that's backed by (mounted from) a file, in other
words one that has a "source" of the mount; that doesn't mean it deals in
blocks. The hierarchy now becomes:

* FS
  * ProcFS
  * DevPtsFS
  * TmpFS
  * FileBackedFS
    * (future) Plan9FS
    * BlockBasedFS
      * Ext2FS
2020-07-05 12:26:27 +02:00
Sergey Bugaev
0c72a9eda7 Kernel: Fix .. directory entry at mount point handling a little
It's still broken, but at least it now appears to work if the file system
doesn't return the same inode for "..".
2020-07-05 12:26:27 +02:00
Sergey Bugaev
3645b9e2a6 Kernel: Make sure to drop region with interrupts enabled
A region can drop an inode if it was mmaped from the inode and held the last
reference to it, and that may require some locking.
2020-07-05 12:26:27 +02:00
Sergey Bugaev
6111cfda73 AK: Make Vector::unstable_remove() return the removed value
...and rename it to unstable_take(), to align with other take...() methods.
2020-07-05 12:26:27 +02:00
Sergey Bugaev
63f458ffc1 Kernel: Fix KBufferBuilder::append()
insertion_ptr() already includes the offset.
2020-07-05 12:26:27 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Andreas Kling
0d577ab781 Kernel: Add "child added" and "child removed" InodeWatcher events
The child name is not yet accessible to userspace, but will be in a
future patch.
2020-07-04 13:37:51 +02:00
Andreas Kling
ea17d2d3da Kernel: Remove debug spam in finalizer task 2020-07-04 13:00:48 +02:00
AnotherTest
9609539236 Kernel: Change the value of SO_KEEPALIVE to reflect LibC's constant
This change was partially introduced in 861eb8d, which changed the
constant in LibC without changing the one in the kernel.
2020-07-04 10:49:36 +02:00
Tom
0f2530524e Kernel: Remove /proc/PID/regs
There isn't an easy way to retreive all register contents anymore,
so remove this functionality. We do have the ability to trace
processes, so it shouldn't really be needed anymore.
2020-07-03 21:16:56 +02:00
Tom
bb84fad0bf Kernel: Fix retreiving frame pointer from a thread
If we're trying to walk the stack for another thread, we can
no longer retreive the EBP register from Thread::m_tss. Instead,
we need to look at the top of the kernel stack, because all threads
not currently running were last in kernel mode. Context switches
now always trigger a brief switch to kernel mode, and Thread::m_tss
only is used to save ESP and EIP.

Fixes #2678
2020-07-03 21:16:56 +02:00
Nico Weber
cbbd55bd6b LibC: Remove a few comments now that we have man pages for this. 2020-07-03 19:37:28 +02:00
Tom
9b4e6f6a23 Kernel: Consolidate features into CPUFeature enum
This allows us to consolidate printing out all the CPU features
into one log statement. Also expose them in /proc/cpuinfo
2020-07-03 19:32:34 +02:00
Tom
e373e5f007 Kernel: Fix signal delivery
When delivering urgent signals to the current thread
we need to check if we should be unblocked, and if not
we need to yield to another process.

We also need to make sure that we suppress context switches
during Process::exec() so that we don't clobber the registers
that it sets up (eip mainly) by a context switch. To be able
to do that we add the concept of a critical section, which are
similar to Process::m_in_irq but different in that they can be
requested at any time. Calls to Scheduler::yield and
Scheduler::donate_to will return instantly without triggering
a context switch, but the processor will then asynchronously
trigger a context switch once the critical section is left.
2020-07-03 19:32:34 +02:00
Tom
a308b176ce Kernel: Allow recursion when writing to the debug log
This allows printing in the case e.g. a page fault happens
during a log statement
2020-07-03 19:32:34 +02:00
Tom
3cc0e86cd8 Kernel: Change kmalloc lock to be recursive
If the heap code dumps a stack trace (e.g. out of memory) then
it may recursively call into it. Rather than deadlocking, allow
recursion.
2020-07-03 19:32:34 +02:00
Tom
57b61b2dde Kernel: Split initialization of Processor structure
We need to very early on initialize the Processor structure so
that we can use RecursiveSpinLock early on.
2020-07-03 19:32:34 +02:00
Andreas Kling
a98712035c Kernel: Fix non-blocking write() blocking instead of short-writing
If a partial write succeeded, we could then be in an unexpected state
where the file description was non-blocking, but we could no longer
write to it.

Previously, the kernel would block in that state, but instead we now
handle this as a proper short write and return the number of bytes
we were able to write.

Fixes #2645.
2020-07-03 13:54:18 +02:00
Andreas Kling
47f5b24cc8 Kernel: Remove no-longer-used GDT selector from Thread
Now that we use software context switching, each thread no longer has
its own GDT entry (yay!) so we can get rid of this Thread member. :^)
2020-07-02 21:50:42 +02:00
Emanuele Torre
aabb482d5c Meta: move Kernel/.bochsrc => Meta/bochsrc
The run script is not in Kernel/ anymore, let's move `.bochsrc` in Meta/
so that it can be used with the new build system.

Also make bochs use `grub_disk_image` instead of `_disk_image`
2020-07-01 12:53:39 +02:00
Tom
5674a77bd6 PATA: Ignore interrupts that weren't generated by the disk 2020-07-01 12:07:01 +02:00
Tom
a2fd824dff PATA: LBA48 uses 16 bit features register 2020-07-01 12:07:01 +02:00
Tom
96109e9776 Kernel: Boot all APS all the way into their own idle loop 2020-07-01 12:07:01 +02:00
Tom
691d767fba Kernel: Block initializing the Scheduler on the APs until the BSP initialized global data 2020-07-01 12:07:01 +02:00
Tom
2a38cc9a12 Kernel: Add a quickmap region for each processor
Threads need to be able to concurrently quickmap things.
2020-07-01 12:07:01 +02:00
Tom
d249b5df8f Kernel: Protect Console with SpinLock 2020-07-01 12:07:01 +02:00
Tom
16783bd14d Kernel: Turn Thread::current and Process::current into functions
This allows us to query the current thread and process on a
per processor basis
2020-07-01 12:07:01 +02:00
Tom
d99901660d Kernel/LibCore: Expose processor id where a thread last ran 2020-07-01 12:07:01 +02:00
Tom
d98edb3171 Kernel: List all CPUs in /proc/cpuinfo 2020-07-01 12:07:01 +02:00
Tom
fb41d89384 Kernel: Implement software context switching and Processor structure
Moving certain globals into a new Processor structure for
each CPU allows us to eventually run an instance of the
scheduler on each CPU.
2020-07-01 12:07:01 +02:00
Tom
10407061d2 PATA: Avoid double-preparing for irq 2020-07-01 12:07:01 +02:00
Tom
3ac6d31b45 Kernel: Serialize debug output 2020-07-01 12:07:01 +02:00
Peter Elliott
e1aef94a40 Kernel: Make Random work on CPUs without rdrand
- If rdseed is not available, fallback to rdrand.
- If rdrand is not available, block for entropy, or use insecure prng
  depending on if user wants fast or good random.
2020-06-27 19:40:33 +02:00
3541
4fa6301523 Kernel: Add g_cpu_supports_rdseed
CPUs which support RDRAND do not necessarily support RDSEED. This
introduces a flag g_cpu_supports_rdseed which is set appropriately
by CPUID. This causes Haswell CPUs in particular (and probably a lot
of AMD chips) to now fail to boot with #2634, rather than an illegal
instruction.

It seems like the KernelRng needs either an initial reseed call or
more random events added before the first call to get_good_random,
but I don't feel qualified to make that kind of change.
2020-06-27 12:57:03 +02:00
Peter Elliott
af0b2d1d86 Kernel: Harvest randomness from various drivers
Random now gets entropy from the following drivers:
- KeyboardDevice
- PATAChannel
- PS2MouseDevice
- E1000NetworkAdapter
- RTL8139NetworkAdapter

Of these devices,  PS2MouseDevice and PATAChannel provide the vast
majority of the entropy.
2020-06-25 21:05:40 +02:00
Peter Elliott
2e8cfe5435 LibCrypto: Add CTR cipher mode
Kernel: Changed fortuna implementation to use CTR mode instead of
manually implementing a counter.
2020-06-25 21:05:40 +02:00
Peter Elliott
0f32155fa4 Kernel: Replace existing random implementation with Fortuna 2020-06-25 21:05:40 +02:00
Peter Elliott
f2d51f13a6 Kernel: Implement the Fortuna PRNG algorithm 2020-06-25 21:05:40 +02:00
Sergey Bugaev
6efbbcd4ba Kernel: Port mounts to reference inodes directly
...instead of going through their identifiers. See the previous commit for
reasoning.
2020-06-25 15:49:04 +02:00
Sergey Bugaev
df66c28479 Kernel: Deemphasize inode identifiers
These APIs were clearly modeled after Ext2FS internals, and make perfect sense
in Ext2FS context. The new APIs are more generic, and map better to the
semantics exported to the userspace, where inode identifiers only appear in
stat() and readdir() output, but never in any input.

This will also hopefully reduce the potential for races (see commit c44b4d61f3).

Lastly, this makes it way more viable to implement a filesystem that only
synthesizes its inodes lazily when queried, and destroys them when they are no
longer in use. With inode identifiers being used to reference inodes, the only
choice for such a filesystem is to persist any inode it has given out the
identifier for, because it might be queried at any later time. With direct
references to inodes, the filesystem will know when the last reference is
dropped and the inode can be safely destroyed.
2020-06-25 15:49:04 +02:00
Andreas Kling
28bfd73b68 Kernel: Minor cleanups in sendfd/recvfd
Applying some nice suggestions by @bugaevc. :^)
2020-06-25 10:58:37 +02:00
Andreas Kling
d4195672b7 Kernel+LibC: Add sys$recvfd() and sys$sendfd() for fd passing
These new syscalls allow you to send and receive file descriptors over
a local domain socket. This will enable various privilege separation
techniques and other good stuff. :^)
2020-06-24 23:08:09 +02:00
Nico Weber
d2684a8645 LibC+Kernel: Implement ppoll
ppoll() is similar() to poll(), but it takes its timeout
as timespec instead of as int, and it takes an additional
sigmask parameter.

Change the sys$poll parameters to match ppoll() and implement
poll() in terms of ppoll().
2020-06-23 14:12:20 +02:00
Andreas Kling
4dbbe1885f Kernel: Silence debug spam on exec 2020-06-22 21:18:25 +02:00
Andreas Kling
8a1dbe5483 Kernel: Silence some debug spam in Scheduler 2020-06-22 21:18:16 +02:00
Nico Weber
d23e655c83 LibC: Implement pselect
pselect() is similar() to select(), but it takes its timeout
as timespec instead of as timeval, and it takes an additional
sigmask parameter.

Change the sys$select parameters to match pselect() and implement
select() in terms of pselect().
2020-06-22 16:00:20 +02:00
Andreas Kling
8d6910b78e Kernel: Use map_typed() in HPET code and add a register access helper 2020-06-21 00:58:55 +02:00
Andreas Kling
37598de582 Kernel: Remove DMI decoder from the kernel
As suggested by @supercomputer7, we can simply expose this as a blob
and decode it in userspace instead.

Fixes #2599.
2020-06-20 18:39:46 +02:00
Nico Weber
dd53e070c5 Kernel+LibC: Remove setreuid() / setregid() again
It looks like they're considered a bad idea, so let's not add
them before we need them. I figured it's good to have them in
git history if we ever do need them though, hence the add/remove
dance.
2020-06-18 23:19:16 +02:00
Nico Weber
a38754d9f2 Kernel+LibC: Implement seteuid() and friends!
Add seteuid()/setegid() under _POSIX_SAVED_IDS semantics,
which also requires adding suid and sgid to Process, and
changing setuid()/setgid() to honor these semantics.

The exact semantics aren't specified by POSIX and differ
between different Unix implementations. This patch makes
serenity follow FreeBSD. The 2002 USENIX paper
"Setuid Demystified" explains the differences well.

In addition to seteuid() and setegid() this also adds
setreuid()/setregid() and setresuid()/setresgid(), and
the accessors getresuid()/getresgid().

Also reorder uid/euid functions so that they are the
same order everywhere (namely, the order that
geteuid()/getuid() already have).
2020-06-18 23:19:16 +02:00
Andreas Kling
0609eefd57 Kernel: Add "setkeymap" pledge promise 2020-06-18 22:19:36 +02:00
Andreas Kling
10fd862a55 Kernel: Unbreak sys$setkeymap()
This syscall was disabling SMAP too late and would crash every time
when trying to set a new keymap.
2020-06-17 20:32:53 +02:00
Nico Weber
662131bd38 Kernel: clang-format ENUMERATE_SYSCALLS 2020-06-17 18:48:40 +02:00
Andreas Kling
720825e3bd Kernel: Don't remove shbuf permission-to-reattach when releasing
The "Reference" object is not just a counter, it also represents the
permission to map a shbuf itself.

Without this change, a shbuf could not be re-mapped by the same
process after it released all of its refs on it.
2020-06-17 18:43:50 +02:00
Andreas Kling
723f4e5ee6 Meta: Scale back overly informal user-facing strings
We were getting a little overly memey in some places, so let's scale
things back to business-casual.

Informal language is fine in comments, commits and debug logs,
but let's keep the runtime nice and presentable. :^)
2020-06-17 18:35:49 +02:00
Sergey Bugaev
e0d0d52455 Kernel: Use symbolic constants for file modes
This fixes a bug where the mode of a FIFO was reported as 001000 instead
of 0010000 (you see the difference? me nethier), and hopefully doesn't
introduce new bugs. I've left 0777 and similar in a few places, because
that is *more* readable than its symbolic version.
2020-06-17 15:02:03 +02:00
Sergey Bugaev
47d83800e1 Kernel+LibC: Do not return -ENAMETOOLONG from sys$readlink()
That's not how readlink() is supposed to work: it should copy as many bytes
as fit into the buffer, and return the number of bytes copied. So do that,
but add a twist: make sys$readlink() actually return the whole size, not
the number of bytes copied. We fix up this return value in userspace, to make
LibC's readlink() behave as expected, but this will also allow other code
to allocate a buffer of just the right size.

Also, avoid an extra copy of the link target.
2020-06-17 15:02:03 +02:00
Hüseyin ASLITÜRK
00edc89288 Kernel: TTY:VirtualConsole, replace character attribute with code_point 2020-06-16 13:15:17 +02:00
Hüseyin ASLITÜRK
174987f930 Kernel: Replace char and u8 data types to u32 for code point
Remove character property from event and add code_point property.
2020-06-16 13:15:17 +02:00
Hüseyin ASLITÜRK
b4577ffcf3 Kernel: KeyboardDevice, remove char mapping logic
Remove char mapping logic and constant character map.
2020-06-13 12:36:30 +02:00
Hüseyin ASLITÜRK
f4d14c42d0 Kernel: Process, replace internal data type to CharacterMapData 2020-06-13 12:36:30 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Sergey Bugaev
31b025fcfc Kernel: Allow sys$accept(address = nullptr) 2020-06-09 21:12:34 +02:00
Tom
0bc92c259d Kernel: Detect APs and boot them into protected mode
This isn't fully working, the APs pretend like they're
fully initialized and are just halted permanently for now.
2020-06-04 18:15:23 +02:00
Tom
841364b609 Kernel: Add mechanism to identity map the lowest 2MB 2020-06-04 18:15:23 +02:00
Hüseyin ASLITÜRK
46b92fa173 Kernel: Add scancode value to KeyEvent 2020-06-03 21:52:40 +02:00
Sergey Bugaev
1e266aec27 Kernel: Always inline some KResult / KResultOr<> methods
Namely, those that contain assertions that can be easily eliminated at call site.
2020-06-02 21:49:47 +02:00
Sergey Bugaev
1b4e88fb59 Kernel: Allow File::close() to fail
And pass the result through to sys$close() return value.

Fixes https://github.com/SerenityOS/serenity/issues/427
2020-06-02 21:49:47 +02:00
Tom
b5f827d560 HPET: Fix accessing HPET registers
This resolves a bochs panic during bootup:

[Kernel]: HPET @ P0x07ff0fc0
00691951632p[HPET  ] >>PANIC<< Unsupported HPET read at address 0x0000fed00100

These changes however don't fully resolve #2162
2020-06-01 17:35:51 +02:00
Sergey Bugaev
05b7fec517 Kernel: Tighten up some promise checks
Since we're not keeping compatibility with OpenBSD about what promises are
required for which syscalls, tighten things up so that they make more sense.
2020-05-31 21:38:50 +02:00
Sergey Bugaev
a77405665f Kernel: Fix overflow in Process::validate_{read,write}_typed()
Userspace could pass us a large count to overflow the check. I'm not enough of a
haxx0r to write an actual exploit though.
2020-05-31 21:38:50 +02:00
Andreas Kling
ab40cc60d1 Kernel: Fix glitched audio output in SB16 driver
We were not setting the DMA transfer mode correctly. I have absolutely
no clue how this could ever have worked, but it did work for months
until it suddenly didn't.

Anyways, this fixes that. The sound is still a little bit glitchy and
that could probably be fixed by using the SB16's auto-initialized mode.
2020-05-31 03:40:58 +02:00
Andreas Kling
165f69023b LibVT: Allow updating the window progress via an escape sequence
You can now request an update of the terminal's window progress by
sending this escape sequence:

<esc>]9;<value>;<max_value>;<escape><backslash>

I'm sure we can find many interesting uses for this! :^)
2020-05-30 23:00:35 +02:00
Andreas Kling
1ef5d609d9 AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()
I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
2020-05-30 11:31:49 +02:00
Paul Redmond
4d4e578edf Ports: Fix CMake-based ports
The SDL port failed to build because the CMake toolchain filed pointed
to the old root. Now the toolchain file assumes that the Root is in
Build/Root.

Additionally, the AK/ and Kernel/ headers need to be installed in the
root too.
2020-05-29 20:21:10 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Sergey Bugaev
3847d00727 Kernel+Userland: Support remounting filesystems :^)
This makes it possible to change flags of a mount after the fact, with the
caveats outlined in the man page.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
d395b93b15 Kernel: Misc tweaks 2020-05-29 07:53:30 +02:00
Sergey Bugaev
53647e347f Kernel+Base: Mount root filesystem read-only :^)
We remount /home and /root as read-write, to keep the ability to modify files
there. /tmp remains read-write, as it is mounted from a TmpFS.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
fdb71cdf8f Kernel: Support read-only filesystem mounts
This adds support for MS_RDONLY, a mount flag that tells the kernel to disallow
any attempts to write to the newly mounted filesystem. As this flag is
per-mount, and different mounts of the same filesystems (such as in case of bind
mounts) can have different mutability settings, you have to go though a custody
to find out if the filesystem is mounted read-only, instead of just asking the
filesystem itself whether it's inherently read-only.

This also adds a lot of checks we were previously missing; and moves some of
them to happen after more specific checks (such as regular permission checks).

One outstanding hole in this system is sys$mprotect(PROT_WRITE), as there's no
way we can know if the original file description this region has been mounted
from had been opened through a readonly mount point. Currently, we always allow
such sys$mprotect() calls to succeed, which effectively allows anyone to
circumvent the effect of MS_RDONLY. We should solve this one way or another.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
b905126365 Kernel+LibC: Move O_* and MS_* flags to UnixTypes.h
That's where the other similar definitions reside. Also, use bit shift
operations for MS_* values.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
b6845de3f6 Kernel: Fix error case in Process::create_user_process()
If we fail to exec() the target executable, don't leak the thread (this actually
triggers an assertion when destructing the process), and print an error message.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
6627c3ea3a Kernel: Fix some failing assertions
When mounting Ext2FS, we don't care if the file has a custody (it doesn't if
it's a device, which is a common case). When doing a bind-mount, we do need a
custody; if none is provided, let's return an error instead of crashing.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
f945d7c358 Kernel: Always require read access when mmaping a file
POSIX says, "The file descriptor fildes shall have been opened with read
permission, regardless of the protection options specified."
2020-05-29 07:53:30 +02:00
Sergey Bugaev
6af2418de7 Kernel: Pass a Custody instead of Inode to VFS methods
VFS no longer deals with inodes in public API, only with custodies and file
descriptions. Talk directly to the file system if you need to operate on a
inode. In most cases you actually want to go though VFS, to get proper
permission check and other niceties. For this to work, you have to provide a
custody, which describes *how* you have opened the inode, not just what the
inode is.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
a9946a99f2 Kernel: Pass a FileDescription to File::chmod() and File::chown()
We're going to make use of it in the next commit. But the idea is we want to
know how this File (more specifically, InodeFile) was opened in order to decide
how chown()/chmod() should behave, in particular whether it should be allowed or
not. Note that many other File operations, such as read(), write(), and ioctl(),
already require the caller to pass a FileDescription.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
2d412c5ad1 Kernel: Report source of synthetic filesystems as "none"
As opposed to the fs name.

This matches the new convention we have for specifying it in mount(8).
2020-05-29 07:53:30 +02:00
Andreas Kling
d83d46fd7a Kernel: Remove outdated FIXME in InterruptManagement::locate_apic_data 2020-05-28 10:55:51 +02:00
etaIneLp
7bc871ca8d Kernel: Stop bootloader from setting video mode with Multiboot
Meta: Update INSTALL.md and grub configs for new boot_mode option
2020-05-28 00:50:55 +02:00
Sergey Bugaev
df128821b2 Kernel: Introduce "boot_mode" and "init" cmdline options
Together, they replace the old text_debug option.

* boot_mode should be either "graphical" (the default) or "text". We could
  potentially support other values here in the future.
* init specifies which userspace process the kernel should spawn to bootstrap
  userspace. By default, this is SystemServer, but you can specify e.g.
  init=/bin/Shell to run system diagnostics.
2020-05-27 11:19:38 +02:00
Sergey Bugaev
f11270e7ce Kernel: Port VirtualConsole to LibVT :^)
Unfortunately this drops the feature of preserving VGA buffer contents.

Resolves https://github.com/SerenityOS/serenity/issues/2399
2020-05-27 11:19:38 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Sergey Bugaev
cddaeb43d3 Kernel: Introduce "sigaction" pledge
You now have to pledge "sigaction" to change signal handlers/dispositions. This
is to prevent malicious code from messing with assertions (and segmentation
faults), which are normally expected to instantly terminate the process but can
do other things if you change signal disposition for them.
2020-05-26 14:35:10 +02:00
Angel
6137475c39 Kernel: fix assertion on readlink() syscall
The is_error() check on the KResultOr returned when reading the link
target had a stray ! operator which causes link resolution to crash the
kernel with an assertion error.
2020-05-26 12:45:01 +02:00
Brian Gianforcaro
6a74af8063 Kernel: Plumb KResult through FileDescription::read_entire_file() implementation.
Allow file system implementation to return meaningful error codes to
callers of the FileDescription::read_entire_file(). This allows both
Process::sys$readlink() and Process::sys$module_load() to return more
detailed errors to the user.
2020-05-26 10:15:40 +02:00
Brian Gianforcaro
c459e4ecb2 Kernel: Clang format file system in prep for changes. 2020-05-26 10:15:40 +02:00
etaIneLp
82d0352a67 Kernel: Unmap first MB after jumping above 3GB 2020-05-26 09:50:12 +02:00
etaIneLp
826dc94187 Kernel: Create page structures correctly in boot.s 2020-05-26 09:50:12 +02:00
Sergey Bugaev
431bbde6df Kernel: Fix returning random children from waitid(WNOHANG)
In case WNOHANG was specified, we want to always set should_unblock to
true (which we do since commit 4402207b98), not
wait_finished -- the latter causes us to immediately return this child to our
caller, which is not what we want -- perhaps we should return another child
which has actually exited or stopped, or nobody at all.

To avoid confusion, also rename wait_finished to fits_the_spec.

This fixes service keepalive functionality in SystemServer.
2020-05-25 12:38:37 +02:00
Andreas Kling
a75c290e51 Kernel: Use TypedMapping for accessing IOAPIC registers 2020-05-23 15:57:48 +02:00
Andreas Kling
e870b936c3 Kernel: Add non-const version of TypedMapping::operator->() 2020-05-23 15:57:19 +02:00
Andreas Kling
59a56a78c0 Kernel: Oops, we need to use map_typed_writable() for write access :^) 2020-05-23 15:50:50 +02:00
Andreas Kling
a04c8d7101 Kernel: Use TypedMappings when looking for APIC information 2020-05-23 15:46:56 +02:00
Andreas Kling
dd924b730a Kernel+LibC: Fix various build issues introduced by ssize_t
Now that ssize_t is derived from size_t, we have to
2020-05-23 15:27:33 +02:00
Andreas Kling
2fe6b3725a Kernel: Use TypedMappings in the very unfinished APIC code 2020-05-23 15:25:43 +02:00
Andreas Kling
1afbd8936a Kernel+LibC: Let's say that off_t is a ssize_t 2020-05-23 15:25:43 +02:00
Andreas Kling
d63b6287f5 Kernel: Add missing casts when calling AK::min() 2020-05-23 15:25:43 +02:00