Commit Graph

2900 Commits

Author SHA1 Message Date
Yonatan Goldschmidt
3a90a01dd4 Ext2FS: Fix indirect-blocks iteration
For singly-indirect blocks, "callback" is just "add_block".
For doubly-indirect blocks, "callback" is the lambda function
iterating on singly-indirect blocks: so instead of adding itself to the
list, the doubly-indirect block will add all its childs, but they add
themselves again when they run the callback of singly-indirect blocks.
And nothing adds the doubly-indirect block itself :(

This leads to a double free of all child blocks of the doubly-indirect
block, which is the failed assert described in #1549.

Closes: #1549.
2020-05-22 10:50:41 +02:00
Andreas Kling
57b86fd082 Kernel: Fix invalid jump in case RDRAND fails
If RDRAND doesn't give us data, we want to try again, not jump to some
low address like 0x80 :^)
2020-05-20 19:54:56 +02:00
Andreas Kling
0c5e441a0b Revert "Kernel: Add implementation of operator new and delete to kmalloc.cpp"
This reverts commit 6d0d848720.
2020-05-20 16:24:26 +02:00
Andreas Kling
21c3045c47 Revert "Kernel: Don't link against libstdc++"
This reverts commit bde7bc3472.
2020-05-20 16:24:26 +02:00
Andreas Kling
250c3b363d Revert "Build: Include headers from LibC, LibM, and LibPthread with -isystem"
This reverts commit c1eb744ff0.
2020-05-20 16:24:26 +02:00
Andreas Kling
81d35c6891 Kernel: Always inline stac(), clac() and SmapDisabler
Let's not be paying the function call overhead for these tiny ops.
Maybe there's an argument for having fewer gadgets in the kernel but
for now we're actually seeing stac() in profiles so let's put
that above theoretical security issues.
2020-05-20 14:17:01 +02:00
Sergey Bugaev
746db0bedb Kernel: Validate access to whole regions 2020-05-20 14:11:13 +02:00
Sergey Bugaev
0dd68a2949 Kernel: Look for a user region first
We're far more likely to be looking for a user region than otherwise, so
optimize for that case.
2020-05-20 14:11:13 +02:00
Sergey Bugaev
d2b500fbcb AK+Kernel: Help the compiler inline a bunch of trivial methods
If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
2020-05-20 14:11:13 +02:00
Andrew Kaster
c1eb744ff0 Build: Include headers from LibC, LibM, and LibPthread with -isystem
Make sure that userspace is always referencing "system" headers in a way
that would build on target :). This means removing the explicit
include_directories of Libraries/LibC in favor of having it export its
headers as SYSTEM. Also remove a redundant include_directories of
Libraries in the 'serenity build' part of the build script. It's already
set at the top.

This causes issues for the Kernel, and for crt0.o. These special cases
are handled individually.
2020-05-20 08:37:50 +02:00
Andrew Kaster
bde7bc3472 Kernel: Don't link against libstdc++
It has nothing we need anymore :^)
2020-05-20 08:37:50 +02:00
Andrew Kaster
6d0d848720 Kernel: Add implementation of operator new and delete to kmalloc.cpp
This was missing before, we were getting it for free from libstdc++
2020-05-20 08:37:50 +02:00
Sergey Bugaev
7541122206 Kernel+LibC: Switch isatty() to use a fcntl()
We would want it to work with only stdio pledged.
2020-05-20 08:31:31 +02:00
Sergey Bugaev
88e23113ae Kernel: Tweak FileBackedFS API to avoid intermediary copies
read_block() and write_block() now accept the count (how many bytes to read
or write) and offset (where in the block to start; defaults to 0). Using these
new APIs, we can avoid doing copies between intermediary buffers in a lot more
cases. Hopefully this improves performance or something.
2020-05-19 11:07:35 +02:00
Sergey Bugaev
de4b7d9c21 Kernel: Make FS::block_size a size_t 2020-05-19 11:07:35 +02:00
Sergey Bugaev
9cbdd5f01e Kernel: Inline Inode::fsid() 2020-05-19 11:07:35 +02:00
Andreas Kling
4402207b98 Kernel: WaitBlocker should always unblock immediately on WNOHANG
This fixes a problem where we'd block if a process with no children
would call sys$waitid() with WNOHANG. This unbreaks bash :^)
2020-05-18 13:07:20 +02:00
AnotherTest
8582a06899 Kernel + LibC: Handle running processes in do_waitid() 2020-05-17 11:58:08 +02:00
AnotherTest
9d54f21859 Kernel: wait() should not block if WNOHANG is specified 2020-05-17 11:58:08 +02:00
Andreas Kling
f7a75598bb Kernel: Remove Process::any_thread()
This was a holdover from the old times when each Process had a special
main thread with TID 0. Using it was a total crapshoot since it would
just return whichever thread was first on the process's thread list.

