Commit Graph

2840 Commits

Author SHA1 Message Date
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
Andreas Kling
871d450b93 Kernel: Remove redundant "ACPI" from filenames in ACPI/ 2020-04-09 18:17:27 +02:00
Andreas Kling
1c865ee8d4 Kernel: Merge ACPI::StaticParser into ACPI::Parser
There's no need for StaticParser to be a separate thing from Parser.
2020-04-09 18:15:02 +02:00
Andreas Kling
a3ca745b5a Kernel: Use StringView for ACPI table signatures 2020-04-09 18:03:57 +02:00
Andreas Kling
f614f0e2cb Kernel: Add typed_map<T>(PhysicalAddress) and use it in ACPI parsing
There was a frequently occurring pattern of "map this physical address
into kernel VM, then read from it, then unmap it again".

This new typed_map() encapsulates that logic by giving you back a
typed pointer to the kind of structure you're interested in accessing.

It returns a TypedMapping<T> that can be used mostly like a pointer.
When destroyed, the TypedMapping object will unmap the memory. :^)
2020-04-09 17:19:11 +02:00
Andreas Kling
4644217094 Kernel: Remove "non-operational" ACPI parser state
If we don't support ACPI, just don't instantiate an ACPI parser.
This is way less confusing than having a special parser class whose
only purpose is to do nothing.

We now search for the RSDP in ACPI::initialize() instead of letting
the parser constructor do it. This allows us to defer the decision
to create a parser until we're sure we can make a useful one.
2020-04-09 17:19:11 +02:00
Andreas Kling
e983c745f7 Kernel: Simplify ACPI initialization a bit
Construct the parser, no matter which kind, in ACPI::initialize().
2020-04-09 14:10:44 +02:00
Andreas Kling
85c0557839 Kernel: Simplify PCI::initialize() a bit more 2020-04-09 13:42:17 +02:00
Andreas Kling
95e44a33c1 Kernel: Move ACPI initialization from init.cpp to ACPI::initialize() 2020-04-09 13:39:10 +02:00
Andreas Kling
f25d2f5518 Kernel: Move NetworkTask startup into NetworkTask::spawn() 2020-04-09 13:31:05 +02:00
Andreas Kling
66f7c8e0e8 Kernel: Simplify PCI::initialize()
Choosing between I/O and MMIO is not as difficult as we were making it.
2020-04-08 18:07:35 +02:00
Andreas Kling
e171c25a67 Kernel: Fix typos in PCI access boot message 2020-04-08 17:41:46 +02:00
Andreas Kling
f2ebfb9e4e Kernel: Simplify PCI initialization logic
- Get rid of the PCI::Initializer object which was not serving any real
  purpose or holding any data members.
- Move command line parsing from init to PCI::initialize().
2020-04-08 17:39:17 +02:00
Andreas Kling
a6a8f36a83 Kernel: Use nested Kernel::PCI namespaces more to reduce PCI:: spam 2020-04-08 17:29:37 +02:00
Andreas Kling
e5ec332eb1 Kernel: Make most of the PCI::MMIOAccess members private
This class is really meant to be used via a base class pointer.
2020-04-08 17:26:39 +02:00
Andreas Kling
c8b309a3b5 Kernel: Simplify PCI::MMIOAccess segment storage
Instead of nesting a bunch of heap allocations, just store them in
a simple HashMap<u16, MMIOSegment>.

Also fix a bunch of double hash lookups like this:

    ASSERT(map.contains(key));
    auto thing = map.get(key).value();

They now look like this instead:

    auto thing = map.get(key);
    ASSERT(thing.has_value());
2020-04-08 17:23:20 +02:00
Andreas Kling
7d28d9b2af Kernel: Move PCI::MMIOSegment declaration into MMIOAccess.cpp
This is only used inside PCI::MMIOAccess, no need to expose it.
2020-04-08 17:19:46 +02:00
Andreas Kling
44e889785a Kernel: Fix up various PCI-related function signatures
- Make things const when they don't need to be non-const.
- Don't return AK::String when it's always a string literal anyway.
- Remove excessive get_ prefixes per coding style.
2020-04-08 17:19:46 +02:00
Andreas Kling
15cffc4089 Kernel: Add some human-readable I/O helpers in PCI/Access.cpp 2020-04-08 17:19:46 +02:00
Andreas Kling
e1709a0904 Kernel: Remove an unnecessary layer of indirection in the PCI code
The PCI access layer was composed of a bunch of virtual functions that
did nothing but call other virtual functions. The first layer was never
overridden so there was no need for them to be virtual.

