Commit Graph

141 Commits

Author SHA1 Message Date
Andreas Kling
0317ca5ccc Kernel+LibC: Make all SharedBuffers purgeable (default: non-volatile)
This patch makes SharedBuffer use a PurgeableVMObject as its underlying
memory object.

A new syscall is added to control the volatile flag of a SharedBuffer.
2019-12-09 20:06:47 +01:00
Andreas Kling
dbb644f20c Kernel: Start implementing purgeable memory support
It's now possible to get purgeable memory by using mmap(MAP_PURGEABLE).
Purgeable memory has a "volatile" flag that can be set using madvise():

- madvise(..., MADV_SET_VOLATILE)
- madvise(..., MADV_SET_NONVOLATILE)

When in the "volatile" state, the kernel may take away the underlying
physical memory pages at any time, without notifying the owner.
This gives you a guilt discount when caching very large things. :^)

Setting a purgeable region to non-volatile will return whether or not
the memory has been taken away by the kernel while being volatile.
Basically, if madvise(..., MADV_SET_NONVOLATILE) returns 1, that means
the memory was purged while volatile, and whatever was in that piece
of memory needs to be reconstructed before use.
2019-12-09 19:12:38 +01:00
Andrew Kaster
9058962712 Kernel: Allow setting thread names
The main thread of each kernel/user process will take the name of
the process. Extra threads will get a fancy new name
"ProcessName[<tid>]".

Thread backtraces now list the thread name in addtion to tid.

Add the thread name to /proc/all (should it get its own proc
file?).

Add two new syscalls, set_thread_name and get_thread_name.
2019-12-08 14:09:29 +01:00
Andreas Kling
95b086f47f Kernel+LibPthread: Implement pthread_detach() 2019-12-07 14:52:27 +01:00
Andreas Kling
6b150c794a Kernel: Implement very simple kernel module loading
It's now possible to load a .o file into the kernel via a syscall.
The kernel will perform all the necessary ELF relocations, and then
call the "module_init" symbol in the loaded module.
2019-11-28 20:59:11 +01:00
Hüseyin ASLITÜRK
794ca16cca Kernel: Implement the setkeymap() syscall. 2019-11-25 11:53:02 +01:00
Andrew Kaster
618aebdd8a Kernel+LibPthread: pthread_create handles pthread_attr_t
Add an initial implementation of pthread attributes for:
  * detach state (joinable, detached)
  * schedule params (just priority)
  * guard page size (as skeleton) (requires kernel support maybe?)
  * stack size and user-provided stack location (4 or 8 MB only, must be aligned)

Add some tests too, to the thread test program.

Also, LibC: Move pthread declarations to sys/types.h, where they belong.
2019-11-18 09:04:32 +01:00
Andreas Kling
3da6d89d1f Kernel+LibC: Remove the isatty() syscall
This can be implemented entirely in userspace by calling tcgetattr().
To avoid screwing up the syscall indexes, this patch also adds a
mechanism for removing a syscall without shifting the index of other
syscalls.

Note that ports will still have to be rebuilt after this change,
as their LibC code will try to make the isatty() syscall on startup.
2019-11-17 20:03:42 +01:00
Andreas Kling
69efa3f630 Kernel+LibPthread: Implement pthread_join()
It's now possible to block until another thread in the same process has
exited. We can also retrieve its exit value, which is whatever value it
passed to pthread_exit(). :^)
2019-11-14 20:58:23 +01:00
Andreas Kling
72fae05c07 Kernel: Use C++ structured bindings to bind syscall parameters
Some syscalls have to pass parameters through a struct, since we can
only fit 3 parameters with our calling convention.

This patch makes use of C++ structured binding to clean up the places
where we expand those parameters structs into local variables.
2019-11-10 21:19:08 +01:00
Andreas Kling
18348cebf1 Kernel+LibC: Implement the openat() syscall
POSIX's openat() is very similar to open(), except you also provide a
file descriptor referring to a directory from which relative paths
should be resolved.

Passing it the magical fd number AT_FDCWD means "resolve from current
directory" (which is indeed also what open() normally does.)

This fixes libarchive's bsdtar, since it was trying to do something
extremely wrong in the absence of openat() support. The issue has
recently been fixed upstream in libarchive:

https://github.com/libarchive/libarchive/issues/1239

However, we should have openat() support anyway, so I went ahead and
implemented it. :^)

Fixes #748.
2019-11-10 13:51:27 +01:00
Andreas Kling
fbeb1ab15b Kernel: Use a lookup table for syscalls
Instead of the big ugly switch statement, build a lookup table using
the syscall enumeration macro.

This greatly simplifies the syscall implementation. :^)
2019-11-09 22:42:19 +01:00
Andreas Kling
cc68654a44 Kernel+LibC: Implement clock_gettime() and clock_nanosleep()
Only the CLOCK_MONOTONIC clock is supported at the moment, and it only
has millisecond precision. :^)
2019-11-02 19:34:06 +01:00
Calvin Buckley
7e4e092653 Kernel: Add a Linux-style getrandom syscall
The way it gets the entropy and blasts it to the buffer is pretty
ugly IMHO, but it does work for now. (It should be replaced, by
not truncating a u32.)

