Commit Graph

2218 Commits

Author SHA1 Message Date
Andreas Kling
137a45dff2 Kernel: read()/write() should respect timeouts when used on a sockets
Move timeout management to the ReadBlocker and WriteBlocker classes.
Also get rid of the specialized ReceiveBlocker since it no longer does
anything that ReadBlocker can't do.
2020-01-26 17:54:23 +01:00
Andreas Kling
2ce9a705e3 IPv4: Mark UDP sockets as connected immediately upon connect()
This makes it possible to write() to a blocking UDPSocket. Previously
this was not possible since can_write() depends on is_connected().
2020-01-26 14:43:08 +01:00
Andreas Kling
388d40d755 IPv4: Fix bitrot in IPv4Socket debug logging 2020-01-26 14:42:44 +01:00
Andreas Kling
22d563b1aa IPv4: Don't hold IPv4Socket lock when blocking on byte-buffered receive 2020-01-26 10:26:27 +01:00
Andreas Kling
1d506a935c Ext2FS: Give names to some KBuffers
The more we give names to KBuffers, the easier it gets to understand
what's what in a kernel region dump. :^)
2020-01-26 10:18:18 +01:00
Andreas Kling
b011857e4f Kernel: Make writev() work again
Vector::ensure_capacity() makes sure the underlying vector buffer can
contain all the data, but it doesn't update the Vector::size().

As a result, writev() would simply collect all the buffers to write,
and then do nothing.
2020-01-26 10:10:15 +01:00
Andreas Kling
b93f6b07c2 Kernel: Make sched_setparam() and sched_getparam() operate on threads
Instead of operating on "some random thread in PID", these now operate
on the thread with a specific TID. This matches other systems better.
2020-01-26 09:58:58 +01:00
Andreas Kling
67950c80c8 Kernel: Zero-initialize LocalSocket::m_address
It was possible to read uninitialized kernel memory via getsockname().
Of course, kmalloc() is a good boy and scrubs new allocations with 0xBB
so all you got was a bunch of 0xBB.
2020-01-26 09:48:53 +01:00
Marios Prokopakis
da296f5865 Ext2FS: allocate_blocks allocates contiguous blocks (#1095)
This implementation uses the new helper method of Bitmap called
find_longest_range_of_unset_bits. This method looks for the biggest 
range of contiguous bits unset in the bitmap and returns the start of
the range back to the caller.
2020-01-26 09:48:24 +01:00
Andreas Kling
edbe7d3769 Kernel: Unbreak canonical mode TTY erase after LibVT changes
Now that LibVT's backspace character (8) is non-destructive, the kernel
line editing code has to take care of erasing manually.
2020-01-25 20:44:33 +01:00
Andreas Kling
f4e7aecec2 Kernel: Preserve CoW bits when splitting VM regions 2020-01-25 17:57:10 +01:00
Andreas Kling
7cc0b18f65 Kernel: Only open a single description for stdio in non-fork processes 2020-01-25 17:05:02 +01:00
Andreas Kling
603bf6fb4a Build: Remove -fno-sized-deallocation -Wno-sized-deallocation
Add sized variants of the global operator delete functions so we don't
have to use these GCC options anymore.
2020-01-25 16:59:21 +01:00
Andreas Kling
81ddd2dae0 Kernel: Make sys$setsid() clear the calling process's controlling TTY 2020-01-25 14:53:48 +01:00
Andreas Kling
f309381d4e Ext2FS: Use more dbg() in Ext2FS code
We should use dbg() instead of dbgprintf() as much as possible to
protect ourselves against format string bugs. Here's a bunch of
conversions in Ext2FS.
2020-01-25 14:30:53 +01:00
Andreas Kling
2bf11b8348 Kernel: Allow empty strings in validate_and_copy_string_from_user()
Sergey pointed out that we should just allow empty strings everywhere.
2020-01-25 14:14:11 +01:00
Andreas Kling
69de90a625 Kernel: Simplify Process constructor
Move all the fork-specific inheritance logic to sys$fork(), and all the
stuff for setting up stdio for non-fork ring 3 processes moves to
Process::create_user_process().

Also: we were setting up the PGID, SID and umask twice. Also the code
for copying the open file descriptors was overly complicated. Now it's
just a simple Vector copy assignment. :^)
2020-01-25 14:13:47 +01:00
Andreas Kling
0f5221568b Kernel: sys$execve() should not EFAULT for empty argument strings
It's okay to exec { "/bin/echo", "" } and it should not EFAULT.
2020-01-25 12:21:30 +01:00
Andreas Kling
e576c9e952 Kernel: Clear ESI and EDI on syscall entry
Since these are not part of the system call convention, we don't care
what userspace had in there. Might as well scrub it before entering
the kernel.