Now that I've removed all uses of it, we don't need it anymore. :^)
2020-05-16 12:40:15 +02:00
Andreas Kling
24d5855428 Kernel: Let the wait blocker inspect *all* child threads of a process
Previously would only grab the first thread in the thread list that
had the same PID as our waitee and check if it was stopped.
2020-05-16 12:38:24 +02:00
Andreas Kling
0e7f85c24a Kernel: Sending a signal to a process now goes to the main thread
Instead of falling back to the suspicious "any_thread()" mechanism,
just fail with ESRCH if you try to kill() a PID that doesn't have a
corresponding TID.
2020-05-16 12:33:48 +02:00
Andreas Kling
c9e38c5255 Kernel: Remove awkward "#define printf dbgprintf" 2020-05-16 12:03:25 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Andreas Kling
204fb27333 Kernel: Remove now-unused KernelInfoPage.h 2020-05-16 11:34:54 +02:00
Andreas Kling
2d35810e0a Kernel: Add TimeManagement::now_as_timeval()
Hide the implementation of time-of-day computation in TimeManagement.
2020-05-16 11:34:01 +02:00
Andreas Kling
2dc051c866 Kernel: Remove sys$getdtablesize()
I'm not sure why this was a syscall. If we need this we can add it in
LibC as a wrapper around sysconf(_SC_OPEN_MAX).
2020-05-16 11:34:01 +02:00
Andreas Kling
426c4e387d Kernel: Use copy_to_user() in sys$gettimeofday() 2020-05-16 11:34:01 +02:00
Andreas Kling
3a92d0828d Kernel: Remove the "kernel info page" used for fast gettimeofday()
We stopped using gettimeofday() in Core::EventLoop a while back,
in favor of clock_gettime() for monotonic time.

Maintaining an optimization for a syscall we're not using doesn't make
a lot of sense, so let's go back to the old-style sys$gettimeofday().
2020-05-16 11:33:59 +02:00
Andreas Kling
16c858d9f0 Kernel: Remove dubious use of "volatile" in E1000 adapter driver 2020-05-16 10:55:54 +02:00
Andreas Kling
03eb0e5638 Kernel: Let's say that IO::delay(N) delays for N microseconds
Supposedly that's how much delay you get when doing I/O on port 0x80.
2020-05-16 10:55:54 +02:00
Andreas Kling
85aafe492d Kernel: Remove dubious use of "volatile" in HPET code 2020-05-16 10:55:54 +02:00
Andreas Kling
ca4f714d68 Kernel: Use consistent names for kmalloc globals and remove volatile 2020-05-16 10:55:54 +02:00
Shannon Booth
2ffbdf5680 Toolchain/Ports: Update to gcc 10.1.0 2020-05-16 09:51:31 +02:00
Shannon Booth
113a95e9e1 Kernel: Annotate UnhandledInterruptHandler::eoi with [[noreturn]] 2020-05-16 09:51:31 +02:00
Shannon Booth
8c1b01e79b Kernel: Tidy up SharedBuffer interface
Make is_shared_with() const and hide private members.
2020-05-16 09:44:00 +02:00
Sergey Bugaev
752617cbb2 Kernel: Disallow opening socket files
You can still open files that have sockets attached to them from inside
the kernel via VFS::open() (and in fact, that is what LocalSocket itslef uses),
but trying to do that from userspace using open() will now fail with ENXIO.
2020-05-15 11:43:58 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Andreas Kling
415d6fb230 Revert "Build: Use fakeroot if non-root build is possible"
This reverts commit 3d342f72a7.

