Commit Graph

6397 Commits

Author SHA1 Message Date
Andreas Kling
5dd5d5ca4e MenuApplets: Use unveil()
The Clock and Audio applets really only need ("/res", "r") for LibGUI.

The CPUGraph applet also needs ("/proc/all", "r") for reading the CPU
usage data. Somewhat surprisingly, this also adds ("/etc/passwd", "r")
since CProcessStatisticsReader does username lookups.
2020-01-21 15:52:48 +01:00
Andreas Kling
a2ed805d23 AudioServer: Drop "rpath" and "wpath" pledges
Once the event loop is constructed, we will have opened /dev/audio for
output and no more filesystem lookups need to happen.
2020-01-21 15:40:48 +01:00
Andreas Kling
5b992b130a LibDraw: Remove old PNG_STOPWATCH_DEBUG debug code 2020-01-21 15:40:14 +01:00
Andreas Kling
1060d59ddd PaintBrush: Show which line thickness is selected in the tool menus
Put each tool's thickness altering actions into a GActionGroup and make
them mutually exclusive so we get that nice radio button appearance.

This all feel very clunky and we should move towards having something
like a "tool settings" pane that gets populated by the currently active
tool instead.
2020-01-21 13:47:57 +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
efbd1620d9 Terminal: Unveil the user's config file
I mistakenly thought that we were keeping the config file open, but we
don't. So we'll need to unveil the config path in case we need to write
out a new configuration.
2020-01-21 13:08:22 +01:00
Andreas Kling
3097eb4717 Terminal: Use unveil()
This app needs ("/bin/Terminal", "x") in order to fork+exec itself when
the user requests a new Terminal window. I really like how this reduces
reduces the impact of pledging "exec". :^)

It also needs ("/res", "r") like all GUI apps. We delay the first call
to unveil until after we've already opened the app's config file, so
there's no need to worry about that.
2020-01-21 12:16:17 +01:00
Andreas Kling
21886ff9e2 About: Use unveil() 2020-01-21 12:12:07 +01:00
Andreas Kling
39931733a5 Calculator: Use unveil()
A barebones GUI app like this only needs read access to /res (for fonts
and themes, in case settings change) once it's up and running.
2020-01-21 12:03:08 +01:00
Andreas Kling
1b3cac2f42 Kernel: Don't forget about unveiled paths with zero permissions
We need to keep these around, otherwise the calling process can remove
and re-add a path to increase its permissions.
2020-01-21 11:42:28 +01:00
Liav A
200a5b0649 Kernel: Remove map_for_kernel() in MemoryManager
We don't need to have this method anymore. It was a hack that was used
in many components in the system but currently we use better methods to
create virtual memory mappings. To prevent any further use of this
method it's best to just remove it completely.

Also, the APIC code is disabled for now since it doesn't help booting
the system, and is broken since it relies on identity mapping to exist
in the first 1MB. Any call to the APIC code will result in assertion
failed.

In addition to that, the name of the method which is responsible to
create an identity mapping between 1MB to 2MB was changed, to be more
precise about its purpose.
2020-01-21 11:29:58 +01:00
Liav A
60c32f44dd Kernel: ACPI code doesn't rely on identity mapping anymore
The problem was mostly in the initialization code, since in that stage
the parser assumed that there is an identity mapping in the first 1MB of
the address space. Now during initialization the parser will create the
correct mappings to locate the required data.
2020-01-21 11:29:58 +01:00
Liav A
325022cbd7 Kernel: DMIDecoder no longer depends on identity-mapping
DMIDecoder creates the mappings using the standard helpers, thus no
need to rely on the identity mapping in the first 1MB in memory.
2020-01-21 11:29:58 +01:00
Liav A
aca317d889 Kernel: PCI MMIO no longer uses map_for_kernel()
PCI MMIO access is done by modifying the related PhysicalPage directly,
then we request to remap the region to create the mapping.
2020-01-21 11:29:58 +01:00
Atilla Lonny
24f2596345 Base: Add Nord theme
Nord (specifically Polar Night) is a popular soft dark blue/grey theme.

Personally, I find it to be a very nice middle-ground between the contrast of the
dark and light (default) theme.

