Commit Graph

454 Commits

Author SHA1 Message Date
Jami Kettunen
0b3f1e70ca Keymap: Clean up source a bit 2019-12-30 14:02:00 +01:00
Andreas Kling
1f31156173 Kernel: Add a mode flag to sys$purge and allow purging clean inodes 2019-12-29 13:16:53 +01:00
joshua stein
d622e4d224 Build: build Userland binaries separately
Touching one source file shouldn't require relinking all binaries,
consider each one separate.  Also fix building library dependencies.
2019-12-28 21:09:33 +01:00
Andreas Kling
2cbc3c6ee5 LibC+ping: Let's use the traditional timersub() et al prototypes
This also fixes the build, since ping.cpp already had a timersub().
2019-12-27 23:07:28 +01:00
Andreas Kling
d1c16944ce gron: Implement a simplified variant of @tomnomnom's "gron"
This program takes JSON input and turns it into JavaScript statements
that construct the same data step by step. This format is much more
greppable than what "jp" gives us. :^)
2019-12-27 03:27:37 +01:00
Andreas Kling
23591f2a95 munch: Add a simple userland program for chewing up lots of memory 2019-12-26 11:48:34 +01:00
Andreas Kling
33efeaf71a crash: Add "-X" option for attempting to execute non-executable memory 2019-12-25 13:35:57 +01:00
joshua stein
c127d16326 Build: support library and generator dependencies
Instead of directly manipulating LDFLAGS, set LIB_DEPS in each
subdirectory Makefile listing the libraries needed for
building/linking such as "LIB_DEPS = Core GUI Draw IPC Core".

This adds each library as an -L and -l argument in LDFLAGS, but
also adds the library.a file as a link dependency on the current
$(PROGRAM).  This causes the given library to be (re)built before
linking the current $(PROGRAM), but will also re-link any binaries
depending on that library when it is modified, when running make
from the root directory.

Also turn generator tools like IPCCompiler into dependencies on the
files they generate, so they are built on-demand when a particular
directory needs them.

This all allows the root Makefile to just list directories and not
care about the order, as all of the dependency tracking will figure
it out.
2019-12-25 10:11:09 +01:00
Mauri de Souza Nunes
cb4e51a7a5 Userland: Add syscall -l option and man page 2019-12-24 20:23:37 +01:00
Andrés Vieira
5f9c408a08 Userland: Add support for printing multiple columns to the cal command
Now cal is able to print the entire year when only that is passed
as an argument. For example: `cal 1992`.

However this meant breaking the highlighted day escape sequence
as it messed up the layout and the character count for each of the
rows :(

Now the current day is specified like 17* (for example for day 17).
2019-12-24 11:48:16 +01:00
joshua stein
ac25438d54 Build: clean up build system, use one shared Makefile
Allow everything to be built from the top level directory with just
'make', cleaned with 'make clean', and installed with 'make
install'.  Also support these in any particular subdirectory.

Specifying 'make VERBOSE=1' will print each ld/g++/etc. command as
it runs.

Kernel and early host tools (IPCCompiler, etc.) are built as
object.host.o so that they don't conflict with other things built
with the cross-compiler.
2019-12-20 20:20:54 +01:00
Andreas Kling
b32e961a84 Kernel: Implement a simple process time profiler
The kernel now supports basic profiling of all the threads in a process
by calling profiling_enable(pid_t). You finish the profiling by calling
profiling_disable(pid_t).

This all works by recording thread stacks when the timer interrupt
fires and the current thread is in a process being profiled.
Note that symbolication is deferred until profiling_disable() to avoid
adding more noise than necessary to the profile.

A simple "/bin/profile" command is included here that can be used to
start/stop profiling like so:

    $ profile 10 on
    ... wait ...
    $ profile 10 off

After a profile has been recorded, it can be fetched in /proc/profile

There are various limits (or "bugs") on this mechanism at the moment:

- Only one process can be profiled at a time.
- We allocate 8MB for the samples, if you use more space, things will
  not work, and probably break a bit.
- Things will probably fall apart if the profiled process dies during
  profiling, or while extracing /proc/profile
2019-12-11 20:36:56 +01:00
Andreas Kling
fd5eb79d19 LibGUI: Make GMenu inherit from CObject
This is primarily to make it possible to pass a GMenu* where a CObject*
is expected.
2019-12-09 21:05:44 +01:00
Andreas Kling
dfc5eb2b6d purge: Add a small command-line utility for purging all volatile memory 2019-12-09 19:16:45 +01:00
Andreas Kling
6f4c380d95 AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
2019-12-09 17:51:21 +01:00
Andreas Kling
f41ae755ec Kernel: Crash on memory access in non-readable regions
This patch makes it possible to make memory regions non-readable.
This is enforced using the "present" bit in the page tables.
A process that hits an not-present page fault in a non-readable
region will be crashed.
2019-12-02 19:18:52 +01:00
Andrés Vieira
f8a0eb616c Userland: Add the cal command (#838)
This is a very simple implementation of the cal command to display
a calendar into the command line.

For now this only prints the current month highlighting the current
day.
2019-12-02 15:22:55 +01:00
Andreas Kling
e2b88f66d3 modunload: Take the module-to-unload as a command-line argument 2019-11-29 21:35:10 +01:00
Andreas Kling
f60c40ab2e jp: Print double-quotes around string values in output 2019-11-29 21:35:01 +01:00
Andreas Kling
86c61218a7 modload: Take the module-to-load as a command-line argument
Instead of hard-coding /mod/TestModule.o :^)
2019-11-29 21:19:23 +01:00
Andreas Kling
e56daf547c Kernel: Disallow syscalls from writeable memory
Processes will now crash with SIGSEGV if they attempt making a syscall
from PROT_WRITE memory.

This neat idea comes from OpenBSD. :^)
2019-11-29 16:30:05 +01:00
Andreas Kling
a43b115a6c Kernel: Implement basic module unloading :^)
Kernel modules can now be unloaded via a syscall. They get a chance to
run some code of course. Before deallocating them, we call their
"module_fini" symbol.
2019-11-28 21:07:22 +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
Andreas Kling
75ed262fe5 Kernel+ifconfig: Add an MTU value to NetworkAdapter
This defaults to 1500 for all adapters, but LoopbackAdapter increases
it to 65536 on construction.