This is causing trouble for macOS users. Also it's painfully slow
compared to using the sudo method. This should definitely not be
the default since it punishes people who have genext2fs installed.
2020-05-13 01:18:14 +02:00
Andreas Kling
0ac9986c2f Kernel: Add a stringification helper for KeyCode 2020-05-12 17:02:20 +02:00
Nikolay Kochulin
3d342f72a7 Build: Use fakeroot if non-root build is possible
If genext2fs and fakeroot are installed, the build will no longer
require superuser privileges.
2020-05-12 10:22:46 +02:00
Yonatan Goldschmidt
c377e6af29 Ports: Add preliminary dropbear port
This is very basic and doesn't support many features. Instead
of describing what it *doesn't* support, I'll describe what I
have tested:
1. Public key authentication (password is not supported)
2. Single command execution
3. PTY-less interactive bash shell (/bin/sh doesn't work)
4. Multi-user (i.e you can ssh as 'anon' as well as root)
2020-05-11 09:50:42 +02:00
Yonatan Goldschmidt
107c83bd42 Kernel+LibC: Add AF_MAX
Will be updated as we add more protocols (e.g AF_INET6)
2020-05-11 09:50:42 +02:00
Linus Groh
d3d29ea1cc Demos: Add LibGfx Demo :^) 2020-05-10 13:34:59 +02:00
Linus Groh
f4153366b5 Kernel: Add missing copyright header to Ptrace.cpp 2020-05-09 23:45:16 +02:00
Nicholas Hollett
2708cc0f72 LaunchServer: Add the LaunchServer to centralise file associations.
Step one of moving DesktopServices::open handling out of process. This
makes it easier to do things like read in associations for which program
opens which files or protocols. This gives users the ability to modify
the associations without having to rebuild :^)
2020-05-09 15:12:56 +02:00
Andreas Kling
9c927538ad Kernel: ioctl(TCSETSF) on a TTY should flush input
This is where we end up when calling tcsetattr() with TCSAFLUSH.
This fixes vttest not accepting the first keystroke as input.
2020-05-09 12:30:51 +02:00
Andreas Kling
5bfd893292 Kernel+Userland: Add "settime" pledge promise for setting system time
We now require the "settime" promise from pledged processes who want to
change the system time.
2020-05-08 22:54:17 +02:00
Andreas Kling
1cddb1055f Kernel: Only allow superuser to call sys$clock_settime() 2020-05-08 22:47:21 +02:00
Andreas Kling
652b22ee9c Kernel: Remove SmapDisabler in sys$clock_settime() 2020-05-08 22:47:03 +02:00
Andreas Kling
85a3678b4f Kernel: Assert on startup if we don't find any physical pages
Instead of checking this on every page allocation, just check it once
on startup. :^)
2020-05-08 22:15:02 +02:00
Andreas Kling
55f61c0004 Kernel: Add for_each_vmobject_of_type<T>
This makes iterating over a specific type of VMObjects a bit nicer.
2020-05-08 22:10:47 +02:00
Andreas Kling
239fd33405 Services: Move Taskbar and SystemMenu from Applications to Services 2020-05-08 22:00:41 +02:00
Andreas Kling
cf3b58fbe8 Services: Renamed from Servers
It didn't feel right to have a "DHCPClient" in a "Servers" directory.
Rename this to Services to better reflect the type of programs we'll
be putting in there.
2020-05-08 21:57:44 +02:00
Andreas Kling
042b1f6814 Kernel: Propagate failure to commit VM regions in more places
Ultimately we should not panic just because we can't fully commit a VM
region (by populating it with physical pages.)

This patch handles some of the situations where commit() can fail.
2020-05-08 21:47:08 +02:00
Andreas Kling
c24304dca3 Kernel: Use NonnullRefPtrVector for HardwareTimer and HPETComparator 2020-05-08 21:22:58 +02:00
Andreas Kling
d92f62db43 Kernel: Remove ref-counting from interrupt override metadata
I don't see a reason for these to be reference-counted, and removing it
simplifies a bunch of surrounding data structures.
2020-05-08 21:12:16 +02:00
Andreas Kling
d74650e80d Kernel: Use NonnullRefPtrVector<T> instead of Vector<RefPtr<T>> some 2020-05-08 21:12:16 +02:00
Yonatan Goldschmidt
3df3ab4598 Build: Support building in Docker
Add missing installations to instructions, and use genext2fs instead
of mounting.
2020-05-07 10:23:26 +02:00
Andreas Kling
beaec6bd2d Kernel: Memory purging was incorrectly "purging" the shared zero page
This caused us to report one purged page per occurrence of the shared
zero page in a purgeable memory region, despite it being a no-op.

Thanks to Sergey for spotting the bad assertion removal that led to
this being found!
2020-05-07 09:44:41 +02:00
Andreas Kling
6fe83b0ac4 Kernel: Crash the current process on OOM (instead of panicking kernel)
This patch adds PageFaultResponse::OutOfMemory which informs the fault
handler that we were unable to allocate a necessary physical page and
cannot continue.

In response to this, the kernel will crash the current process. Because
we are OOM, we can't symbolicate the crash like we normally would
(since the ELF symbolication code needs to allocate), so we also
communicate to Process::crash() that we're out of memory.

