Commit Graph

618 Commits

Author SHA1 Message Date
David Isaksson
410d81706d Utilities: Add way to get a storage devices block size in blockdev 2021-10-09 12:06:47 +02:00
David Isaksson
8d631dcd5e Utilities: Add blockdev utility
This new utility queries a block device for its size via the newly
introduced ioctl STORAGE_DEVICE_GET_SIZE request.
2021-10-09 12:06:47 +02:00
Nico Weber
f46a40a471 Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Rodrigo Tobar
96a67d24e9 Strace: Add formatting for misc syscalls
These are exit, realpath and getrandom. This required a bit of extra
infrastructure to deal with exit's void return type.
2021-10-07 08:47:49 +03:30
Rodrigo Tobar
8125edfe79 Strace: Add formatting for main memory-related syscalls
These include mmap, munmap, mprotect and mmap_set_name.
2021-10-07 08:47:49 +03:30
Rodrigo Tobar
9394cfcaf3 Strace: Add formatting for main socket syscalls
The formatting of these functions is not complete, but gives already
very good information to the user.
2021-10-07 08:47:49 +03:30
Rodrigo Tobar
a09b1879ca Strace: Add main infrastructure and formatting of main I/O operations
This commit introduces the main infrastructure used for turning register
values into user-facing values that can be printed by strace. This
includes the ability to copy data from a particular memory address in
the traced process. On top of this, (partial) formatting has been added
for the most common I/O operations (open, read, write, lseek, close,
stat, fstat).
2021-10-07 08:47:49 +03:30
Rodrigo Tobar
f7a0196764 Strace: Move output formatting to separate function
Moving the formatting of strace's output into a separate function will
allow us to introduce more complexity into the formatting logic without
touching the main body of the program.

The new function uses a switch statement to select how to format the
arguments and result depending on the syscall. At this point we only
include the default formatting, where the registers are simply dumped,
but later on we can add specializations for each system call we want to
support.
2021-10-07 08:47:49 +03:30
Linus Groh
fe802f5ff5 js: Fix pretty-printing of RegExp objects
Regressed in b7e5f08.

Use the newly available RegExpObject::escape_regexp_pattern() instead of
attempting to call the RegExp.prototype.source accessor getter directly.
2021-10-05 18:35:49 +01:00
Jan de Visser
f33a288ca4 SQL Utility: Implement reading sql files
Add a number of command line switches:
- '-r/--read': Read a SQL file and quit the REPL when done
- '-s/--source': Read a SQL file and return to a SQL prompt when done
- '--no-sqlrc': Do not read ~/.sqlrc on startup (see below)

Add a dot-command:
.read <filename>: Read a SQL file and return to a SQL prompt when done

In addition, the sql REPL will source the ~/.sqlrc file on startup if
it exists, unless the --no-sqlrc flag is set on startup.

