Commit graph

3151 commits

Author SHA1 Message Date
Tom dd83f6a266 Kernel: Fix losing PTEs
We can't use a HashMap with a small key that doesn't guarantee
collisions. Change it to a HashTable instead.

Fixes #3254
2020-08-26 01:25:06 +02:00
Tom bcbe2fe525 Kernel: Protect looping over VMObject regions
We need to hold the memory manager lock so nobody else can modify
these lists while we're iterating them.
2020-08-26 01:25:06 +02:00
asynts 10c6f062b3 AK: Add Endian.h header to replace NetworkOrdered.h. 2020-08-25 16:22:14 +02:00
Tom c2b9f8857c Kernel: Optimize SlabAllocator to be lock-free 2020-08-25 09:48:48 +02:00
Tom 81780e607d Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the
kmalloc or eternal pool.
2020-08-25 09:48:48 +02:00
Tom d89582880e Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.

Fixes #3226
2020-08-25 09:48:48 +02:00
Tom ba6e4fb77f Kernel: Fix kmalloc memory corruption
Rather than hardcoding where the kmalloc pool should be, place
it at the end of the kernel image instead. This avoids corrupting
global variables or other parts of the kernel as it grows.

Fixes #3257
2020-08-25 09:48:48 +02:00
Tom 08a569fbe0 Kernel: Make PhysicalPage not movable and use atomic ref counting
We should not be moving ref-counted objects.
2020-08-25 09:48:48 +02:00
Luke b58ca7cf3d Kernel: Scroll wheel amount on Intellimouse is 4 bits instead of 8
When trying to scroll up on virtualizers that don't use the VMware
backdoor and instead use PS2MouseDevice, it would actually scroll
down rapidly.

Looking into it, the mouse delta for scrolling down was 1 and 15
for scrolling up. 15 is suspiciously -1 for a nibble.

According to https://isdaman.com/alsos/hardware/mouse/ps2interface.htm
the Z is actually 4 bits for Intellimouse.

This fixes scrolling up on virtualizers such as VirtualBox.
2020-08-25 09:43:51 +02:00
Ben Wiederhake d5b7c28a5e Kernel: Remove strcpy()
These are not called in the kernel or by libstdc++ anyway.

Remove the tempting function, and prevent future overflows.
2020-08-24 00:45:03 +02:00
Muhammad Zahalqa 7506adbece
Kernel: Avoid some allocations in command line parsing (#3213)
1. Preallocate args hashmap to prevent rehashing.
2. Use move to prevent string copies.
2020-08-23 15:04:49 +02:00
Andreas Kling 31d3eac651 Ext2FS: Fix build with EXT2_DEBUG 2020-08-23 01:25:29 +02:00
Ben Wiederhake 1aad0f8b16 Kernel: Stop supporting sprintf
The kernel no longer needs sprintf (which might, in theory, overflow),
so we can hide the C++ declaration and make the function uncallable
from within the kernel.

However, libstdc++ still links against it, as libstdc++ uses it for
demangling, from AK::demangle().
2020-08-22 20:55:10 +02:00
Ben Wiederhake b6afe1f0ce Kernel: Prefer snprintf over sprintf 2020-08-22 20:55:10 +02:00
Ben Wiederhake 0240baa42d AK+Kernel: Support snprintf
In contrast to sprintf, which might overflow the given buffer.

I feel bad about the code duplication, but that is a pre-existing issue.
2020-08-22 20:55:10 +02:00
Andreas Kling 2fd9e72264 Revert "Kernel: Switch singletons to use new Singleton class"
This reverts commit f48feae0b2.
2020-08-22 18:01:59 +02:00
Andreas Kling 0addcb45b8 Kernel: Make Process::dump_regions() sort the regions before dumping 2020-08-22 18:01:59 +02:00
Ben Wiederhake 9a0cd9a50d Kernel: Prevent confusing silent misuse of PCI::Address 2020-08-22 17:18:14 +02:00
Andreas Kling 8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling b0a24a83be Revert "Kernel: Fix regression where MemoryManager is initialized twice"
This reverts commit 8a75e0b892.
2020-08-22 16:34:15 +02:00
Andreas Kling 68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
Andreas Kling 8a21491d86 Revert "Kernel: Copy command line to a safe place"
This reverts commit 41c005cb14.
2020-08-22 16:34:12 +02:00
Andreas Kling 0db7e04c2e Revert "Kernel: Make PhysicalPage not movable and use atomic ref counting"
This reverts commit a89ccd842b.
2020-08-22 16:34:11 +02:00
Andreas Kling 23f335bcd7 Revert "Kernel: Fix kmalloc memory corruption"
This reverts commit b306f240a4.
2020-08-22 16:34:08 +02:00
Tom b306f240a4 Kernel: Fix kmalloc memory corruption
Rather than hardcoding where the kmalloc pool should be, place
it at the end of the kernel image instead. This avoids corrupting
global variables or other parts of the kernel as it grows.

Fixes #3257
2020-08-22 10:46:24 +02:00
Tom a89ccd842b Kernel: Make PhysicalPage not movable and use atomic ref counting
We should not be moving ref-counted objects.
2020-08-22 10:46:24 +02:00
Tom 41c005cb14 Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the
kmalloc or eternal pool.
2020-08-22 10:46:24 +02:00
Tom 5a98e329d1 AK: Get rid of make_singleton function
Just default the InitFunction template argument.
2020-08-22 10:46:24 +02:00
Tom 8a75e0b892 Kernel: Fix regression where MemoryManager is initialized twice
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.
2020-08-22 10:46:24 +02:00
Tom f0906250a1 Kernel: Move Singleton class to AK 2020-08-22 10:46:24 +02:00
Nico Weber 19a8aa72d2 Kernel: Fix reading RTC
The CMOS sets bit 2 (0x4) if times are binary, if it's not
set they're in BCD.

The CMOS sets bit 1 (0x1) if hours are on a 12 hour clock.
In that case, the highest bit in the hour byte is set for
PM times (both in binary and BCD times).

Three bugs:

1. The lower 7 bits were masked off incorrectly when calling
   bcd_to_binary(). Use 0x7F as mask, not 0x70.

2. The highest bit to check if a time was PM was checked after
   BCD conversion of the low 7 bits, which clobbered that bit.
   Do the check before BCD conversion.

3. In the 12 hour clock, midnight and noon are "12", so those
   need to be converted to 0 even if for non-PM times (else
   midnight is "12", not "0").

With this, SerenityOS consistently shows UTC as the current time,
as it should.

If folks want it to display local time instead, they can get this
by adding `-rtc base=localtime` to Meta/run.sh -- but a better fix
would be to add timezone management and convert from UTC system
clock to the user timezone at display time.
2020-08-21 20:57:52 +02:00
AnotherTest 67f7f6840d AK+LibC+Kernel: Move the implementation of memmem to AK 2020-08-21 16:00:42 +02:00
Tom cf8ce839da Kernel: Fix assertion when releasing contiguous memory region
There is no guarantee that the memory manager lock is held when
physical pages are released, so just acquire the memory manager
lock.
2020-08-21 12:03:20 +02:00
Tom f48feae0b2 Kernel: Switch singletons to use new Singleton class
Fixes #3226
2020-08-21 11:47:35 +02:00
Tom 527c8047fe Kernel: Add an atomic Singleton class
This allows easier one-time thread-safe atomic initialization
of the various singletons in the Kernel.
2020-08-21 11:47:35 +02:00
Nico Weber 49d6405164 Kernel: Log time in addition to date in RTC startup 2020-08-20 20:53:43 +02:00
Andreas Kling 079d2fe088 Kernel: Pack arguments, environment and auxiliary values better
Previously we were putting strings at the bottom of the allocated stack
region, and pointer arrays (argv, env, auxv) at the top. There was no
reason for this other than "it seemed easier to do it that way at the
time I wrote it."

This patch packs the strings and pointer vectors into the same area at
the top of the stack.

This reduces the memory footprint of all programs by 4 KiB. :^)
2020-08-20 16:34:44 +02:00
AnotherTest 688e54eac7 Kernel: Distinguish between new and old process groups with equal pgids
This does not add any behaviour change to the processes, but it ties a
TTY to an active process group via TIOCSPGRP, and returns the TTY to the
kernel when all processes in the process group die.
Also makes the TTY keep a link to the original controlling process' parent (for
SIGCHLD) instead of the process itself.
2020-08-19 21:21:34 +02:00
Andreas Kling 607e085823 Ext2FS: Fix inode link leak on all new inodes
The initial inode link count was wrong in Ext2FS, as the act of adding
new inodes to their new parent bumps the count.

