Commit graph

1764 commits

Author SHA1 Message Date
Andreas Kling 0311e8d50a HackStudio: Start working on an IDE for SerenityOS
This will be fun. :^)
2019-10-21 18:46:55 +02:00
Andrew Kaster 138abb9098 ELF: Fail layout when program header hooks return nullptr (#673)
ELFLoader::layout() had a "failed" variable that was never set. This
patch checks the return value of each hook (alloc/map section and tls)
and fails the load if they return null.

I also needed to patch Process so that the alloc_section_hook and 
map_section_hook actually return nullptr when allocating a region fails.

Fixes #664 :)
2019-10-20 16:24:42 +02:00
Drew Stratford 4c35c8d7fd TTY: Implement Canonical mode and basic echoing.
The TTY driver now respects the ICANON flag, enabling basic line
editing like VKILL, VERASE, VEOF and VWERASE. Additionally,
ICANON is now set by default.

Basic echoing has can now be enabled via the ECHO flag, though
more complicated echoing like ECHOCTL or ECHONL has not been
implemented.
2019-10-20 10:51:12 +02:00
Tidux d09a28856f Kernel: Move Boot/ into Arch/i386/Boot (#667) 2019-10-20 08:15:39 +02:00
Andreas Kling e08991319a Net: Put a bunch of socket debug logging behind FOO_DEBUG
Also remove an unused Socket::listen() implementation.
2019-10-18 16:50:23 +02:00
Andreas Kling ec65b8db2e Revert "Kernel: Make DoubleBuffer use a KBuffer instead of kmalloc()ing"
This reverts commit 1cca5142af.

This appears to be causing intermittent triple-faults and I don't know
why yet, so I'll just revert it to keep the tree in decent shape.
2019-10-18 15:58:06 +02:00
Andreas Kling 1cca5142af 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 PTY'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 :^)
2019-10-18 14:55:04 +02:00
Andreas Kling 4027a64fc5 Kernel: VirtualConsole can use kmalloc_eternal() for permanent stuff
Less pressure on kmalloc heap.
2019-10-18 14:14:54 +02:00
Andreas Kling 2f37fa487d Kernel: Keep TTY names in character buffers instead of Strings
Just going over some little unnecessary little kmalloc allocations.
2019-10-18 14:13:43 +02:00
Andreas Kling 340b524c0d Kernel: Minor cleanup in TCPSocket::send_tcp_packet() 2019-10-17 23:39:31 +02:00
Nufflee 7b6aba4284 KeyboardDevice: Rename 0xe0 flag for clarity. 2019-10-17 23:39:24 +02:00
Nufflee 0979f372a6 KeyboardDevice: Support whole numpad and Num Lock.
We now support all numpad keys and the Num Lock key.
2019-10-17 23:39:24 +02:00
Nufflee 9d5792b73d KeyboardDevice: Implement Caps Lock handling. 2019-10-17 23:39:24 +02:00
Tom 00a7c48d6e APIC: Enable APIC and start APs 2019-10-16 19:14:02 +02:00
Andreas Kling e4015ab7cc Kernel: Remove unused FileBackedDiskDevice class 2019-10-14 12:47:08 +02:00
Andreas Kling 98c7fd7aed Kernel: Clarify code that saves FPU state after FNINIT
After we clear the FPU state in a thread when it uses the FPU for the
first time, we also save the clean slate in the thread's FPU state
buffer. When we're doing that, let's write through current->fpu_state()
just to make it clear what's going on.

It was actually safe, since we'd just overwritten the g_last_fpu_thread
pointer anyway, but this patch improves the communication of intent.

Spotted by Bryan Steele, thanks!
2019-10-13 20:39:59 +02:00
Calvin Buckley 5050f7b5ee Kernel: Use word-sized entropy as much as possible in syscall 2019-10-13 18:03:21 +02: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
Andreas Kling 16e66716ba Runner: Enable QEMU's KVM mode by default
This makes QEMU run significantly faster on Linux systems with KVM.
2019-10-13 15:07:23 +02:00
Andreas Kling 44fb71261a Kernel: Fix accidental restore of bogus FPU state after fork
Cloned threads (basically, forked processes) inherit the complete FPU
state of their origin thread. There was a bug in the lazy FPU state
save/restore mechanism where a cloned thread would believe it had a
buffer full of valid FPU state (because the inherited flag said so)
but the origin thread had never actually copied any FPU state into it.

This patch fixes that by forcing out an FPU state save after doing
the initial FPU initialization (FNINIT) in a thread. :^)
2019-10-13 14:39:04 +02:00
Andreas Kling 40beb4c5c0 Kernel: Don't leak an FPU state buffer for every spawned thread
We were leaking 512 bytes of kmalloc memory for every new thread.
This patch fixes that, and also makes sure to zero out the FPU state
buffer after allocating it, and finally also makes the LogStream
operator<< for Thread look a little bit nicer. :^)
2019-10-13 14:36:55 +02:00
Brandon Scott 48ef1d1bd1 HexEditor: Initial application release
The very first release of the Hex Editor for Serenity.
2019-10-13 08:45:49 +02:00
Tom b0773a8ea6 AK: Add Atomic.h
Use gcc built-in atomics
2019-10-12 19:30:59 +02:00
Andreas Kling a6e4c504e2 Kernel: Make SlabAllocator fall back to kmalloc() when slabs run out
This is obviously not ideal, and it would be better to teach it how to
allocate more pages, etc. But since the physical page allocator itself
currently uses SlabAllocator, it's a little bit tricky :^)
2019-10-10 11:58:15 +02:00
Andreas Kling 9bb0374d7d Kernel: Delay moving accepted sockets to SetupState::Completed a bit
Make sure we don't move accepted sockets to the Completed setup state
until we've actually constructed a FileDescription for them.

This is important, since this state transition will trigger connect()
to unblock on the client side, and the client may try writing to the
socket right away.

