Commit Graph

1249 Commits

Author SHA1 Message Date
Sergey Bugaev
dec95cb8b3 LibGUI: Let GModel specify the drag data type
GModel subclasses can now override drag_data_type() to specify which type
GAbstractView should set for drag data. The default implementation returns a
null string, which disables dragging from this widget.
2020-01-22 21:22:23 +01:00
Sergey Bugaev
d3ce7ae0e3 LibGUI: Move most of mouse event handling to GAbstractView
This deduplicates existing code, and also gives all the model-backed widgets
selection manipulation and drag support for free :^)
2020-01-22 21:22:23 +01:00
Sergey Bugaev
fd11c96e8e LibGUI: Misc tweaks
Minus two empty lines because clang-format insists on it,
and plus an underscore.
2020-01-22 21:22:23 +01:00
Sergey Bugaev
91d3fc54be LibGUI: Move index_at_event_position() up to GAbstractView
It's now an abstract (pure virtual) public method in GAbstractView that
individual widgets have to implement. This will allow us to move more
selection-related logic into GAbstractView in order to share it between
implementations.
2020-01-22 21:22:23 +01:00
Sergey Bugaev
ff66101f9e LibGUI: Add GItemView::index_at_event_position()
This replaces GItemView::item_at_event_position(), which used to return a raw
int, requiring callers to call model()->index() with it again.
2020-01-22 21:22:23 +01:00
Sergey Bugaev
2ccad40a16 LibGUI: Add GListView::index_at_event_position()
And port GListView::mousedown_event() to it.
2020-01-22 21:22:23 +01:00
Sergey Bugaev
b4923938e1 LibVT: Input dragged file path into the terminal on drop
We also support dropping plain text and non-file URLs.
2020-01-22 21:22:23 +01:00
Andreas Kling
72d68b4025 LibCore: Fix broken "stay_within" mechanism in event dispatch
The "stay_within" parameter to CObject::dispatch_event() optionally
specifies a node in the CObject parent chain where event dispatch
should stop bubbling upwards.

Since event dispatch is done recursively, this was not working right,
as we would simply return from the innermost dispatch loop, leaving
the event un-accepted, which meant that the penultimately inner
dispatch loop would pick up the event and keep bubbling it anyway.

This made it possible for events to jump across window boundaries
within an application, in cases where one window was a CObject ancestor
of another window. This is typically the case with dialog windows.

Fix #1078.
2020-01-21 21:55:25 +01:00
Andreas Kling
a5e482833d LibGUI: Make GDialog accept escape key press events
Anyone who "handles" an event should really also be accepting it.
2020-01-21 21:55:25 +01:00
Andreas Kling
82cb5b6f64 LibGUI: GFileSystemModel::index() now survives negative inputs
If asked to create an index with negative row and/or column, we should
just return an invalid GModelIndex() instead of asserting.
2020-01-21 21:55:25 +01:00
Andreas Kling
ecd5589d4f LibGUI: Fix missing initializer for GColumnsView::m_model_column 2020-01-21 21:55:25 +01:00
Andreas Kling
a14f08fcc9 LibGUI: Import GColorPicker from the PaintBrush application 2020-01-21 21:55:25 +01:00
Andreas Kling
66598f60fe SystemMonitor: Show process unveil() state as "Veil"
A process has one of three veil states:

- None: unveil() has never been called.
- Dropped: unveil() has been called, and can be called again.
- Locked: unveil() has been called, and cannot be called again.
2020-01-21 18:56:23 +01:00
Andreas Kling
5b992b130a LibDraw: Remove old PNG_STOPWATCH_DEBUG debug code 2020-01-21 15:40:14 +01:00
Andreas Kling
07075cd001 Kernel+LibC: Clean up open() flag (O_*) definitions
These were using a mix of decimal, octal and hexadecimal for no reason.
2020-01-21 13:34:39 +01:00
Andreas Kling
6081c76515 Kernel: Make O_RDONLY non-zero
Sergey suggested that having a non-zero O_RDONLY would make some things
less confusing, and it seems like he's right about that.

We can now easily check read/write permissions separately instead of
dancing around with the bits.

This patch also fixes unveil() validation for O_RDWR which previously
forgot to check for "r" permission.
2020-01-21 13:27:08 +01:00
Andreas Kling
0569123ad7 Kernel: Add a basic implementation of unveil()
This syscall is a complement to pledge() and adds the same sort of
incremental relinquishing of capabilities for filesystem access.

The first call to unveil() will "drop a veil" on the process, and from
now on, only unveiled parts of the filesystem are visible to it.

Each call to unveil() specifies a path to either a directory or a file
along with permissions for that path. The permissions are a combination
of the following:

- r: Read access (like the "rpath" promise)
- w: Write access (like the "wpath" promise)
- x: Execute access
- c: Create/remove access (like the "cpath" promise)

Attempts to open a path that has not been unveiled with fail with
ENOENT. If the unveiled path lacks sufficient permissions, it will fail
with EACCES.

