Commit graph

44217 commits

Author SHA1 Message Date
kleines Filmröllchen bbb256e8b5 AK: Introduce Indexable concept
This was dearly missing and can be used in many existing templates.
2022-12-12 15:03:57 +00:00
Baitinq af1c26f05b Browser: Go back/forward when pressing back/forward mouse buttons
This currently doesn't work when running Serenity through QEMU, as it
doesn't pass the side button events over to Serenity due to some bug or
missing feature.
2022-12-12 15:00:08 +00:00
Luke Wilde 2f3ebce7c8 LibJS: Keep GeneratorObject's stored execution context's internals alive
This would previously crash with a heap UAF when storing the result of
`yield 1` into `e` on the second `next` call:
```js
function* a() { const e = yield 1; }
b = a();
b.next();
gc();
b.next();
```
2022-12-12 13:58:32 +00:00
Luke Wilde 6431dd7904 LibJS: Make it possible to visit the edges of an ExecutionContext 2022-12-12 13:58:32 +00:00
Luke Wilde 40cc38869e LibJS: Move ExecutionContext function implementations out of line 2022-12-12 13:58:32 +00:00
Ali Mohammad Pur 4311c2164e Shell: Disable interactive mode on '-c'
This also disables the full suite of interactive stuff in LibLine.
2022-12-12 13:57:06 +00:00
Tim Schumacher 3fccf2481c LibCore: Make not discarding all requested bytes from a stream an error 2022-12-12 14:16:42 +01:00
Tim Schumacher 9a3e95785e LibCore: Propagate errors from Stream::*_entire_buffer 2022-12-12 14:16:42 +01:00
Tim Schumacher 6c7c5a6786 LibCore: Rename Stream::*_or_error to *_entire_buffer
All of our functions are `_or_error` (or are about to be), and maybe
making it less reminiscient of AK::Stream will make people use it more.
2022-12-12 14:16:42 +01:00
Tim Schumacher ed4c2f2f8e LibCore: Rename Stream::read_all to read_until_eof
This generally seems like a better name, especially if we somehow also
need a better name for "read the entire buffer, but not the entire file"
somewhere down the line.
2022-12-12 14:16:42 +01:00
Tim Schumacher 5061a905ff LibCore: Remove Stream::is_{readable,writable}
Next to functions like `is_eof` these were really confusing to use, and
the `read`/`write` functions should fail anyways if a stream is not
readable/writable.
2022-12-12 14:16:42 +01:00
kleines Filmröllchen 5a346c4297 Help+LibManual: Without arguments, open index page instead of crashing
This is the old behavior before the recent LibManual refactor. It also
moves the definition of the index page into LibManual for better reuse.
2022-12-12 00:37:29 -07:00
sin-ack cda5a530e6 Ports: Add zig port :^)
:yakkie:

The build process for the Zig compiler is more involved than most of
the other ports, because the Zig compiler is mostly self-hosting. In
order to build it, the zig-bootstrap build system is used, which does
the following:

1) Build LLVM for the host OS;
2) Build Zig for the host OS with the SerenityOS target enabled;
3) Build zlib, zstd and LLVM for SerenityOS using `zig cc` as the C/C++
   compiler;
4) Build Zig for SerenityOS using the host Zig.