This makes DNS lookups way more reliable since we don't just fail to
write() right after connect()ing to LookupServer sometimes. :^)
2019-10-08 21:44:50 +02:00
Andreas Kling 3aa27b5b0e Kernel: Don't put LocalSocket in SetupState::Completed in bind()
This was causing connect() to unblock immediately for local sockets,
since that's exactly what ConnectBlocker checks for.

Instead, just move to SetupState::Completed when it's accept()ed.
2019-10-08 21:32:04 +02:00
Jesse Buhagiar 06b6af61c6 Kernel: Made DiskCache entries a KBuffer
The Cache entries found in `DiskBackedFileSystem` are now stored in a
`KBuffer` object, instead of relying on `kmalloc_eternal`. The number
of entries was exceeding that of the number of bytes allocated to
`kmalloc_eternal`, which in turn caused `mount()` to fail epically
when called.
2019-10-08 11:10:30 +02:00
Drew Stratford c136fd3fe2 Kernel: Send SIGSEGV on seg-fault
Now programs can catch the SIGSEGV signal when they segfault.

This commit also introduced the send_urgent_signal_to_self method,
which is needed to send signals to a thread when handling exceptions
caused by the same thread.
2019-10-07 16:39:47 +02:00
Drew Stratford 7fc903b97a Kernel: Add exception_code to RegisterDump.
Added the exception_code field to RegisterDump, removing the need
for RegisterDumpWithExceptionCode. To accomplish this, I had to
push a dummy exception code during some interrupt entries to properly
pad out the RegisterDump. Note that we also needed to change some code
in sys$sigreturn to deal with the new RegisterDump layout.
2019-10-07 16:39:47 +02:00
supercomputer7 334e039294 PartitionTable: Removing unnecessary declarations from GPT & MBR classes 2019-10-07 11:32:42 +02:00
supercomputer7 de49714f36 PartitionTable: Initial GPT Support, Adding Block Limit
Also added a script to handle creation of GPT partitioned disk (with
GRUB config file). Block limit will be used to disallow potential access
to other partitions.
2019-10-07 10:11:39 +02:00
Andreas Kling 0a38e0028f Browser: Start working on a simple browser using LibHTML
This was inevitable. :^)
2019-10-05 10:20:17 +02:00
Andreas Kling 3f2c1a2e3d Kernel: Add SIOCGIFHWADDR ioctl to get the MAC address of an adapter 2019-10-02 18:20:11 +02:00
Andreas Kling 345086ab72 BXVGADevice: Log a debug message whenever the resolution changes
Fixes #618.
2019-10-02 17:16:46 +02:00
Andreas Kling 35138437ef Kernel+SystemMonitor: Add fault counters
This patch adds three separate per-process fault counters:

- Inode faults

    An inode fault happens when we've memory-mapped a file from disk
    and we end up having to load 1 page (4KB) of the file into memory.

- Zero faults

    Memory returned by mmap() is lazily zeroed out. Every time we have
    to zero out 1 page, we count a zero fault.

- CoW faults

    VM objects can be shared by multiple mappings that make their own
    unique copy iff they want to modify it. The typical reason here is
    memory shared between a parent and child process.
2019-10-02 14:13:49 +02:00
Andreas Kling c33ac7f170 Kernel: Don't update Thread TSS if scheduler tick reschedules it
If we didn't find anything else that wants to run, we don't need to
update the current thread's TSS since we're just gonna return to the
same thread anyway.
2019-10-02 13:47:44 +02:00
Andreas Kling 5ab044beae Ext2FS: Make Ext2FSInode::is_directory() fast
This patch overloads Inode::is_directory() with a faster version that
doesn't require instantiating the whole InodeMetadata.

If you have an Ext2FSInode&, calling is_directory() should be instant
since we can just look directly at the raw inode bits.
2019-10-02 13:47:44 +02:00
Andreas Kling d553bae749 Kernel: Allocate more 8-byte slabs than anything else
We need these for PhysicalPage objects. Ultimately I'd like to get rid
of these objects entirely, but while we still have to deal with them,
let's at least handle large demand a bit better.
2019-10-02 13:47:40 +02:00
Andreas Kling d481ae95b5 Kernel: Defer creation of Region CoW bitmaps until they're needed
Instead of allocating and populating a Copy-on-Write bitmap for each
Region up front, wait until we actually clone the Region for sharing
with another process.

In most cases, we never need any CoW bits and we save ourselves a lot
of kmalloc() memory and time.
2019-10-01 19:58:41 +02:00
Andreas Kling 3d4ed7f38d Kernel: mmap() with both MAP_PRIVATE and MAP_SHARED is an error 2019-10-01 19:31:55 +02:00
Andreas Kling c58d1868cb Kernel: Fix munmap() bad splitting of already-split Regions
When splitting an Region that's already the result of an earlier split,
we have to take the Region's offset-in-VMObject into account since it
may be non-zero.
2019-10-01 11:40:40 +02:00
Andreas Kling 4bfd4dc6c7 AK: Remove empty files JsonArray.cpp and JsonObject.cpp 2019-10-01 11:24:54 +02:00
Andreas Kling ac20919b13 Kernel: Make it possible to turn off VM guard pages at compile time
This might be useful for debugging since guard pages introduce a fair
amount of noise in the virtual address space.
2019-09-30 17:22:16 +02:00
Andreas Kling c5e057438c MBVGADevice: Log address/pitch/width/height when created 2019-09-30 15:04:16 +02:00
Andreas Kling 8e775d241e Kernel: Make DiskBackedFS flush writes if cache is completely dirty
If we want to make a new entry in the disk cache when it's completely
full of dirty blocks, we'll now synchronously flush the writes at that
point. Maybe it's not ideal, but at least we can keep going.
2019-09-30 11:46:56 +02:00
Andreas Kling 922fd703c9 Kernel: Convert the DiskBackedFS write API to take "const u8*"
This way clients are not required to have instantiated ByteBuffers
and can choose whatever memory scheme works best for them.