It implements an (unused for now) flags argument, like Linux but
instead of OpenBSD's. This is in case we want to distinguish
between entropy sources or any other reason and have to implement
a new syscall later. Of course, learn from Linux's struggles with
entropy sourcing too.
2019-10-13 18:03:21 +02:00
Drew Stratford
45ded86bcb Kernel: Move fchdir to end of enumerate syscalls.
The introduction fchdir in the middle of the EUMERATE_SYSCALLS
expression changed other syscall numbers, which broke compatibility.
This commit fixes that by moving it to the end.
2019-09-13 16:30:22 +02:00
Mauri de Souza Nunes
7d85fc00e4 Kernel: Implement fchdir syscall
The fchdir() function is equivalent to chdir() except that the
directory that is to be the new current working directory is
specified by a file descriptor.
2019-09-13 14:04:38 +02:00
Andreas Kling
9ffe8feff4 Kernel: Only #include stuff from <LibC/...> if __serenity__ is defined 2019-09-03 21:14:42 +02:00
Rok Povsic
18fbe4ac83 Kernel: Add realpath syscall 2019-08-25 19:47:37 +02:00
Jesse Buhagiar
bc22456f89 Kernel: Added unmount ability to VFS
It is now possible to unmount file systems from the VFS via `umount`.
It works via looking up the `fsid` of the filesystem from the `Inode`'s
metatdata so I'm not sure how fragile it is. It seems to work for now
though as something to get us going.
2019-08-17 09:29:54 +02:00
Andreas Kling
6ad3efe067 Kernel+LibC: Add get_process_name() syscall
It does exactly what it sounds like:

    int get_process_name(char* buffer, int buffer_size);
2019-08-15 20:55:10 +02:00
Andreas Kling
7d6689055f Kernel+LibC+crash: Add mprotect() syscall
This patch adds the mprotect() syscall to allow changing the protection
flags for memory regions. We don't do any region splitting/merging yet,
so this only works on whole mmap() regions.

Added a "crash -r" flag to verify that we crash when you attempt to
write to read-only memory. :^)
2019-08-12 19:33:24 +02:00
Jesse
401c87a0cc Kernel: mount system call (#396)
It is now possible to mount ext2 `DiskDevice` devices under Serenity on
any folder in the root filesystem. Currently any user can do this with
any permissions. There's a fair amount of assumptions made here too,
that might not be too good, but can be worked on in the future. This is
a good start to allow more dynamic operation under the OS itself.

It is also currently impossible to unmount and such, and devices will
fail to mount in Linux as the FS 'needs to be cleaned'. I'll work on
getting `umount` done ASAP to rectify this (as well as working on less
assumption-making in the mount syscall. We don't want to just be able
to mount DiskDevices!). This could probably be fixed with some `-t`
flag or something similar.
2019-08-02 15:18:47 +02:00
Andreas Kling
5ded77df39 Kernel+ProcessManager: Let processes have an icon and show it in the table.
Processes can now have an icon assigned, which is essentially a 16x16 RGBA32
bitmap exposed as a shared buffer ID.

You set the icon ID by calling set_process_icon(int) and the icon ID will be
exposed through /proc/all.

To make this work, I added a mechanism for making shared buffers globally
accessible. For safety reasons, each app seals the icon buffer before making
it global.

Right now the first call to GWindow::set_icon() is what determines the
process icon. We'll probably change this in the future. :^)
2019-07-29 07:26:01 +02:00
Andreas Kling
c8e2bb5605 Kernel: Add a mechanism for listening for changes to an inode.
The syscall is quite simple:

    int watch_file(const char* path, int path_length);

It returns a file descriptor referring to a "InodeWatcher" object in the
kernel. It becomes readable whenever something changes about the inode.

Currently this is implemented by hooking the "metadata dirty bit" in
Inode which isn't perfect, but it's a start. :^)
2019-07-22 20:01:11 +02:00
Andreas Kling
af81645a2a Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug output.
This is very handy for the DebugLogStream implementation, among others. :^)
2019-07-21 21:43:37 +02:00
Andreas Kling
3fce2fb205 Kernel+LibC: Add a dbgputch() syscall and use it for userspace dbgprintf().
The "stddbg" stream was a cute idea but we never ended up using it in
practice, so let's simplify this and implement userspace dbgprintf() on top
of a simple dbgputch() syscall instead.

