Commit graph

4944 commits

Author SHA1 Message Date
Andreas Kling
1b2ef8582c Kernel: Make File's can_read/can_write take a const FileDescription&
Asking a File if we could possibly read or write it will never mutate
the asking FileDescription&, so it should be const.
2019-11-04 14:03:14 +01:00
Andreas Kling
e8fee92357 Kernel: Don't update fd offset on read/write error
If something goes wrong with a read or write operation, we don't want
to add the error number to the fd's offset. :^)
2019-11-04 13:58:28 +01:00
Andreas Kling
ecd23ce1a1 IPv4: Non-blocking IPv4 sockets should return -EAGAIN in recvfrom()
...if there are no packets in the receive queue.
2019-11-04 13:42:25 +01:00
Andreas Kling
43a6c70c2a LibCore: Make CTCPServer's local address/port getters return Optionals 2019-11-04 13:07:41 +01:00
Andreas Kling
e4c80961d9 run: Only enable KVM if /dev/kvm is r/w for the current user 2019-11-04 13:04:02 +01:00
Andreas Kling
50d937152a LibCore: Constify CTCPServer's local_address() and local_port() 2019-11-04 12:49:48 +01:00
Conrad Pankoff
fbe8569412 LibCore: Add local_{address,port} functions to CTCPServer 2019-11-04 12:49:15 +01:00
Mauri de Souza Nunes
b61414fb96 Userland: Add syscall program
The Plan9 OS has this  program that can test a system call with the
given arguments. For the most basic system calls it can be very
helpful and aid with testing or just to play with a given syscall
without writing a dedicated program.

Some examples:
    syscall write 1 hello 5
    syscall -o read 0 buf 5
    syscall mkdir /tmp/my-dir
    syscall exit 2
    ...