If an IPv4 packet is larger than the MTU, we'll need to break it into
smaller fragments before transmitting it. This part is a FIXME. :^)
2019-11-28 14:14:26 +01:00
Andreas Kling
5b8cf2ee23 Kernel: Make syscall counters and page fault counters per-thread
Now that we show individual threads in SystemMonitor and "top",
it's also very nice to have individual counters for the threads. :^)
2019-11-26 21:37:38 +01:00
Andreas Kling
712ae73581 Kernel: Expose per-thread information in /proc/all
Previously it was not possible to see what each thread in a process was
up to, or how much CPU it was consuming. This patch fixes that.

SystemMonitor and "top" now show threads instead of just processes.
"ps" is gonna need some more fixing, but it at least builds for now.

Fixes #66.
2019-11-26 21:37:30 +01:00
Andreas Kling
9a6d506ac8 ps: Show "/dev/pts/0" as "pts/0" instead of "0"
Also tweak the alignment of the output a bit.
2019-11-26 15:01:46 +01:00
Hüseyin ASLITÜRK
28ada30783 Userland: Add keymap program. 2019-11-25 11:53:02 +01:00
Andreas Kling
653e61d9cf LibProtocol: Add a Download object so users don't have to manage ID's
LibProtocol::Client::start_download() now gives you a Download object
with convenient hooks (on_finish & on_progress).

Also, the IPC handshake is snuck into the Client constructor, so you
don't need to perform it after instantiating a Client.

This makes using LibProtocol much more pleasant. :^)
2019-11-24 13:22:01 +01:00
Andreas Kling
600c15aa3a pro: Take the URL to download as a command-line argument
Also, don't print anything other than the download payload to stdout.
This gives us a very simple HTTP download utility :^)
2019-11-23 22:16:23 +01:00
Andreas Kling
eb85103271 ProtocolServer: Send the download payload to clients as a shared buffer
The DownloadFinished message from the server now includes a buffer ID
that can be mapped into the client program.

To avoid prematurely destroying the buffer, the server will hang on to
it until the client lets it know that they're all good. That's what the
ProtocolServer::DisownSharedBuffer message is about.

In the future it would be nice if the kernel had a mechanism to allow
passing ownership of a shared buffer along with an IPC message somehow.
2019-11-23 22:11:44 +01:00
Andreas Kling
88c5126fa7 pro: Add a little userland utility for testing ProtocolServer 2019-11-23 21:50:36 +01:00
Andreas Kling
107011f119 AudioServer: Allow muting the system audio
This patch adds muting to ASMixer, which works by substituting what we
would normally send to the sound card with zero-filled memory instead.
We do it this way to ensure that the queued sample buffers keep getting
played (silently.)

This is obviously not the perfect way of doing this, and in the future
we should improve on this, and also find a way to utilize any hardware
mixing functions in the sound card.
2019-11-22 21:44: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
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
66a2b582c3 LibPthread: Implement a basic first pthread mutex
This patch adds these API's:

- pthread_mutex_init()
- pthread_mutex_lock()
- pthread_mutex_unlock()

No mutex attributes are supported yet, so we only do the simplest mutex
wihout recursive locking.
2019-11-16 12:23:36 +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
794f2d5645 LibHTML: Rename parse_html() => parse_html_document() 2019-11-06 20:52:18 +01:00
Andreas Kling
f5cf8d4ad8 Revert "LibHTML: Rename parse_html() => parse_html_document()"
This reverts commit f6439789db.
Oops, I committed unrelated changes here, let me clean that up..
2019-11-06 20:51:07 +01:00
Andreas Kling
f6439789db LibHTML: Rename parse_html() => parse_html_document() 2019-11-06 20:31:56 +01:00
Andreas Kling
173ae370db disk_benchmark: Add a -c flag to enable use of disk caches
By default, disk_benchmark will now use the O_DIRECT flag, causing it
to bypass the kernel's disk caches. This gives you "disk performance"
numbers rather than "disk cache performance" numbers.

You can use "disk_benchmark -c" to enable the caches.

Fixes #703.
2019-11-05 19:37:23 +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
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
Andreas Kling
be19606501 cp: Fail immediately if there's not enough space for the destination
Instead of writing until we run out of space, just fail immediately.
2019-11-02 23:47:22 +01:00
Andreas Kling
73b2cb9ed8 cp: Read/write 32 KB at a time to go faster :^)
This is a huge speed-up (3x) when copying large files. Ideally this
would be optimized by the kernel somehow, but we're not there yet.
2019-11-02 16:39:26 +01:00
Andreas Kling
f2a9bbe96e disk_benchmark: Use 64-bit values for bytes-per-second values
Let's dress for the job we want, and prepare for faster speeds. :^)
2019-11-02 10:42:41 +01:00
Andreas Kling
f9d679ae37 cp: Try to pre-size the destination file to the final size up front
Since we usually know how many bytes we're going to write, we can be
nice to the kernel and ftruncate() the destination to the expected size
up front, reducing the amount of FS churn.
2019-11-02 10:00:18 +01:00