This patch removes the indirection and moves logic from PCI::Access
down into the various PCI::get_foo() helpers that were the sole users.
2020-04-08 17:19:46 +02:00
Andreas Kling
e5a20697da Kernel: Fix awkward RTC log message at boot 2020-04-08 17:19:46 +02:00
Andreas Kling
5cc09b0245 Kernel: Simplify VMWareBackdoor somewhat
- If there is no VMWare backdoor, don't allocate memory for it.
- Remove the "unsupported" state, instead just don't instantiate.
- Move the command-line parsing from init to the driver.
- Move mouse packet reception from PS2MouseDevice to VMWareBackdoor.
2020-04-08 17:19:46 +02:00
Andreas Kling
bb2be4bb99 Kernel: Make VMWareBackdoor eternal (since it's never freed) 2020-04-08 17:19:46 +02:00
Andreas Kling
e4ab908fe0 Kernel: Move global constructor invocation a bit earlier 2020-04-08 17:19:46 +02:00
Andreas Kling
a066dd1fac Kernel: Move sync and finalization tasks into their own files
Instead of clogging up the initialization sequence, put these tasks
in their own files.
2020-04-08 17:19:46 +02:00
Andreas Kling
befe4c6709 Kernel: Remove DebugLogDevice
This was a cute idea but ultimately it's just not useful since we
already have the dbgputch() and dbgputstr() syscalls.
2020-04-08 17:19:46 +02:00
Andreas Kling
c8087a42fc Kernel: Move more things from init() to init_stage2()
The purpose of init() is to get multi-tasking up and running. We don't
want to do anything in init() that doesn't advance that goal.

This patch moves some things from init() to init_stage2(), and adds a
comment block explaining the split.
2020-04-08 17:19:46 +02:00
Andreas Kling
a7bbfda034 Kernel: Rename KParams => Kernel::CommandLine
Let's make this read more like English.
2020-04-08 17:19:46 +02:00
Andreas Kling
dc7340332d Kernel: Update cryptically-named functions related to symbolication 2020-04-08 17:19:46 +02:00
Liav A
65dd9d5ad3 Kernel: Ensure we flush the entire ext2 superblock 2020-04-06 17:18:36 +02:00
Liav A
23fb985f02 Kernel & Userland: Allow to mount image files formatted with Ext2FS 2020-04-06 15:36:36 +02:00
Liav A
ecee76b741 Kernel: Change Ext2FS to be backed by a file instead of a block device
In contrast to the previous patchset that was reverted, this time we use
a "special" method to access a file with block size of 512 bytes (like
a harddrive essentially).
2020-04-06 15:36:36 +02:00
Xiao NuoFu
7fd77e9ffe Kernel/Net: make setsockopt pretend it understands SO_KEEPALIVE. 2020-04-06 11:44:13 +02:00
nimelehin
c0a4cf5e8d Kernel: Support best fit allocation policy in kmalloc()
Add find_best_fit() which implements best fit allocation algorithm.
Kmalloc now uses a best fit allocation policy for large allocations.
2020-04-06 08:33:13 +02:00
nimelehin
0d08ed2693 Kernel: Implement kmalloc() using AK::Bitmap
kmalloc's bitmap is wrapped with AK::Bitmap to access AK::Bitmap's
functions.
2020-04-06 08:31:48 +02:00
Liav A
a7d708e47d Kernel: Don't enumerate blocks of ext2 symlinks by default
Also, we assert if we encounter a block that is bigger than blocks
count in the superblock.

Fixes #1608.
2020-04-05 15:27:31 +02:00
Andreas Kling
1d468ed6d3 AK: Stop allowing implicit downcast with RefPtr and NonnullRefPtr
We were allowing this dangerous kind of thing:

RefPtr<Base> base;
RefPtr<Derived> derived = base;

This patch changes the {Nonnull,}RefPtr constructors so this is no
longer possible.

To downcast one of these pointers, there is now static_ptr_cast<T>:

RefPtr<Derived> derived = static_ptr_cast<Derived>(base);

Fixing this exposed a ton of cowboy-downcasts in various places,
which we're now forced to fix. :^)
2020-04-05 11:19:00 +02:00
AnotherTest
3e8cf79efa Servers: Add a new DHCP client
This adds a DHCPClient...Server that leases IPv4s.
2020-04-05 09:50:48 +02:00
AnotherTest
77191d82dc Kernel: Add the SO_BINDTODEVICE socket option
This patch adds a way for a socket to ask to be routed through a
specific interface.
Currently, this option only applies to sending, however, it should also
apply to receiving...somehow :^)
2020-04-05 09:50:48 +02:00
AnotherTest
7d0bf9b5a9 Kernel+AK: Separate out MACAddress and move it into AK 2020-04-05 09:50:48 +02:00
Andreas Kling
53d0ca2ad8 Kernel: Strip SUID+SGID bits from file when written to or chowned
Fixes #1624.
2020-04-04 19:46:55 +02:00
Andreas Kling
54cb1e36b6 Kernel: Enforce file system veil on file creation
Fixes #1621.
2020-04-04 16:41:39 +02:00
AnotherTest
2ea934bcfd Kernel: Do not reject broadcast UDP packets right away
This patch relaxes how we think about UDP packets being "for us" a bit;
the proper way to handle this would be to also check if the matched
socket has SO_BROADCAST set, but we don't have that :)
2020-04-04 12:23:46 +02:00
Andreas Kling
c2a8bbcb59 Revert "Kernel: Change Ext2FS to be backed by a file instead of a block device"
This reverts commit 6b59311d4b.

