1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 15:35:06 +00:00
Commit graph

319 commits

Author SHA1 Message Date
Sahan Fernando
099b83fd28 Everywhere: Fix incorrect uses of String::format and StringBuilder::appendf
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-11 21:06:32 +01:00
Andreas Kling
cf3d2411fa UserspaceEmulator: Implement the ftruncate and umask syscalls
It's now possible to copy files with FileManager running in UE. :^)
2021-01-11 12:01:42 +01:00
Brendan Coles
b53664a8ef UserspaceEmulator: Implement clock_settime syscall 2021-01-10 18:20:29 +01:00
Andreas Kling
2f3b901f7f AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used.

Instead of having valid/invalid states and storing an error in case
it's invalid, a MappedFile is now always valid, and the factory
function that creates it will return an OSError if mapping fails.
2021-01-10 16:49:13 +01:00
Andreas Kling
b4918bbe2f LibC: Move bzero() and bcopy() per Dr. POSIX 2021-01-09 19:56:59 +01:00
Andreas Kling
6a970611d6 UserspaceEmulator: Fix build after MOVSX shadowing changes 2021-01-08 12:29:46 +01:00
Gal Horowitz
2fd2396d63 UserspaceEmulator: Fix incorrect shadowing on mov sign extend
Unlike zero-extend moves, the upper bytes are not just zeroed,
but rather are based on the sign bit of the source, which means
if the source is tainted, so should the upper bytes be.
2021-01-08 12:17:06 +01:00
Andreas Kling
febc8a5ac7 UserspaceEmulator: Remove hand-rolled is_foo() helpers in favor of RTTI 2021-01-01 19:37:36 +01:00
Andreas Kling
e27d281bf1 UserspaceEmulator: Support sys$mremap()
This makes UE able to run dynamically linked executables once again.
2020-12-31 14:22:56 +01:00
Luke
0f66589007 Everywhere: Fix more typos 2020-12-31 01:47:41 +01:00
asynts
7e62ffbc6e AK+Format: Remove TypeErasedFormatParams& from format function. 2020-12-30 20:33:53 +01:00
Andreas Kling
0e2b7f9c9a Kernel: Remove the per-process icon_id and sys$set_process_icon()
This was a goofy kernel API where you could assign an icon_id (int) to
a process which referred to a global shbuf with a 16x16 icon bitmap
inside it.

Instead of this, programs that want to display a process icon now
retrieve it from the process executable instead.
2020-12-27 01:16:56 +01:00
Lenny Maiorani
b2316701a8 Everywhere: void arguments to C functions
Problem:
- C functions with no arguments require a single `void` in the argument list.

Solution:
- Put the `void` in the argument list of functions in C header files.
2020-12-26 10:10:27 +01:00
Andreas Kling
d55fb7b5e2 UserspaceEmulator: Use ring 3 segment selectors
We were using ring 0 selectors everywhere (the bottom 3 bits of a
selector determines the ring.) This doesn't really make any practical
difference since UE doesn't run code in other rings anyway, but let's
have correct-looking segment selectors. :^)
2020-12-25 15:39:26 +01:00
Andreas Kling
40e9edd798 LibELF: Move AuxiliaryValue into the ELF namespace 2020-12-25 14:48:30 +01:00
Andreas Kling
6c9a6bea1e Kernel+LibELF: Abort ELF executable load sooner when something fails
Make it possible to bail out of ELF::Image::for_each_program_header()
and then do exactly that if something goes wrong during executable
loading in the kernel.

Also make the errors we return slightly more nuanced than just ENOEXEC.
2020-12-25 14:42:42 +01:00
Andreas Kling
1e4c010643 LibELF: Remove ELF::Loader and move everyone to ELF::Image
This commit gets rid of ELF::Loader entirely since its very ambiguous
purpose was actually to load executables for the kernel, and that is
now handled by the kernel itself.

