Commit Graph

92 Commits

Author SHA1 Message Date
Lenny Maiorani
6ac454e70a DevTools: Remove redundant default destructor and forward declarations
Problem:
- Default destructors (and constructors) are in `.cpp` files. This
  prevents the compiler's optimizer from inlining them when it thinks
  inlining is appropriate (unless LTO is used).
- Forward declarations can prevent some optimizations, such as
  inlining of constructors and destructors.

Solution:
- Remove them or set them to `= default` and let the compiler handle
  the generation of them.
- Remove unneeded forward declarations.
2021-05-21 22:53:33 +01:00
Andreas Kling
7957f13e98 Revert "LibC: Simplify malloc size classes"
This reverts commit f91bcb8895.
2021-05-18 08:32:05 +02:00
Lenny Maiorani
f91bcb8895 LibC: Simplify malloc size classes
Problem:
- `size_classes` is a C-style array which makes it difficult to use in
  algorithms.
- `all_of` algorithm is re-written for the specific implementation.

Solution:
- Change `size_classes` to be an `Array`.
- Directly use the generic `all_of` algorithm instead of
  reimplementing.
2021-05-18 08:06:01 +02:00
Gunnar Beutner
ee6600ea24 UE: Don't look up binaries in PATH when the user specified a full path
When the user specifies a path such as ./test we'd incorrectly look for
the binary in the PATH environment variable and end up executing an
incorrect binary (e.g. /bin/test). We should only look up binaries in
PATH if the user-specified path does not contain a slash.
2021-05-17 19:34:53 +02:00
Gunnar Beutner
26e711f953 UE: Use Vector<String> for the command-line arguments
Core::ArgsParser gained support for String a while ago. So let's use
that.
2021-05-17 19:34:53 +02:00
Linus Groh
0aab774343 Everywhere: Fix a bunch of typos 2021-05-17 17:48:55 +01:00
Gunnar Beutner
52054eb922 UE: Make sure we return the right values for get{peer,sock}name
These two functions didn't previously return error codes correctly and
would crash when an invalid address buffer was specified.
2021-05-17 13:32:19 +02:00
Gunnar Beutner
89956cb0d6 Kernel+Userspace: Implement the accept4() system call
Unlike accept() the new accept4() system call lets the caller specify
flags for the newly accepted socket file descriptor, such as
SOCK_CLOEXEC and SOCK_NONBLOCK.
2021-05-17 13:32:19 +02:00
Gunnar Beutner
529f605ac8 UE: Make sure the buffers for get{sock,peer}name() are large enough
Previously struct sockaddr was used which isn't guaranteed to be
large enough to hold the socket address get{sock,peer}name() returns.

Also, the addrlen argument was initialized incorrectly and should
instead use the address length specified by the caller.
2021-05-17 13:32:19 +02:00
sin-ack
2159f90e00 Userland+LibCore: Update FileWatcher + its users for InodeWatcher 2.0
With the new InodeWatcher API, the old style of creating a watcher per
inode will no longer work.  Therefore the FileWatcher API has been
updated to support multiple watches, and its users have also been
refactored to the new style.  At the moment, all operations done on a
(Blocking)FileWatcher return Result objects, however, this may be
changed in the future if it becomes too obnoxious. :^)

Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-12 22:38:20 +02:00
Brendan Coles
57c96ce501 UserspaceEmulator: Allow running executables not in PATH 2021-05-09 09:39:40 +02:00
Gunnar Beutner
e468bf08b1 UserspaceEmulator: Make sure TLS allocation behavior matches kernel 2021-05-03 08:25:44 +02:00
Gunnar Beutner
92cc8a47dd UserspaceEmulator: Add missing argument for sys$allocate_tls 2021-05-03 08:25:44 +02:00
Gunnar Beutner
ce0c76dcb5 UserspaceEmulator: Add stub for sys$futex 2021-05-03 08:25:44 +02:00
Gunnar Beutner
6cf59b6ae9 Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr 2021-05-01 21:25:06 +02:00
Hendiadyoin1
f6aad70541 LibX86+UserspaceEmulator: Add MMX insns prototypes 2021-05-01 08:56:52 +02:00
Hendiadyoin1
acd65a5f86 UserspaceEmulator: Add more Instructions
Adds:
* CMC
* POPA
* POPAD
* POPF
* PUSHA
* PUSHAD
* PUSHF
* PUSH_RM16
* SAHF
* FPU:
  * FNOP
  * FPREM
  * FSINCOS
  * FCMOVxx
  * FISTTP
2021-04-25 09:56:29 +02:00
Hendiadyoin1
39d34fb1f1 UE: Implement FLD_RM80 and FSTP_RM80
We do a bit too big reads and writes, but this should not be that bad
although it may taint memory graphs
2021-04-23 22:50:53 +02:00
Hendiadyoin1
f1957bb86b UE+LibX86: Support bigger reads and writes 2021-04-23 22:50:53 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
0058a1173e UserspaceEmulator: Convert String::format() => String::formatted() 2021-04-21 23:49:02 +02:00
Gunnar Beutner
f033416893 Kernel+LibC: Clean up how assertions work in the kernel and LibC
This also brings LibC's abort() function closer to the spec.
2021-04-18 11:11:15 +02:00
Linus Groh
2b0c361d04 Everywhere: Fix a bunch of typos 2021-04-18 10:30:03 +02:00
Hendiadyoin1
b8d381690c UserspaceEmulator: use outln_if 2021-04-16 20:03:35 +02:00
Gunnar Beutner
03d705d531 UserspaceEmulator: Print stacktrace for unhandled exceptions 2021-04-16 19:00:30 +02:00
Tobias Christiansen
c4a9f0db82 UserspaceEmulator: Improve detection of memory leaks
Previous a mallocation was marked as 'reachable' when any other
mallocation or memory region had a pointer to that mallocation. However
there could be the situation that two mallocations have pointers to each
other while still being unreachable from anywhere else. They would be
marked as 'reachable' regardless.