This regressed in df66c28479.
2020-08-19 21:17:02 +02:00
Brian Gianforcaro 8e97de2df9 Kernel: Use Userspace<T> for the recvfrom syscall, and Socket implementation
This fixes a bunch of unchecked kernel reads and writes, seems like they
would might exploitable :). Write of sockaddr_in size to any address you
please...
2020-08-19 21:05:28 +02:00
Brian Gianforcaro 9f9b05ba0f Kernel: Use Userspace<T> for the sendto syscall, and Socket implementation
Note that the data member is of type ImmutableBufferArgument, which has
no Userspace<T> usage. I left it alone for now, to be fixed in a future
change holistically for all usages.
2020-08-19 21:05:28 +02:00
Muhammad Zahalqa e035640cd5
Kernel: Remove unneeded #include in ProcessorInfo.cpp (#3211) 2020-08-19 11:25:12 +02:00
Muhammad Zahalqa 64ea64fca5
Kernel: Remove an unimplemented function (#3210) 2020-08-19 11:24:40 +02:00
Muhammad Zahalqa 983f4f935c
Kernel: Do not wait before first attempt at locking SpinLock (#3212) 2020-08-19 11:10:53 +02:00
Andreas Kling 71e8554740 Kernel: Remove the now-unused FS::DirectoryEntry
This object was cumbersome and annoying (mostly due to its manually
managed, statically sized name buffer.) And now we no longer need it!
2020-08-18 18:26:54 +02:00
Andreas Kling 6ad2d31952 Ext2FS: Stop using FS::DirectoryEntry
We were only using this as a temporary helper object while constructing
directories. Create a simpler Ext2FSDirectoryEntry instead for this.
2020-08-18 18:26:54 +02:00
Andreas Kling 108263314a TmpFS: Stop using FS::DirectoryEntry in TmpFSInode
The list of children can just be a bunch of { name, inode }.
2020-08-18 18:26:54 +02:00
Andreas Kling c096cb9352 TmpFS: Avoid unnecessary inode lookup in TmpFSInode::lookup()
We don't have to ask the VFS to find our child inode, we have a pointer
to it right here.
2020-08-18 18:26:54 +02:00
Andreas Kling eeaba41d13 Kernel: Add DirectoryEntryView for VFS directory traversal
Unlike DirectoryEntry (which is used when constructing directories),
DirectoryEntryView does not manage storage for file names. Names are
just StringViews.

This is much more suited to the directory traversal API and makes
it easier to implement this in file system classes since they no
longer need to create temporary name copies while traversing.
2020-08-18 18:26:54 +02:00
Muhammad Zahalqa ff577e22a3 Kernel: ProcessorInfo.cpp remove unused headers 2020-08-18 13:41:08 +02:00