Commit graph

43944 commits

Author SHA1 Message Date
Linus Groh
1dd8655514 LibJS: Replace standalone js_symbol() with Symbol::create() 2022-12-07 16:43:06 +00:00
Linus Groh
525f22d018 LibJS: Replace standalone js_string() with PrimitiveString::create()
Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
2022-12-07 16:43:06 +00:00
Linus Groh
5db38d7ba1 LibJS: Replace standalone js_bigint() with BigInt::create()
Three standalone Cell creation functions remain in the JS namespace:

- js_bigint()
- js_string()
- js_symbol()

All of them are leftovers from early iterations when LibJS still took
inspiration from JSC, which itself has jsString(). Nowadays, we pretty
much exclusively use static create() functions to construct types
allocated on the JS heap, and there's no reason to not do the same for
these.
Also change the return type from BigInt* to NonnullGCPtr<BigInt> while
we're here.

This is patch 1/3, replacement of js_string() and js_symbol() follow.
2022-12-07 16:43:06 +00:00
Thomas Queiroz
07f1aad3dd Kernel: Add missing VERIFY in MM::allocate_committed_physical_page 2022-12-07 16:31:16 +00:00
Thomas Queiroz
c681330450 Kernel: Don't panic if MemoryManager::find_free_physical_page fails 2022-12-07 16:31:16 +00:00
Thomas Queiroz
8e8ea99bf3 Kernel: Return nullptr instead of PANICking in KmallocSlabHeap
I dared to return nullptr :^)
2022-12-07 16:31:16 +00:00
Andreas Kling
4828f0b636 UserspaceEmulator: Implement MOV_RM16_seg 2022-12-07 13:18:48 +01:00
Andreas Kling
661a940ddd UserspaceEmulator: Implement MOV_seg_RM32 and MOV_seg_RM16
This allows hosted programs to write to segment registers. :^)
2022-12-07 13:18:48 +01:00
Andreas Kling
bd1f39ebaa UserspaceEmulator: Implement PUSH_{CS,DS,ES,FS,GS,SS}
You can now push the segment registers on the stack! :^)
2022-12-07 13:18:48 +01:00
Andreas Kling
b6472c250c UserspaceEmulator: Add SoftCPU getters for FS and GS 2022-12-07 13:18:48 +01:00
Andreas Kling
fba91a4307 UserspaceEmulator: Initialize the FS segment on startup
Set it to 0x23, matching the initial value in a native process.
2022-12-07 13:18:48 +01:00
Timothy Flynn
b159bdd4fd LibSQL+SQLServer+sql: Send and parse the correct number of changed rows
The sql REPL had the created/updated rows swapped by mistake. Also make
sure SQLServer fills in the correct value depending on the executed
command, and that the DELETE command indicates the rows it deleted.
2022-12-07 13:09:00 +01:00
Timothy Flynn
b9d8c25b0b LibSQL+SQLServer+SQLStudio+sql: Send result rows over IPC as SQL::Value
We've been sending the values converted to a string, but now that the
Value type is transferrable over IPC, send the values themselves. Any
client that wants the value as a string may do so easily, whereas this
will allow less trivial clients to avoid string parsing.
2022-12-07 13:09:00 +01:00
Timothy Flynn
27ce88864f SQLServer: Do not store statement execution results at the class level
If a statement is executed multiple times in quick succession, we may
overwrite the results of a previous execution. Instead of storing the
result, pass it around as it is sent to the client.
2022-12-07 13:09:00 +01:00
Timothy Flynn
f9d23e1d2f LibSQL+SQLServer+SQLStudio+sql: Propagate connection errors immediately
Currently, when clients connect to SQL server, we inform them of any
errors opening the database via an asynchronous IPC. But we already know
about these errors before returning from the connect() IPC, so this
roundabout propagation is a bit unnecessary. Now if we fail to open the
database, we will simply not send back a valid connection ID.

Disconnect has a similar story. Rather than disconnecting and invoking
an asynchronous IPC to inform the client of the disconnect, make the
disconnect() IPC synchronous (because all it does is remove the database
from the map of open databases). Further, the only user of this command
is the SQL REPL when it wants to connect to a different database, so it
makes sense to block it. This did require moving a bit of logic around
in the REPL to accommodate this change.
2022-12-07 13:09:00 +01:00
Timothy Flynn
aec75d749a LibSQL+SQLServer+SQLStudio+sql: Allocate per-statement-execution IDs
In order to execute a prepared statement multiple times, and track each
execution's results, clients will need to be provided an execution ID.
This will create a monotonically increasing ID each time a prepared
statement is executed for this purpose.
2022-12-07 13:09:00 +01:00
Timothy Flynn
e2f71d2808 LibSQL+SQLServer+SQLStudio+sql: Use proper types for SQL IPC and IDs
When storing IDs and sending values over IPC, this changes SQLServer to:

1. Stop using -1 as a nominal "bad" ID. Store the IDs as unsigned, and
   use Optional in the one place that the IPC needs to indicate an ID
   was not allocated.

2. Let LibIPC encode/decode enumerations (SQLErrorCode) on our behalf.

3. Use size_t for array sizes.
2022-12-07 13:09:00 +01:00
Timothy Flynn
3a915483b0 IPCCompiler: Mark size_t as a primitive type
This allows size_t to be used within an IPC message without being passed
by const-reference.
2022-12-07 13:09:00 +01:00
Timothy Flynn
8fcb8c30c6 SQLServer+SQLStudio+sql: Allow sending placeholder values to SQLServer 2022-12-07 13:09:00 +01:00
Timothy Flynn
b13527b8b2 SQLServer: Parse SQL a single time to actually "prepare" the statement
One of the benefits of prepared statements is that the SQL string is
parsed just once and re-used. This updates SQLStatement to do just that
and store the parsed result.
2022-12-07 13:09:00 +01:00
Timothy Flynn
83bb25611e LibSQL: Add an IPC encoder/decoder for SQL::Value
This will allow clients to send placeholder values for prepared
statements over IPC.
2022-12-07 13:09:00 +01:00
Timothy Flynn
b2b9ae27fd LibSQL: Parse and execute sequential placeholder values
This partially implements SQLite's bind-parameter expression to support
indicating placeholder values in a SQL statement. For example:

    INSERT INTO table VALUES (42, ?);

In the above statement, the '?' identifier is a placeholder. This will
allow clients to compile statements a single time while running those
statements any number of times with different placeholder values.

