Commit graph

1733 commits

Author SHA1 Message Date
Andreas Kling 0e9e70ca4f IPv4: Disconnected non-blocking sockets were not signalling EOF
After a socket has disconnected, we shouldn't return -EAGAIN. Instead
we should allow userspace to read/recvfrom the socket until its packet
queue has been exhausted.

At that point, we now return 0, signalling EOF.

It might be even better to start returning -ENOTCONN after signalling
EOF once. I'm not sure how that should work, needs looking into.
2019-11-18 17:37:54 +01:00
Andreas Kling b0f38c1733 Build: Oops, typo in the path to LibHTML code generators in makeall.sh
This worked locally because I already had the built generators lying
around, but failed for other people who hadn't built them yet. Oops!
2019-11-18 16:45:14 +01:00
Andreas Kling da23864c8d LibHTML: Let's just build host-side tools in makeall.sh instead
Instead of trying to build the host-side code generator helpers right
before we need them in the LibHTML build process, just build them ahead
of time in makeall.sh, like we already do for {IPC,Form}Compiler.
2019-11-18 16:30:18 +01:00
Andreas Kling c23addd1fb Kernel: When userspaces calls a removed syscall, fail with ENOSYS
This is a bit gentler than jumping to 0x0, which always crashes the
whole process. Also log a debug message about what happened, and let
the user know that it's probably time to rebuild the program.
2019-11-18 12:35:14 +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 3093b019d0 Kernel: Let's have sys$uname() report "i686" instead of "i386"
We wouldn't be able to run on an 80386 without considerable changes,
so let's be honest here and call it i686.
2019-11-17 19:39:12 +01:00
Andreas Kling 8ccbd7002b Ext2FS: Rename allocate_inode() => find_a_free_inode()
Since this function doesn't actually mark the inode as allocated,
let's tone down the name a little bit.
2019-11-17 19:19:02 +01:00
Andreas Kling a712d4ac0c Ext2FS: Writing to a slow symlink should not treat it like a fast one
We would misinterpret short writes to the first 60 bytes of a slow
symlink as writes to a fast symlink.
2019-11-17 19:19:00 +01:00
Andreas Kling 5d08665d9a Ext2FS: Remove unnecessary extra cache lookup in get_inode() 2019-11-17 19:11:19 +01:00
Andreas Kling ba997c0a72 Ext2FS: Add some FIXME's while browsing this code 2019-11-17 18:59:14 +01:00
Andreas Kling b2df670cf5 Kernel: Just hang if VFS::mount_root() fails 2019-11-17 18:58:25 +01:00
Andreas Kling e34ed04d1e Kernel+LibPthread+LibC: Create secondary thread stacks in userspace
Have pthread_create() allocate a stack and passing it to the kernel
instead of this work happening in the kernel. The more of this we can
do in userspace, the better.

This patch also unexposes the raw create_thread() and exit_thread()
syscalls since they are now only used by LibPthread anyway.
2019-11-17 17:29:20 +01:00
Andreas Kling 02f89dc419 Kernel+SystemMonitor: Show VM region "shared" and "stack" bits in UI
Expose these two region bits through /proc/PID/vm and show them in the
SystemMonitor process memory map view.
2019-11-17 12:15:46 +01:00
Andreas Kling 794758df3a Kernel: Implement some basic stack pointer validation
VM regions can now be marked as stack regions, which is then validated
on syscall, and on page fault.

If a thread is caught with its stack pointer pointing into anything
that's *not* a Region with its stack bit set, we'll crash the whole
process with SIGSTKFLT.

Userspace must now allocate custom stacks by using mmap() with the new
MAP_STACK flag. This mechanism was first introduced in OpenBSD, and now
we have it too, yay! :^)
2019-11-17 12:15:43 +01:00
Andreas Kling 8d4d63d9b6 Ext2FS: Minor cleanup, remove an unused function 2019-11-16 17:29:09 +01:00
Andreas Kling 73d6a69b3f Kernel: Release the big process lock while yielding in sys$yield()
Otherwise, a thread calling sched_yield() will prevent other threads
in that process from entering the kernel.
2019-11-16 12:18:59 +01:00
Andreas Kling 7ef9c703d2 Kernel: Unbreak SlabAllocator after startup-time constructors
Now that the kernel supports startup-time constructors, we were first
doing slab_alloc_init(), and then the constructors ran later on,
zeroing out the freelist pointers.