Note the slight asymmetry between the --read command line flag (which
results in the program quitting when the file is read) and the .read
command (which doesn't cause a quit).

Also fix merge conflict with #10091
2021-10-05 02:22:19 +02:00
Jan de Visser
89835ec83c SQL Utility: Redesigned the input loop
The existing input loop called the `read_sql` method recursively. This
lead to strange behaviour in the event loop. This is solved by
encapsulating the REPL in an object and ensuring the `read_sql` method
is not called recursively. The method now returns after the first
recognized SQL statement or command.
2021-10-05 02:22:19 +02:00
Jan de Visser
9d9f082221 SQL Utility: Implement connection switching
You can now connect to a different database using the .connect meta
command.
2021-10-05 02:22:19 +02:00
Jan de Visser
e923cb3739 SQLServer+SQL+LibSQL: Allow sql client to specify the database name
The database the sql client connected to was 'hardcoded' to the login
name of the calling user.
- Extended the IPC API to be more expressive when connecting, by
returning the name of the database the client connected to in the
'connected' callback.
- Gave the sql client a command line argument (-d/--database) allowing
an alternative database name to be specified

A subsequent commit will have a dot command allowing the user to
connect to different databases from the same sql session.
2021-10-05 02:22:19 +02:00
Mahmoud Mandour
aca87ce146 sql: Account for the single quotes in syntax highlighting
Previously, a String literal token like 'hello' had every char
highlighted but for the last 'o' and the closing single quote. This is
because the token start is at the opening single quote but the `length`
variable only accounted for the value length without the single quotes.
2021-10-04 15:51:48 +02:00
Linus Groh
b7e5f08e56 LibJS: Convert Object::get() to ThrowCompletionOr
To no one's surprise, this patch is pretty big - this is possibly the
most used AO of all of them. Definitely worth it though.
2021-10-03 20:14:03 +01:00
davidot
f4f1397735 js: Allow for completion of lexically declared variables
This does require us to have a method which lists all the bindings in
a declarative environment which is not in the spec.
2021-10-03 17:42:05 +02:00
davidot
0be0e7ea6e js: Fix that auto completion of properties failed
For this we store the global environment in which we can do a lookup
for the references variable. This is probably not entirely as the spec
would specify as we would need a running executing context at all times
you do things with references.

Fixes #10281
2021-10-03 17:42:05 +02:00
Andreas Kling
6a1b82df2b LibJS: Put zombie cell tracking code behind a compile-time flag
Since this is a debug-only feature, let's not have it impact GC marking
performance when you don't need it.
2021-10-02 16:39:28 +02:00
Nico Weber
6c9bc18a79 Userland: Fix typos 2021-10-01 01:18:52 +01:00
davidot
830ea0414c LibJS: Make scoping follow the spec
Before this we used an ad-hoc combination of references and 'variables'
stored in a hashmap. This worked in most cases but is not spec like.
Additionally hoisting, dynamically naming functions and scope analysis
was not done properly.

This patch fixes all of that by:
  - Implement BindingInitialization for destructuring assignment.
  - Implementing a new ScopePusher which tracks the lexical and var
    scoped declarations. This hoists functions to the top level if no
    lexical declaration name overlaps. Furthermore we do checking of
    redeclarations in the ScopePusher now requiring less checks all over
    the place.
  - Add methods for parsing the directives and statement lists instead
    of having that code duplicated in multiple places. This allows
    declarations to pushed to the appropriate scope more easily.
  - Remove the non spec way of storing 'variables' in
    DeclarativeEnvironment and make Reference follow the spec instead of
    checking both the bindings and 'variables'.
  - Remove all scoping related things from the Interpreter. And instead
    use environments as specified by the spec. This also includes fixing
    that NativeFunctions did not produce a valid FunctionEnvironment
    which could cause issues with callbacks and eval. All
    FunctionObjects now have a valid NewFunctionEnvironment
    implementation.
  - Remove execute_statements from Interpreter and instead use
    ASTNode::execute everywhere this simplifies AST.cpp as you no longer
    need to worry about which method to call.
  - Make ScopeNodes setup their own environment. This uses four
    different methods specified by the spec
    {Block, Function, Eval, Global}DeclarationInstantiation with the
    annexB extensions.
  - Implement and use NamedEvaluation where specified.

Additionally there are fixes to things exposed by these changes to eval,
{for, for-in, for-of} loops and assignment.

Finally it also fixes some tests in test-js which where passing before
but not now that we have correct behavior :^).
2021-09-30 08:16:32 +01:00
Rodrigo Tobar
3efd7b458a LibELF+readelf: Remove duplicated dtag->string map
A copy of the same mapping was found both in LibELF and in the readelf
utility, which uses LibELF; keeping them both is redundant and removing
the duplicate saves (a bit of) space.
2021-09-26 12:45:55 +02:00
Linus Groh
e37cf73300 LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObject
The old name is the result of the perhaps somewhat confusingly named
abstract operation OrdinaryFunctionCreate(), which creates an "ordinary
object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an
"exotic object" (https://tc39.es/ecma262/#exotic-object).

However, the term "Ordinary Function" is not used anywhere in the spec,
instead the created object is referred to as an "ECMAScript Function
Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so
let's call it that.

The "ordinary" vs. "exotic" distinction is important because there are
also "Built-in Function Objects", which can be either implemented as
ordinary ECMAScript function objects, or as exotic objects (our
NativeFunction).

More work needs to be done to move a lot of infrastructure to
ECMAScriptFunctionObject in order to make FunctionObject nothing more
than an interface for objects that implement [[Call]] and optionally
[[Construct]].
2021-09-25 17:51:30 +02:00
Mustafa Quraish
07419b8931 diff: Only color output when stdout is a tty
If we're redirecting the output somewhere, we likely don't want to
have ANSI codes in the middle of our diff output.
2021-09-24 14:32:52 +02:00
Mustafa Quraish
4173f2ffad diff: Show start/end of line ranges in source/target files
This behaves very much like the regular diff command, showing the
start lines and ranges of additions/changes/deletions in both the
source and target files.
2021-09-24 14:32:52 +02:00
Idan Horowitz
e12a707ca1 checksum: Stop reusing the same Core::File for multiple files
Since we were just repeatedly calling `->open()` on the same Core::File
no one was clearing it's internal buffer, which means hashing multiple
files in one go would result in different hashes than hashing each file
separately.
2021-09-21 20:36:19 +03:00
David Isaksson
5a91f5b320 Utilities: Fix asctl volume units
A while back the internal volume representation was changed from int to
double, but asctl was apparently never changed. This patch fixes that
issue.
2021-09-19 21:52:32 +02:00
Ali Mohammad Pur
436693c0c9 LibTLS: Use a setter for on_tls_ready_to_write with some more smarts
The callback should be called as soon as the connection is established,
and if we actually set the callback when it already is, we expect it to
be called immediately.
2021-09-19 21:10:23 +04:30
Andreas Kling
1be4cbd639 AK: Make Utf8View constructors inline and remove C string constructor
Using StringView instead of C strings is basically always preferable.
The only reason to use a C string is because you are calling a C API.
2021-09-18 19:54:24 +02:00
Mustafa Quraish
f552c26c79 Utilities: Add a basic diff utility 2021-09-17 16:56:59 +00:00
Ben Wiederhake
c680ef0a09 crash: Run automatically during CI 2021-09-16 20:51:24 +00:00
Ben Wiederhake
e8d37b7b17 crash: Check whether the msyscall mitigation actually works 2021-09-16 20:51:24 +00:00
Andreas Kling
63a0ebcc90 js: Add a simple loadJSON(path) built-in to load JSON from a file
This is very handy when you want to load data from /proc, for example.
2021-09-16 21:49:50 +02:00
Brian Gianforcaro
5df74c99ab Utilities: Use ElapsedTimer::start_new in allocate 2021-09-12 17:24:44 +00:00
Brian Gianforcaro
74ee7cabf2 Utilities: Use ElapsedTimer::start_new() in disk_bechmark 2021-09-12 17:24:44 +00:00
Brian Gianforcaro
df04283d61 LibCore: Make Account::authenticate take a SecretString
To encourage users to use the SecretString API, change the API so that
Account::authenticate only accepts a SecretString.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
9e667453c7 LibCore: Make get_password return SecretString instead of String
We shouldn't let secrets sit around in memory, as they could potentially
be retrieved by an attacker, or left in memory during a core dump.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
3590c55b69 Utilities: Fix incorrect error handling in traceroute
The result will be -1 on error, and the error value will be stored in
errno. PVS-Studio found this because result it saw result < 0 and new
EFAULT is < 0, so this could never be true.
2021-09-12 16:36:52 +02:00
Linus Groh
2b8d5696ab LibJS: Allocate a Realm next to GlobalObject in Interpreter::create()
Also pass a Realm reference to the Bytecode::Interpreter constructor,
just like we pass the GlobalObject.
2021-09-12 11:10:20 +01:00
Liav A
8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
2021-09-12 11:52:16 +02:00
Idan Horowitz
6704961c82 AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.

As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
2021-09-11 20:36:43 +03:00
Liav A
04ba31b8c5 Kernel+Userland: Remove loadable kernel moduless
These interfaces are broken for about 9 months, maybe longer than that.
At this point, this is just a dead code nobody tests or tries to use, so
let's remove it instead of keeping a stale code just for the sake of
keeping it and hoping someone will fix it.

To better justify this, I read that OpenBSD removed loadable kernel
modules in 5.7 release (2014), mainly for the same reason we do -
nobody used it so they had no good reason to maintain it.
Still, OpenBSD had LKMs being effectively working, which is not the
current state in our project for a long time.
An arguably better approach to minimize the Kernel image size is to
allow dropping drivers and features while compiling a new image.
2021-09-11 19:05:00 +02:00
Andreas Kling
c364520c24 LibJS+js+test-js: Add GC debug mode that keeps cells "alive" as zombies
This patch adds a `-z` option to js and test-js. When run in this mode,
garbage cells are never actually destroyed. We instead keep them around
in a special zombie state.

This allows us to validate that zombies don't get marked in future GC
scans (since there were not supposed to be any more references!) :^)