I would scrub EBP too, but that breaks the comfy kernel-thru-userspace
stack traces we currently get. It can be done with some effort.
2020-01-25 10:34:32 +01:00
Andreas Kling
b0192cfb38 Meta: Remove some copyright headers added in error 2020-01-25 10:34:32 +01:00
Sergey Bugaev
c0b32f7b76 Meta: Claim copyright for files created by me
This changes copyright holder to myself for the source code files that I've
created or have (almost) completely rewritten. Not included are the files
that were significantly changed by others even though it was me who originally
created them (think HtmlView), or the many other files I've contributed code to.
2020-01-24 15:15:16 +01:00
Andreas Kling
03d73cbaae Kernel: Allow Socket subclasses to fail construction
For example, socket(AF_INET) should only succeed for valid SOCK_TYPEs.
2020-01-23 21:33:15 +01:00
Andreas Kling
3de5439579 AK: Let's call decrementing reference counts "unref" instead of "deref"
It always bothered me that we're using the overloaded "dereference"
term for this. Let's call it "unreference" instead. :^)
2020-01-23 15:14:21 +01:00
Andreas Kling
15aac1f9e9 Build: Fix silly mistake in makeall.sh 2020-01-23 10:41:07 +01:00
Andreas Kling
e64c335e5a Revert "Kernel: Replace IRQHandler with the new InterruptHandler class"
This reverts commit 6c72736b26.

I am unable to boot on my home machine with this change in the tree.
2020-01-22 22:27:06 +01:00
Oliver Kraitschy
8e21e31b3a Build: use absolute path for /sbin/mke2fs
Distros like Debian and Ubuntu don't have /sbin in PATH, thus mke2fs is
not found.
2020-01-22 22:04:29 +01:00
Jesse Buhagiar
9cbce68b1d Meta: Change copyright holder of `FloppyDiskDevice.* 2020-01-22 14:37:44 +01:00
Liav A
6c72736b26 Kernel: Replace IRQHandler with the new InterruptHandler class
System components that need an IRQ handling are now inheriting the
InterruptHandler class.

In addition to that, the initialization process of PATAChannel was
changed to fit the changes.
PATAChannel, E1000NetworkAdapter and RTL8139NetworkAdapter are now
inheriting from PCI::Device instead of InterruptHandler directly.
2020-01-22 12:22:09 +01:00
Liav A
1ee37245cd Kernel: Introduce IRQ sharing support
The support is very basic - Each component that needs to handle IRQs
inherits from InterruptHandler class. When the InterruptHandler
constructor is called it registers itself in a SharedInterruptHandler.
When an IRQ is fired, the SharedInterruptHandler is invoked, then it
iterates through a list of the registered InterruptHandlers.

Also, InterruptEnabler class was created to provide a way to enable IRQ
handling temporarily, similar to InterruptDisabler (in CPU.h, which does
the opposite).

In addition to that a PCI::Device class has been added, that inherits
from InterruptHandler.
2020-01-22 12:22:09 +01:00
Liav A
2a160faf98 Kernel: Run clang-format on KeyboardDevice.cpp 2020-01-22 12:22:09 +01:00
Andreas Kling
30ad7953ca Kernel: Rename UnveilState to VeilState 2020-01-21 19:28:59 +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
f38cfb3562 Kernel: Tidy up debug logging a little bit
When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.

This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
2020-01-21 16:16:20 +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
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
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
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
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
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
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