This meant that all slab allocators thought they were completelty
exhausted and forwarded all requests to kmalloc() instead.
2019-11-15 12:48:39 +01:00
Andreas Kling cb5021419e Kernel: Move Thread::m_joinee_exit_value into the JoinBlocker
There's no need for this to be a permanent Thread member. Just use a
reference in the JoinBlocker instead.
2019-11-14 21:04:34 +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
Sergey Bugaev d29a078ab3 Kernel: Implement the killpg() syscall 2019-11-14 20:10:16 +01:00
Sergey Bugaev 1e1ddce9d8 Kernel: Unwind kernel stacks before dying
While executing in the kernel, a thread can acquire various resources
that need cleanup, such as locks and references to RefCounted objects.
This cleanup normally happens on the exit path, such as in destructors
for various RAII guards. But we weren't calling those exit paths when
killing threads that have been executing in the kernel, such as threads
blocked on reading or sleeping, thus causing leaks.

This commit changes how killing threads works. Now, instead of killing
a thread directly, one is supposed to call thread->set_should_die(),
which will unblock it and make it unwind the stack if it is blocked
in the kernel. Then, just before returning to the userspace, the thread
will automatically die.
2019-11-14 20:05:58 +01:00
Andreas Kling dd1996ca68 run: Unbreak this script when running with a regular Bourne /bin/sh
We can't use bashisms in our scripts anymore, since we're trying to
keep them POSIXy (to make them easier to run for our own shell someday)
2019-11-13 21:57:51 +01:00
Andreas Kling 69ca9cfd78 LibPthread: Start working on a POSIX threading library
This patch adds pthread_create() and pthread_exit(), which currently
simply wrap our existing create_thread() and exit_thread() syscalls.

LibThread is also ported to using LibPthread.
2019-11-13 21:49:24 +01:00
supercomputer7 4fe2ee0221 Kernel: Add a kernel boot parameter to force PIO mode
Also added an option in the run script to force PIO operation mode with
the IDE controller.
In addition, we're no longer limited to PIIX3 and PIIX4 chipsets for DMA
2019-11-13 18:30:25 +01:00
Sergey Bugaev cfdbb712fb Kernel: Fix failing in can_read()/can_write()
Now that the SystemMonitor queries which open files can be read and written to,
having can_read()/can_write() unconditionally call ASSERT_NOT_REACHED() leads
to system crashes when inspecting the WindowServer.