2019-11-04 12:47:54 +01:00
balatt
d5b66a02c4 Userland: Add the utility "nl" (number line) (#693)
I wrote a version of nl for Serenity with a lot but not all of the 
options in POSIX nl. It includes line count type (-b), increment (-i),
delimiter (-s), start number (-v), and width (-w).
2019-11-04 12:44:32 +01:00
balatt
0d471266ce wc: Rewritten with added features (#690)
Now gets a true byte count by using the file size.

* When giving a single-line string without a trailing newline, the line
  count should not go up ('printf "test" | wc -l' should output '0')

* Doesn't hang up when using two or more switch options in a row.
  (It would hang if I did 'wc -lw test.frm').

  While mine works with multiple args like that, they don't switch
  anything, you have to do wc -l -w etc but I think that is an issue
  with CArgsParser.

* It can now take standard input without needing a "-".

* When encountering a file that doesn't exist, it doesn't exit.

  It prints the counts for each file that does, and prints an error to
  stderr for each file that doesn't. 

* Has slight buffering between counts to be closer to GNU and BSD wc.
2019-11-04 12:42:30 +01:00
Andreas Kling
f5c2ae1192 GTextEditor: Move the cursor to column 0 after deleting a whole line 2019-11-04 12:36:10 +01:00
Jesse Buhagiar
70fb92fa0e LibC: Implemented atof()
`atof()` has now been implemented as part of the standard C library.
It supports scientific notation such as `1.2e-3` etc, ala the version
found as part of `glibc`.

It's a bit chunky, so there's probably room for optimisations here
and there, however, for now it works as intended (and allows Quake
to run).
2019-11-04 12:34:46 +01:00
Andreas Kling
c538648465 Ext2FS: Uncache unused Inodes after flushing contents to disk
Don't keep Inodes around in memory forever after we've interacted with
them once. This is a slight performance pessimization when accessing
the same file repeatedly, but closing it for a while in between.

Longer term we should find a way to keep a limited number of unused
Inodes cached, whichever ones we think are likely to be used again.
2019-11-04 12:23:19 +01:00
Andreas Kling
19398cd7d5 Kernel: Reorganize memory layout a bit
Move the kernel image to the 1 MB physical mark. This prevents it from
colliding with stuff like the VGA memory. This was causing us to end
up with the BIOS screen contents sneaking into kernel memory sometimes.

This patch also bumps the kmalloc heap size from 1 MB to 3 MB. It's not
the perfect permanent solution (obviously) but it should get the OOM
monkey off our backs for a while.
2019-11-04 12:04:35 +01:00
Andreas Kling
ea4e02ed86 LibCore: Flush outgoing IPC messages before trying to send a new one
This ensures that messages are sent in order.
2019-11-04 10:52:01 +01:00
Drew Stratford
5efbb4ae95 Kernel: Fix bug in Thread::dispatch_signal().
dispatch_signal() expected a RegisterDump on the kernel stack. However
in certain cases, like just after a clone, this was not the case and
dispatch_signal() would instead write to an incorrect user stack pointer.

We now use the threads TSS in situations where the RegisterDump may not
be valid, fixing the issue.
2019-11-04 10:12:59 +01:00
Drew Stratford
44f22c99ef Thread.cpp: add method get_RegisterDump_from_stack().
This refactors some the RegisterDump code from dispatch_signal
into a stand-alone function, allowing for better reuse.
2019-11-04 10:12:59 +01:00
Andreas Kling
a6e9119537 Kernel: Tweak some outdated kprintfs in Region 2019-11-04 00:48:45 +01:00
Andreas Kling
d67c6a92db Kernel: Move page fault handling from MemoryManager to Region
After the page fault handler has found the region in which the fault
occurred, do the rest of the work in the region itself.

This patch also makes all fault types consistently crash the process
if a new page is needed but we're all out of pages.
2019-11-04 00:47:03 +01:00
Andreas Kling
0e8f1d7cb6 Kernel: Don't expose a region's page directory to the outside world
Now that region manages its own mapping/unmapping, there's no need for
the outside world to be able to grab at its page directory.
2019-11-04 00:26:00 +01:00
Andreas Kling
6ed9cc4717 Kernel: Remove Region API's for setting/unsetting the page directory
This is done implicitly by mapping or unmapping the region.
2019-11-04 00:24:20 +01:00
Andreas Kling
e3dda4e87b Kernel: Fix weird Region constructor that took nullable RefPtr<Inode>
It's never valid to construct a Region with a null Inode pointer using
this constructor, so just take a NonnullRefPtr<Inode> instead.
2019-11-04 00:21:08 +01:00
Andreas Kling
9b2dc36229 Kernel: Merge MemoryManager::map_region_at_address() into Region::map() 2019-11-04 00:05:57 +01:00
Andreas Kling
98b328754e Kernel: Fix bad setup of CoW faults for offset regions
Regions with an offset into their VMObject were incorrectly adding the
page offset when indexing into the CoW bitmap.
2019-11-03 23:54:35 +01:00
Andreas Kling
5b7f8634e3 Kernel: Set the G (global) bit for kernel page tables
Since the kernel page tables are shared between all processes, there's
no need to (implicitly) flush the TLB for them on every context switch.

Setting the G bit on kernel page tables allows the CPU to keep the
translation caches around.
2019-11-03 23:51:55 +01:00
Andreas Kling
4bf1a72d21 Kernel: Teach Region how to remap itself
Now remapping (i.e flushing kernel metadata to the CPU page tables)
is done by simply calling Region::remap().
2019-11-03 21:11:08 +01:00
Andreas Kling
3dce0f23f4 Kernel: Regions should be mapped into a PageDirectory, not a Process
This patch changes the parameter to Region::map() to be a PageDirectory
since that matches how we think about the memory model:

Regions are views onto VMObjects, and are mapped into PageDirectories.
Each Process has a PageDirectory. The kernel also has a PageDirectory.
2019-11-03 21:11:08 +01:00
Andreas Kling
2cfc43c982 Kernel: Move region map/unmap operations into the Region class
The more Region can take care of itself, the better.
2019-11-03 21:11:08 +01:00
Alexander
9e03f3ce20 ProcFS: Identify virtual filesystems' device in df (#728) 2019-11-03 20:58:10 +01:00
rhin123
9e608885d1 TextEditor: Added undo functionality
Created a stack where a vector of undo actions are stored.
2019-11-03 20:21:14 +01:00
Andreas Kling
a221cddeec Kernel: Clean up a bunch of wrong-looking Region/VMObject code
Since a Region is merely a "window" onto a VMObject, it can both begin
and end at a distance from the VMObject's boundaries.
Therefore, we should always be computing indices into a VMObject's
physical page array by adding the Region's "first_page_index()".

There was a whole bunch of code that forgot to do that. This fixes
many wrong behaviors for Regions that start part-way into a VMObject.
2019-11-03 15:44:13 +01:00
Andreas Kling
fe455c5ac4 Kernel: Move page remapping into Region::remap_page(index)
Let Region deal with this, instead of everyone calling MemoryManager.
2019-11-03 15:32:11 +01:00
Andreas Kling
dc35b1d647 Kernel: Remove nonsense in bootstrap code
This code was not doing anything important. Since we're building the
kernel with -mregparm=3, the first function argument goes in %eax.
2019-11-03 14:40:28 +01:00
Andreas Kling
7e56cf1800 Ext2FS: Lock the filesystem during initialization and during sync
If we get preempted during initialization, we really don't want to try
doing a sync on a partially-initialized filesystem.
2019-11-03 13:56:55 +01:00
Nicolas Van Bossuyt
81c4dcadf1 Kernel: Prevent kprintf() from asserting in Console::the() (#718)
This triggered a stack overflow because ubsan can call kprintf() at any
time, even before Console is initialized.
2019-11-03 13:17:55 +01:00
Andreas Kling
8216019b2e Build: Fix more bugs in the POSIX sh-ification of scripts 2019-11-03 13:11:43 +01:00
Andreas Kling
53cfed7c8b LibCore: Put a limit on how many unsent messages an IPC server queues
This patch adds a limit of 200 unsent messages per client. If a client
does not handle its incoming messages and we manage to queue up 200
messages for it, we'll now disconnect that client. :^)
2019-11-03 12:40:57 +01:00
Andreas Kling
31c1b8ec3e LibCore: Have IPC server connections queue up unsendable messages
If an IPC client is giving us EAGAIN when trying to send him a message,
we now queue up the messages inside the CoreIPCServer::Connection and
will retry flushing them on next post/receive.

This prevents WindowServer from freezing up when one of its clients is
not taking care of its incoming messages.
2019-11-03 12:36:35 +01:00
Andreas Kling
8c45891c80 AK: Allow overriding the Queue segment size with a template parameter 2019-11-03 12:33:51 +01:00
Andreas Kling
78a744da77 AK: Add Queue::head()
This returns a const T& for the first element in the queue, without
dequeuing it.
2019-11-03 12:09:19 +01:00
Andreas Kling
c1d3ac7108 Ext2FS: Fix unpopulated block list cache after mkdir()
When creating a new directory, we set the initial size to 1 block.
This meant that we were allocating a block up front, but the Inode's
internal block list cache was not populated with this block.

This broke write_bytes() on a new directory, since it assumed that
the block list cache would be up to date if the call to write_bytes()
would not change the directory's size.

This patch fixes the issue in two ways: First, we cache the initial
block list created for new directories.
Second, we now repopulate the block list cache in write_bytes() if it
is empty when we get there. This is basically just a safety fallback
to avoid having this kind of bug in the future.
2019-11-03 10:22:09 +01:00
Andreas Kling
3d239be7b4 Ports: Undo POSIX sh compliance changes for now
Partial revert of 704f48d7f3.
These changes made the ports system unusable.
2019-11-03 10:05:02 +01:00
Andreas Kling
4565b2d2d9 LibM: Add back ampsin() since it was still used by tan() 2019-11-03 09:59:44 +01:00
Andreas Kling
1282b778e7 LibGUI: Move GTextPosition and GTextRange LogStream<< to their headers 2019-11-03 09:57:14 +01:00
Jesse
bcf3a4457f LibM: Fixed sin() precision (#726)
The old implementation of sin() had a very unacceptable amount of
error that was causing a lot of texture perspective issues in Quake.
This has been remedied through the use of the hardware `fsin`
x87 instruction. As has been noted in #246, this instruction is both
very slow, and can become wildly inaccurate for more precise values,
however the current implementation made an incorrect assumption about
applications "will end up writing their own implemtnation anyways",
which is not the case for Quake in Software mode, which relies heavily
on a correct `sin()` and `cos()` function for `R_ScanEdges()`.

Realistically, we should be using something like the CORDIC algorithm
(https://en.wikipedia.org/wiki/CORDIC) or `Taylor Expansion`, however
for now these provides a somewhat accurate result that allows Quake to
run without any texture or geometry issues.
2019-11-03 09:56:39 +01:00
George Pickering
704f48d7f3 POSIX compliance: (most) shell scripts converted to generic shell
Ports/.port_include.sh, Toolchain/BuildIt.sh, Toolchain/UseIt.sh
have been left largely untouched due to use of Bash-exclusive
functions and variables such as $BASH_SOURCE, pushd and popd.
2019-11-03 09:26:22 +01:00
Stephen Gregoratto
2cc5f3a93f Ports: update make to 4.2.1, disable Guile
Some systems (e.g. Arch Linux) build their gmake with Guile support and
thus have it installed. This patch disables Guile autodetection in the
configure script. It also updates the version of gmake to 4.2.1.

Fixes #645.
2019-11-03 09:23:24 +01:00
Andreas Kling
dcf8d359f3 Kernel: Fick infinite recursion when filling up disk cache
We can't be calling the virtual FS::flush_writes() in order to flush
the disk cache from within the disk cache, since an FS subclass may
try to do cache stuff in its flush_writes() implementation.

Instead, separate out the implementation of DiskBackedFS's flushing
logic into a flush_writes_impl() and call that from the cache code.
2019-11-03 00:21:17 +01:00
Andreas Kling
1e36d899f1 Ext2FS: Use KBuffers for the cached bitmap blocks
Also cache the block group descriptor table in a KBuffer on file system
initialization, instead of on first access.

This reduces pressure on the kmalloc heap somewhat.
2019-11-03 00:10:24 +01:00
Andreas Kling
ddd8332015 cat: Use a 32 KB I/O buffer here to improve "cat a > b" scenario
This is roughly twice as fast as the old 4 KB buffer size. We still
don't go nearly as fast as "cp", since we don't ftruncate() up front
like "cp" does.
2019-11-03 00:09:17 +01:00