This patch includes some drive-by cleanup in LibDebug and CrashDaemon
enabled by the fact that we no longer need to keep the ref-counted
ELF::Loader around.
2020-12-25 02:14:56 +01:00
Brendan Coles
9ca34c3047 UserspaceEmulator: Implement profiling, disown, purge syscalls 2020-12-21 09:57:51 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Andreas Kling
71d92cef17 UserspaceEmulator: Add lazy caching of debug info for shared libraries
Keep the debug symbols for shared libraries in memory after we opened
them the first time. This dramatically speeds up symbolication of
backtraces when running dynamically linked programs in UE.
2020-12-20 15:45:39 +01:00
Brendan Coles
c8fb00fe4d UserspaceEmulator: Implement geteuid, getegid, ptsname syscalls 2020-12-17 00:02:03 +01:00
Brendan Coles
a46e48089d UserspaceEmulator: Implement beep syscall 2020-12-16 17:27:20 +01:00
Itamar
72ca45e300 UserspaceEmulator: Support dynamically loaded programs
When loading dynamic objects, the emulator loads the interpreter,
generates an auxiliary vector and starts executing the loader.

Additionally, this commits also makes the MallocTracer and backtrace
symbolication work for dynamically loaded programs.
2020-12-14 23:05:53 +01:00
Itamar
28cda567c1 UserspaceEmulator: Support the name argument in mmap for file backed mappings 2020-12-14 23:05:53 +01:00
Itamar
d2262b8f6d UserspaceEmulator: Update memory protection of underlying pages
If a MmapRegion is file backed, we need to call mprotect on its
underlying pages.
2020-12-14 23:05:53 +01:00
Ben Wiederhake
ebbae015ef UserspaceEmulator: Fix page determination
Note that this *only* affects the last few bytes of the ELF headers, since all
other allocations are PAGE_SIZE aligned.
2020-12-10 20:41:12 +01:00
Ben Wiederhake
809a8ee693 UserspaceEmulator: Implement readlink syscall 2020-12-08 09:37:30 +01:00
Ben Wiederhake
88b090a808 UserspaceEmulator: Handle overflow in virt$realpath 2020-12-08 09:37:30 +01:00
Simon Danner
751e759be2 UserspaceEmulator: Implement clock_nanosleep 2020-11-23 18:41:42 +01:00
Simon Danner
09b095e62a UserspaceEmulator: Add support for watch_file 2020-11-22 10:53:58 +01:00
Andreas Kling
da413a464a UserspaceEmulator: Inline some very hot functions
This improves the browser's load time on welcome.html by ~2%.
2020-11-19 21:46:01 +01:00
Andreas Kling
1965fc5b98 UserspaceEmulator: Keep Emulator& closer to the action in some places
This avoids the cost of calling Emulator::the() in some very hot paths.
2020-11-16 15:11:02 +01:00
Andreas Kling
d14695f823 UserspaceEmulator: Cache the region we're executing code from
Instead of caching a raw pointer to the next instruction, cache the
region we're fetching instructions from, and a pointer to its base.
This way we don't need to keep invalidating and reloading the cache
whenever the CPU jumps.
2020-11-16 15:11:02 +01:00
Andreas Kling
b4ff85f138 UserspaceEmulator: Reduce malloc thrashing in backtrace capture 2020-11-16 15:11:02 +01:00
Andreas Kling
e1f617950e UserspaceEmulator: Make big malloc block lookup O(1) as well
By passing the Region& to the auditing functions, we know exactly which
block we are hitting. This allows us to track big mallocations the same
way we already do chunked ones.

This gets rid of the O(n) scan in find_mallocation() for allocations
larger than the maximum malloc chunk size. :^)
2020-11-16 15:11:02 +01:00
Andreas Kling
8d9dd4c518 UserspaceEmulator: Make Region a top-level class 2020-11-16 15:11:02 +01:00
Andreas Kling
3c64cec4d7 UserspaceEmulator: Devirtualize read/write/execute region permissions
These are getting quite hot (~4% of general emulation profile combined)
so let's just devirtualize them and turn the function calls into simple
boolean checks.
2020-11-16 09:44:30 +01:00
Andreas Kling
f41b9946e2 UserspaceEmulator: Hang malloc metadata on malloc block MmapRegions
Instead of tracking known malloc blocks in a separate hash table,
add an optional malloc metadata pointer to MmapRegion.