Like pledge(), subsequent calls to unveil() with the same path can only
remove permissions, not add them.

Once you call unveil(nullptr, nullptr), the veil is locked, and it's no
longer possible to unveil any more paths for the process, ever.

This concept comes from OpenBSD, and their implementation does various
things differently, I'm sure. This is just a first implementation for
SerenityOS, and we'll keep improving on it as we go. :^)
2020-01-20 22:12:04 +01:00
Andreas Kling
b25210ee1b LibGUI: Use clamp() is various places 2020-01-20 13:17:16 +01:00
Andreas Kling
e07b34b9b8 Kernel+AK: Add/fix uintptr_t and intptr_t definitions
We should move towards using uintptr_t instead of u32 for pointers
everywhere, to prepare for an eventual 64-bit port.
2020-01-20 13:13:03 +01:00
Shannon Booth
6ea70f5724 LibDraw: Add beginnings of a triangle class
Currently the points of a triangle do not need to be initialised in a
certain orientation. Currently, the only real method in the class is
`contains`. However we can continue extending the class if and when we
need more functionality.
2020-01-19 08:45:23 +01:00
Andreas Kling
545e2ba065 LibC: Use the templated type consistently in strtol_impl<T> 2020-01-18 11:41:04 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Shannon Booth
22d1961c9a LibGUI: Handle "Return" key events
I kept on trying to use the enter key to navigate a tree view, when only
left and right arrow keys are used for this. Now also suport the return
key, is used as a toggle to open a tree.
2020-01-18 00:27:39 +01:00
Sergey Bugaev
cee597a728 LibCore: Make CIODevice::read_all() actually read all data
It used to only read the data it could get without blocking. Andreas says this
was intentional, but it's counterintuitive and no code that uses read_all()
actually expects it to return only a part of the data. So change it to always
read data until an EOF (or an error) is received.
2020-01-17 21:49:58 +01:00
Sergey Bugaev
e0013a6b4c Kernel+LibC: Unify sys$open() and sys$openat()
The syscall is now called sys$open(), but it behaves like the old sys$openat().
In userspace, open_with_path_length() is made a wrapper over openat_with_path_length().
2020-01-17 21:49:58 +01:00
Andreas Kling
c6e552ac8f Kernel+LibELF: Don't blindly trust ELF symbol offsets in symbolication
It was possible to craft a custom ELF executable that when symbolicated
would cause the kernel to read from user-controlled addresses anywhere
in memory. You could then fetch this memory via /proc/PID/stack

We fix this by making ELFImage hand out StringView rather than raw
const char* for symbol names. In case a symbol offset is outside the
ELF image, you get a null StringView. :^)

Test: Kernel/elf-symbolication-kernel-read-exploit.cpp
2020-01-16 22:11:31 +01:00
Andreas Kling
60143c8d4e LibC: Add strnlen() 2020-01-16 22:11:31 +01:00
joshua stein
5c25983844 LibVT: enforce a minimum size of 1 column and 1 row
Fixes #829
2020-01-16 12:41:09 +01:00
joshua stein
24b8a27190 LibVT: only use default bold font if it's the same size as our font
When the new font is a different size, just use that font for bold
glyphs as well.  It would be nice to find a matching bold version of
the new font automatically in the future.
2020-01-15 22:30:34 +01:00
Andreas Kling
09fd59a1b5 LibC: Add INADDR_LOOPBACK 2020-01-15 22:11:44 +01:00
joshua stein
c6c7e40bd1 Build: more IPCCompiler-generated dependencies 2020-01-15 21:52:09 +01:00
Andreas Kling
fd64e97c8a LibDraw+LibHTML: Make link colors themeable
Add "Link", "ActiveLink" and "VisitedLink" colors to the system theme
definition, and implement support for them in LibHTML.

