Commit graph

25603 commits

Author SHA1 Message Date
Brian Gianforcaro bffcb3e92a Kernel: Add lock debugging to ProtectedValue / RefCountedContended
Enable the LOCK_DEBUG functionality for these new APIs, as it looks
like we want to move the whole system to use this in the not so distant
future. :^)
2021-08-13 20:42:39 +02:00
Brian Gianforcaro bea74f4b77 Kernel: Reduce LOCK_DEBUG ifdefs by utilizing Kernel::LockLocation
The LOCK_DEBUG conditional code is pretty ugly for a feature that we
only use rarely. We can remove a significant amount of this code by
utilizing a zero sized fake type when not building in LOCK_DEBUG mode.

This lets us keep the same API, but just let the compiler optimize it
away when don't actually care about the location the caller came from.
2021-08-13 20:42:39 +02:00
Brian Gianforcaro 6c18b4e558 Kernel: Introduce LockLocation abstraction from SourceLocation
Introduce a zero sized type to represent a SourceLocation, when we
don't want to compile with SourceLocation support.
2021-08-13 20:42:39 +02:00
Liav A 0a5312730c Kernel/ProcFS: Propagate errors correctly when they occur
Calling error() on KResult is a mistake I made in 7ba991dc37, so
instead of doing that, which triggers an assertion if an error occured,
in Inode::read_entire method with VERIFY(nread <= sizeof(buffer)), we
really should just return the KResult and not to call error() on it.
2021-08-13 20:07:43 +02:00
sin-ack 1d2bde2403 Meta: Add new-project.sh :^)
This script will instantiate a HackStudio template into a project on the
host. It currently supports all templates used by HackStudio.

To avoid having to maintain compatibility between other shells and the
Serenity shell in the postcreate scripts, we build the Serenity shell
with Lagom and use that to run the script.
2021-08-13 21:12:17 +04:30
brapru d456af1cd3 LibCore+LibHTTP: Check the status of the socket after EINPROGRESS
Previously the system would assume the socket was connected after the
file descriptor became writeable. Just because the fd is signaled as
ready for output does not necessarily indicate the socket is connected.
Instead, we should check the status of the socket with SO_ERROR and
handle successes/errors accordingly.
2021-08-13 20:30:19 +04:30
brapru 6743170f4e Kernel: Clear SO_ERROR on successful socket connection
When TCP sockets successfully establish a connection, any SO_ERROR
should be cleared back to success. For example, SO_ERROR gets set to
EINPROGRESS on asynchronous connect calls and should be cleared when
the socket moves to the Established state.
2021-08-13 20:30:19 +04:30
brapru 8059f28977 Utilities: Add program argument for netstat to display connection pid
Adds netstat command line argument to display slash-separated pair of
the id and name of the process that owns the socket. User must have
superuser privileges to see information on non-owned sockets.
2021-08-13 20:03:57 +04:30
brapru 1a5b3a1c3f Kernel/ProcFS: Expose TCP/UDP Socket pids
This allows for commands like netstat to reference /proc/net and
identify a connection's owning process. Process information is limited
to superusers and user owned processes.
2021-08-13 20:03:57 +04:30
TheFightingCatfish 0921390109 Ports: Support libcurl in the git build
Previously, libcurl is not used in the git build because the test
program in configure fails to link against it properly. We bypass the
test and make sure we link against all necessary libraries (libssl,
libcrypto and zlib).
2021-08-13 15:43:36 +02:00
TheFightingCatfish ff8630c66f Ports: Disable uname detection when building git
Previously, the git port would fail in various ways because it uses an
uname detection mechanism to update the configurations, and Makefile
would receive incorrect configurations from the host system. This makes
sure the build uses the correct configurations detected by ./configure.

Fixes #9357.
2021-08-13 15:43:36 +02:00
TheFightingCatfish 2fbeacb9e7 Ports: Use TextEditor and less as git's default editor and pager 2021-08-13 15:43:36 +02:00
Ali Mohammad Pur 071fff8cea Meta: Add Lenny Maiorani to the contributors list :^) 2021-08-13 17:49:04 +04:30
Lenny Maiorani 077e78a8d7 IntrusiveRedBlackTree: Remove redundant subtraction of 0
Problem:
- ToT clang will not build due to casting `nullptr` to `u8*`. This is
  redundant because it casts to get a `0` then subtracts it.