Now we can survive "allocate 300 MB" (only the allocate process dies.)
This is definitely not perfect and can easily end up killing a random
innocent other process who happened to allocate one page at the wrong
time, but it's a *lot* better than panicking on OOM. :^)
2020-05-06 22:28:23 +02:00
Andreas Kling
c633c1c2ea Kernel: Assert on OOM in Region::commit()
This function has a lot of callers that don't bother checking if it
returns successfully or not. We'll need to handle failure in a bunch
of places and then we can remove this assertion.
2020-05-06 22:28:23 +02:00
Andreas Kling
43593455db Kernel: Don't assert on OOM in allocate_user_physical_page()
We now give callers a chance to react to OOM situations.
2020-05-06 22:28:23 +02:00
Andreas Kling
76dd1e3284 LibCore: Add a standard downloads directory (~/Downloads) 2020-05-05 23:56:57 +02:00
Nathan Lanza
f4e6c4c6f0
Kernel: Use Multiboot macros instead of magic constants (#2090)
MUTLIBOOT_FRAMEBUFFER_TYPE_{RGB,EGA_TEXT} are defined in the Multiboot.h
header. Use those definitions instead of hard-coding 1 and 2.
2020-05-04 09:52:04 +02:00
Ben Wiederhake
dce3faff08 Kernel: Don't crash on invalid fcntl 2020-05-03 22:46:28 +02:00
Michael Lelli
58a34fbe09
Kernel: Fix pledge syscall applying new pledges when it fails (#2076)
If the exec promises fail to apply, then the normal promises should
not apply either. Add a test for this fixed functionality.
2020-05-03 00:41:18 +02:00
Andreas Kling
b8f778a430 Demos: Add a little "Mouse" demo for showing mouse button states
This was very helpful when adding support for 5-button mice! :^)
2020-05-02 22:13:54 +02:00
Andreas Kling
c5882d3a18 Kernel: Detect 5-button PS/2 mouse if present :^)
The detection works very similarly to how we detect a mouse wheel, just
another magical sequence of "set sample rate" requests to the mouse
followed by an ID check.
2020-05-02 22:06:17 +02:00
Andreas Kling
888e35f0fe AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
2020-04-30 11:43:25 +02:00
Andreas Kling
51df4bdbfc DisplaySettings: Rename from DisplayProperties 2020-04-29 15:53:51 +02:00
Andreas Kling
385dacce05 Kernel: Fix integer overflow in framebuffer resolution handling
This made it possible to map the E1000 MMIO range into userspace and
mess with the registers.

Thanks to @grigoritchy for finding this!

Fixes #2015.
2020-04-29 09:37:36 +02:00
Andreas Kling
463c2e3768 Kernel: Be a little more defensive when indexing E1000 Rx/Tx buffers 2020-04-28 20:31:51 +02:00
Andreas Kling
4419685b7e Kernel: Leave VMObject alone on OOM during CoW fault
If we OOM during a CoW fault and fail to allocate a new page for the
writing process, just leave the original VMObject alone so everyone
else can keep using it.
2020-04-28 17:05:14 +02:00
Andreas Kling
9c856811b2 Kernel: Add Region helpers for accessing underlying physical pages
Since a Region is basically a view into a potentially larger VMObject,
it was always necessary to include the Region starting offset when
accessing its underlying physical pages.

Until now, you had to do that manually, but this patch adds a simple
Region::physical_page() for read-only access and a physical_page_slot()
when you want a mutable reference to the RefPtr<PhysicalPage> itself.

A lot of code is simplified by making use of this.
2020-04-28 17:05:14 +02:00
Brian Gianforcaro
49c438ce32 Kernel: Update TimerQueue next due timer only when necessary
Previously we blindly just called update_next_timer_due() when
ever we modified the timer list. Since we know the list is sorted
this is a bit wasteful, and we can do better.

This change refactors the code so we only update the next due time
when necessary. In places where it was possible the code was modified
to directly modify the next due time, instead of having to go to the
front of the list to fetch it.
2020-04-27 11:24:21 +02:00
Brian Gianforcaro
eeb5318c25 Kernel: Expose timers via a TimerId type
The public consumers of the timer API shouldn't need to know
the how timer id's are tracked internally. Expose a typedef
instead to allow the internal implementation to be protected
from potential churn in the future.

It's also just good API design.
2020-04-27 11:14:41 +02:00
Brian Gianforcaro
25a620a573 Kernel: Enable timeout support for sys$futex(FUTEX_WAIT)
Utilize the new Thread::wait_on timeout parameter to implement
timeout support for FUTEX_WAIT.