This makes debugging LibC startup a little bit easier. :^)
2019-07-21 19:45:31 +02:00
Andreas Kling
d2b521f0ab Kernel+LibC: Add a dump_backtrace() syscall.
This is very simple but already very useful. Now you're able to call to
dump_backtrace() from anywhere userspace to get a nice symbolicated
backtrace in the debugger output. :^)
2019-07-21 09:59:17 +02:00
Jesse
a27c9e3e01 Kernel+Userland: Addd reboot syscall (#334)
Rolling with the theme of adding a dialog to shutdown the machine, it is
probably nice to have a way to reboot the machine without performing a full
system powerdown.

A reboot program has been added to `/bin/` as well as a corresponding
`syscall` (SC_reboot). This syscall works by attempting to pulse the 8042
keyboard controller. Note that this is NOT supported on  new machines, and
should only be a fallback until we have proper ACPI support.

The implementation causes a triple fault in QEMU, which then restarts the
system. The filesystems are locked and synchronized before this occurs,
so there shouldn't be any corruption etctera.
2019-07-19 09:58:12 +02:00
Robin Burchell
b907608e46 SharedBuffer: Split the creation and share steps
This allows us to seal a buffer *before* anyone else has access to it
(well, ok, the creating process still does, but you can't win them all).

It also means that a SharedBuffer can be shared with multiple clients:
all you need is to have access to it to share it on again.
2019-07-18 10:06:20 +02:00
Andreas Kling
c110cf193d Kernel: Have the open() syscall take an explicit path length parameter.
Instead of computing the path length inside the syscall handler, let the
caller do that work. This allows us to implement to new variants of open()
and creat(), called open_with_path_length() and creat_with_path_length().
These are suitable for use with e.g StringView.
2019-07-08 20:01:49 +02:00
Andreas Kling
27f699ef0c AK: Rename the common integer typedefs to make it obvious what they are.
These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
2019-07-03 21:20:13 +02:00
Robin Burchell
952382b413 Kernel/Userland: Add a halt syscall, and a shutdown binary to invoke it 2019-06-16 12:25:30 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Andreas Kling
54448b5d24 Kernel: Syscall header should forward-declare timeval with C linkage. 2019-06-07 11:52:27 +02:00
Andreas Kling
bc951ca565 Kernel: Run clang-format on everything. 2019-06-07 11:43:58 +02:00
Andreas Kling
93d3d1ede1 Kernel: Add fchown() syscall. 2019-06-01 20:31:36 +02:00
Robin Burchell
9cd0f6ffac Kernel/LibC: Implement sched_* functionality to set/get process priority
Right now, we allow anything inside a user to raise or lower any other process's
priority. This feels simple enough to me. Linux disallows raising, but
that's annoying in practice.
2019-05-30 02:57:15 +02:00
Robin Burchell
0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +02:00
Andreas Kling
ae470ec955 Kernel: Add getpeername() syscall, and fix getsockname() behavior.
We were copying the raw IPv4 addresses into the wrong part of sockaddr_in,
and we didn't set sa_family or sa_port.
2019-05-20 20:33:03 +02:00
Andreas Kling
212a263f0a Kernel+LibC: Implement getsockname() syscall. 2019-05-19 19:55:27 +02:00
Andreas Kling
189b342e6f LibC: Add mmap_with_name() that names the allocation immediately.
This allows us to skip the separate call to set_mmap_name() in code that
we control, e.g malloc() and GraphicsBitmap.
2019-05-19 15:54:56 +02:00
Andreas Kling
3cba2a8a78 Kernel: Add a beep() syscall that beeps the PC speaker.
Hook this up in Terminal so that the '\a' character generates a beep.
Finally emit an '\a' character in the shell line editing code when
backspacing at the start of the line.
2019-05-15 21:40:41 +02:00
Andreas Kling
99aead4857 Kernel: Add a writev() syscall for writing multiple buffers in one go.
We then use this immediately in the WindowServer/LibGUI communication in
order to send both message + optional "extra data" with a single syscall.
2019-05-10 03:19:25 +02:00
Andreas Kling
8b249bd09b Kernel+Userland: Implement mknod() syscall and add a /bin/mknod program. 2019-05-03 22:59:58 +02:00
Andreas Kling
d07be1087a Kernel+LibC: Add exit_thread() syscall. 2019-04-29 15:17:20 +02:00
Andreas Kling
5c68929aa1 Kernel: Add a systrace() syscall and implement /bin/strace using it.
Calling systrace(pid) gives you a file descriptor with a stream of the
syscalls made by a peer process. The process must be owned by the same
UID who calls systrace(). :^)
2019-04-22 18:44:45 +02:00
Andreas Kling
301a269ca0 Get rid of SERENITY macro since the compiler already defines __serenity__
This makes it a bit easier to use AK templates out-of-tree.
2019-04-20 12:58:49 +02:00
Andreas Kling
26a06f3fcd Kernel: More work towards POSIX SHM, also add ftruncate(). 2019-04-09 01:10:00 +02:00
Andreas Kling
99f3cc26c3 Kernel+LibC: Add stubs for POSIX shared memory API.
Specifically shm_open() and shm_unlink(). This patch just adds stubs.
2019-04-08 23:44:12 +02:00
Andreas Kling
37ae00a4dd Kernel+Userland: Add the rename() syscall along with a basic /bin/mv. 2019-04-07 23:35:26 +02:00