Also converted some of the Ext2FS code to use stack buffers instead.
2019-09-30 11:23:36 +02:00
Andreas Kling 1fc2612667 Kernel: Make DiskBackedFS::read_block() write to client-provided memory
Instead of having DiskBackedFS allocate a ByteBuffer, leave it to each
client to provide buffer space.

This is significantly faster in many cases where we can use a stack
buffer and avoid heap allocation entirely.
2019-09-30 11:04:30 +02:00
Andreas Kling a61f6ccc27 Kernel: Implement a simpler, bigger cache for DiskBackedFS
The hashmap cache was ridiculously slow and hurt us more than it helped
us. This patch replaces it with a flat memory cache that keeps up to
10'000 blocks in cache with a simple dirty bit.

The syncd task will wake up periodically and call flush_writes() on all
file systems, which now causes us to traverse the cache and write all
dirty blocks to disk.

There's a ton of room for improvement here, but this itself is already
drastically better when doing repeated GCC invocations.
2019-09-30 10:34:50 +02:00
Andreas Kling 8f45a259fc ByteBuffer: Remove pointer() in favor of data()
We had two ways to get the data inside a ByteBuffer. That was silly.
2019-09-30 08:57:01 +02:00
Sergey Bugaev 9a41dda029 Kernel: Expose blocking and cloexec fd flags in ProcFS 2019-09-28 22:27:45 +02:00
Sergey Bugaev 02ee8cbbe2 Applications: Add a new Help app
This is a neat simple app that can display the Serenity manual ^)
2019-09-28 18:29:42 +02:00
Sergey Bugaev 6ec625d6f3 Userland+LibHTML: Add the html command
This is a simple command that can be used to display HTML from a given
file, or from the standard input, in an HtmlView. It replaces the `tho`
(test HTML output) command.
2019-09-28 18:29:42 +02:00
Sergey Bugaev 2e80b2b32f Libraries: Add LibMarkdown 2019-09-28 18:29:42 +02:00
Sergey Bugaev 3652bec746 Kernel: Make proper use of the new keep_empty argument 2019-09-28 18:29:42 +02:00
Conrad Pankoff 07ca753124 Kernel: Fix BIOS date/time on hardware
It turns out some BIOS vendors don't support non-BCD date/time mode, but
we were relying on it being available. We no longer do this, but instead
check whether the BIOS claims to provide BCD or regular binary values for
its date/time data.
2019-09-28 13:59:49 +02:00
Conrad Pankoff 062218b4cf Kernel: Support writing doubly-indirect ext2 blocks 2019-09-28 09:29:10 +02:00
Conrad Pankoff fa20a447a9 Kernel: Repair unaligned regions supplied by the boot loader
We were just blindly trusting that the bootloader would only give us
page-aligned memory regions. This is apparently not always the case,
so now we can try to repair those regions.

Fixes #601
2019-09-28 09:23:52 +02:00
Andreas Kling 2584636d19 Kernel: Fix partial munmap() deallocating still-in-use VM
We were always returning the full VM range of the partially-unmapped
Region to the range allocator. This caused us to re-use those addresses
for subsequent VM allocations.

This patch also skips creating a new VMObject in partial munmap().
Instead we just make split regions that point into the same VMObject.

This fixes the mysterious GCC ICE on large C++ programs.
2019-09-27 20:21:52 +02:00
Andreas Kling d5f3972012 Kernel: No need to manually deallocate kernel stack Region in ~Thread()
Since we're keeping this Region in an OwnPtr, it will be torn down when
we get to ~OwnPtr anyway.
2019-09-27 19:10:52 +02:00
Andreas Kling c58455fb63 Kernel: Tweak SlabAllocator size classes
Shrink the 52 class down to 48 since it was mostly made for Region,
and Region just shrank to 48 :^)
2019-09-27 14:25:42 +02:00
Andreas Kling 7f9a33dba1 Kernel: Make Region single-owner instead of ref-counted
This simplifies the ownership model and makes Region easier to reason
about. Userspace Regions are now primarily kept by Process::m_regions.

Kernel Regions are kept in various OwnPtr<Regions>'s.

Regions now only ever get unmapped when they are destroyed.
2019-09-27 14:25:42 +02:00
Andreas Kling 7a7f6a24e9 Kernel: Fix bitrotted FORK_DEBUG logging code 2019-09-27 14:25:39 +02:00
Andreas Kling 2482fc3538 IPv4: Implement socket ioctls SIOCGIFADDR and SIOCSIFADDR
This allows userspace programs to get and set (superuser-only) the IPv4
address of a network adapter. :^)
2019-09-23 19:06:03 +02:00
Andreas Kling 65409e8f04 LocalSocket: Teach recvfrom() how to block if needed, and simplify it
If we can't already read when we enter recvfrom() on a LocalSocket,
we'll now block the current thread until we can.

Also added a buffer_for(FileDescription&) helper so that the client
and server can share some of the code. :^)
2019-09-22 21:30:30 +02:00
Andreas Kling bba24b09f7 Kernel: Avoid creating a temporary String("mmap") for every mmap() call 2019-09-22 19:47:00 +02:00
Andreas Kling e364846622 Ext2FS: Don't allocate blocks until we're committed to a new inode
Otherwise we would leak the blocks in case we returned earlier than
expected. :^)
2019-09-22 18:50:24 +02:00
Andreas Kling bd7c38e7b6 Ext2FS: Oops, fix wrong ENOSPC in create_inode() 2019-09-22 18:44:05 +02:00
Andreas Kling bff59eff4b Ext2FS: Fix two bugs in block allocation:
1) Off-by-one in block allocation when block size != 1 KB