Cells get notified when they become a zombie (via did_become_zombie())
and this is used by WeakContainer cells to deregister themselves from
the heap.
2021-09-11 16:52:03 +02:00
Ben Wiederhake
2e4ec891da Everywhere: Fix format-vulnerabilities
Command used:
grep -Pirn '(out|warn)ln\((?!["\)]|format,|stderr,|stdout,|output, ")' \
     AK Kernel/ Tests/ Userland/
(Plus some manual reviewing.)

Let's pick ArgsParser as an example:
    outln(file, m_general_help);
This will fail at runtime if the general help happens to contain braces.

Even if this transformation turns out to be unnecessary in a place or
two, this way the code is "more obviously" correct.
2021-09-11 15:16:26 +01:00
Rodrigo Tobar
73e42917f9 Utilities: Show dynamic ELF info with "show all" option 2021-09-11 15:37:38 +03:00
Ben Wiederhake
e118ad3273 wasm: Avoid making StringView of temporary ByteBuffer 2021-09-11 13:22:51 +03:00
Ben Wiederhake
d9c1162a20 nproc: Avoid making StringView of temporary ByteBuffer 2021-09-11 13:22:51 +03:00
Timothy Flynn
cf1923edeb js: Implement pretty-printing of Intl.NumberFormat 2021-09-11 11:05:50 +01:00
Andreas Kling
6ad427993a Everywhere: Behaviour => Behavior 2021-09-07 13:53:14 +02:00
Liav A
25ea7461a0 Kernel/PCI: Simplify the entire subsystem
A couple of things were changed:
1. Semantic changes - PCI segments are now called PCI domains, to better
match what they are really. It's also the name that Linux gave, and it
seems that Wikipedia also uses this name.
We also remove PCI::ChangeableAddress, because it was used in the past
but now it's no longer being used.
2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as
they made a bunch of unnecessary complexity. Instead, Windowed access is
removed entirely (this was tested, but never was benchmarked), so we are
left with IO access and memory access options. The memory access option
is essentially mapping the PCI bus (from the chosen PCI domain), to
virtual memory as-is. This means that unless needed, at any time, there
is only one PCI bus being mapped, and this is changed if access to
another PCI bus in the same PCI domain is needed. For now, we don't
support mapping of different PCI buses from different PCI domains at the
same time, because basically it's still a non-issue for most machines
out there.
2. OOM-safety is increased, especially when constructing the Access
object. It means that we pre-allocating any needed resources, and we try
to find PCI domains (if requested to initialize memory access) after we
attempt to construct the Access object, so it's possible to fail at this
point "gracefully".
3. All PCI API functions are now separated into a different header file,
which means only "clients" of the PCI subsystem API will need to include
that header file.
4. Functional changes - we only allow now to enumerate the bus after
a hardware scan. This means that the old method "enumerate_hardware"
is removed, so, when initializing an Access object, the initializing
function must call rescan on it to force it to find devices. This makes
it possible to fail rescan, and also to defer it after construction from
both OOM-safety terms and hotplug capabilities.
2021-09-07 13:47:37 +02:00
Timothy Flynn
1a7443bec7 js: Implement pretty-printing of Intl.ListFormat 2021-09-06 23:49:56 +01:00