Commit graph

3987 commits

Author SHA1 Message Date
Nico Weber
79a5ba58a5 LibJS: Add tests for bitwise & and ^
And fix some edge case conversion bugs found by the tests.
2020-07-23 13:06:49 +02:00
Brian Gianforcaro
bbc7e8429b LibC: Remove duplicate gs touch during gettid()/getpid() fast path
While profiling I noticed that gettid() was hitting gs register
twice, once for the initial fetch of s_cache_tid out of TLS for
the initialization check, and then again when we return the actual
value.

Optimize the implementation to cache the value so we avoid the
double fetch during the 99% case where it's already set. With
this change gettid() goes from being the 3rd most sampled function
in test-js, to pretty much disappearing into  ~20th place.

Additionally add the same optimization to getpid().
2020-07-23 12:28:11 +02:00
Nico Weber
b9ce56aee6 LibWeb: Make btoa() and atob() correctly handle values between 128 and 255
btoa() takes a byte string, so it must decode the UTF-8 argument into
a Vector<u8> before calling encode_base64.

Likewise, in atob() decode_base64 returns a byte string, so that needs
to be converted to UTF-8.

With this, `btoa(String.fromCharCode(255))` is '/w==' as it should
be, and `atob(btoa(String.fromCharCode(255))) == String.fromCharCode(255)`
remains true.
2020-07-22 19:22:00 +02:00
Nico Weber
5ba8aba197 AK: Make encode_base64 take a ByteBuffer and return a String
That makes the interface symmetric with decode_base64 and it's
what all current callers want (except for one, which is buggy).
2020-07-22 19:22:00 +02:00
Nico Weber
9e32ad6c99 LibJS: Fix \x escapes of bytes with high bit set
With this, typing `"\xff"` into Browser's console no longer
makes the app crash.

While here, also make the \u handler call append_codepoint()
instead of calling an overload where it's not immediately clear
which overload is getting called. This has no behavior change.
2020-07-22 19:21:35 +02:00
Nico Weber
01522b8d71 LibTextCodec: Simplify Latin1Decoder::to_utf8
No intended behavior change.
2020-07-22 19:16:00 +02:00
AnotherTest
c9c7069f9e LibGUI: Remove unnecessary LibHTTP #include
This closes #2848.
2020-07-22 17:48:11 +02:00
Nico Weber
248b79d687 LibJS: Add FIXMEs to a few functions that need UTF-16 handling 2020-07-22 17:26:34 +02:00
Nico Weber
979e02c0a8 LibJS: Implement String.prototype.charCodeAt
It's broken for strings with characters outside 7-bit ASCII, but
it's broken in the same way as several existing functions (e.g.
charAt()), so that's probably ok for now.
2020-07-22 15:48:01 +02:00
Andreas Kling
7230b7aad7 LibWeb: Replaced elements had backwards application of intrinsic ratio
If we know the width, but not the height, we have to *divide* with the
intrinsic ratio to get the height (not multiply.) :^)

This makes things like <img width=300 src=image.png> work right.
2020-07-22 01:47:36 +02:00
Andreas Kling
f43590f534 LibWeb: Set the intrinsic width/height of <img> instead of hacking it
Images were added before replaced element layout knew about intrinsic
sizes, so this was a bit backwards. We now instead transfer the known
intrinsic sizes from the ImageLoader to the LayoutImage.
2020-07-22 01:39:51 +02:00
Andreas Kling
a3feb46ad7 LibWeb: Parse "width" and "height" presentation attributes on <img>
These are HTML lengths that map to CSS width and height respectively.
2020-07-22 01:16:27 +02:00
Andreas Kling
5a7e57457e LibWeb: Add a dedicated function for parsing HTML length values
Presentation attribute lengths (width, height, etc.) can always be
unit-less (e.g "400") so going via the normal CSS parsing path only
works when the document is in quirks mode.

Add a separate parse_html_length() that always allows unit-less values.
2020-07-22 01:13:18 +02:00
Luke
201cc1bfcc LibWeb: Assert we're parsing a fragment on fragment cases
The specification says that parts labelled as a "fragment case" will
only occur when parsing a fragment. It says that if it occurs when
not parsing a fragment, then it is a specification error.

We should probably assume at this point that it's an implementation
error. This fixes a few little mistakes that were caught out by this.

Also moves the context element outside insertion mode reset,
as other (unimplemented) parts refer to it, such as
"adjusted current node".

