Commit graph

8376 commits

Author SHA1 Message Date
Brian Gianforcaro 34f0d98e67 Meta: Add Lagom CMake dir to .gitignore
Meta/Lagom/build seems to be the expected cmake output directory.
(It's hardcoded in Libraries/LibJS/Tests/run-tests.)

Add it to the project .gitignore
2020-04-13 23:15:05 +02:00
Jean-Baptiste Boric 0c25826138 Build: Use c++ as default HOST_CXX 2020-04-13 23:14:48 +02:00
Linus Groh 8e08d111da js: Output text using printf() and return undefined in help() 2020-04-13 23:12:17 +02:00
Andreas Kling c8edcf1d71 Kernel: Don't ignore validation result in ptrace(PT_PEEK)
Also mark all of the address validation functions [[nodiscard]] to turn
this kind of bug into a compile error in the future.
2020-04-13 22:40:38 +02:00
Andreas Kling e432a27676 Kernel: Use copy_from_user() in ptrace(PT_PEEK) 2020-04-13 22:39:07 +02:00
Andreas Kling 1d43544e08 Kernel: Switch the first-8MB-of-upper-3GB pseudo mappings to 4KB pages
This memory range was set up using 2MB pages by the code in boot.S.
Because of that, the kernel image protection code didn't work, since it
assumed 4KB pages.

We now switch to 4KB pages during MemoryManager initialization. This
makes the kernel image protection code work correctly again. :^)
2020-04-13 22:35:37 +02:00
Andres Vieira e9c65b6566 Meta: Add Arch Linux (and derivatives) build instructions
This patch adds a one liner to install all the dependency packages
needed to compile and run Serenity on Arch Linux, Manjaro, etc
2020-04-13 17:38:27 +02:00
Andreas Kling 8249280500 LibJS: Use HashMap::ensure_capacity() in enter_scope()
Preallocate some space in the scope variable map. This avoids a bunch
of incremental rehashing in the common case.
2020-04-13 17:27:25 +02:00
Stephan Unverwerth 8f82f6c574 LibJS: Add more number test cases for #1680 2020-04-13 17:23:22 +02:00
Andreas Kling 062d6af16e LibJS: Remove Interpreter::declare_variable()
Since declarations are now hoisted and handled on scope entry, the job
of a VariableDeclaration becomes to actually initialize variables.

As such, we can remove the part where we insert variables into the
nearest relevant scope. Less work == more speed! :^)
2020-04-13 17:22:24 +02:00
Andreas Kling ac7459cb40 LibJS: Hoist variable declarations to the nearest relevant scope
"var" declarations are hoisted to the nearest function scope, while
"let" and "const" are hoisted to the nearest block scope.

This is done by the parser, which keeps two scope stacks, one stack
for the current var scope and one for the current let/const scope.

When the interpreter enters a scope, we walk all of the declarations
and insert them into the variable environment.

We don't support the temporal dead zone for let/const yet.
2020-04-13 17:22:23 +02:00
Linus Groh b9415dc0e9 LibJS: Use assertNotReached() in tests 2020-04-13 16:28:50 +02:00
Linus Groh 92a9fe0e49 LibJS: Fix test files indentation (4 spaces) 2020-04-13 16:28:50 +02:00
Linus Groh 0040d6bf2d js: Add assertNotReached() function in test mode 2020-04-13 16:28:50 +02:00
Andreas Kling 94647fa4ab LibThread: Simplify the userspace Lock to remove CAS on unlock()
Instead of using a separate synchronization variable, just use the lock
holder TID for synchronization. This way, we only need to CAS when
first acquiring a lock.
2020-04-13 12:33:42 +02:00
Andreas Kling 02e0fab19a AK: Let FlyString::hash() assume that the string was already hashed
Since the FlyString deduplication mechanism uses a HashTable, we know
that any StringImpl inside a non-null FlyString will already have its
lazily computed hash.
2020-04-13 12:27:05 +02:00
Andreas Kling d1ffdea550 LibC: Fix truncated strncpy() in getlogin() 2020-04-13 12:27:05 +02:00
Andreas Kling dda9ffe906 LibC: Fix truncated strncpy() in /etc/group parsing 2020-04-13 12:27:05 +02:00
Andreas Kling e3df925e48 LibC: Fix strncpy() overflow in /etc/passwd parsing 2020-04-13 12:27:05 +02:00
Andreas Kling c1607dc41f LibC: Fix strncpy() overflow in gethostbyname() 2020-04-13 12:27:05 +02:00
Andreas Kling 038fdc2017 LibC: Simplify ASSERT() to reduce code size
Instead of pushing the message, file name, line# and function name
separately, we now mash the message, file name and line# into a string
constant and pass that.

