Commit graph

139 commits

Author SHA1 Message Date
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
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
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
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
b4ff85f138 UserspaceEmulator: Reduce malloc thrashing in backtrace capture 2020-11-16 15:11:02 +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
Andreas Kling
d4509647d8 UserspaceEmulator: Honor the read/write/execute bits in mmap regions
UE will now correctly crash when accessing an mmap memory region in
some way it's not supposed to be accessed.
2020-11-14 15:33:56 +01:00
Andreas Kling
ae81ced21c UserspaceEmulator: Emulate the sys$get_stack_bounds() syscall 2020-11-13 11:05:46 +01:00
Andreas Kling
ae10c9d8ec UserspaceEmulator: Fix busted backtraces with --report-to-debug
Some of the output was still going to stderr in this mode, we need to
use reportln() to make sure it goes to the right place.
2020-11-08 01:15:02 +01:00
Andreas Kling
013c7ccd73 UserspaceEmulator: Don't audit accesses within realloc(), malloc_size()
These functions access malloc-related memory outside of UE's accounting
boundaries, so just ignore them.
2020-11-08 01:15:02 +01:00
AnotherTest
4d756c7d2d UserspaceEmulator: Remove some unneeded String copies 2020-10-25 10:13:03 +01:00
AnotherTest
57f0f8c9b7 UserspaceEmulator: Handle SO_BINDTODEVICE in setsockopt 2020-10-25 10:13:03 +01:00
AnotherTest
290e7957b7 UserspaceEmulator: Add support for setsid 2020-10-25 10:13:03 +01:00
AnotherTest
fcc38422c6 UserspaceEmulator: Add support for set_thread_name
It should be noted that creating threads is still not supported.
2020-10-25 10:13:03 +01:00
AnotherTest
617c5ba045 UserspaceEmulator: Add support for fchown 2020-10-25 10:13:03 +01:00
AnotherTest
41aa78f6de UserspaceEmulator: Add support for chmod 2020-10-25 10:13:03 +01:00
AnotherTest
b1d36243e5 UserspaceEmulator: Add support for setgroups 2020-10-25 10:13:03 +01:00
AnotherTest
457e00f319 UserspaceEmulator: Add support for sched_(g s)etparam 2020-10-25 10:13:03 +01:00
AnotherTest
33730cbd92 UserspaceEmulator: Add support for some more ioctl() requests 2020-10-25 10:13:03 +01:00
AnotherTest
aee0df19c1 UserspaceEmulator: Add support for emulating SC_mount 2020-10-25 10:13:03 +01:00
AnotherTest
9afe9069a9 UserspaceEmulator: Optionally write reports to the debug log
...and take a flag '--report-to-debug' that determines this behaviour.
2020-10-25 10:13:03 +01:00
Paul Scharnofske
d94f674bbb
Use new format functions in remaining DevTools. (#3755)
* AK: Add formatter for JsonValue.

* Inspector: Use new format functions.

* Profiler: Use new format functions.

* UserspaceEmulator: Use new format functions.
2020-10-13 18:34:27 +02:00
asynts
e089855af0 UserspaceEmulator: Remove remaining printf calls. 2020-10-04 17:04:55 +02:00
asynts
d5ffb51a83 AK: Don't add newline for outf/dbgf/warnf.
In the future all (normal) output should be written by any of the
following functions:

    out    (currently called new_out)
    outln
    dbg    (currently called new_dbg)
    dbgln
    warn   (currently called new_warn)
    warnln

However, there are still a ton of uses of the old out/warn/dbg in the
code base so the new functions are called new_out/new_warn/new_dbg. I am
going to rename them as soon as all the other usages are gone (this
might take a while.)

I also added raw_out/raw_dbg/raw_warn which don't do any escaping,
this should be useful if no formatting is required and if the input
contains tons of curly braces. (I am not entirely sure if this function
will stay, but I am adding it for now.)
2020-10-04 17:04:55 +02:00
Linus Groh
bcfc6f0c57 Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
asynts
ba3488a6d5 UserspaceEmulator: Replace printf usages with format.
This replaces almost all usages. Some have to remain because 'outf'
always appends a newline. (It inherits this behaviour from LogStream.)
2020-10-02 13:44:42 +02:00
Andreas Kling
709581e141 UserspaceEmulator: Implement the getsid() syscall 2020-09-28 23:34:55 +02:00
Nico Weber
31e7f73aae UserspaceEmulator: Support all msg_iovlens in recvmsg and sendmsg
The kernel doesn't support msg_iovlens != 1 yet and nothing passes
an amount != 1, but if anyone ever adds support for this they won't
have to worry about ue at least.
2020-09-19 00:39:05 +02:00
Nico Weber
47b3e98af8 Kernel+LibC+UserspaceEmulator: Add SO_TIMESTAMP, and cmsg definitions
When SO_TIMESTAMP is set as an option on a SOCK_DGRAM socket, then
recvmsg() will return a SCM_TIMESTAMP control message that
contains a struct timeval with the system time that was current
when the socket was received.
2020-09-17 17:23:01 +02:00
Nico Weber
b36a2d6686 Kernel+LibC+UserspaceEmulator: Mostly add recvmsg(), sendmsg()
The implementation only supports a single iovec for now.
Some might say having more than one iovec is the main point of
recvmsg() and sendmsg(), but I'm interested in the control message
bits.
2020-09-17 17:23:01 +02:00