Due to a quirk in the on-disk layout of ext2, file systems with a block
size of 1 KB have block #1 as their first block, while all others start
on block #0.

2) We had no fallback mechanism when the preferred group was full

We now allocate blocks from the preferred block group as long as it's
possible, and fall back to a simple scan through all groups when the
preferred one is full.
2019-09-22 18:37:17 +02:00
Andreas Kling 9c549c178a Kernel: Pad virtual address space allocations with guard pages
Put one unused page on each side of VM allocations to make invalid
accesses more likely to generate crashes.

Note that we will not add this guard padding for mmap() at a specific
memory address, only to "mmap it anywhere" requests.
2019-09-22 15:12:29 +02:00
Andreas Kling a50cfc5f1f Boot: Bump our requested resolution to 1280x1024
This makes bare metal boots a bit nicer on machines where that mode
is available to us.
2019-09-21 16:31:52 +02:00
Andreas Kling 4616a13e94 Build: Let's put the kernel in /boot/kernel for all builds 2019-09-21 15:25:08 +02:00
Andreas Kling 8cfb859368 IPv4: Support overriding the default TTL (64)
Made getsockopt() and setsockopt() virtual so we can handle them in the
various Socket subclasses. The subclasses map kinda nicely to "levels".

This will allow us to implement things like "traceroute", although..
I spent some time trying to do that, but then hit a wall when it turned
out that the user-mode networking in QEMU doesn't preserve TTL in the
ICMP packets passing through.
2019-09-19 21:42:59 +02:00
Sergey Bugaev e9dd94063f Kernel: Do not panic on fstat(fifo)
Instead, let's return an empty buffer with st_mode indicating it's a fifo.
2019-09-17 21:56:42 +02:00
Drew Stratford 6e51ebad8c Kernel: Stop hardcoding syscall in signal trampoline.
We now no longer hardcode the sigreturn syscall in
the signal trampoline. Because of the way inline asm inputs
work, I've had to enclose the trampoline in the function
signal_trampoline_dummy.
2019-09-17 16:00:37 +02:00
Conrad Pankoff 224fbb7910 Kernel: Fix returning pages to regions >= 2GB 2019-09-17 09:27:23 +02:00
Conrad Pankoff 9c5e3cd818 Kernel: Ignore memory the bootloader gives us above 2^32 2019-09-17 09:27:23 +02:00
Andreas Kling a34f3a3729 Kernel: Fix some bitrot in MemoryManager debug logging code 2019-09-16 14:45:44 +02:00
Andreas Kling 5d491fa1cd Kernel: Add a simple slab allocator for small allocations
This is a freelist allocator with static size classes that works as a
complement to the generic kmalloc(). It's a lot faster than kmalloc()
since allocation just means popping from the freelist.

It's also significantly more compact when there are a lot of objects
smaller than the minimum kmalloc chunk size (32 bytes.)

This patch enables it for the Region and PhysicalPage classes.
In the PhysicalPage (8 bytes) case, it's a huge improvement since we
no longer waste 75% of the storage allocated.

There are also a number of ways this can be improved, so let's keep
working on it going forward.
2019-09-16 10:33:27 +02:00
Andreas Kling 1c692e87a6 Kernel: Move kmalloc() into a Kernel/Heap/ directory 2019-09-16 09:01:44 +02:00
Conrad Pankoff 6fd096999e Applications: Add "Welcome" application, inspired by Windows 98 2019-09-16 07:49:43 +02:00
Andreas Kling e60bbadbbc Kernel: Add LogStream operator<< for PhysicalAddress 2019-09-15 20:47:49 +02:00
Andreas Kling a40afc4562 Kernel: Get rid of MemoryManager::allocate_page_table()
We can just use the physical page allocator directly, there's no need
for a dedicated function for page tables.
2019-09-15 20:34:03 +02:00
Andreas Kling 85d629103d Kernel: Implement shebang executables ("#!/bin/sh")
This patch makes it possible to *run* text files that start with the
characters "#!" followed by an interpreter.

I've tested this with both the Serenity built-in shell and the Bash
shell, and it works as expected. :^)
2019-09-15 11:47:21 +02:00
Andreas Kling e1481dcb42 Kernel: Stop idling after handling an IRQ
If we receive an IRQ while the idle task is running, prevent it from
re-halting the CPU after the IRQ handler returns.

Instead have the idle task yield to the scheduler, so we can see if
the IRQ has unblocked something.
2019-09-14 20:21:10 +02:00
Andreas Kling b35ad5b523 Kernel: Fix bad assertion in Lock::unlock_if_locked()
We shouldn't assert if you call this on a Lock held by another Thread
in the same Process. Instead, we should just not unlock.
2019-09-14 20:21:06 +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
Andreas Kling 2d1f3ec749 Kernel: fchdir() should fail for non-searchable directories
So sayeth POSIX.
2019-09-13 14:35:18 +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 b9be6b7bb4 Ext2FS: Trying to create a too-long directory entry should ENAMETOOLONG
Also added some assertions to DirectoryEntry in case someone tries to
instantiate them with names that would overflow the name buffer.

DirectoryEntry is a crappy data structure, and the name buffer is also
crappy. Added a FIXME about replacing it with something nicer.

Before this patch, the DirectoryEntry::name buffer would overflow if
you did "touch extremely-long-file-name". Duh.

Fixes #538.
2019-09-10 21:04:27 +02:00
Andreas Kling b07cf6843e Runner: Forward host TCP port 8823 to guest port 23 in QEMU
This makes it easier to test TelnetServer when running in QEMU.
2019-09-09 09:19:43 +02:00
Andreas Kling 54caeb1f1a RTL8139: Fix bogus (but harmless) TX buffer index in send_raw()
This was getting fixed up by the loop that chooses the next TX buffer
anyway, but let's do this correctly.