This means that the failure path only has to push a single address onto
the stack, reducing the code size and causing the compiler to inline
many more functions containing an assertions (e.g RefPtr::operator*())

Obviously if you wanted minimal size, you could turn assertions off
entirely, but I really like running with assertions, so let's make
a little effort to reduce their impact. :^)
2020-04-13 12:27:05 +02:00
AnotherTest 8ebee4bce6 LibLine: Update display when deleting forward 2020-04-13 12:26:43 +02:00
Brian Gianforcaro 2a65db7c12
LibJS: Implement Error.prototype.name setter (#1776)
The MDN example for creating a custom error type in javascript uses:

    function CustomError(foo, message, fileName, lineNumber) {
        var instance = new Error(message, fileName, lineNumber);
        instance.name = 'CustomError';
        instance.foo = foo;
        Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
        return instance;
    }

The name property on the Error prototype needs to be settable for
this to work properly.
2020-04-13 11:19:53 +02:00
Stephan Unverwerth 984c290ec0 LibJS: Do not execute scripts with parse errors
This adds missing checks in several LibJS consumers.
2020-04-13 10:42:25 +02:00
Brian Gianforcaro 50b6b6ef86 js: Make load() available when running with --test-mode
The work I did to add assert as a native function in js
was a step in the wrong direction. Now that js supports
load() it makes sense to just move assert and anything
we want to add to the test harness into pure javascript.
2020-04-13 10:31:06 +02:00
Andreas Kling a0592912c3 LibC: Simplify the gettid() cache by just clearing the cache in fork()
It's hilarious how much better this is.

Thanks to Sergey for suggesting it! :^)
2020-04-13 10:27:14 +02:00
Stephan Unverwerth bbd592cb6c LibJS: Tweak FunctionPrototype::to_string and constructors
The output of FunctionPrototype::to_string is now more in line
with the output in Firefox. The builtin constructors have been
extended to include their function name in the output.
2020-04-13 01:14:21 +02:00
Brian Gianforcaro 0d41e542b7 LibJS: Throw on assignment of an const variable
Was stubbed out as an assert, should be handled with a runtime exception.
2020-04-13 01:12:31 +02:00
Itamar 8e87d340c3 strace: Update ptrace() usage
ptrace with PT_TRACEME was updated to also stop the traced thread on
exit from execve.
2020-04-13 00:53:22 +02:00
Itamar 479348c9e7 Debugger: Add pledges 2020-04-13 00:53:22 +02:00
Itamar 3e9a7175d1 Debugger: Add DebugSession
The DebugSession class wraps the usage of Ptrace.
It is intended to be used by cli & gui debugger programs.

Also, call objdump for disassemly
2020-04-13 00:53:22 +02:00
Itamar 50fd2cabff ptrace: Report error in PT_PEEK via errno
The syscall wrapper for ptrace needs to return the peeked value when
using  PT_PEEK.
Because of this, the user has to check errno to detect an error in
PT_PEEK.

This commit changes the actual syscall's interface (only for PT_PEEK) to
allow the syscall wrapper to detect an error and change errno.
2020-04-13 00:53:22 +02:00
Itamar aae3f7b914 Process: Fix siginfo for code CLD_STOPPED
si_code, si_status where swapped
2020-04-13 00:53:22 +02:00
Itamar 9e51e295cf ptrace: Add PT_SETREGS
PT_SETTREGS sets the regsiters of the traced thread. It can only be
used when the tracee is stopped.

Also, refactor ptrace.
The implementation was getting long and cluttered the alraedy large
Process.cpp file.