Solution:
- Remove it since subtracting `0` doesn't do anything.
2021-08-13 17:39:33 +04:30
Ali Mohammad Pur 15f95220ae AK+Everywhere: Delete Variant's default constructor
This was exposed to the user by mistake, and even accumulated a bunch of
users that didn't blow up out of sheer luck.
2021-08-13 17:31:39 +04:30
Jesse Buhagiar 90e6b9d453 LibGL: Implement glColor3fv 2021-08-13 16:54:37 +04:30
Brian Gianforcaro 296452a981 Kernel: Make cloning of FileDescriptions OOM safe 2021-08-13 11:09:25 +02:00
Brian Gianforcaro e7fb70b05c Kernel: Allow kmalloc(..) / kmalloc_aligned(..) to return nullptr
Now that we have a significant amount of code paths handling OOM, lets
enable kmalloc and friends to actually return nullptr. This way we can
start stressing these paths and validating all of they work as expected.
2021-08-13 11:09:25 +02:00
Brian Gianforcaro 27111cfc6c SystemMonitor: Unveil /usr/local/bin so symbolization works on ports 2021-08-13 11:08:38 +02:00
Brian Gianforcaro ed6d842f85 Kernel: Fix OOB read in sys$dbgputstr(..) during fuzzing
The implementation uses try_copy_kstring_from_user to allocate a kernel
string using, but does not use the length of the resulting string.
The size parameter to the syscall is untrusted, as try copy kstring will
attempt to perform a `safe_strlen(..)` on the user mode string and use
that value for the allocated length of the KString instead. The bug is
that we are printing the kstring, but with the usermode size argument.

During fuzzing this resulted in us walking off the end of the allocated
KString buffer printing garbage (or any kernel data!), until we stumbled
in to the KSym region and hit a fatal page fault.

This is technically a kernel information disclosure, but (un)fortunately
the disclosure only happens to the Bochs debug port, and or the serial
port if serial debugging is enabled. As far as I can tell it's not
actually possible for an untrusted attacker to use this to do something
nefarious, as they would need access to the host. If they have host
access then they can already do much worse things :^).
2021-08-13 11:08:11 +02:00
Brian Gianforcaro 40a942d28b Kernel: Remove char* versions of path argument / kstring copy methods
The only two paths for copying strings in the kernel should be going
through the existing Userspace<char const*>, or StringArgument methods.

Lets enforce this by removing the option for using the raw cstring APIs
that were previously available.
2021-08-13 11:08:11 +02:00
Brian Gianforcaro 5121e58d4a Kernel: Fix sys$dbgputstr(...) to take a char* instead of u8*
We always attempt to print this as a string, and it's defined as such in
LibC, so fix the signature to match.
2021-08-13 11:08:11 +02:00
Brian Gianforcaro 1ee1ef5103 Kernel: Introduce a StringView overload of dbgputstr(..) 2021-08-13 11:08:11 +02:00
Brian Gianforcaro 060503ef25 Kernel: Annotate KString methods as [[nodiscard]] 2021-08-13 11:08:11 +02:00
Brian Gianforcaro f2d684fc24 AK: Annotate String.count as [[nodiscard]] 2021-08-13 11:08:11 +02:00
Liav A 18eb262157 Kernel: Move VirtIO code into the Bus source folder
The VirtIO code handles functionality related to the VirtIO bus, so it
really should be in the Bus folder.
2021-08-13 08:06:47 +02:00
Jean-Baptiste Boric f641cc6470 Meta: Tune default QEMU disk size
Having lots of small files in Base/ may require more inodes in the
ext2 filesystem than the format utility sets aside by default. Let's
make a more educated guess since we have a rough idea of how many
inodes we need by counting files and directories.
2021-08-13 08:04:59 +02:00
Liav A 23a8cd1021 Documentation: Fix a few typos in the ProcFS Indexing document 2021-08-13 08:01:55 +02:00
Kenneth Myhra 6ace2187e2 Ports/stress-ng: Remove custom pause function from patch
This removes the custom pause function in patch so that we can use our
own LibC pause function.
2021-08-13 07:54:26 +02:00
Jean-Baptiste Boric b6b6add78f LibC: Implement pause function 2021-08-13 03:16:58 +02:00
Jean-Baptiste Boric f2b8b46bb0 LibC: Implement sigsuspend function 2021-08-13 03:16:58 +02:00
Andreas Kling 7abf58ecaf Profiler: Store event type as enum
Also check for the most common event type (sample) first instead of
leaving it as the fallback. This avoids a lot of string comparisons
while parsing profiles.
2021-08-13 03:06:07 +02:00
Andreas Kling 5a2ccbffc5 Profiler: Remove "Signpost " prefix from timeline tooltips 2021-08-13 03:03:53 +02:00
Ali Mohammad Pur 0f1425c895 AK: Avoid OOB access in UniformBumpAllocator::destroy_all()
Otherwise we would end up calling T::~T() on some random memory right
after our mapped block, which is most likely a pretty bad thing to do :P
2021-08-13 04:42:34 +04:30
sin-ack 0e5e6f2e08 Base: Convert postcreate scripts to use heredoc 2021-08-13 01:20:35 +04:30
sin-ack 4c6a97e757 Shell: Make caller specify the string parsing end condition
Heredocs have a different parse end condition than double-quoted
strings. parse_doublequoted_string_inner would assume that a string
would always end in a double quote, so let's generalize it to
parse_string_inner and have it take a StringEndCondition enum which
specifies how the string terminates.
2021-08-13 01:20:35 +04:30
sin-ack c419b1ade6 Shell: Remove dbgln related to process group IDs
This is insignificant debugging information and will print out during
runs with Lagom.
2021-08-12 22:42:50 +02:00
Liav A 65730f459d SystemServer: Generalize chown_all_framebuffer_devices function
Instead of neatly searching for all framebuffer device nodes and
changing ownership of them, let's generalize this function so we can
apply the same pattern on tty nodes.
2021-08-12 21:10:55 +02:00
Daniel Bertalan 49d795b985 Meta: Enable nonnull-compare warnings
Previously, this was disabled because GCC flagged seemingly correct and
well-defined code. This was however not the case because GCC implicitly
marked some pointers non-null, even if we wanted to handle them
ourselves, and deleted null checks on them. By re-introducing this
warning, we will know if the compiler tries to discard our code again.
2021-08-12 21:10:44 +02:00
Daniel Bertalan c2c12e9dc5 LibC+DynamicLoader: Prevent GCC from removing null checks
GCC implements `fputc`, `fputs` and `fwrite` as builtin functions, whose
`FILE*` argument is implicitly marked `__attribute__((nonnull))`. This
causes our `VERIFY(stream)` statements to be removed. This does not
happen with Clang, as they do not use the `nonnull` attribute in this
way.
2021-08-12 21:10:44 +02:00
Daniel Bertalan b19fe744ab LibWeb: Remove pointless type casts
In these cases, the parameters' static type matched the desired dynamic
type, so these calls were discarded.
2021-08-12 21:10:44 +02:00
Daniel Bertalan f95a11a7da LibC: Don't delete null check in gettimeofday
The `nonnull` attribute may delete null checks in the generated code, as
per the [GCC documentation]:

> The compiler may also perform optimizations based on the knowledge
> that nonnul parameters cannot be null. This can currently not be
> disabled other than by removing the nonnull attribute.

Disassembling the function as compiled by GCC, we can see that there is
no branch based on if `tv` is null.  This means that `gettimeofday`
would produce UB if passed a null parameter, even if we wanted to
predictably return an error.  Clang refuses to compile this due to a
`pointer-bool-conversion` warning.

In this commit, `settimeofday` is changed as well to match
`gettimeofday`'s null argument handling.

[GCC documentation]:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute
2021-08-12 21:10:44 +02:00
Ali Mohammad Pur 8b6397446e LibWasm: Move some Values and Vector<Value>s instead of copying them 2021-08-12 21:03:53 +02:00
Ali Mohammad Pur fa2ae02564 LibWasm: Avoid calculating stack bounds on each wasm call
We only need to know the initial bounds, which we calculate by default
when the interpreter is constructed.
This cuts down on syscalls and makes wasm calls a lot cheaper.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur 2b35e9f9be LibWasm: Generate Value::type() on the fly instead of storing it
The variant member already contains enough information to give us the
type when needed, so remove the type member and synthesize it when
needed, this allows lots of optimisation opportunaties when copying and
moving Values around.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur f0e7e5bbe8 Meta: Un-escape escaped strings when generating Wasm tests 2021-08-12 21:03:53 +02:00
Ali Mohammad Pur 4060f18d7e LibWasm: Replace memory write macros with templated functions 2021-08-12 21:03:53 +02:00
Ali Mohammad Pur b6381f785d LibWasm: Make memory operation address calculation match the spec
...or rather, match what the spec _means_ to say, not what it actually
says.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur ad3de4648a LibWasm: Replace memory read macros with templated functions 2021-08-12 21:03:53 +02:00
Ali Mohammad Pur 563b402f04 LibWasm: Replace the numeric operation macros with templated functions
This should make debugging and profiling much better, at little to no
runtime cost.
Also moves off the operator definitions to a separate header, so it
should also improve the editing experience quite a bit.
2021-08-12 21:03:53 +02:00