As we compute the relative time from the user specified absolute
time, we try to delay that computation as long as possible before
we call into Thread::wait_on(..). To enable this a small bit of
refactoring was done pull futex_queue fetching out and timeout fetch
and calculation separation.
2020-04-26 21:31:52 +02:00
Brian Gianforcaro
faf15e3721 Kernel: Add timeout support to Thread::wait_on
This change plumbs a new optional timeout option to wait_on.
The timeout is enabled by enqueing a timer on the timer queue
while we are waiting. We can then see if we were woken up or
timed out by checking if we are still on the wait queue or not.
2020-04-26 21:31:52 +02:00
Brian Gianforcaro
1d68837456 Kernel: Refactor TimeQueue::add_timer to use timeval
The current API of add_timer makes it hard to use as
you are forced to do a bunch of time arithmetic at the
caller. Ideally we would have overloads for common time
types like timespec or timeval to keep the API as straight
forward as possible. This change moves us in that direction.

While I'm here, we should really also use the machines actual
ticks per second, instead of the OPTIMAL_TICKS_PER_SECOND_RATE.
2020-04-26 21:31:52 +02:00
Andreas Kling
fb826aa59a Kernel: Make sys$sethostname() superuser-only
Also take the hostname string lock exclusively.
2020-04-26 15:51:57 +02:00
Luke Payne
f191b84b50 Kernel: Added the ability to set the hostname via new syscall
Userland/hostname: Now takes parameter to set the hostname
LibC/unistd: Added sethostname function
2020-04-26 12:59:09 +02:00
Brian Gianforcaro
0f3990cfa3 Kernel: Support signaling all processes with pid == -1
This is a special case that was previously not implemented.
The idea is that you can dispatch a signal to all other processes
the calling process has access to.

There was some minor refactoring to make the self signal logic
into a function so it could easily be easily re-used from do_killall.
2020-04-26 12:54:10 +02:00
Brian Gianforcaro
1f64e3eb16 Kernel: Implement FUTEX_WAKE of arbitrary count.
Previously we just woke all waiters no matter how many were
requested. Fix this by implementing WaitQueue::wake_n(..).
2020-04-26 12:35:35 +02:00
Drew Stratford
4a37362249 LibPthread: implicitly call pthread_exit on return from start routine.
Previously, when returning from a pthread's start_routine, we would
segfault. Now we instead implicitly call pthread_exit as specified in
the standard.

pthread_create now creates a thread running the new
pthread_create_helper, which properly manages the calling and exiting
of the start_routine supplied to pthread_create. To accomplish this,
the thread's stack initialization has been moved out of
sys$create_thread and into the userspace function create_thread.
2020-04-25 16:51:35 +02:00
Andreas Kling
2454c3b7fb Applications: Remove ChanViewer app
The HTTP JSON API this relied on is no longer available via HTTP and
I would rather make the website work in Browser anyway. :^)
2020-04-23 18:38:54 +02:00
Andreas Kling
bed0e6d250 Kernel: Make Process and Thread non-copyable and non-movable 2020-04-22 12:36:35 +02:00
Andreas Kling
50218f7edc Build: Use the GCC port if building on "SerenityOS" :^) 2020-04-20 19:52:35 +02:00
Itamar
edaa9c06d9 LibELF: Make ELF::Loader RefCounted 2020-04-20 17:25:50 +02:00
Andreas Kling
7eeea4d57f Kernel: rmdir("/") should fail instead of asserting
We can't assume there's always a parent custody -- when we open "/"
there isn't gonna be one!

Fixes #1858.
2020-04-19 18:07:16 +02:00
Brendan Coles
1c44ae6d19 Demos: Add Screensaver demo 2020-04-19 02:09:50 +02:00
Andreas Kling
dee5d8a047 Build: Make sure to create a /home/anon/Desktop directory 2020-04-18 22:07:15 +02:00
Andreas Kling
e3b450005f Kernel: Remove CommandLine::get() in favor of lookup()
lookup() returns an Optional<String> which allows us to implement easy
default values using lookup(key).value_or(default_value);
2020-04-18 14:22:42 +02:00
Sergey Bugaev
54550365eb Kernel: Use shared locking mode in some places
The notable piece of code that remains to be converted is Ext2FS.
2020-04-18 13:58:29 +02:00
Sergey Bugaev
05ba4295e9 Kernel: Introduce shared locking mode
A Lock can now be held either in shared or exclusive mode. Multiple threads can
hold the same lock in shared mode at one time, but if any thread holds the lock
in exclusive mode, no other thread can hold it at the same time in either mode.
2020-04-18 13:58:29 +02:00
Sergey Bugaev
2f15449531 Kernel: Compactify FileDescrption
The next commit is going to make it bigger again by increasing the size of Lock,
so make use of bitfields to make sure FileDescription still fits into 64 bytes,
and so can still be allocated with the SlabAllocator.
2020-04-18 13:58:29 +02:00
Stephan Unverwerth
1806592d58 Demos: Add 3D Cube Demo
This renders a spinning 3D cube and demonstrates the 3D math classes
from LibGfx.
2020-04-18 12:28:54 +02:00
Andreas Kling
905519bc76 Kernel: Fix dumb logic typo in HardwareTimer::handle_irq() 2020-04-16 18:53:38 +02:00
Andreas Kling
c891c87cb5 Kernel: Rename HardwareTimer::change_function() => set_callback()
Also make it non-virtual since nothing needs to override it.
2020-04-16 18:51:39 +02:00
Andreas Kling
b035267afa Kernel: Remove "stale callback" concept from time management
If a hardware timer doesn't have a callback registered, it's now simply
represented by a null m_callback.
2020-04-16 18:50:22 +02:00
Andreas Kling
4b1f056e3a Kernel: Rename HardwareTimer::m_function_to_call => m_callback 2020-04-16 18:49:20 +02:00
Andreas Kling
1e89f7d64e Kernel: Remove an unnecessary indirection between timer and scheduler
We don't need a wrapper Function object that just forwards the timer
callback to the scheduler tick function. It already has the same
signature, so we can just plug it in directly. :^)