Fixes #522.
2019-09-09 08:51:08 +02:00
Drew Stratford b65bedd610 Kernel: Change m_blockers to m_blocker.
Because of the way signals now work there should
not be more than one blocker per thread. This
changes the blocker and thread class to reflect
that.
2019-09-09 08:35:43 +02:00
Drew Stratford e529042895 Kernel: Remove reduntant kernel/user signal stacks.
Due to the changes in signal handling m_kernel_stack_for_signal_handler_region
and m_signal_stack_user_region are no longer necessary, and so, have been
removed. I've also removed the similarly reduntant m_tss_to_resume_kernel.
2019-09-09 08:35:43 +02:00
Conrad Pankoff dfb538a413 Kernel: Write logs into dmesg from the start of the boot process 2019-09-09 08:14:00 +02:00
Andreas Kling e386579436 Kernel: Fix bitrotted code behind #ifdef SIGNAL_DEBUG 2019-09-08 14:29:59 +02:00
Andreas Kling 23eafdb8d6 Kernel: waitpid() should unblock and -ECHILD if SIG_IGN reaps child 2019-09-08 14:01:00 +02:00
Conrad Pankoff c983e96664 Kernel: Use timeval_sub for TCP retransmissions and lower timer to 500ms 2019-09-08 12:34:20 +02:00
Conrad Pankoff 3f1c3a341b Kernel: Handle listening socket disappearing during incoming handshake 2019-09-08 12:34:20 +02:00
Conrad Pankoff feb6d1afe0 Kernel: Use a WeakPtr instead of a RefPtr for TCP socket originator 2019-09-08 12:34:20 +02:00
Conrad Pankoff a2b61e30c5 Kernel: Put some network log messages behind debug flags 2019-09-08 12:34:20 +02:00
Conrad Pankoff 328d52b323 Kernel: Send ACK/FIN in response to FIN packets on active connections
This is to work around our lack of a shutdown() implementation.
2019-09-08 12:34:20 +02:00
Conrad Pankoff 117d8db2a2 Kernel: Implement outgoing TCP retransmission and better ACK handling
This approach is a bit naiive - whenever we send a packet out, we
check to see if there are any other packets we should try to send.
This works well enough for a busy connection but not very well for a
quiet one. Ideally we would check for not-acked packets on some kind
of timer, and use the length of this not-acked list as feedback to
throttle the writes coming from userspace.
2019-09-08 12:34:20 +02:00
Conrad Pankoff b8e3c7ef01 Kernel: Remember all ARP replies, even ones we didn't request
This allows us to take advantage of unsolicited ARP replies, such as
those that are emitted by many systems after their network interfaces
are enabled, or after their DHCP client sets their IP.

This also makes us a bit more vulnerable to ARP flooding, but we need
some kind of eviction strategy anyway, so we can deal with that later.
2019-09-08 12:34:20 +02:00
Conrad Pankoff b45cfae7f4 Kernel: Don't mark incoming sockets as connected in NetworkTask
An incoming socket should only be considered connected after a
program has received it from accept(). Before that point, it's only
"half" open, and it might not ever actually be served to a program.

Socket::accept is where m_connected is correctly set.
2019-09-08 12:34:20 +02:00
Conrad Pankoff 72f728b0d6 Kernel: Hold socket back from accept() until it's fully set up 2019-09-08 12:34:20 +02:00
Conrad Pankoff d53c9d4416 Kernel: Use RefPtr instead of SocketHandle for TCPSocket clients
Using a SocketHandle takes a lock on the socket, which we don't want
to do.
2019-09-08 12:34:20 +02:00
Conrad Pankoff cfcb53fe77 Kernel: Don't set sequence manually; send_tcp_packet will do it 2019-09-08 12:34:20 +02:00
Conrad Pankoff e8a10848b5 Kernel: Make sure IPv4Socket is marked as listening in listen() 2019-09-08 12:34:20 +02:00
Conrad Pankoff 706e04d340 Kernel: Don't increment ACK number without SYN, FIN, or data 2019-09-08 12:34:20 +02:00
Conrad Pankoff 749719b4d0 Kernel: Fix debug messages in IPv4Socket 2019-09-08 12:34:20 +02:00
Conrad Pankoff 040947ee47 TelnetServer: Implement basic telnet server
Fixes #407

Depends on #530 to run reliably.
2019-09-08 10:56:34 +02:00
Andreas Kling 33e6cb8b80 Kernel: Remove spammy logging about absolute_path() on non-custodies 2019-09-08 09:37:28 +02:00
Andreas Kling 899233a925 Kernel: Handle running programs that don't have a TLS image
Programs without a PT_TLS header won't have a master TLS image for us
to copy, so we shouldn't try to copy the m_master_tls_region then.
2019-09-07 17:06:25 +02:00
Jesse Buhagiar ecbc0322c1 Applications: Create a display properties manager
An interactive application to modify the current display settings, such as
the current wallpaper as well as the screen resolution. Currently we're
adding the resolutions ourselves, because there's currently no way to
detect was resolutions the current display adapter supports (or at least
I can't see one... Maybe VBE does and I'm stupid). It even comes with
a very nice template'd `ItemList` that can support a vector of any type,
which makes life much simpler.
2019-09-07 16:51:15 +02:00
Andreas Kling ec6bceaa08 Kernel: Support thread-local storage
This patch adds support for TLS according to the x86 System V ABI.
Each thread gets a thread-specific memory region, and the GS segment
register always points _to a pointer_ to the thread-specific memory.

In other words, to access thread-local variables, userspace programs
start by dereferencing the pointer at [gs:0].