Reverting these changes since they broke things.
Fixes #1608.
2020-04-03 21:29:03 +02:00
Andreas Kling
9ae3cced76 Revert "Kernel & Userland: Allow to mount image files formatted with Ext2FS"
This reverts commit a60ea79a41.

Reverting these changes since they broke things.
Fixes #1608.
2020-04-03 21:28:57 +02:00
Andreas Kling
522d8c5d71 Kernel: Non-readable-but-writable regions should still be mapped
Fixes #1436.
2020-04-03 10:10:56 +02:00
Marco Wang
3fae4cb054 Kernel: Prepend missing license 2020-04-03 09:12:29 +02:00
AnotherTest
b3d7c5d9de Kernel: Send Fragmented IPv4 packets if payload size > mtu
This adds IPv4 fragmentation, so now we can send huuuuuuge packets
properly.
2020-04-02 14:38:28 +02:00
Liav A
a60ea79a41 Kernel & Userland: Allow to mount image files formatted with Ext2FS 2020-04-02 12:03:08 +02:00
Liav A
6b59311d4b Kernel: Change Ext2FS to be backed by a file instead of a block device
This ensures that we can mount image files as virtual disks without the
need of implementing gross hacks like loopback devices :)
2020-04-02 12:03:08 +02:00
Liav A
2f2016f51d Kernel: Remove unnecessary printf specifier 2020-04-02 12:03:08 +02:00
Liav A
b1365d94f4 Kernel: Align read operation in HPET registers' block 2020-04-01 18:35:57 +02:00
Brendan Coles
e8b17c42bb Base: Change root user home directory from / to /root 2020-03-31 11:43:46 +02:00
Itamar
6b74d38aab Kernel: Add 'ptrace' syscall
This commit adds a basic implementation of
the ptrace syscall, which allows one process
(the tracer) to control another process (the tracee).

While a process is being traced, it is stopped whenever a signal is
received (other than SIGCONT).

The tracer can start tracing another thread with PT_ATTACH,
which causes the tracee to stop.

From there, the tracer can use PT_CONTINUE
to continue the execution of the tracee,
or use other request codes (which haven't been implemented yet)
to modify the state of the tracee.

Additional request codes are PT_SYSCALL, which causes the tracee to
continue exection but stop at the next entry or exit from a syscall,
and PT_GETREGS which fethces the last saved register set of the tracee
(can be used to inspect syscall arguments and return value).

A special request code is PT_TRACE_ME, which is issued by the tracee
and causes it to stop when it calls execve and wait for the
tracer to attach.
2020-03-28 18:27:18 +01:00
Itamar
c9396be83f WaitBlocker: don't unblock if thread has pending SIGCONT
Previosuly, if we sent a SIGCONT to a stopped thread
and then waitpid() with WSTOPPED on that thread before
the signal was dispatched,
then the WaitBlocker would first unblock (because the thread is stopped)
and only after that the thread would get the SIGCONT signal.
This would mean that when waitpid returns
the waitee is not stopped.

To fix this, we do not unblock the waiting thread
if the waitee thread has a pending SIGCONT.
2020-03-28 18:27:18 +01:00
Andreas Kling
c50fbf6da0 Kernel: Remove the floppy driver
Nobody was using this code, and it was not actively worked on, so let's
just not have it. Press F.
2020-03-28 10:09:48 +01:00
Andreas Kling
f3c245fb96 Kernel: Make ^W and ^U actually erase characters
This is quite hackish but it makes using the js REPL a lot nicer. :^)
2020-03-26 08:18:47 +01:00
Andreas Kling
fac6f62cf7 Build: Oops, LibJS tests were meant to go in /home/anon/js-tests 2020-03-25 16:16:04 +01:00
Andreas Kling
202055a72a Build: Copy LibJS/Tests into /home/anon/js-tests
The test runner currently depends on the bash port being installed.
If you have it, you can run the LibJS test suite inside Serenity
by simply entering /home/anon/js-tests and doing ./run-tests :^)
2020-03-25 15:53:47 +01:00
Liav A
5f579904c1 Interrupts: Handle spurious IRQs from eoi() method 2020-03-24 16:15:33 +01:00
Liav A
8d9b6c57b5 Interrupts: Use Optional container in IOAPIC
We return the Optional container in find_redirection_entry_by_vector()
method instead of a raw integer. This makes the code more readable and
correct.
2020-03-24 16:15:33 +01:00
Liav A
0b7fc525e1 Interrupts: Simplify IRQ disabling & enabling in IRQController(s)
Instead of blindly setting masks, if we want to disable an IRQ and it's
already masked, we just return. The same happens if we want to enable an
IRQ and it's unmasked.
2020-03-24 16:15:33 +01:00
Liav A
3f98a67d75 Interrupts: Remove unused methods 2020-03-24 16:15:33 +01:00
Liav A
8b38be3072 Kernel: Simplify disable_irq() and enable_irq() methods in IRQHandler
Setting the m_enabled variable to true or false can help
with monitoring the IRQHandler object(s) later, and there's no good
reason to have an if-else statement in those methods anyway.
2020-03-24 16:15:33 +01:00
Liav A
cb676f1211 Interrupts: Do a specific EOI when using the PIC
Before this change, we did a non-specific EOI, which could lead to
problems with other IRQs that are handled in the PIC. Since the original
8259A datasheet permits such functionality and we are not losing any
functionality, this change is acceptable even though we don't experience
problems with the EOI currently.
2020-03-24 16:15:33 +01:00
Liav A
06e7fc9dee Kernel: Limit IRQ rate within E1000 network adapter
This is not a complete fix, since spurious IRQs under heavy loads can
still occur. However, this fix limits the amount of spurious IRQs.