Same with the clock updating function.
2020-04-16 18:49:20 +02:00
Andreas Kling
44d58b85ef Kernel: Simplify the way we pass HardwareTimers around a bit
Instead of passing around indices into the m_hardware_timers vector,
just pass around a HardwareTimer* instead.
2020-04-16 18:49:20 +02:00
Andreas Kling
fa40b725f9 Kernel: Refuse to set overflowy resolution values in BXVGADevice 2020-04-15 17:15:40 +02:00
Liav A
d6318f2cc6 Kernel: Ensure that we receive IRQs in PIO mode when IOAPIC is enabled
The IOAPIC manual states that "Interrupt Mask-R/W. When this bit is 1,
the interrupt signal is masked. Edge-sensitive interrupts signaled on
a masked interrupt pin are ignored." - Therefore we have to ensure that
we disable interrupts globally with cli(), but also to ensure that we
invoke enable_irq() before sending the hardware command that generates
an IRQ almost immediately.
2020-04-15 16:40:16 +02:00
Liav A
f5090ab810 Kernel: Restore ATA PIO functionality
First, before this change, specifying 'force_pio' in the kernel
commandline was meaningless because we nevertheless set the DMA flag to
be enabled.

Also, we had a problem in which we used IO::repeated_out16() in PIO
write method. This might work on buggy emulators, but I suspect that on
real hardware this code will fail.

The most difficult problem was to restore the PIO read operation.
Apparently, it seems that we can't use IO::repeated_in16() here because
it will read zeroed data. Currently we rely on a simple loop that
invokes IO::in16() to a buffer. Also, the interrupt handling stage in
the PIO read method is moved to be handled inside the loop of reading
the requested sectors.
2020-04-15 12:35:10 +02:00
Sergey Bugaev
f18d6610d3 Kernel: Don't include null terminator in sys$readlink() result
POSIX says, "Conforming applications should not assume that the returned
contents of the symbolic link are null-terminated."

If we do include the null terminator into the returning string, Python
believes it to actually be a part of the returned name, and gets unhappy
about that later. This suggests other systems Python runs in don't include
it, so let's do that too.

Also, make our userspace support non-null-terminated realpath().
2020-04-14 18:40:24 +02:00
Andreas Kling
815b73bdcc Kernel: Simplify sys$setgroups(0, ...)
If we're dropping all groups, just clear the extra_gids and return.
2020-04-14 15:30:25 +02:00
Andreas Kling
9962db5bf8 Kernel: Remove SmapDisablers in {peek,poke}_user_data() 2020-04-14 09:52:49 +02:00
Andreas Kling
0f760797a7 Kernel: Remove SmapDisablers in sys$ptrace() implementation
Instead, use copy_from_user() or copy_to_user() which does additional
verification and will panic the kernel on attempted kernel access.
2020-04-14 09:50:14 +02:00
Andreas Kling
0440f4f257 Kernel: Fix little mistakes in ptrace(PT_PEEK)
Output address validation should be done for the tracer's address space
and not the tracee's.

Also use copy_to_user() instead of copy_from_user(). The two are really
identical at the moment, but maybe we can add some assertions to make
sure we're doing what we think we're doing.

Thanks to Sergey for spotting these!
2020-04-14 09:45:04 +02:00
Itamar
d04409b444 CPU: Handle Debug exception
We currently only care about debug exceptions that are triggered
by the single-step execution mode.

