Commit Graph

102 Commits

Author SHA1 Message Date
Max Wipfli
fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Andreas Kling
e59bf87374 Userland: Replace VERIFY(is<T>) with verify_cast<T>
Instead of doing a VERIFY(is<T>(x)) and *then* casting it to T, we can
just do the cast right away with verify_cast<T>. :^)
2021-06-24 21:13:09 +02:00
Hendiadyoin1
5d24b5f4be UserspaceEmulator: Add a simple debugging Console
For now this only allows us to single-step through execution and inspect
part of the execution environment for debugging
This also allows to run to function return and sending signals to the VM

This changes the behavior of SIGINT for UE to pause execution and then
terminate if already paused

A way of setting a watchpoint for a function would be a good addition in
the future, the scaffold for this is already present, we only need to
figure out a way to find the address of a function

On a side note I have changed all occurences of west-const to east const
2021-06-23 12:41:37 +04:30
Gunnar Beutner
631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Hendiadyoin1
5ffe23e4f3 AK+LibX86: Generalize u128/256 to AK::UFixedBigInt
Doing these as custom classes might be faster, especially when writing
them in SSE, but this would cause a lot of Code duplication and due to
the nature of constexprs and the intelligence of the compiler they might
be using SSE/MMX either way
2021-06-11 18:14:11 +04:30
Jelle Raaijmakers
a32fe8df33 UserspaceEmulator: Stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Ben Wiederhake
a7c265f341 Everywhere: Sort out superfluous QuickSort.h imports
They were sorta unneeded. :^)
2021-05-29 23:41:54 +01:00
Gunnar Beutner
1f57cc5957 UE: Make sure signal_trampoline_dummy is not optimized away with -flto
This adds __attribute__((used)) to the function declaration so the
compiler doesn't discard it. It also makes the function NEVER_INLINE
so that we don't end up with multiple copies of the function. This
is necessary because the function uses inline assembly to define some
unique labels.
2021-05-28 07:59:05 +02:00
Andreas Kling
de395a3df2 AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both
of them into String::find() and use that everywhere.

Also add some tests to cover basic behavior.
2021-05-24 11:59:18 +02:00
Gunnar Beutner
39f0739381 LibC+UE: Keep more unused chunked blocks around
Previously each malloc size class would keep around a limited number of
unused blocks which were marked with MADV_SET_VOLATILE which could then
be reinitialized when additional blocks were needed.

This changes malloc() so that it also keeps around a number of blocks
without marking them with MADV_SET_VOLATILE. I termed these "hot"
blocks whereas blocks which were marked as MADV_SET_VOLATILE are called
"cold" blocks because they're more expensive to reinitialize.

In the worst case this could increase memory usage per process by
1MB when a program requests a bunch of memory and frees all of it.

Also, in order to make more efficient use of these unused blocks
they're now shared between size classes.
2021-05-23 19:31:39 +02:00
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