Commit Graph

2900 Commits

Author SHA1 Message Date
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