The debug exception is translated to a SIGTRAP, which can be caught
and handled by the tracing thread.
2020-04-13 23:20:59 +02:00
Andreas Kling
c8edcf1d71 Kernel: Don't ignore validation result in ptrace(PT_PEEK)
Also mark all of the address validation functions [[nodiscard]] to turn
this kind of bug into a compile error in the future.
2020-04-13 22:40:38 +02:00
Andreas Kling
e432a27676 Kernel: Use copy_from_user() in ptrace(PT_PEEK) 2020-04-13 22:39:07 +02:00
Andreas Kling
1d43544e08 Kernel: Switch the first-8MB-of-upper-3GB pseudo mappings to 4KB pages
This memory range was set up using 2MB pages by the code in boot.S.
Because of that, the kernel image protection code didn't work, since it
assumed 4KB pages.

We now switch to 4KB pages during MemoryManager initialization. This
makes the kernel image protection code work correctly again. :^)
2020-04-13 22:35:37 +02:00
Itamar
3e9a7175d1 Debugger: Add DebugSession
The DebugSession class wraps the usage of Ptrace.
It is intended to be used by cli & gui debugger programs.

Also, call objdump for disassemly
2020-04-13 00:53:22 +02:00
Itamar
50fd2cabff ptrace: Report error in PT_PEEK via errno
The syscall wrapper for ptrace needs to return the peeked value when
using  PT_PEEK.
Because of this, the user has to check errno to detect an error in
PT_PEEK.

This commit changes the actual syscall's interface (only for PT_PEEK) to
allow the syscall wrapper to detect an error and change errno.
2020-04-13 00:53:22 +02:00
Itamar
aae3f7b914 Process: Fix siginfo for code CLD_STOPPED
si_code, si_status where swapped
2020-04-13 00:53:22 +02:00
Itamar
9e51e295cf ptrace: Add PT_SETREGS
PT_SETTREGS sets the regsiters of the traced thread. It can only be
used when the tracee is stopped.

Also, refactor ptrace.
The implementation was getting long and cluttered the alraedy large
Process.cpp file.

This commit moves the bulk of the implementation to Kernel/Ptrace.cpp,
and factors out peek & poke to separate methods of the Process class.
2020-04-13 00:53:22 +02:00
Itamar
0431712660 ptrace: Stop a traced thread when it exists from execve
This was a missing feature in the PT_TRACEME command.

This feature allows the tracer to interact with the tracee before the
tracee has started executing its program.

It will be useful for automatically inserting a breakpoint at a
debugged program's entry point.
2020-04-13 00:53:22 +02:00
Itamar
4568a628f9 Thread: Set m_blocker to null in Thread::unblock()
Before this commit, m_blocker was only set to null in Thread::block,
after the thread has been unblocked.

Starting with this commit, m_blocker is also set to null in
Thread::unblock.

This change will allow us to implement a missing feature of the PT_TRACE
command of the ptrace syscall - stopping the traced thread when it
exits the execve syscall.

That feature will be implemented by sending a blocking SIGSTOP to the
traced thread after it has executed the execve logic and before it
starts executing the new program in userspace.

However, since Process::exec arranges the tss to return to userspace
(the so-called "yield-teleport"), the code in Thread::block that should
be run after the thread unblocks, and sets m_blocker to null, never
actually runs.

Setting m_blocker to null in Thread::unblock allows us to avoid an
incorrect state where the thread is in a Running state but conatins a
pointer to a Blocker.
2020-04-13 00:53:22 +02:00
Itamar
b306ac9b2b ptrace: Add PT_POKE
PT_POKE writes a single word to the tracee's address space.

Some caveats:
- If the user requests to write to an address in a read-only region, we
temporarily change the page's protections to allow it.