The Process keeps a master copy of the TLS segment that new threads
should use, and when a new thread is created, they get a copy of it.
It's basically whatever the PT_TLS program header in the ELF says.
2019-09-07 15:55:36 +02:00
Andreas Kling 73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Drew Stratford 95fe775d81 Kernel: Add SysV stack alignment to signal trampoline
In both dispatch signal and asm_signal_trampoline we
now ensure that the stack is 16 byte aligned, as per
the System V ABI.
2019-09-05 16:37:09 +02:00
Drew Stratford 81d0f96f20 Kernel: Use user stack for signal handlers.
This commit drastically changes how signals are handled.

In the case that an unblocked thread is signaled it works much
in the same way as previously. However, when a blocking syscall
is interrupted, we set up the signal trampoline on the user
stack, complete the blocking syscall, return down the kernel
stack and then jump to the handler. This means that from the
kernel stack's perspective, we only ever get one system call deep.

The signal trampoline has also been changed in order to properly
store the return value from system calls. This is necessary due
to the new way we exit from signaled system calls.
2019-09-05 16:37:09 +02:00
Drew Stratford 259a1d56b0 Thread: added member m_kernel_stack_top.
This value stores the top of a threads kernel_stack.
2019-09-05 16:37:09 +02:00
Andreas Kling bf43d94a2f Kernel: Disable interrupts throughout ~Region()
We don't want an interrupt handler to access the VM data structures
while their internal consistency is broken.
2019-09-05 11:15:05 +02:00
Andreas Kling 1188a036e9 SoundPlayer: Start working on a GUI sound player application
This can play anything that AWavLoader can load (so obviously only WAV
files at the moment.)

It works by having a timer that wakes up every 100ms and tries to send
a sample buffer to the AudioServer. If our server-side queue is full
then we wait until the next timer iteration and try again.

We display the most recently enqueued sample buffer in a nice little
widget that just plots the samples in green-on-black. :^)
2019-09-04 20:18:41 +02:00
Andreas Kling e25ade7579 Kernel: Rename "vmo" to "vmobject" everywhere 2019-09-04 11:27:14 +02:00
Andreas Kling e5500e2a22 Kernel: Fix wrong I/O ports for the ATA alternate status registers
The alternate status register is not part of the same set of registers
as all the other stuff.

Also rename wait_400ns() to io_delay() since we had no guarantee that
it was waiting for 400ns..
2019-09-04 11:11:03 +02:00
Andreas Kling 8cbb38a237 Kernel: Remove unused gunk from PATADiskDevice 2019-09-04 11:06:10 +02:00
Andreas Kling 9ffe8feff4 Kernel: Only #include stuff from <LibC/...> if __serenity__ is defined 2019-09-03 21:14:42 +02:00
Conrad Pankoff a3468dc993 Kernel: Pad packets out to 64 bytes in rtl8139 driver 2019-09-03 15:24:48 +02:00
Conrad Pankoff c8fa95b8cd Kernel: Only set tx buffer address once in rtl8139 driver 2019-09-03 15:24:48 +02:00
Conrad Pankoff 7c9adcf24e Kernel: Reword some constants/comments in rtl8139 driver for clarity 2019-09-03 15:24:48 +02:00
Conrad Pankoff ff2997f018 Kernel: Use regular kmalloc for buffers in rtl8139 driver 2019-09-03 15:24:48 +02:00
Andreas Kling c82627aae2 Kernel: Don't allow non-superusers to bind TCP/UDP ports < 1024 2019-09-02 18:49:54 +02:00
Conrad Pankoff 41d113713d ProcFS: Expose ARP table 2019-09-02 09:42:27 +02:00
Andreas Kling 6fe0fa30f2 Kernel: Fix broken passing of String as printf() argument in realpath() 2019-08-29 21:01:33 +02:00
Andreas Kling d720388acf Kernel: Support partial munmap()
You can now munmap() a part of a region. The kernel will then create
one or two new regions around the "hole" and re-map them using the same
physical pages as before.

This goes towards fixing #175, but not all the way since we don't yet
do munmap() across multiple mappings.
2019-08-29 20:57:02 +02:00
Andreas Kling 0e53b1d1ad Kernel: Add some convenient getters to Region
Add getters for the underlying Range, the access bits, and also add
contains(Range) which just wraps m_range.contains().
2019-08-29 20:55:40 +02:00
Andreas Kling 10e0e13bf3 Kernel: Add LogStream operator<< for Range 2019-08-29 20:54:50 +02:00
Jesse Buhagiar 1112899a63 Kernel: Fixed FDC motor_enable()
Motor Enable now selects the correct drive. The ternary
operations were backwards. QEMU doesn't care (obviously) but
on a real PC, the drive doesn't actually ever get selected...
2019-08-29 10:18:39 +02:00
Conrad Pankoff b15a7c435f Kernel: Implement is_zero for RoutingDecision 2019-08-29 06:25:06 +02:00
Conrad Pankoff 302d521485 Kernel: Take a copy of MACAddress in RoutingDecision 2019-08-29 06:25:06 +02:00
Conrad Pankoff 498f8c01a2 Kernel: Use a public member for NetworkAdapter on_receive 2019-08-29 06:25:06 +02:00
Conrad Pankoff 6d1418aa7a Kernel: Add simple ARP routing layer
This replaces the previous placeholder routing layer with a real one!
It's still very primitive, doesn't deal with things like timeouts very
well, and will probably need several more iterations to support more
normal networking things.

I haven't confirmed that this works with anything other than the QEMU
user networking layer, but I suspect that's what nearly everybody is
using at this point, so that's the important target to keep working.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 626e176cab Kernel: Remove IP configuration from LoopbackAdapter
This is configured in NetworkTask_main now, so there's no need to do it
here as well.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 13abb3e88b Kernel: Remove now-unused singleton methods from our network devices 2019-08-29 06:25:06 +02:00
Conrad Pankoff 93c16590f1 Kernel: Remove specific devices from network code
By setting up the devices in init() and looping over the registered
network adapters in NetworkTask_main, we can remove the remaining
hard-coded adapter references from the network code.