This makes finding the malloc metadata for a given pointer extremely
fast since it can piggyback on the page table array. :^)
2020-11-16 09:33:30 +01:00
Andreas Kling
fe7036d8f4 UserspaceEmulator: Improve error text on jump to non-executable memory
The memory is non-executable, not non-readable. :^)
2020-11-16 09:10:49 +01:00
Nico Weber
6252e5b1f6 UserspaceEmulator: Implement 32-bit FIDIV, 16-bit FIADD/FISUB/FISUBR/FIDIV/FIDIVR/FISTP, and fix 32-bit FIADD
Not motivated by anything in particular, they just looked easy to fill
in. With this, all arithmetic FI* FPU instructions are implemented.

Switch to the mXXint style in a few more functions, this part is no-op.
2020-11-15 20:16:55 +01:00
Andreas Kling
6dab0af9af UserspaceEmulator: Add a fast path for forward REP STOSD
Same as REP STOSB, except for 32-bit fills instead.
2020-11-15 18:09:15 +01:00
Andreas Kling
102e1d330c UserspaceEmulator: Add a fast path for forward REP STOSB
This is used by memset() so we get a lot of mileage out of optimizing
this instruction.

Note that we currently audit every individual byte accessed separately.
This could be greatly improved by adding a range auditing mechanism to
MallocTracer.
2020-11-15 18:09:08 +01:00
Andreas Kling
92e152f11d UserspaceEmulator: Add virtual data()/shadow_data() accessors to Region 2020-11-15 18:09:04 +01:00
Andreas Kling
59b4874443 UserspaceEmulator: Add a page-address-to-MMU-region lookup map
To make SoftMMU::find_region() O(1), this patch invests 3MiB into a
lookup table where we track each possible page base address and map
them to the SoftMMU::Region corresponding to that address.

This is another large improvement to general emulation performance. :^)
2020-11-15 18:08:59 +01:00
Andreas Kling
a4a389156d UserspaceEmulator: Make sure the (crappy) VM allocator is page-aligned
We don't want the next_address pointer losing its alignment somehow.
This whole thing should be replaced at some point, since UE hosted
programs won't be able to run forever with this allocation strategy.
2020-11-15 18:08:56 +01:00
Nico Weber
be73f9f544 UserspaceEmulator: Implement FISUBR_RM32
Fixes crash when playing `ue Breakout` with the mouse.
2020-11-15 09:36:37 +01:00
Andreas Kling
12d923bb7e UserspaceEmulator: Fix some FPU instructions' handling of RM32/RM64
m32int is a 32-bit integer stored in memory, and should not be mistaken
for a floating point number. :^)

Also add missing handling of 64-bit FPU register operands to some of
the RM64 instructions.
2020-11-14 23:47:50 +01:00
Andreas Kling
647e92b74f UserspaceEmulator: Skip destroying the Emulator object on shutdown
There are some destruction order races that can cause hangs while
shutting down UE. Since there's no particular value right now in
destroying the Emulator object properly, just avoid destruction and
add a FIXME about looking into it later.
2020-11-14 23:39:44 +01:00
Andreas Kling
b5b535aa81 UserspaceEmulator: Untaint flags in FCOMI and FUCOMI for now
This makes UE logging bearable until we can get proper shadow data
support for the FPU stack.
2020-11-14 23:11:07 +01:00
Andreas Kling
8fd97bee7f UserspaceEmulator: Forget ChunkedBlocks after they are munmap()'ed
This is not ideal since we lose free() backtraces, but it will require
some thinking to get this right.
2020-11-14 23:07:07 +01:00