Instead, just return true from can_read()/can_write() (indicating that the
read()/write() syscalls should not block) and return -EINVAL when trying to
actually read from or write to these devices.
2019-11-13 16:37:04 +01:00
Dominik Madarász 0a51e4bf9f Build: Make sure PATH is passed properly (#765) 2019-11-12 10:26:50 +01:00
Emanuel Sprung 3042c942d8 Toolchain: Add QEMU build script and improve documentation
Added a script to build QEMU from source as part of the Toolchain.
The script content could be in BuildIt.sh but has been put in
a seperate file to make the build optional.

Added PATH=$PATH to sudo calls to hand over the Toolchain's PATH
setup by UseIt.sh. This enabled the script's to use the QEMU
contained in the SerenityOS toolchain.

Deleted old documentation in Meta and replaced it by a new
documentation in the Toolchain folder.
2019-11-11 21:29:56 +01:00
Andreas Kling dd2900eda0 Launcher: Remove the Launcher app, and all hacks in support of it
The Launcher's functionality has been replaced by the app shortcuts in
the system menu.

There were various window management hacks to ensure that the launcher
stayed below all other windows while also being movable, etc.
2019-11-11 13:13:08 +01:00
Andreas Kling 11fd7aed2a Kernel: open() with a zero-length path should fail with EINVAL 2019-11-11 13:13:08 +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 07806d1273 Kernel: Process should release its TTY immediately on exit
Don't wait for someone to wait() on a dead process before releasing its
TTY object. This fixes the child process death detection used by the
Terminal application, which relies on getting an EOF on the master PTY
in order to know it's time to wait() on the child process. :^)
2019-11-10 08:49:23 +01:00
Andreas Kling b285a1944e Kernel: Clear the x86 DF flag when entering the kernel
The SysV ABI says that the DF flag should be clear on function entry.
That means we have to clear it when jumping into the kernel from some
random userspace context.
2019-11-09 22:42:19 +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 06a80bcf69 Kernel+SystemMonitor: Publish can_read/write state for open files
The can_read() and can_write() states for file descriptions are now
published in /proc, allowing SystemMonitor to display it.
2019-11-09 22:42:19 +01:00
Liav A bce510bf6f Kernel: Fix the search method of free userspace physical pages (#742)
Now the userspace page allocator will search through physical regions,
and stop the search as it finds an available page.

Also remove an "address of" sign since we don't need that when
counting size of physical regions
2019-11-08 22:39:29 +01:00
supercomputer7 c3c905aa6c Kernel: Removing hardcoded offsets from Memory Manager
Now the kernel page directory and the page tables are located at a
safe address, to prevent from paging data colliding with garbage.
2019-11-08 17:38:23 +01:00
Andreas Kling 39fcd92210 Kernel: Remove debug spam about dump_backtrace() calling itself
This was too noisy and important-sounding, when it doesn't really
matter that much. It's not the end of the world if symbolication fails
for one reason or another.
2019-11-08 17:36:29 +01:00
Andreas Kling 2c693094d9 Kernel: If a process is interrupted during usleep(), return -EINTR 2019-11-06 21:01:44 +01:00
Andreas Kling 2f16e31afc Kernel: A running process should keep its TTY alive
It's not safe to use a raw pointer for Process::m_tty. A pseudoterminal
pair will disappear when file descriptors are closed, and we'd end up
looking dangly. Just use a RefPtr.
2019-11-06 16:52:54 +01:00
Andreas Kling 083c5f8b89 Kernel: Rework Process::Priority into ThreadPriority
Scheduling priority is now set at the thread level instead of at the
process level.

This is a step towards allowing processes to set different priorities
for threads. There's no userspace API for that yet, since only the main
thread's priority is affected by sched_setparam().
2019-11-06 16:30:06 +01:00
Andreas Kling e33bbdb6ba AK: Remove unused AK::not_implemented()
Whatever this was supposed to be, it was ironically... not implemented.
2019-11-06 13:58:08 +01:00
Andreas Kling 14dc323f4d Kernel: Sort the C++ objects in the Makefile 2019-11-06 13:45:21 +01:00
Andreas Kling 49635e62fa LibELF: Move AK/ELF/ into Libraries/LibELF/
Let's arrange things like this instead. It didn't feel right for all of
the ELF handling code to live in AK.
2019-11-06 13:42:38 +01:00
Andreas Kling 31beff8afb Kernel: Remove unnecessary init_ksyms() function 2019-11-06 13:36:37 +01:00
Andreas Kling 4f4d4670fe Kernel: Don't instantiate and throw away ProcFS + DevPtsFS on boot
Oops, we were creating these and then throwing them away. They will
get instantiated a bit later, when we bring up the mounts in /etc/fstab
from userspace.
2019-11-06 13:21:44 +01:00
Andreas Kling 9a4b117f48 Kernel: Simplify kernel entry points slightly
It was silly to push the address of the stack pointer when we can also
just change the callee argument to be a value type.
2019-11-06 13:15:55 +01:00
Andreas Kling 349d2ec1c2 Kernel: Link with libgcc
This allows us to get rid of all the custom 64-bit division helpers.
I wanted to do this ages ago but couldn't get it working. Turns out it
was unstable due to libgcc using the regular ABI and the kernel being
built with -mregparm=3.

Now that we build the kernel with regular calls, we can just link with
libgcc and get this stuff for free. :^)
2019-11-06 13:07:07 +01:00
Andreas Kling 1c6f8d3cbd Kernel: Don't build with -mregparm=3
It was really confusing to have different calling conventions in kernel
and userspace. Also this has prevented us from linking with libgcc.
2019-11-06 13:04:47 +01:00