This also assigns IPs according to the default range supplied by QEMU
in its slirp networking mode.
2019-08-29 06:25:06 +02:00
Conrad Pankoff 41e9ad5ea0 Kernel: Add const to packet data in send_raw call 2019-08-29 06:25:06 +02:00
Conrad Pankoff 36d349f7a7 Kernel: Add on_receive callback to NetworkAdapter 2019-08-29 06:25:06 +02:00
Conrad Pankoff 682fe48222 Kernel: Show netmask/gateway in ProcFS when available 2019-08-29 06:25:06 +02:00
Conrad Pankoff 1aa7437ad7 Kernel: Add netmask and gateway to NetworkAdapter 2019-08-29 06:25:06 +02:00
Conrad Pankoff 61bdf09d78 Kernel: Run NetworkTask in init stage 2 to allow use of locks 2019-08-29 06:25:06 +02:00
Conrad Pankoff bed069bd14 Kernel: Ask for all relevant IRQs in rtl8139 driver 2019-08-29 06:25:06 +02:00
Conrad Pankoff 5f86a979ea Kernel: Ignore IPv6 packets; log unknown Ethernet payload types 2019-08-29 06:25:06 +02:00
Conrad Pankoff 4a4e66b2d0 Kernel/AK: Add is_zero helpers for IP and MAC addresses 2019-08-29 06:25:06 +02:00
Conrad Pankoff fac1148679 Kernel: Always format MACAddress with two-byte hex digits in to_string 2019-08-29 06:25:06 +02:00
Conrad Pankoff eb01735ec5 Kernel: Add list-compatible constructor for MACAddress 2019-08-29 06:25:06 +02:00
Sergey Bugaev 8ea25ca3b0 ProcFS: Port JSON generation to streaming serializers
This way we don't allocate giant JSON objects on the kernel heap first.
Hopefully fixes https://github.com/SerenityOS/serenity/issues/484
2019-08-27 14:56:09 +02:00
Andreas Kling dde10f534f Revert "Kernel: Avoid a memcpy() of the whole block when paging in from inode"
This reverts commit 11896d0e26.

This caused a race where other processes using the same InodeVMObject
could end up accessing the newly-mapped physical page before we've
actually filled it with bytes from disk.

It would be nice to avoid these copies without breaking anything.
2019-08-26 13:50:55 +02:00
Andreas Kling f5d779f47e Kernel: Never forcibly page in entire executables
We were doing this for the initial kernel-spawned userspace process(es)
to work around instability in the page fault handler. Now that the page
fault handler is more robust, we can stop worrying about this.

Specifically, the page fault handler was previous not able to handle
getting a page fault in anything but the currently executing task's
page directory.
2019-08-26 13:20:01 +02:00
Andreas Kling e29fd3cd20 Kernel: Display virtual addresses as V%p instead of L%x
The L was a leftover from when these were called linear addresses.
2019-08-26 11:31:58 +02:00
Sergey Bugaev e1a6f8a27d LibThread: Introduce a new threading library
This library is meant to provide C++-style wrappers over lower
level APIs such as syscalls and pthread_* functions, as well as
utilities for easily running pieces of logic on different
threads.
2019-08-26 11:31:14 +02:00
Rok Povsic eb9ccf1c0a FileSystem: Add FIXME about resolve_path bug 2019-08-25 19:47:37 +02:00
Rok Povsic 18fbe4ac83 Kernel: Add realpath syscall 2019-08-25 19:47:37 +02:00
Andreas Kling 11896d0e26 Kernel: Avoid a memcpy() of the whole block when paging in from inode 2019-08-25 14:34:53 +02:00
Andreas Kling ac7a559d96 Ext2FS: Avoid a String allocation in lookup()
By using find() with a custom finder, we can avoid creating a temporary
key value that's only used for the hash lookup.
2019-08-25 06:45:37 +02:00
Andreas Kling b020a5e7ce Kernel: Don't create a String every time we look up a Custody by name 2019-08-25 06:45:14 +02:00
Andreas Kling 952baf32cd TmpFS: Notify any associated InodeVMObject on inode changes 2019-08-24 19:59:01 +02:00
Andreas Kling 5978993f00 TmpFS: Fix two bugs that broke GCC inside Serenity
- TmpFSInode::write_bytes() needs to allow non-zero offsets
- TmpFSInode::read_bytes() wasn't respecting the offset

GCC puts the temporary files generated during compilation in /tmp,
so this exposed some bugs in TmpFS.
2019-08-24 19:58:09 +02:00
Andreas Kling b018cd653f Kernel: Fix oversized InodeVMObject after inode size changes 2019-08-24 19:35:47 +02:00
Andreas Kling 9bd68b189e KBuffer: capacity() should return internal capacity, not internal size
KBuffer is just meant to be a dumb wrapper around KBufferImpl.
With this change, we actually start to see KBuffers with different size
and capacity, which allows some reallocation-avoiding optimizations.
2019-08-24 18:33:22 +02:00
Andreas Kling 5768b384b9 Kernel: Give each TTY 1 KB of input buffer
This papers over an immediate issue where pseudoterminals would choke
on more than 16 characters of pasted input in the GUI terminal.