Also cleans up insertion mode reset.
2020-07-22 00:02:40 +02:00
Andreas Kling
223b96c820 LibC: Make sure malloc chunks are 8-byte aligned
I noticed this while doing some instruction-level debugging. :^)
2020-07-21 22:48:17 +02:00
Andreas Kling
b820e4626c LibC: Add a cache for getpid()
This works the same as gettid(). No sense in making a syscall to the
kernel every time you ask for the PID since it won't change.
Just like gettid(), the cache is invalidated on fork().
2020-07-21 19:08:01 +02:00
Andreas Kling
4a572df465 LibDebug: Put DWARF debug logging spam behind DEBUG_SPAM
With this logging enabled, it takes way too long to load debug info.
2020-07-21 19:08:01 +02:00
Benoît Lormeau
60a7187db2 AudioServer: Give the AudioClient a way to keep track of the main mix volume 2020-07-21 19:02:25 +02:00
Andreas Kling
30025dd576 LibC: Notify UserspaceEmulator about malloc *after* scrubbing
This makes sure that the emulator marks new malloc memory as
uninitialized (even after we've "initialized" it by scrubbing with
the scrub byte.)
2020-07-21 16:38:58 +02:00
Andreas Kling
685e006e27 LibWeb: Use "namespace Web::Foo {" since C++20 allows it :^)
Thanks @nico for teaching me about this!
2020-07-21 16:23:08 +02:00
AnotherTest
4065182811 LibTLS: Reschedule the timeout if we're too slow
Previously, we would not care if the handshake timer timed out because
the server was too slow, or because we were too slow, this caused
connections to fail when the system was under heavy load.
This patch fixes this behaviour (and closes #2843) by checking if the
timeout delay was within margin of error of the max timeout.
2020-07-21 13:01:35 +02:00
Andreas Kling
be5f42adea UserspaceEmulator+LibX86: Start tracking uninitialized memory :^)
This patch introduces the concept of shadow bits. For every byte of
memory there is a corresponding shadow byte that contains metadata
about that memory.

Initially, the only metadata is whether the byte has been initialized
or not. That's represented by the least significant shadow bit.

Shadow bits travel together with regular values throughout the entire
CPU and MMU emulation. There are two main helper classes to facilitate
this: ValueWithShadow and ValueAndShadowReference.

ValueWithShadow<T> is basically a struct { T value; T shadow; } whereas
ValueAndShadowReference<T> is struct { T& value; T& shadow; }.

The latter is used as a wrapper around general-purpose registers, since
they can't use the plain ValueWithShadow memory as we need to be able
to address individual 8-bit and 16-bit subregisters (EAX, AX, AL, AH.)

Whenever a computation is made using uninitialized inputs, the result
is tainted and becomes uninitialized as well. This allows us to track
this state as it propagates throughout memory and registers.

This patch doesn't yet keep track of tainted flags, that will be an
important upcoming improvement to this.

I'm sure I've messed up some things here and there, but it seems to
basically work, so we have a place to start! :^)
2020-07-21 02:37:29 +02:00
Muhammad Zahalqa
f2d3cc7325 LibPThread: Make pthread_exit a noreturn function
LibPThread: mark pthread_exit a noreturn function using compiler attributes
LibThread: remove a call to pthread_exit from Thread::start lambda expression
as it make the return of teh lambda unreachable.
2020-07-21 01:10:41 +02:00
Luke
19d6884529 LibWeb: Implement quirks mode detection
This allows us to determine which mode to render the page in.