It is encouraged to provide a better fix in the future, probably
something that takes into account handling of PCI level-triggered
interrupts.
2020-03-24 16:15:33 +01:00
Liav A
dbc536e917 Interrupts: Assert if trying to install an handler on syscall vector
Installing an interrupt handler on the syscall IDT vector can lead to
fatal results, so we must assert if that happens.
2020-03-24 16:15:33 +01:00
Liav A
f86be46c98 Kernel: Abstract IRQ controller handling from Interrupt handlers
Now we don't send raw numbers, but we let the IRQController object to
figure out the correct IRQ number.
This helps in a situation when we have 2 or more IOAPICs, so if IOAPIC
1 is assigned for IRQs 0-23 and IOAPIC 2 is assigned for IRQs 24-47,
if an IRQHandler of IRQ 25 invokes disable() for example, it will call
his responsible IRQController (IOAPIC 2), and the IRQController will
subtract the IRQ number with his assigned offset, and the result is that
the second redirection entry in IOAPIC 2 will be masked.
2020-03-24 16:15:33 +01:00
Liav A
666990fbcb Kernel: Correct Spurious Interrupt handlers' controller model() method
We don't return blindly the IRQ controller's model(), if the Spurious
IRQ handler is installed in IOAPIC environment, it's misleading to
return "IOAPIC" string since IOAPIC doesn't really handle Spurious
IRQs, therefore we return a "" string.
2020-03-24 16:15:33 +01:00
Liav A
4cc96a7aa9 Kernel: Create an interface for conversion between IRQs and interrupts 2020-03-24 16:15:33 +01:00
Liav A
c2c0e9fb04 Kernel: Ensure that we don't use a hard-disabled IRQController 2020-03-24 16:15:33 +01:00
Liav A
893d4a41c2 Kernel: Enable IRQs before sending commands to the E1000 adapter
This change prevents a race condition, in which case we send a command
and we are losing an interrupt.
2020-03-24 16:15:33 +01:00
Liav A
7c859efa85 Kernel: Change the Spurious Interrupt Handler offset in the APIC
The Spurious Interrupt Handler number that is written to
APIC_REG_SIV is correct now.
2020-03-24 16:15:33 +01:00
Liav A
f7b207c7ae CPU: Move EOI call to the end of handle_interrupt() 2020-03-24 16:15:33 +01:00
Liav A
1bc7ba8df8 Kernel: Run QEMU machine with two virtual processors 2020-03-24 16:15:33 +01:00
Liav A
c55d5eeef9 Kernel: Change noacpi GRUB entry to use the right boot argument 2020-03-24 16:15:33 +01:00
Andreas Kling
7d862dd5fc AK: Reduce header dependency graph of String.h
String.h no longer pulls in StringView.h. We do this by moving a bunch
of String functions out-of-line.
2020-03-23 13:48:44 +01:00
Shannon Booth
c47ef61ed8 Toolchain/Ports: Update gcc to 9.3.0
Ever closer to C++20! Also fix up some of those pesky "'s
2020-03-23 08:22:41 +01:00
Andreas Kling
4f72f6b886 AK: Add FlyString, a simple flyweight string class
FlyString is a flyweight string class that wraps a RefPtr<StringImpl>
known to be unique among the set of FlyStrings. The class is very
unoptimized at the moment.

When to use FlyString:

- When you want O(1) string comparison
- When you want to deduplicate a lot of identical strings

When not to use FlyString:

- For strings that don't need either of the above features
- For strings that are likely to be unique
2020-03-22 13:03:43 +01:00
Shannon Booth
d7133ea326 Kernel: Fix compilation error with ACPI_DEBUG enabled 2020-03-22 08:51:40 +01:00
Shannon Booth
757c14650f Kernel: Simplify process assertion checking if region is in range
Let's use the helper function for this :)
2020-03-22 08:51:40 +01:00
Shannon Booth
81adefef27 Kernel: Run clang-format on files
Let's rip off the band-aid
2020-03-22 01:22:32 +01:00
BenJilks
c64b5e73f5
Build: Add FreeBSD support (#1492) 2020-03-21 09:46:30 +01:00
Liav A
b536547c52 Process: Use monotonic time for timeouts 2020-03-19 15:48:00 +01:00
Liav A
b4c92c24ee Scheduler: Use monotonic time for blocking threads 2020-03-19 15:48:00 +01:00
Liav A
4484513b45 Kernel: Add new syscall to allow changing the system date 2020-03-19 15:48:00 +01:00
Liav A
4fcc10c6c3 Kernel: Delete unnecessary files 2020-03-19 15:48:00 +01:00
Liav A
9db291d885 Kernel: Introduce the new Time management subsystem
This new subsystem includes better abstractions of how time will be
handled in the OS. We take advantage of the existing RTC timer to aid
in keeping time synchronized. This is standing in contrast to how we
handled time-keeping in the kernel, where the PIT was responsible for
that function in addition to update the scheduler about ticks.
With that new advantage, we can easily change the ticking dynamically
and still keep the time synchronized.

In the process context, we no longer use a fixed declaration of
TICKS_PER_SECOND, but we call the TimeManagement singleton class to
provide us the right value. This allows us to use dynamic ticking in
the future, a feature known as tickless kernel.

The scheduler no longer does by himself the calculation of real time
(Unix time), and just calls the TimeManagment singleton class to provide
the value.

Also, we can use 2 new boot arguments:
- the "time" boot argument accpets either the value "modern", or
  "legacy". If "modern" is specified, the time management subsystem will
  try to setup HPET. Otherwise, for "legacy" value, the time subsystem
  will revert to use the PIT & RTC, leaving HPET disabled.
  If this boot argument is not specified, the default pattern is to try
  to setup HPET.
- the "hpet" boot argumet accepts either the value "periodic" or
  "nonperiodic". If "periodic" is specified, the HPET will scan for
  periodic timers, and will assert if none are found. If only one is
  found, that timer will be assigned for the time-keeping task. If more
  than one is found, both time-keeping task & scheduler-ticking task
  will be assigned to periodic timers.
  If this boot argument is not specified, the default pattern is to try
  to scan for HPET periodic timers. This boot argument has no effect if
  HPET is disabled.

In hardware context, PIT & RealTimeClock classes are merely inheriting
from the HardwareTimer class, and they allow to use the old i8254 (PIT)
and RTC devices, managing them via IO ports. By default, the RTC will be
programmed to a frequency of 1024Hz. The PIT will be programmed to a
frequency close to 1000Hz.

About HPET, depending if we need to scan for periodic timers or not,
we try to set a frequency close to 1000Hz for the time-keeping timer
and scheduler-ticking timer. Also, if possible, we try to enable the
Legacy replacement feature of the HPET. This feature if exists,
instructs the chipset to disconnect both i8254 (PIT) and RTC.
This behavior is observable on QEMU, and was verified against the source
code:
ce967e2f33

The HPETComparator class is inheriting from HardwareTimer class, and is
responsible for an individual HPET comparator, which is essentially a
timer. Therefore, it needs to call the singleton HPET class to perform
HPET-related operations.

The new abstraction of Hardware timers brings an opportunity of more new
features in the foreseeable future. For example, we can change the
callback function of each hardware timer, thus it makes it possible to
swap missions between hardware timers, or to allow to use a hardware
timer for other temporary missions (e.g. calibrating the LAPIC timer,
measuring the CPU frequency, etc).
2020-03-19 15:48:00 +01:00
Liav A
5d90e9cfb8 Kernel & LibC: Add CLOCK_REALTIME constant 2020-03-19 15:48:00 +01:00
Liav A
53d6fe8141 ACPI: Delete irrelevant HPET definitions
Also, the definition of the HPET ACPI table is correct now, in
accordance to the HPET specification, revision 1.0a, October 2004.
2020-03-19 15:48:00 +01:00
Liav A
a0a7204915 Interrupts: Add an interface to determine if SMP is enabled 2020-03-19 15:48:00 +01:00
Liav A
e880fe0765 Kernel: Use a const reference to RegisterState in IRQ handling 2020-03-19 15:48:00 +01:00
Liav A
aa43314e8b Kernel: Remove unnecessary include from PATAChannel.cpp 2020-03-19 15:48:00 +01:00
Liav A
9a303cc5a5 Kernel: Add the NonMaskableInterruptDisabler class
This class will be used later to disable NMIs when we
initialize the RTC timer.
2020-03-19 15:48:00 +01:00
Alex Muscar
d013753f83
Kernel: Resolve relative paths when there is a veil (#1474) 2020-03-19 09:57:34 +01:00
rhin123
39c21f368a Calendar: Implement basic GUI calendar application 2020-03-18 08:17:01 +01:00
Andreas Kling
ad92a1e4bc Kernel: Add sys$get_stack_bounds() for finding the stack base & size
This will be useful when implementing conservative garbage collection.
2020-03-16 19:06:33 +01:00
marprok
0fd5f0e4bd Userland: ifconfig can change the IP address of the default gateway
ioctl can now perform a request for a specific route and change
the address of it's default gateway.
2020-03-15 19:09:31 +01:00
Liav A
b13417ddb4 ACPI: Examine bit width in Generic address structure before asserting
Also, the switch-case flow is simplified for IO access within a Generic
address strucuture's handling.
2020-03-12 12:36:38 +01:00
Liav A
5d7855adea ACPI: Keep common flags in structures for later usage 2020-03-12 12:36:38 +01:00
marprok
3cbc2f4381 Ext2FS: Reset the found_a_group flag 2020-03-12 12:35:00 +01:00
Marios Prokopakis
8cf962a102
Userland: Set the mask of a network adapter with ifconfig (#1388)
A new IP address or a new network mask can be specified in the command
line arguments of ifconfig to replace the old values of a given network
adapter. Additionally, more information is being printed for each adapter.
2020-03-11 21:30:41 +01:00
Andreas Kling
3803196edb Kernel: Get rid of SmapDisabler in sys$fstat() 2020-03-10 13:34:24 +01:00
Till Mayer
ac3c19b91c Games: Added solitaire to build-root-filesystem.sh 2020-03-09 21:36:59 +01:00
Liav A
0f45a1b5e7 Kernel: Allow to reboot in ACPI via PCI or MMIO access
Also, we determine if ACPI reboot is supported by checking the FADT
flags' field.
2020-03-09 10:53:13 +01:00
Liav A
8639ee2640 PCI: Enable LogStream output for addresses 2020-03-09 10:53:13 +01:00
Liav A
032ce1948e LibBareMetal: Return FlatPtr from PhysicalAddress::offset_in_page() 2020-03-09 10:53:13 +01:00
Liav A
4479e874da Kernel: Ensure RTL8139NetworkAdapter uses virtual memory correctly 2020-03-08 14:13:30 +01:00
Liav A
9dbc273675 Kernel: Ensure E1000NetworkAdapter uses virtual memory correctly 2020-03-08 14:13:30 +01:00
Liav A
d6e122fd3a Kernel: Allow contiguous allocations in physical memory
For that, we have a new type of VMObject, called
ContiguousVMObject, that is responsible for allocating contiguous
physical pages.
2020-03-08 14:13:30 +01:00
Ben Wiederhake
b066586355 Kernel: Fix race in waitid
This is similar to 28e1da344d
and 4dd4dd2f3c.

The crux is that wait verifies that the outvalue (siginfo* infop)
is writable *before* waiting, and writes to it *after* waiting.
In the meantime, a concurrent thread can make the output region
unwritable, e.g. by deallocating it.
2020-03-08 14:12:12 +01:00
Ben Wiederhake
d8cd4e4902 Kernel: Fix race in select
This is similar to 28e1da344d
and 4dd4dd2f3c.

The crux is that select verifies that the filedescriptor sets
are writable *before* blocking, and writes to them *after* blocking.
In the meantime, a concurrent thread can make the output buffer
unwritable, e.g. by deallocating it.
2020-03-08 14:12:12 +01:00
Ben Wiederhake
0edae63cc0 Kernel: Fix inconsistent inclusion style
This also makes it easier to automatically parse the dependency tree.
Thankfully, this is the only place where a change was necessary.
2020-03-08 14:09:08 +01:00
Andreas Kling
fa9fba6901 Kernel: Add missing #includes now that <AK/StdLibExtras.h> is smaller 2020-03-08 13:06:51 +01:00
Andreas Kling
b1058b33fb AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it
possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-08 13:06:51 +01:00
Andreas Kling
f2f16e1c24 IPv4: Keep IPv4 socket locked during receive operations
We unlock/relock around blocking, but outside of that we now keep the
socket locked.

This fixes an intermittent ASSERT(m_can_read) failure.
2020-03-07 11:27:55 +01:00
Andreas Kling
7a6c4a72d5 LibWeb: Move everything into the Web namespace 2020-03-07 10:27:02 +01:00
Liav A
f3f8b88d8f Kernel: Fix syntax error in FIFO_DEBUG 2020-03-06 22:29:24 +01:00
Tibor Nagy
30152b6c88 Kernel: Fix syntax errors in PS2MOUSE_DEBUG
Found with Cppcheck.
2020-03-06 22:20:53 +01:00
Liav A
a6c53cadc8 Meta: Claim copyright on PCI files 2020-03-06 16:03:58 +01:00
Liav A
9991a36d1a CPU: Prevent leakage of virtual addresses to kernel log 2020-03-06 15:57:19 +01:00
Liav A
5cbde297ec Meta: Claim copyright on ACPI files 2020-03-06 15:56:51 +01:00
Andreas Kling
c6693f9b3a Kernel: Simplify a bunch of dbg() and klog() calls
LogStream can handle VirtualAddress and PhysicalAddress directly.
2020-03-06 15:00:44 +01:00
Andreas Kling
75a6b27f73 Ext2FS: Remove unused allocate_block()
We only use allocate_blocks() now. If you want a single block, you can
just call allocate_blocks() with a count of 1.
2020-03-06 11:22:23 +01:00
Liav A
e2889e665f Kernel: Shorten the model name of i8529 PIC class 2020-03-06 11:19:51 +01:00
Liav A
7ef5d222f1 Kernel: Change data in /proc/interrupts to be more richer
Also, during interrupt handlers' enumeration, we call all interrupts
handlers that are not UnhandledInterruptHandler.
2020-03-06 11:19:51 +01:00
Liav A
773afefe7c Kernel: Change HandlerPurpose to HandlerType
Also, GenericInterruptHandler class requires to implement two new
methods.
2020-03-06 11:19:51 +01:00
Andreas Kling
2709116334 Kernel: Fix strange looking output on unhandled page fault 2020-03-06 10:41:08 +01:00
Andreas Kling
8bb361889c AK: Remove Optional::operator bool()
This was causing some obvious-in-hindsight but hard to spot bugs where
we'd implicitly convert the bool to an integer type and carry on with
the number 1 instead of the actual value().
2020-03-06 10:32:58 +01:00
Liav A
425a2ca6ad Init Stage: Allow to boot with smp=on
One can now set the kernel boot argument smp to on, and therefore, to
instruct the kernel to use the IOAPIC instead of the PIC.
2020-03-06 10:32:32 +01:00
Liav A
c335c94242 Kernel: Simplify APIC::enable()
We install a SpuriousInterruptHandler when calling APIC::enable(),
and we don't enable local interrupts for now.
2020-03-06 10:32:32 +01:00
Liav A
a3fa40fc07 Kernel: Enable IRQs before sending commands to devices
Without this fix, a very fast IRQ can preempt the enable_irq() call,
leaving that IRQ being unhandled.
2020-03-06 10:32:32 +01:00
Liav A
f33fb151b4 CPU: Allow to use IRQs in range of 50 to 178 2020-03-06 10:32:32 +01:00
Liav A
30fc78bfaf Kernel: Acquire ISA interrupt overrides from Interrupt Management
Also, InterruptDisabler were added to prevent critical function from
being interrupted. In addition, the interrupt numbers are abstracted
from IDT offsets, thus, allowing to create a better routing scheme
when using IOAPICs for interrupt redirection.
2020-03-06 10:32:32 +01:00
Liav A
d9d792d37f Kernel: Print MultiProcessor features 2020-03-06 10:32:32 +01:00
Andreas Kling
94f287b1c0 Kernel: Unmap non-readable pages
This was caught by running all crash tests with "crash -A".
Basically, non-readable pages need to not be mapped *at all* so that
a "page not present" exception is provoked on access.

Unfortunately x86 does not support write-only mappings, so this is
the best we can do.

Fixes #1336.
2020-03-06 09:58:59 +01:00
Liav A
85eb1d26d5 Kernel: Run clang-format on Process.cpp & ACPIDynamicParser.h 2020-03-05 19:04:04 +01:00
Liav A
1b8cd6db7b Kernel: Call ACPI reboot method first if possible
Now we call ACPI reboot method first if possible, and if ACPI reboot is
not available, we attempt to reboot via the keyboard controller.
2020-03-05 19:04:04 +01:00
Ben Wiederhake
4dd4dd2f3c Kernel: Fix race in clock_nanosleep
This is a complete fix of clock_nanosleep, because the thread holds the
process lock again when returning from sleep()/sleep_until().
Therefore, no further concurrent invalidation can occur.
2020-03-03 20:13:32 +01:00
Andreas Kling
686ade6b5a AK: Make quick_sort() a little more ergonomic
Now it actually defaults to "a < b" comparison, instead of forcing you
to provide a trivial less-than comparator. Also you can pass in any
collection type that has .begin() and .end() and we'll sort it for you.
2020-03-03 16:02:58 +01:00
Liav A
251b7f3776 CPU: Change debug messages to fit the latest changes 2020-03-02 22:23:39 +01:00
Liav A
f0ca29eb4b Kernel: Run clang-format on various files 2020-03-02 22:23:39 +01:00
Liav A
0fc60e41dd Kernel: Use klog() instead of kprintf()
Also, duplicate data in dbg() and klog() calls were removed.
In addition, leakage of virtual address to kernel log is prevented.
This is done by replacing kprintf() calls to dbg() calls with the
leaked data instead.
Also, other kprintf() calls were replaced with klog().
2020-03-02 22:23:39 +01:00
Liav A
19aa53e1f9 Kernel: Use IOAddress class in PATAChannel class
This change make the code a bit more readable. Also, kprintf() calls
are replaced with klog() calls.
2020-03-02 22:23:39 +01:00
Liav A
15dfca4a79 Kernel: Use IOAddress class in Network adapters' drivers
Also, kprintf() calls were replaced with klog() calls.
2020-03-02 22:23:39 +01:00
Andreas Kling
918ebabf60 Kernel: MemoryManager should create cacheable regions by default 2020-03-02 13:04:17 +01:00
Andreas Kling
47beab926d Kernel: Remove ability to create kernel-only regions at user addresses
This was only used by the mechanism for mapping executables into each
process's own address space. Now that we remap executables on demand
when needed for symbolication, this can go away.
2020-03-02 11:20:34 +01:00
Andreas Kling
e56f8706ce Kernel: Map executables at a kernel address during ELF load
This is both simpler and more robust than mapping them in the process
address space.
2020-03-02 11:20:34 +01:00
Andreas Kling
678c87087d Kernel: Load executables on demand when symbolicating
Previously we would map the entire executable of a program in its own
address space (but make it unavailable to userspace code.)

This patch removes that and changes the symbolication code to remap
the executable on demand (and into the kernel's own address space
instead of the process address space.)

This opens up a couple of further simplifications that will follow.
2020-03-02 11:20:34 +01:00
howar6hill
055344f346 AK: Move the wildcard-matching implementation to StringUtils
Provide wrappers in the String and StringView classes, and add some tests.
2020-03-02 10:38:08 +01:00
Andreas Kling
0acac186fb Kernel: Make the "entire executable" region shared
This makes Region::clone() do the right thing with it on fork().
2020-03-02 06:13:29 +01:00
Andreas Kling
5c2a296a49 Kernel: Mark read-only PT_LOAD mappings as shared regions
This makes Region::clone() do the right thing for these now that we
differentiate based on Region::is_shared().
2020-03-01 21:26:36 +01:00
Andreas Kling
ecfde5997b Kernel: Use SharedInodeVMObject for executables after all
I had the wrong idea about this. Thanks to Sergey for pointing it out!

Here's what he says (reproduced for posterity):

> Private mappings protect the underlying file from the changes made by
> you, not the other way around. To quote POSIX, "If MAP_PRIVATE is
> specified, modifications to the mapped data by the calling process
> shall be visible only to the calling process and shall not change the
> underlying object. It is unspecified whether modifications to the
> underlying object done after the MAP_PRIVATE mapping is established
> are visible through the MAP_PRIVATE mapping." In practice that means
> that the pages that were already paged in don't get updated when the
> underlying file changes, and the pages that weren't paged in yet will
> load the latest data at that moment.
> The only thing MAP_FILE | MAP_PRIVATE is really useful for is mapping
> a library and performing relocations; it's definitely useless (and
> actively harmful for the system memory usage) if you only read from
> the file.

This effectively reverts e2697c2ddd.
2020-03-01 21:16:27 +01:00
Andreas Kling
bb7dd63f74 Kernel: Run clang-format on Process.cpp 2020-03-01 21:16:27 +01:00
Andreas Kling
7e6c2068bf Kernel: Fix suspicious local shadowing in PerformanceEventBuffer 2020-03-01 21:08:04 +01:00
Andreas Kling
687b52ceb5 Kernel: Name perfcore files "perfcore.PID"
This way we can trace many things and we get one perfcore file per
process instead of everyone trying to write to "perfcore"
2020-03-01 20:59:02 +01:00
Andreas Kling
ecdd9a5bc6 Kernel: Reduce code duplication a little bit in Region allocation
This patch reduces the number of code paths that lead to the allocation
of a Region object. It's quite hard to follow the various ways in which
this can happen, so this is an effort to simplify.
2020-03-01 15:56:23 +01:00
Andreas Kling
5e0c4d689f Kernel: Move ProcessPagingScope to its own files 2020-03-01 15:38:09 +01:00
Andreas Kling
2839bb0be1 Kernel: Restore the previous thread state on SIGCONT after SIGSTOP
When stopping a thread with the SIGSTOP signal, we now store the thread
state in Thread::m_stop_state. That state is then restored on SIGCONT.
This fixes an issue where previously-blocked threads would unblock
upon resume. Now they simply resume in the Blocked state, and it's up
to the regular unblocking mechanism to unblock them.

Fixes #1326.
2020-03-01 15:14:17 +01:00
Andreas Kling
c3c8eae25a Kernel: Remove some unnecessary .characters() when doing dbg()<<String 2020-03-01 13:23:26 +01:00
Andreas Kling
22d0a6d92f AK: Remove unnecessary casts to size_t, after Vector changes
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
2020-03-01 12:58:22 +01:00