Further, this will help mitigate SQL injection attacks.
2022-12-07 13:09:00 +01:00
Timothy Flynn
53f8d62ea4 LibSQL: Partially implement the UPDATE command
This implements enough to update rows filtered by a WHERE clause.
2022-12-07 13:09:00 +01:00
MacDue
1574f2c3f6 Meta+Userland: Pass Gfx::FloatSize by value
Just two floats like Gfx::FloatPoint.
2022-12-07 11:48:27 +01:00
MacDue
27fae78335 Meta+Userland: Pass Gfx::IntSize by value
Just two ints like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
e011eafd37 Meta+Userland: Pass Gfx::FloatPoint by value
Just a small 8-byte value like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
7be0b27dd3 Meta+Userland: Pass Gfx::IntPoint by value
This is just two ints or 8 bytes or the size of the reference on
x86_64 or AArch64.
2022-12-07 11:48:27 +01:00
MacDue
bbc149ebb9 Meta+Userland: Pass Gfx::Color by value
Gfx::Color is always 4 bytes (it's just a wrapper over u32) it's less
work just to pass the color directly.

This also updates IPCCompiler to prevent from generating
Gfx::Color const &, which makes replacement easier.
2022-12-07 11:48:27 +01:00
Marcus Nilsson
f76c7f3788 LibGL: Generate GL_OUT_OF_MEMORY error in glBufferData when OOM 2022-12-07 11:46:37 +01:00
Linus Groh
54abfcf835 LibJS: Remove redundant AK_MAKE_NON{COPYABLE,MOVABLE} from Symbol class
These are already applied to the Cell base class.
2022-12-07 09:58:59 +00:00
Linus Groh
f490ba13ff LibJS: Move creation of global symbols into Symbol.for()
This is now according to the spec. Having a non-standard lookup API
that creates symbols on the fly doesn't seem ideal.
2022-12-07 09:58:59 +00:00
Linus Groh
b821356ba6 LibJS: Add const/non-const VM::global_symbol_registry() getters
This will allow us to replace the strange get_global_symbol() API that
creates symbols on the fly when not found.
2022-12-07 09:58:59 +00:00
Linus Groh
d5457375e6 LibJS: Store NonnullGCPtr<Symbol> values in m_global_symbol_registry 2022-12-07 09:58:59 +00:00
Linus Groh
2c579ed0df LibJS: Rename m_global_symbol_map to m_global_symbol_registry
The spec calls it "GlobalSymbolRegistry".
2022-12-07 09:58:59 +00:00
Linus Groh
112b3f7342 LibJS: Convert MarkupGenerator to the new String 2022-12-07 09:58:38 +00:00
Linus Groh
f23b55ae86 AK: Add StringView(String const&) constructor
This allows us to pass the new String type to functions that take a
StringView directly, having to call bytes_as_string_view() every time
gets old quickly.
2022-12-07 09:58:38 +00:00
Linus Groh
daec065fde LibJS: Move initialize_instance_elements() from VM to Object
This makes more sense as an Object method rather than living within the
VM class for no good reason. Most of the other 7.3.xx AOs already work
the same way.
Also add spec comments while we're here.
2022-12-07 00:23:51 +00:00
Linus Groh
cdeaced54e LibJS: Add spec link and comment to VM::execution_context_stack() 2022-12-07 00:14:10 +00:00
Linus Groh
91a9f41155 LibJS: Add spec link and comment to VM::running_execution_context() 2022-12-07 00:14:01 +00:00
Linus Groh
1832474a37 LibJS: Remove forgotten VM::construct() declaration
This has been a standalone AO function for a long time now.
2022-12-06 23:46:47 +00:00
Linus Groh
1f4437ff2b LibJS: Remove unused VM::join_arguments() function
The last uses of this were removed in ff5e07d.
2022-12-06 23:45:24 +00:00
Linus Groh
c756585deb LibWeb: Ignore -Wshadow in TRY_OR_RETURN_OOM() 2022-12-06 21:31:00 +00:00
Linus Groh
5103e08b77 AK: Ignore -Wshadow in TRY() and MUST()
This makes the warning in CLion disappear when nesting them.
2022-12-06 21:31:00 +00:00
Linus Groh
d2e143eec7 AK: Add a helper macro to temporarily ignore diagnostics with _Pragma() 2022-12-06 21:31:00 +00:00
Maciej
6e4f886999 3DFileViewer: Properly propagate errors from WavefrontOBJLoader
Fixes 3 FIXMEs.
2022-12-06 17:24:45 +00:00
Andreas Kling
a3e82eaad3 AK: Introduce the new String, replacement for DeprecatedString
DeprecatedString (formerly String) has been with us since the start,
and it has served us well. However, it has a number of shortcomings
that I'd like to address.

Some of these issues are hard if not impossible to solve incrementally
inside of DeprecatedString, so instead of doing that, let's build a new
String class and then incrementally move over to it instead.

Problems in DeprecatedString:

- It assumes string allocation never fails. This makes it impossible
  to use in allocation-sensitive contexts, and is the reason we had to
  ban DeprecatedString from the kernel entirely.

- The awkward null state. DeprecatedString can be null. It's different
  from the empty state, although null strings are considered empty.
  All code is immediately nicer when using Optional<DeprecatedString>
  but DeprecatedString came before Optional, which is how we ended up
  like this.

- The encoding of the underlying data is ambiguous. For the most part,
  we use it as if it's always UTF-8, but there have been cases where
  we pass around strings in other encodings (e.g ISO8859-1)

- operator[] and length() are used to iterate over DeprecatedString one
  byte at a time. This is done all over the codebase, and will *not*
  give the right results unless the string is all ASCII.

How we solve these issues in the new String:

- Functions that may allocate now return ErrorOr<String> so that ENOMEM
  errors can be passed to the caller.

- String has no null state. Use Optional<String> when needed.

- String is always UTF-8. This is validated when constructing a String.
  We may need to add a bypass for this in the future, for cases where
  you have a known-good string, but for now: validate all the things!

- There is no operator[] or length(). You can get the underlying data
  with bytes(), but for iterating over code points, you should be using
  an UTF-8 iterator.

Furthermore, it has two nifty new features:

- String implements a small string optimization (SSO) for strings that
  can fit entirely within a pointer. This means up to 3 bytes on 32-bit
  platforms, and 7 bytes on 64-bit platforms. Such small strings will
  not be heap-allocated.

- String can create substrings without making a deep copy of the
  substring. Instead, the superstring gets +1 refcount from the
  substring, and it acts like a view into the superstring. To make
  substrings like this, use the substring_with_shared_superstring() API.

One caveat:

- String does not guarantee that the underlying data is null-terminated
  like DeprecatedString does today. While this was nifty in a handful of
  places where we were calling C functions, it did stand in the way of
  shared-superstring substrings.
2022-12-06 15:21:26 +01:00
Timothy Flynn
d50b9165cd Meta: Manually compute the length of the WASM JS REPL source string
The REPL does not have a reliable way to tell us the UTF-8 byte count of
the source string, so we must use strlen() ourselves.
2022-12-06 13:53:24 +00:00
Hendiadyoin1
fcc3348bc8 LibJS: Intercept returns through finally blocks in Bytecode
This is still not perfect, as we now actually crash in the
`try-finally-continue` tests, while we now succeed all
`try-catch-finally-*` tests.

Note that we do not yet go through the finally block when exiting the
unwind context through a break or continue.
2022-12-06 16:09:24 +03:30
Hendiadyoin1
c2108489a5 LibJS: Don't try to manage unwind contexts in the execution loop in BC
We are already doing this in a good manner via the generated code,
doing so in the execution loop as well will cause us to pop contexts
multiple times, which is not very good.
2022-12-06 16:09:24 +03:30
Hendiadyoin1
133faa0acc LibJS: Remove FinishUnwind instruction
This is essentially a LeaveUnwind+Jump, so lets just do that, that will
make it easier to optimize it, or see unwind state transitions
2022-12-06 16:09:24 +03:30