Exposes "doctype" and "compatMode" on Document.
Exposes "name", "publicId" and "systemId" on DocumentType.
2020-07-21 01:08:32 +02:00
thankyouverycool
c90fe7ce93 LibGUI: Use ControlBoxButtons in SpinBox and ComboBox
Converts the buttons of these widgets into ControlBoxButtons.
2020-07-20 21:03:48 +02:00
thankyouverycool
bf59cd7ca5 LibGUI: Add ControlBoxButton to LibGUI
ControlBoxButton consolidates the paint_event for buttons
used in composite box widgets like ComboBox and SpinBox. Its
button bitmaps are built with create_from_ascii like WindowFrame
and ScrollBar controls, making theming more uniform.
2020-07-20 21:03:48 +02:00
Andreas Kling
76523a3d2d LibGUI: Show the special home directory icon in GUI::FilePicker 2020-07-19 21:42:00 +02:00
Andreas Kling
dc696ba85c LibGUI: Show a special icon for the home directory in FileSystemModel 2020-07-19 21:37:19 +02:00
Andreas Kling
9710c9742c LibGUI+FileManager: Add setting for showing/hiding dotfiles
GUI::FileSystemModel can now be told to display (or not display) files
whose name start with a dot (other than . and ..)
2020-07-19 21:15:00 +02:00
Peter Elliott
82ba7d546a LibC: add mkfifo(3) 2020-07-19 11:46:37 +02:00
thankyouverycool
a4b2d6cf1e LibGUI: Set parent icon, margins and disable resize for InputBox
Gives a more compact, uniform appearance to input boxes.
2020-07-18 16:27:57 +02:00
thankyouverycool
d976b31ef6 LibGUI: Paint slider knob as indented when disabled
Better visual feedback when sliders won't budge.
2020-07-18 16:27:57 +02:00
Nullspeak
51b2b0d5e5 WindowServer: New title bar vars for themes
The theming system can now control title bar height, title button
size, title stripe color and the title text shadow color.
The implemented theme metrics system could be later extended to LibGUI
to allow themes to change widget padding, border width, etc.
2020-07-17 23:19:08 +02:00
Andreas Kling
5f0d24cab2 LibGUI: Turn a heap-allocated event into a stack-allocated one 2020-07-16 20:46:44 +02:00
Andreas Kling
6d27915f4b LibCore: Turns some heap-allocated events into stack-allocated ones 2020-07-16 20:46:44 +02:00
Andreas Kling
869a3e2cf3 LibC: Notify UserspaceEmulator about BigAllocationBlock mallocs
We were forgetting to inform UE about these, which caused it to believe
subsequent calls to free() were invalid.
2020-07-16 20:46:44 +02:00
stelar7
d871301fd9 LibGfx: Set correct frame type on JPEG images 2020-07-16 17:52:54 +02:00
Tom
65a11fb5f9 LibGUI: Add InputBox::show with required parent window argument
Similar to MessageBox::show, this encourages passing in a window.
2020-07-16 16:10:21 +02:00
Tom
27bd2eab22 LibWeb: Require parent window argument for MessageBox
Since the vast majority of message boxes should be modal, require
the parent window to be passed in, which can be nullptr for the
rare case that they don't. By it being the first argument, the
default arguments also don't need to be explicitly stated in most
cases, and it encourages passing in a parent window handle.

Fix up several message boxes that should have been modal.
2020-07-16 16:10:21 +02:00
Tom
6568765e8f LibGUI: Add parent window argument to FilePicker functions
Since FilePicker almost always should be modal, add the parent
window as mandatory first argument.
2020-07-16 16:10:21 +02:00
Tom
9844088964 LibGUI: Clear previous main widget's window 2020-07-16 16:10:21 +02:00
Tom
bbdf0665fc WindowServer: Expose window parent information and more modal improvements
* The parent information is necessary by the Taskbar to be able to
  determine a modal window's parent
* Minimize and maximize modal window stacks together
2020-07-16 16:10:21 +02:00
thankyouverycool
1f8e9727ec LibGUI: Remove on_activity_change from ComboBox
Unnecessary since the inclusion of window accessories.
2020-07-16 00:45:35 +02:00
thankyouverycool
a038f82326 LibGUI: Disallow typing in DisplayOnly TextEditors 2020-07-16 00:06:18 +02:00
Andreas Kling
4aa81a4fd9 LibC: Communicate malloc() and free() operations to UserspaceEmulator
Use the sneaky SALC secret mechanism of UserspaceEmulator to inform it
about malloc operations.
2020-07-15 23:25:20 +02:00
Andreas Kling
cb47ab15ec LibIPC: Tweak a misleading perror()
If we get an error from recv(), let's blame "recv" instead of "read".
2020-07-15 18:47:45 +02:00
Matthew Olsson
02305d01ea LibJS: Add Number.prototype.toString 2020-07-15 18:24:55 +02:00
Tom
ec3737510d WindowServer: Add accessory windows
Accessory windows are windows that, when activated, will activate
their parent and bring all other accessory windows of that parent
to the front of the window stack. Accessory windows can only be
active input windows. The accessory window's parent is always the
active window regardless of whether it is also the active input
window.

In order to route input correctly, input is now sent to the active
input window, which can be any accessory window or their parent,
or any regular window.
2020-07-15 17:15:45 +02:00
Andreas Kling
036ce64cef LibX86: Don't cache whether instruction have a sub-opcode
We can just check if the first opcode byte is 0x0f to know this.
2020-07-15 13:42:15 +02:00
Andreas Kling
6a926a8c61 LibX86+UserspaceEmulator: Don't store a32 in MemoryOrRegisterReference
The a32 bit tells us whether a memory address is 32-bit or not.
We already have this information in Instruction, so just plumb that
around instead of double-caching the bit.
2020-07-15 13:42:15 +02:00