![Preview](https://i.imgur.com/6sVnT4i.png)
2020-01-21 11:25:44 +01:00
Andreas Kling
05a2a0c492 WindowServer: unveil("/bin", "x") so we can start applications
Without this, we can't start programs via the system menu. This begs
the question: should WindowServer really be allowed to fork and exec
in the first place?
2020-01-21 10:48:14 +01:00
Andreas Kling
22cfb1f3bd Kernel: Clear unveiled state on exec() 2020-01-21 10:46:31 +01:00
Andreas Kling
cf48c20170 Kernel: Forked children should inherit unveil()'ed paths 2020-01-21 09:44:32 +01:00
Andreas Kling
d8357ceb26 SystemMonitor: Add an "Unveiled paths" section to the per-process tabs
This shows the data from /proc/PID/unveil in a nice table view. :^)
2020-01-20 22:32:44 +01:00
Andreas Kling
17e5fc301b WindowServer: Use unveil()
WindowServer needs persistent access to a few things:

- /res (for themes, fonts, cursors, apps, wallpapers, etc.)
- /etc/passwd (for username lookup, not sure this is actually needed..)
- /home/anon/WindowManager.ini (FIXME: this should not be hard-coded..)

These things are unveiled temporarily, and then dropped:

- /tmp (for setting up sockets)
- /dev (for opening input and framebuffer devices)

This leaves WindowServer running with a very limited view of the file
system, how neat is that!
2020-01-20 22:23:18 +01:00
Andreas Kling
cec0268ffa id: Use unveil()
And so "id" becomes our first user of unveil(), giving himself access
to read /etc/passwd and /etc/group :^)
2020-01-20 22:21:41 +01:00
Andreas Kling
02406b7305 ProcFS: Add /proc/PID/unveil
This file exposes a JSON array of all the unveiled paths in a process.
2020-01-20 22:19:02 +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
e711936c78 Userland: Add a dummy passthrough "flock" program
This allows you to run our build system's Makefiles inside SerenityOS
itself (since they rely on "flock")

Obviously it doesn't do any locking as we don't support that yet.
2020-01-20 20:44:29 +01:00
Andreas Kling
f4f958f99f Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing
Background: DoubleBuffer is a handy buffer class in the kernel that
allows you to keep writing to it from the "outside" while the "inside"
reads from it. It's used for things like LocalSocket and TTY's.
Internally, it has a read buffer and a write buffer, but the two will
swap places when the read buffer is exhausted (by reading from it.)

Before this patch, it was internally implemented as two Vector<u8>
that we would swap between when the reader side had exhausted the data
in the read buffer. Now instead we preallocate a large KBuffer (64KB*2)
on DoubleBuffer construction and use that throughout its lifetime.

This removes all the kmalloc heap traffic caused by DoubleBuffers :^)
2020-01-20 16:08:49 +01:00
Andreas Kling
0a282e0a02 Kernel: Allow naming KBuffers 2020-01-20 14:00:11 +01:00
Andreas Kling
2309029cb4 AK: Allow clamp() with min==max 2020-01-20 13:49:05 +01:00
Andreas Kling
e901a3695a Kernel: Use the templated copy_to/from_user() in more places
These ensure that the "to" and "from" pointers have the same type,
and also that we copy the correct number of bytes.
2020-01-20 13:41:21 +01:00
Sergey Bugaev
d5426fcc88 Kernel: Misc tweaks 2020-01-20 13:26:06 +01:00
Sergey Bugaev
9bc6157998 Kernel: Return new fd from sys$fcntl(F_DUPFD)
This fixes GNU Bash getting confused after performing a redirection.
2020-01-20 13:26:06 +01:00
Andreas Kling
b25210ee1b LibGUI: Use clamp() is various places 2020-01-20 13:17:16 +01:00
Andreas Kling
b52d0afecf SB16: Map the DMA buffer in kernelspace so we can write to it
This broke with the >3GB paging overhaul. It's no longer possible to
write directly to physical addresses below the 8MB mark. Physical pages
need to be mapped into kernel VM by using a Region.

Fixes #1099.
2020-01-20 13:13:03 +01:00
Andreas Kling
a0b716cfc5 Add AnonymousVMObject::create_with_physical_page()
This can be used to create a VMObject for a single PhysicalPage.
2020-01-20 13:13:03 +01:00
Andreas Kling
4ebff10bde Kernel: Write-only regions should still be mapped as present
There is no real "read protection" on x86, so we have no choice but to
map write-only pages simply as "present & read/write".