Note that <body link="foo" alink="bar" vlink="baz"> takes precedence
over the system colors. Author style also takes precedence, since we
only fetch the system color in case the CSS color is -libhtml-link.
2020-01-13 20:33:15 +01:00
Andreas Kling
3b2f20ed4d LibM: Implement some naive functionality to make VVVVVV run 2020-01-13 19:01:44 +01:00
DrewStratford
2a8de4cdec LibCore: Fix segfault in CArgsParser (#1072)
CArgsParser::parse_next_param did not properly ensure that, when
a param required a following argument, there were enough parameters left to
complete the parse. This meant that params_left could become negative,
avoiding parse_next_param's termination condition, and cause a segfault
when reading from argv with an out of bounds index.

This fixes the check to ensure that we do in fact have the right amount
of parameters and also adds an assertion to ensure that params_left does
not become negative.
2020-01-13 14:52:25 +01:00
Andrew Kaster
046d6a6bbb LibELF: Add methods to validate the ELF and program headers
These will make sure there's no funny business or funny offsets in the
main ELF header or each Program Header. More can still be done (like
validating section headers), but this is a good start
2020-01-13 13:03:30 +01:00
Andrew Kaster
4cb7c8ea85 LibC: Move even more methods and globals out of crt0.o 2020-01-13 13:03:30 +01:00
Sergey Bugaev
dd54d13d8d Kernel+LibC: Allow passing mount flags to chroot()
Since a chroot is in many ways similar to a separate root mount, we can also
apply mount flags to it as if it was an actual mount. These flags will apply
whenever the chrooted process accesses its root directory, but not when other
processes access this same directory for the outside. Since it's common to
chdir("/") immediately after chrooting (so that files accessed through the
current directory inherit the same mount flags), this effectively allows one to
apply additional limitations to a process confined inside a chroot.

To this effect, sys$chroot() gains a mount_flags argument (exposed as
chroot_with_mount_flags() in userspace) which can be set to all the same values
as the flags argument for sys$mount(), and additionally to -1 to keep the flags
set for that file system. Note that passing 0 as mount_flags will unset any
flags that may have been set for the file system, not keep them.
2020-01-12 20:02:11 +01:00
Andreas Kling
45e7c2ba69 LibDraw: Remove debug spam about loading system themes 2020-01-12 10:01:22 +01:00
0xtechnobabble
ecf58ddd4f TextEditor: Implement replacement functionality
This patch adds a new replace widget that cooperates with the find
widget, the replace widget takes the input in the find textbox, searches
for occurences of that input, and replaces them with the input provied
in the replace textbox.
2020-01-12 01:41:36 +01:00
Andreas Kling
75c5e9af56 LibGUI: Fix assertion failure in GItemView::mouse_up() 2020-01-11 22:12:36 +01:00
Andreas Kling
ec1ae37f69 SystemMonitor+LibCore: Show process pledges in SystemMonitor :^) 2020-01-11 21:33:12 +01:00
Andreas Kling
41c504a33b Kernel: Add pledge() syscall :^)
This patch implements basic support for OpenBSD-style pledge().
pledge() allows programs to incrementally reduce their set of allowed
syscalls, which are divided into categories that each make up a subset
of POSIX functionality.

If a process violates one of its pledged promises by attempting to call
a syscall that it previously said it wouldn't call, the process is
immediately terminated with an uncatchable SIGABRT.

This is by no means complete, and we'll need to add more checks in
various places to ensure that promises are being kept.

But it is pretty cool! :^)
2020-01-11 20:45:51 +01:00
Sergey Bugaev
61c1106d9f Kernel+LibC: Implement a few mount flags
We now support these mount flags:
* MS_NODEV: disallow opening any devices from this file system
* MS_NOEXEC: disallow executing any executables from this file system
* MS_NOSUID: ignore set-user-id bits on executables from this file system

The fourth flag, MS_BIND, is defined, but currently ignored.
2020-01-11 18:57:53 +01:00
Sergey Bugaev
2fcbb846fb Kernel+LibC: Add O_EXEC, move exec permission checking to VFS::open()
O_EXEC is mentioned by POSIX, so let's have it. Currently, it is only used
inside the kernel to ensure the process has the right permissions when opening
an executable.
2020-01-11 18:57:53 +01:00
Sergey Bugaev
4566c2d811 Kernel+LibC: Add support for mount flags
At the moment, the actual flags are ignored, but we correctly propagate them all
the way from the original mount() syscall to each custody that resides on the
mounted FS.
2020-01-11 18:57:53 +01:00
Andreas Kling
eede6cfd06 LibPthread: Fix incompatible pthread_setname_np(), pthread_getname_np()
Other implementations of pthread_setname_np() do not take the name
length as an argument.

For pthread_getname_np(), other implementations take the buffer size
as a size_t.

This patch brings us in line with other implementations.
2020-01-11 12:54:30 +01:00
Andreas Kling
24c736b0e7 Kernel: Use the Syscall string and buffer types more
While I was updating syscalls to stop passing null-terminated strings,
I added some helpful struct types:

    - StringArgument { const char*; size_t; }
    - ImmutableBuffer<Data, Size> { const Data*; Size; }
    - MutableBuffer<Data, Size> { Data*; Size; }

The Process class has some convenience functions for validating and
optionally extracting the contents from these structs:

    - get_syscall_path_argument(StringArgument)
    - validate_and_copy_string_from_user(StringArgument)
    - validate(ImmutableBuffer)
    - validate(MutableBuffer)

There's still so much code around this and I'm wondering if we should
generate most of it instead. Possible nice little project.
2020-01-11 12:47:47 +01:00
Andreas Kling
f5092b1c7e Kernel: Pass a parameter struct to mount()
This was the last remaining syscall that took a null-terminated string
and figured out how long it was by walking it in kernelspace *shudder*.
2020-01-11 10:56:02 +01:00
Andreas Kling
e380142853 Kernel: Pass a parameter struct to rename() 2020-01-11 10:36:54 +01:00
Andreas Kling
46830a0c32 Kernel: Pass a parameter struct to symlink() 2020-01-11 10:31:33 +01:00