This patch replaces the old way of detemining whether a mallocation is
reachable by analyzing the dependencies of the different mallocations
using a graph-approach. Now mallocations are only reachable if pointed
to by other reachable mallocations or other memory regions.

A nice bonus is that this gets rid of a nested for_each_mallocation, so
the complexity of leak finding becomes linear instead of quadratic.
2021-04-12 18:02:16 +02:00
Gunnar Beutner
8ca5b8c065 LibC: Move S_* defines into <fcntl.h>
According to the Single UNIX Specification, Version 2 that's where
those macros should be defined. This fixes the libiconv port.

This also fixes some (but not all) build errors for the diffutils and nano ports.
2021-04-11 09:51:20 +02:00
Hendiadyoin1
2469e07784 UE: only write libc and libsystem location once
This is important when emulating UE itself, which maps these files
two times, and then we forget the original location of it.
2021-04-08 23:57:16 +02:00
Hendiadyoin1
58e373c0f2 UE: Use AK's bit_cast and not reimplement it 2021-04-08 23:57:16 +02:00
Hendiadyoin1
74de4795dc UE: Default initialize regionmap 2021-04-08 23:57:16 +02:00
AnotherTest
cbd62c472e UserspaceEmulator: Default-initialize the siginfo struct used in waitid
Otherwise it'll have some random value from the stack, and the kernel
will not bother setting it to zero.
Also add a debug print and tweak the FIXME message.
2021-03-31 23:49:26 +02:00
Idan Horowitz
0deb0c6891 UserspaceEmulator: Update virt$lseek and virt$ftruncate for 64bit off_t
The syscalls' prototypes were recently changed in preparation for 64bit
storage in serenity, so update them here as well :^)
2021-03-23 19:56:13 +01:00
Brendan Coles
7191098356 UserspaceEmulator: Add support for SC_abort syscall 2021-03-22 07:43:44 +01:00
Brendan Coles
4915cf5ab0 UE: Add killpg, getsockname, getpeername, shutdown, sync syscalls 2021-03-18 21:47:51 +01:00
Brendan Coles
46c7f52896 UserspaceEmulator: Add symlink, rename, set_coredump_metadata syscalls 2021-03-16 21:57:13 +01:00
Brendan Coles
fe97aec8c3 UserspaceEmulator: Print PID in mmap nullptr with MAP_FIXED reportln() 2021-03-16 21:48:29 +01:00
Brendan Coles
7156b61d57 UserspaceEmulator: downgrade TODO to dbgln for invalid fcntl cmd arg 2021-03-15 16:07:31 +01:00
Brendan Coles
1eccd78e3a UserspaceEmulator: Add SC_rmdir syscall 2021-03-14 21:36:36 +01:00
Brendan Coles
ab9f66a069 UserspaceEmulator: Increase stack size from 64 * KiB to 1 * MiB 2021-03-14 13:55:29 +01:00
Brendan Coles
2c24c0e451 UserspaceEmulator: SoftCPU: Add support for FPTAN instruction 2021-03-14 09:45:22 +01:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Andreas Kling
0c35c664e6 UserspaceEmulator: Convert a weird klog(!) to dbgln() 2021-03-12 11:23:26 +01:00
Brendan Coles
ec1fdef818 UserspaceEmulator: SoftCPU: Add support for several x86 FPU instructions
F2XM1
FYL2X
FYL2XP1
FDECSTP
FINCSTP
FSCALE
2021-03-12 09:59:45 +01:00
Ben Wiederhake
292871c4bc UserspaceEmulator: Handle MAP_FIXED with invalid addresses better
Old behavior: Crash due to VERIFY, unless we're completely and entirely out of
memory (m_available_ranges being empty), in which case it would return -ENOMEM.

New behavior: Return ENOMEM (and don't crash). In the case of nullptr,
also emit a helpful diagnostic.

Note that MAP_FIXED with nullptr is technically okay, but tends to be a sign
that something went wrong.

Also, this should improve mmap performance marginally, as it pulls the check out
of a loop that does not modify any parts of the check.

UE is now self-hosting! Fixes #5709.

However, this still needs some love: "ue UserspaceEmulator true" spits out tons
of error messages, probably false-positives, and takes about 229 seconds to run.
Then again, true-in-ue-in-ue-in-Qemu is three levels of emulation, so no wonder
it takes a long time! :D
2021-03-11 08:54:54 +01:00
Ben Wiederhake
22d9bd0c45 UserspaceEmulator: Do not pass MAP_FIXED to Kernel
Since there is usually no correlation between guest memory-layout and UE memory-layout,
this option does not make any sense. Especially since we provide nullptr.
2021-03-11 08:54:54 +01:00
Ben Wiederhake
d5925f33aa UserspaceEmulator: Implement set_process_name syscall 2021-03-11 08:54:54 +01:00
Ben Wiederhake
ec8e3edd05 UserspaceEmulator: Split large file into logical pieces 2021-03-11 08:54:54 +01:00
Andreas Kling
ced8dfa037 UserspaceEmulator: Remove debug spam about tracked malloc blocks 2021-03-10 15:21:26 +01:00
Andreas Kling
82aea65bd3 UserspaceEmulator: Add fast-path for is<MmapRegion>()
Don't use default RTTI for these since they are performance-sensitive.
2021-03-09 15:17:15 +01:00
Andreas Kling
656cd477c2 UserspaceEmulator+LibX86: Sprinkle some [[unlikely]] and ALWAYS_INLINE 2021-03-09 15:10:08 +01:00