A few hacks are required in order to tell `zig cc` and zig about what
Serenity's libc looks like in the build process, but other than that
it's fairly straightforward. All of the patches that are included with
this commit are Zig-upstream ready once the LLVM patches are upstreamed.
2022-12-11 19:55:37 -07:00
sin-ack 27da878bb7 Ports: Export CMAKE_BUILD_PARALLEL_LEVEL for ports scripts
When using cmake --build, CMake will look for this environment variable
to enable parallelism. The Zig port, for example, uses cmake --build,
and will otherwise use a single core if cmake selects Make as the build
system. This should help with all ports which use cmake --build.
2022-12-11 19:55:37 -07:00
sin-ack d9e1a6c566 Kernel: Bump maximum pthread stack size to 32MiB
The Zig compiler asks for this much stack on its main thread via the use
of PT_GNU_STACK.
2022-12-11 19:55:37 -07:00
sin-ack ef6921d7c7 Kernel+LibC+LibELF: Set stack size based on PT_GNU_STACK during execve
Some programs explicitly ask for a different initial stack size than
what the OS provides. This is implemented in ELF by having a
PT_GNU_STACK header which has its p_memsz set to the amount that the
program requires. This commit implements this policy by reading the
p_memsz of the header and setting the main thread stack size to that.
ELF::Image::validate_program_headers ensures that the size attribute is
a reasonable value.
2022-12-11 19:55:37 -07:00
sin-ack 3275015786 Kernel: Implement flock downgrading
This commit makes it possible for a process to downgrade a file lock it
holds from a write (exclusive) lock to a read (shared) lock. For this,
the process must point to the exact range of the flock, and must be the
owner of the lock.
2022-12-11 19:55:37 -07:00
sin-ack 9b425b860c Kernel+LibC+Tests: Implement pwritev(2)
While this isn't really POSIX, it's needed by the Zig port and was
simple enough to implement.
2022-12-11 19:55:37 -07:00
sin-ack 70337f3a4b Kernel+LibC: Implement setregid(2)
This copies and adapts the setresgid syscall, following in the footsteps
of setreuid and setresuid.
2022-12-11 19:55:37 -07:00
sin-ack 2a502fe232 Kernel+LibC+LibCore+UserspaceEmulator: Implement faccessat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
sin-ack fa692e13f9 Kernel: Use real UID/GID when checking for file access
This aligns the rest of the system with POSIX, who says that access(2)
must check against the real UID and GID, not effective ones.
2022-12-11 19:55:37 -07:00
sin-ack 3472c84d14 Kernel: Remove InodeMetadata::may_{read,write,execute}(Process const&)
These have no definition and are never used.
2022-12-11 19:55:37 -07:00
sin-ack d5fbdf1866 Kernel+LibC+LibCore: Implement renameat(2)
Now with the ability to specify different bases for the old and new
paths.
2022-12-11 19:55:37 -07:00
sin-ack eb5389e933 Kernel+LibC+LibCore: Implement mkdirat(2) 2022-12-11 19:55:37 -07:00
sin-ack 6445a706cf Kernel+LibC: Implement readlinkat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
sin-ack 9850a69cd1 Kernel+LibC+LibCore: Implement symlinkat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
sin-ack 5c1d5ed51d Kernel: Implement Process::custody_for_dirfd
This allows deduplicating a bunch of code that has to work with
POSIX' *at syscall semantics.
2022-12-11 19:55:37 -07:00
kleines Filmröllchen 5b335e7fba Tests: Update thread tests and make them pass
The existing tests have only mildly changed, and there is another test
for joining dead non-detached threads.
2022-12-11 19:07:20 -07:00
kleines Filmröllchen 2fcb713037 LibThreading: Overhaul thread behavior with ThreadState
This replaces all state-related variables with a single ThreadState.
These are simplified over what the Kernel has, but capture all
userspace-available thread state.

Locking the state behind an atomic and using proper atomic operations
also gets rid of quite some deadlocks and race conditions that have
existed around m_tid and others beforehand.

In terms of behavior, this introduces the following changes:
- All thread state mishandling (e.g. joining a detached thread) crashes
  the program. Mishandling thread state is a severe kind of concurrency
  bug that might also be indeterministic, so letting it silently
  disappear with the return value of pthread_ APIs is a bad idea. The
  thread state can always be checked beforehand to ensure that no crash
  happens.
- Destructing a still-running thread will crash in AK/Function, so the
  Thread destructor issues its own warning for debugging purposes.
- Thread issues warnings before crashes in many places to aid
  concurrency debugging (the most difficult kind of debugging).
- Joining dead but not detached threads is legal, as per POSIX APIs.
- The thread ID is never reset to 0 after the thread has been started
  and subsequently been assigned a valid thread ID. The thread's exit
  state is still obtainable.
- Detaching threads that are about to exit is considered a programming
  bug and will often (not always, as we can't catch all execution
  sequences involved in such a situation) crash the program on purpose.
  If you want to detach a thread that will definitely exit on its own,
  you have to prevent it from exiting before detach() was called (e.g.
  with an "exit requested" flag).
2022-12-11 19:07:20 -07:00
kleines Filmröllchen 601ede331b LibThreading: Add a thread state enum
This will later be used by Thread to keep track of its state more simply
and obviously.
2022-12-11 19:07:20 -07:00
kleines Filmröllchen fe004d3389 LibThreading: Add Thread formatter
Printing a thread for debugging is used quite often.
2022-12-11 19:07:20 -07:00
kleines Filmröllchen 9e40d4ccd6 LibThreading: Move now-trivial accessors of Thread to cpp file
Some of these might be changed in the future, and because Thread.h is a
commonly included header file, we don't want to change it as much as
possible.
2022-12-11 19:07:20 -07:00
kleines Filmröllchen 7fd7562140 LibThreading: Use Threading namespace in Thread.cpp 2022-12-11 19:07:20 -07:00
kleines Filmröllchen bfb3fc58dd Kernel: Allow dead threads to be joined
Joining dead threads is allowed for two main reasons:
- Thread join behavior should not be racy when a thread is joined and
  exiting at roughly the same time. This is common behavior when threads
  are given a signal to end (meaning they are going to exit ASAP) and
  then joined.