- If the user requests to write to a region that's backed by a
SharedInodeVMObject, we replace the vmobject with a PrivateIndoeVMObject.
2020-04-13 00:53:22 +02:00
Itamar
984ff93406 ptrace: Add PT_PEEK
PT_PEEK reads a single word from the tracee's address space and returns
it to the tracer.
2020-04-13 00:53:22 +02:00
Itamar
77f671b462 CPU: Handle breakpoint trap
Also, start working on the debugger app.
2020-04-13 00:53:22 +02:00
Andreas Kling
c19b56dc99 Kernel+LibC: Add minherit() and MAP_INHERIT_ZERO
This patch adds the minherit() syscall originally invented by OpenBSD.
Only the MAP_INHERIT_ZERO mode is supported for now. If set on an mmap
region, that region will be zeroed out on fork().
2020-04-12 20:22:26 +02:00
Andreas Kling
93f2a4edd3 Kernel: Bump the max stack frame count in sample profiles to 50
Maybe this should be configurable, who knows. For now, 50 works a bit
better for highly nested scenarios like LibJS.
2020-04-12 11:00:38 +02:00
Peter Nelson
eff27f39d5
Kernel: Store previous thread state upon all transitions to Stopped (#1753)
We now store the previous thread state in m_stop_state for all
transitions to the Stopped state via Thread::set_state.

Fixes #1752 whereupon resuming a thread that was stopped with SIGTSTP,
the previous state of the thread is not remembered correctly, resulting
in m_stop_state == State::Invalid and the associated assertion fails.
2020-04-11 23:39:46 +02:00
Andrew Kaster
61acca223f LibELF: Move validation methods to their own file
These validate_elf_* methods really had no business being static
methods of ELF::Image. Now that the ELF namespace exists, it makes
sense to just move them to be free functions in the namespace.
2020-04-11 22:41:05 +02:00
Andrew Kaster
21b5909dc6 LibELF: Move ELF classes into namespace ELF
This is for consistency with other namespace changes that were made
a while back to the other libraries :)
2020-04-11 22:41:05 +02:00
Andreas Kling
b7ff3b5ad1 Kernel: Include the current instruction pointer in profile samples
We were missing the innermost instruction pointer when sampling.
This makes the instruction-level profile info a lot cooler! :^)
2020-04-11 21:04:45 +02:00
Brian Gianforcaro
7cc7d303e3 Kernel: Add $SERENITY_KERNEL_CUSTOM_{CXXFLAGS/LDFLAGS} for build customization
I normally want to build with debug symbols for the kernel so I can use
a debugger. Add a hook to allow me to do so, but to impact no-one else.
2020-04-11 10:03:19 +02:00
Linus Groh
b46a8d7335 MenuApplets: Rename CPUGraph to ResourceGraph
The plan is to extend what currently is known as "CPUGraph" and let the
SystemServer spawn multiple instances of it - which then can show memory
or network usages as well :^)

Simply renaming the applet is the first step.
2020-04-11 10:03:12 +02:00
Liav A
ea58563970 Kernel: Instantiate network adapters in their own detect() methods
This commit is one step forward for pluggable driver modules.
Instead of creating instances of network adapter classes, we let
their detect() methods to figure out if there are existing devices
to initialize.
2020-04-11 10:02:31 +02:00
Liav A
65f939b55c Kernel: Keep records of PCI::Address & PCI::ID pairs for enumeration 2020-04-11 10:02:31 +02:00
Liav A
688dd9ea66 Kernel: Simplify a message in PATAChannel::create() 2020-04-11 10:02:31 +02:00
Liav A
e9df6189f4 Kernel: Assert if we try to initialize VMWareBackdoor more than once 2020-04-11 10:02:31 +02:00
Andreas Kling
dec352dacd Kernel: Ignore zero-length PROGBITS sections in sys$module_load() 2020-04-10 16:36:01 +02:00
Andreas Kling
c06d5ef114 Kernel+LibC: Remove ESUCCESS
There's no official ESUCCESS==0 errno code, and it keeps breaking the
Lagom build when we use it, so let's just say 0 instead.
2020-04-10 13:09:35 +02:00
Conrad Pankoff
a3edeb5868 Kernel: Add explicit offset parameter to File::read etc 2020-04-10 11:59:30 +02:00
Liav A
1570e67881 Kernel: Allow again to boot with partitioned disk
This change ensures that we don't return a zero value blindly
from DiskPartition write/read methods.

Fixes #1719.
2020-04-09 23:43:30 +02:00
Liav A
9bb4a6ecf6 Kernel: Create BXVGA device if found in the PCI bus 2020-04-09 23:43:30 +02:00
Liav A
4d44a3bdfe Kernel: Reorder bitwise operations when creating PCI interrupt overrides 2020-04-09 20:45:44 +02:00
Liav A
e4ad1b92fb MultiProcessor: Silence debug message spam 2020-04-09 20:45:44 +02:00
Liav A
0fa50b6405 Interrupts: Simplify initialization a bit more 2020-04-09 20:45:44 +02:00
Liav A
6b38befd91 Interrupts: Remove irrelevant FIXME comment 2020-04-09 20:45:44 +02:00
Liav A
fec8763c21 Interrupts: Make the MultiProcessorParser functional again 2020-04-09 19:59:53 +02:00
Liav A
a7c5a1fe69 Kernel: Simplify the Time management initialization 2020-04-09 19:59:53 +02:00
Liav A
8e336798b5 Kernel: Run clang-format on init.cpp 2020-04-09 19:59:53 +02:00
Liav A
8139688ef1 Kernel: Simplify the Interrupt management initialization 2020-04-09 19:59:53 +02:00
Liav A
caa7a6c2fb Kernel: Simplify PCI messages on initialization 2020-04-09 19:59:53 +02:00