If we get a read page fault in a non-readable region, that's still a
correctness issue, so we crash the process. It's by no means a complete
protection against invalid reads, since it's trivial to fool the kernel
by first causing a write fault in the same region.
2020-01-20 13:13:03 +01:00
Andreas Kling
4b7a89911c Kernel: Remove some unnecessary casts to uintptr_t
VirtualAddress is constructible from uintptr_t and const void*.
PhysicalAddress is constructible from uintptr_t but not const void*.
2020-01-20 13:13:03 +01:00
Andreas Kling
a246e9cd7e Use uintptr_t instead of u32 when storing pointers as integers
uintptr_t is 32-bit or 64-bit depending on the target platform.
This will help us write pointer size agnostic code so that when the day
comes that we want to do a 64-bit port, we'll be in better shape.
2020-01-20 13:13:03 +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
68d5b39942 WindowServer: Simplify WSMenu MouseWheel event
A mouse move event needs to do a bit more work than what a mouse wheel event
does. Mouse wheel just needs to update the hovered item, and update for a new
hovered item. This also stops us from calling redraw() twice on a wheel event.
2020-01-20 10:35:12 +01:00
Shannon Booth
3e05c83591 WindowServer: Stop infinite menu movement cycle
While I really enjoyed having an infinite cycle when I implemented menu
keys (and seeing it wizz around and around :D), menu key movement should
be consistent between menus - and an inifinite cycle does not make much
sense for a scrollable menu.
2020-01-20 10:35:12 +01:00
Shannon Booth
de74458f13 AK: Add clamp() function
This function can be used to more cleanly write the common operation of
clamping a value between two values.
2020-01-20 10:35:12 +01:00
Andreas Kling
fb7a885cae WindowServer: Allow scrolling of menus that don't fit on screen
Menus now have a scroll offset (index based, not pixel based) which is
controlled either with the mouse wheel or with the up/down arrow keys.

This finally allows us to browse all of the fonts that @xTibor has made
avilable through his serenity-fontdev project:

https://github.com/xTibor/serenity-fontdev

I'm not completely sure about the up/down arrows. They feel like maybe
they occupy a bit too much vertical space.

Also FIXME: this mechanism probably won't look completely right for
menus that have separators in them.

Fixes #1043.
2020-01-19 21:36:33 +01:00
Andreas Kling
5ce1cc89a0 Kernel: Add fast-path for sys$gettid()
The userspace locks are very aggressively calling sys$gettid() to find
out which thread ID they have.

Since syscalls are quite heavy, this can get very expensive for some
programs. This patch adds a fast-path for sys$gettid(), which makes it
skip all of the usual syscall validation and just return the thread ID
right away.

This cuts Kernel/Process.cpp compile time by ~18%, from ~29 to ~24 sec.
2020-01-19 17:32:05 +01:00
Andreas Kling
8d9dd1b04b Kernel: Add a 1-deep cache to Process::region_from_range()
This simple cache gets hit over 70% of the time on "g++ Process.cpp"
and shaves ~3% off the runtime.
2020-01-19 16:44:37 +01:00
Andreas Kling
ae0c435e68 Kernel: Add a Process::add_region() helper
This is a private helper for adding a Region to Process::m_regions.
It's just for convenience since it's a bit cumbersome to do this.
2020-01-19 16:26:42 +01:00
Andreas Kling
1dc9fa9506 Kernel: Simplify PageDirectory swapping in sys$execve()
Swap out both the PageDirectory and the Region list at the same time,
instead of doing the Region list slightly later.
2020-01-19 16:05:42 +01:00
Andreas Kling
d394267f50 AK: Add NonnullOwnPtr::swap() as well for symmetry 2020-01-19 16:03:57 +01:00
Andreas Kling
05836757c6 Kernel: Oops, fix bad sort order of available VM ranges
This made the allocator perform worse, so here's another second off of
the Kernel/Process.cpp compile time from a simple bugfix! (31s to 30s)
2020-01-19 15:53:43 +01:00
Andreas Kling
167b57a6b7 TmpFS: Grow the underlying inode buffer with 2x factor when written to
Before this, we would end up in memcpy() churn hell when a program was
doing repeated write() calls to a file in /tmp.

An even better solution will be to only grow the VM allocation of the
underlying buffer and keep using the same physical pages. This would
eliminate all the memcpy() work.

I've benchmarked this using g++ to compile Kernel/Process.cpp.
With these changes, compilation goes from ~35 sec to ~31 sec. :^)
2020-01-19 14:01:32 +01:00
Andreas Kling
1d02ac35fc Kernel: Limit Thread::raw_backtrace() to the max profiler stack size
Let's avoid walking overly long stacks here, since kmalloc() is finite.
2020-01-19 13:54:09 +01:00