- POSIX requires that exited threads are joinable (at least, there is no
  language in the specification forbidding it).

The behavior is still well-defined; e.g. it doesn't allow a dead
detached thread to be joined or a thread to be joined more than once.
2022-12-11 19:07:20 -07:00
Timothy Flynn 8997d825d5 LibSQL: Don't use the SQL socket file path as its descriptor
This is just used to key the socket fd for system server takeover. On
macOS, this file path has a space in it, which trips up the parsing as
it splits on spaces. That parsing should be fixed (probably shouldn't
rely on spaces as a delimter), but for now, we can change the key to
avoid spaces.
2022-12-11 19:05:07 -07:00
Timothy Flynn 4d3bb5ada4 LibSQL: Do not fchmod the SQL socket on macOS
Similar to: 9a4ee9aa1a.
2022-12-11 19:05:07 -07:00
Arda Cinar 1d687b0b31 MasterWord: Display the last word in a different color for short input
Previously, the word was highlighted red in case it was not found in the
dictionary. That color was repurposed as a general "invalid input" color
to nudge the player that something was wrong with the last input.
Accordingly, the field m_last_word_not_in_dictionary was renamed to
m_last_word_invalid
2022-12-11 22:10:37 +01:00
Arda Cinar cc5ea3aa4c MasterWord: Display messages in a statusbar
In the "inspiration" for this game, messages are displayed on top of the
game area in case an invalid guess is inputted. After a few seconds,
they disappear. In a similar fashion, a statusbar is created on the game
window and similar messages are outputted there.
2022-12-11 22:10:37 +01:00
MacDue d3588a9a2b LibWeb: Support calc() values in background-position 2022-12-11 22:09:24 +01:00
Aliaksandr Kalenik 3922349b71 LibWeb: Use space_used_by_floats to get x offset of box that creates BFC
y of box should be taken in account while calculating space
used by floats.
2022-12-11 22:08:44 +01:00
Aliaksandr Kalenik daece542f5 LibWeb: Check if block creates BFC even if all it's children are inline
Even if block has all children inline there need to be a check
if it creates BFC because otherwise IFC will be looking in
wrong parent BFC to calculate space used by floats.
2022-12-11 22:08:44 +01:00
Itamar 108a8e4c88 LibX86: Only pass ProcessorMode to Instruction constructor
We previously passed both OperandSize and AddressSize to the
constructor.

Both values were only ever 32-bit at construction.
We used AddressSize::Size64 to signify Long mode which was needlessly
complicated.
2022-12-11 22:06:30 +01:00
Itamar 9a136e354d LibX86: Use AddressSize::32 in Long mode
As the existing near-by comment says, the default size of displacements
& immediates is 32 bits even in Long mode.

This makes `disasm` work on our binaries in x86-64 builds.
2022-12-11 22:06:30 +01:00
kleines Filmröllchen dd66f5e838 Help: Link to LibLocale
This managed to fly under my radar for the LibManual PR, and somehow it
only happens for the Clang build but doesn't always trigger on CI.
2022-12-11 13:59:41 -07:00
Snow 2f8c7b1b30 LibGUI: Add shortcut for inserting new line
This adds shortcut for inserting a new empty indented line
above/below current cursor position.

- <Ctrl-Return> for inserting line below.
- <Ctrl-Shift-Return> for inserting line above.
2022-12-11 19:47:42 +00:00
thankyouverycool e06f9174a1 WindowServer: Remove unused bools in Menu::draw()
Added in d522a6f and 1e604b7, their purpose snuffed out in 11bb88f
like the faint pulse of a pleading candle, two lives of short excess,
doomed to itemize their sins to no effect and for all eternity...
2022-12-11 20:25:58 +01:00
thankyouverycool d80c520a92 WindowServer: Include missing visibility argument when making MenuItem
Fixes checkable MenuItems drawing incorrectly due to shifted defaults.
2022-12-11 20:25:58 +01:00
Ali Mohammad Pur fc805e8f03 AK: Specialise AK::is() for NNRP<T>
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 18bc88b806 AK: Add an identity implementation of StringView::from_string_literal()
This is required for the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur e591c604de AK: Add Optional-like value()/has_value() getters to WeakPtr 2022-12-11 20:44:54 +03:30