Longer-term we should find a more elegant solution than using a static
size CircularQueue for this.
2019-08-23 18:55:33 +02:00
Andreas Kling 32810a920f Kernel: Implement kill(0, signal)
This sends the signal to everyone in the same process group as the
calling process.
2019-08-23 18:28:59 +02:00
Andreas Kling 06de0e670c Kernel: Use IteratorDecision in Process::for_each_in_pgrp() 2019-08-23 18:28:59 +02:00
Andreas Kling 933a98f8fa Kernel: Make Lock::lock() assert early that we're not in the scheduler
The scheduler is not allowed to take locks, so if that's happening,
we want to make that clear instead of crashing with the more general
"Interrupts disabled while trying to take Lock" error.
2019-08-22 09:22:30 +02:00
Conrad Pankoff 0b3308f995 Kernel: Remove over-eager const from rtl8139 driver link_up function 2019-08-21 17:16:03 +02:00
Conrad Pankoff 4afe9e4f2a Kernel: Implement rtl8139 network interface driver 2019-08-21 17:10:34 +02:00
Conrad Pankoff 286bafbb19 Kernel: Implement link status in /proc/net/adapters 2019-08-21 17:10:34 +02:00
Andreas Kling 5de483cfbb Kernel: Move DiskDevice::block_size() up to BlockDevice
All block devices should have a block size, after all. This defaults to
PAGE_SIZE if no size is specified.
2019-08-21 16:48:59 +02:00
Andreas Kling 179158bc97 Kernel: Put debug spam about already-paged-in inode pages behind #ifdef 2019-08-19 17:30:36 +02:00
Sergey Bugaev 0f8b45c015 ProcFS: Expose info about devices in /proc/devices 2019-08-18 15:59:59 +02:00
Sergey Bugaev acccf9ccda Kernel: Move device lookup to Device class itself
Previously, VFS stored a list of all devices, and devices had to
register and unregister themselves with it. This cleans up things
a bit.
2019-08-18 15:59:59 +02:00
Andreas Kling 05cd178477 Inspector: Add a GUI tool for viewing a remote process's CObject graph
Here comes the foundation for a neat remote debugging tool.

Right now, it connects to a remote process's CEventLoop RPC socket and
retreives the remote object graph JSON dump. The remote object graph
is then reconstructed and exposed through a GModel subclass, which is
then displayed in a GTreeView.

It's pretty cool, I think. :^)
2019-08-18 10:19:13 +02:00
Conrad Pankoff b957c61e6f Kernel: Implement generic VGA device using multiboot info
This implements a very basic VGA device using the information provided
to us by the bootloader in the multiboot header. This allows Serenity to
boot to the desktop on basically any halfway modern system.
2019-08-18 07:40:53 +02:00
Conrad Pankoff 3932dfbb04 Kernel: Implement generic framebuffer ioctls in BXVGA
This also hides some functions that were previously public, since that
same functionality is now exposed via ioctl functions.
2019-08-18 07:40:02 +02:00
Conrad Pankoff 5e46122a82 Kernel: Add framebuffer ioctls; wrap raw ioctls with a C API 2019-08-18 07:40:02 +02:00
Conrad Pankoff 1868523e00 LibC: Move duplicated winsize struct definition into ioctl_numbers.h 2019-08-18 07:40:02 +02:00
Conrad Pankoff 879bc28e14 Kernel: Disable VGA console in graphical mode 2019-08-18 07:37:12 +02:00
Andreas Kling 272bd1d3ef Kernel: Make crash dumps look aligned once again
This broke with the recent changes to make printf hex fields behave
a bit more correctly.
2019-08-17 21:29:46 +02:00
Jesse ad909e7c3f FloppyDiskDevice: Fixed hang on wait_for_irq() (#458)
It turns out that the `SenseInterrupt` command is actually
very important! The system hangs if it's not there! Whoops...!
2019-08-17 16:26:53 +02:00
Andreas Kling 5f6b6c1665 Kernel: Do the umount() by the guest's root inode identifier
It was previously possible to unmount a filesystem mounted on /mnt by
doing e.g "umount /mnt/some/path".
2019-08-17 14:28:13 +02:00
Andreas Kling da7ae52eee Ext2FS: Clean up prepare_to_unmount() a little bit 2019-08-17 13:49:37 +02:00
Sergey Bugaev 6778abb999 Kernel+SystemServer: Mount filesystems and start TTYServer in userspace 2019-08-17 12:07:55 +02:00
Sergey Bugaev fde8f7f538 Kernel: Expose info about source devices of mounts in /proc/df 2019-08-17 12:07:55 +02:00
Sergey Bugaev 425c356288 Kernel+LibC+Userland: Support mounting other kinds of filesystems 2019-08-17 12:07:55 +02:00
Sergey Bugaev 66a0a12435 DevPtsFS: Do not assume there is one of it
Unfortunately, that also means it can no longer inherit from SynthFS.
2019-08-17 12:07:55 +02:00
Sergey Bugaev 37cc80fb96 ProcFS: Do not assume there is one of it
The complication is around /proc/sys/ variables, which were attached
to inodes. Now they're their own thing, and the corresponding inodes
are lazily created (as all other ProcFS inodes are) and simply refer
to them by index.
2019-08-17 12:07:55 +02:00
Andreas Kling e3f3c980bf IntrusiveList: Make Iterator::operator* return a T&
This makes iteration a little more pleasant :^)
2019-08-17 11:25:32 +02:00
Andreas Kling 910fab564e LocalSocket: Make recvfrom() return 0 to signal EOF when peer is gone
Once the peer has disconnected, recvfrom() should always return 0 once
the socket buffer has been drained.
2019-08-17 11:04:45 +02:00
Andreas Kling 17670ae725 Meta: Fix up clean builds
This is kind of a mess, but because IPC client code depending on the
IPC protocol definition artifacts in the server code, we have to build
the IPC servers first. And their dependencies before that, etc.

One more drop in the "maybe we should switch to CMake" bucket..
2019-08-17 10:05:16 +02:00
Conrad Pankoff d0117744ab Meta: Rearrange makeall.sh for more consistent builds
makeall.sh used to build the AK tests and leave some binary objects laying
around that would get in the way of further incremental builds. There also
wasn't a lot of structure to the order things were built in. This patch
improves both of those things.
2019-08-17 09:31:35 +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
Sergey Bugaev b4c607a8da Kernel: Add TmpFS
This is an FS that stores all of its contents directly in memory.
It's mounted on /tmp by default.
2019-08-15 19:20:51 +02:00