This commit moves the bulk of the implementation to Kernel/Ptrace.cpp,
and factors out peek & poke to separate methods of the Process class.
2020-04-13 00:53:22 +02:00
Itamar 0431712660 ptrace: Stop a traced thread when it exists from execve
This was a missing feature in the PT_TRACEME command.

This feature allows the tracer to interact with the tracee before the
tracee has started executing its program.

It will be useful for automatically inserting a breakpoint at a
debugged program's entry point.
2020-04-13 00:53:22 +02:00
Itamar 4568a628f9 Thread: Set m_blocker to null in Thread::unblock()
Before this commit, m_blocker was only set to null in Thread::block,
after the thread has been unblocked.

Starting with this commit, m_blocker is also set to null in
Thread::unblock.

This change will allow us to implement a missing feature of the PT_TRACE
command of the ptrace syscall - stopping the traced thread when it
exits the execve syscall.

That feature will be implemented by sending a blocking SIGSTOP to the
traced thread after it has executed the execve logic and before it
starts executing the new program in userspace.

However, since Process::exec arranges the tss to return to userspace
(the so-called "yield-teleport"), the code in Thread::block that should
be run after the thread unblocks, and sets m_blocker to null, never
actually runs.

Setting m_blocker to null in Thread::unblock allows us to avoid an
incorrect state where the thread is in a Running state but conatins a
pointer to a Blocker.
2020-04-13 00:53:22 +02:00
Itamar b306ac9b2b ptrace: Add PT_POKE
PT_POKE writes a single word to the tracee's address space.

Some caveats:
- If the user requests to write to an address in a read-only region, we
temporarily change the page's protections to allow it.

- If the user requests to write to a region that's backed by a
SharedInodeVMObject, we replace the vmobject with a PrivateIndoeVMObject.
2020-04-13 00:53:22 +02:00
Itamar 924fda19b0 Debugger: Get entry point of debugged process
Also, start debugging only after execve is done
2020-04-13 00:53:22 +02:00
Itamar 984ff93406 ptrace: Add PT_PEEK
PT_PEEK reads a single word from the tracee's address space and returns
it to the tracer.
2020-04-13 00:53:22 +02:00
Itamar 77f671b462 CPU: Handle breakpoint trap
Also, start working on the debugger app.
2020-04-13 00:53:22 +02:00
AnotherTest c112f53357 Shell: Complete .hidden files if token starts with a dot 2020-04-13 00:49:24 +02:00
AnotherTest 364dbe28d6 LibLine: Remove unused cut_mismatching_chars() function
This is superceded by the suggest() mechanism
2020-04-13 00:49:24 +02:00
AnotherTest fa0525b8bf LibLine: Autocomplete single suggestions
`cd /h<tab>` -> `cd /home/`, pressing tab after that would
descend into `/home/' and show `/home/anon/`
2020-04-13 00:49:24 +02:00
AnotherTest d3e735f279 Shell: Avoid spamming debug output with suggestions 2020-04-13 00:49:24 +02:00
AnotherTest 2a460aa369 Shell: Do not manually write to the editor buffer when completing paths 2020-04-13 00:49:24 +02:00
Linus Groh 6d5d668585 js: Coerce assert() argument to boolean
It's JavaScript after all :^)
2020-04-13 00:47:53 +02:00
Linus Groh 62d0fa5af8 LibWeb: Use specific error classes when throwing exceptions
Generally:

- interpreter.throw_exception<JS::Error>("TypeError", "Message");
+ interpreter.throw_exception<JS::TypeError>("Message");
2020-04-13 00:47:53 +02:00
Linus Groh ad230e8839 Ports: Update git to 2.26.0 2020-04-13 00:46:58 +02:00
Stephan Unverwerth f8f65053bd LibJS: Parse "this" as ThisExpression 2020-04-13 00:45:25 +02:00
Andreas Kling 110ca6b0b6 LibJS: Cache a FlyString for "this" to speed up variable lookup
We were hitting strcmp() in every variable lookup to see if the lookup
was for "this". Caching a FlyString("this") turns that check into one
pointer comparison instead. :^)
2020-04-12 20:40:02 +02:00