Commit graph

388 commits

Author SHA1 Message Date
Muhammad Zahalqa
d9470bdae7 LibCore: close socket on LocalServer dtor 2020-08-09 21:10:01 +02:00
Muhammad Zahalqa
9150f3c266 LibCore: close socket on TCPServer dtor 2020-08-09 21:10:01 +02:00
Muhammad Zahalqa
0246e2ae6c LibCore: close socket on UDPServer dtor 2020-08-09 21:10:01 +02:00
Andreas Kling
bc615572a9 LibCore+Base: Move user-specific config files to $HOME/.config 2020-08-05 17:40:47 +02:00
Brian Gianforcaro
64ba289cfb LibCore: ConfFile::read_entry should not sneakily write default entries
I noticed on boot, WindowServer was getting an veil error:

    [WindowServer(13:13)]: Rejecting path '/res/themes/Default.ini' since it hasn't been unveiled with 'c' permission.
    [WindowServer(13:13)]: 0xc014367f  _ZN6Kernel3VFS34validate_path_against_process_veilEN2AK10StringViewEi +681
    [WindowServer(13:13)]: 0xc01439d7  _ZN6Kernel3VFS12resolve_pathEN2AK10StringViewERNS_7CustodyEPNS1_6RefPtrIS3_EEii +163
    [WindowServer(13:13)]: 0xc0143d03  _ZN6Kernel3VFS4openEN2AK10StringViewEitRNS_7CustodyENS1_8OptionalINS_9UidAndGidEEE +121
    [WindowServer(13:13)]: 0xc016fbc4  _ZN6Kernel7Process8sys$openEPKNS_7Syscall14SC_open_paramsE +854
    [WindowServer(13:13)]: 0xc0164af8  syscall_handler +1320
    [WindowServer(13:13)]: 0xc0164541  syscall_asm_entry +49
    [WindowServer(13:13)]: 0x08097ca0  open_with_path_length +24
    [WindowServer(13:13)]: 0x08097cf8  open +63
    [WindowServer(13:13)]: 0x080a3c59  fopen +31
    [WindowServer(13:13)]: 0x0806abf0  _ZN4Core10ConfigFile4syncEv +48
    [WindowServer(13:13)]: 0x0806af6a  _ZN4Core10ConfigFileD2Ev +16
    [WindowServer(13:13)]: 0x08093e2a  _ZN3Gfx17load_system_themeERKN2AK6StringE +1869
    [WindowServer(13:13)]: 0x08048633  main +491
    [WindowServer(13:13)]: 0x08048dae  _start +94

With some digging I found out that the ConfigFile class was causing
trying to flush writes of default values, not present in the .ini
file back to disk on destruction of the object.

This sneaky behavior from ConfigFile seems to violate the public facing
semantics of the function (it's const). It also makes it very hard to reason
about the system with technologies like unveil where we are trying to
explicitly state what is exposed to apps, how those exposed items can be
used.

The functionality also doesn't seem to be all that useful, as we'll just
return the default value from the API's anyway.

This change removes the write back of default values.
2020-08-02 21:11:28 +02:00
Andreas Kling
5e2b8d160b LibCore: Rename puff.c => puff.cpp
Now that we don't keep a C compiler around in the toolchain (to save
space) we can't have .c files in the build.

This reminds me that #362 exists and we should fix that at some point.
2020-07-29 14:41:57 +02:00
Peter Elliott
1211a036ba LibCore: add get_password().
A serenity-style getpass that is thread-safe
2020-07-28 17:07:22 +02:00
asynts
21de20825a LibCore: Change the signature of Socket::send() to use Span. 2020-07-27 19:58:09 +02:00
Andreas Kling
78518d230c LibCore+LibWeb: Move guess-mimetype-based-on-filename logic to LibCore
This could be useful in more places.
2020-07-27 19:57:20 +02:00
Andreas Kling
e0b8b4ac67 LibCore+LibGUI: Switch to using AK::is and AK::downcast 2020-07-26 17:51:00 +02:00
Andreas Kling
6d27915f4b LibCore: Turns some heap-allocated events into stack-allocated ones 2020-07-16 20:46:44 +02:00
Tom
6751d03ea7 LibCore: Add register_signal and unregister_signal to EventLoop
This allows safer asynchronous handling of signals. Signals are
dispatched with highest priority.
2020-07-09 21:58:07 +02:00
Andreas Kling
41066b009f LibCore: Don't fire Socket::on_ready_to_read if !can_read()
This is a bit of a pickle and I'm unsure what's the best behavior here.

Since notifiers fire asynchronously via the event loop, we may end up
firing a notifier for a socket fd, but then reading/writing that socket
fd before ending up in the notifier callback.

In that situation, the socket is no longer in the same state as it was
when the event loop generated the notifier event.

This patch stops Socket from firing one hook in this situation but this
probably needs a global rethink.

With this change, Browser starts reliably in multi-process mode. :^)
2020-07-06 23:17:10 +02:00
Andreas Kling
e5933ec739 LibCore: Only deliver Read/Write events to listening notifiers
If a notifier has disabled read/write notifications via its event mask,
we should not spam it with events, even if they have a hook callback.
2020-07-06 23:17:10 +02:00
AnotherTest
6f7ac5d2e2 LibCore: Stop select()'ing after an interrupt if a quit was requested
This allows signal handlers to request the loop to terminate.
2020-07-05 15:43:14 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Tom
d99901660d Kernel/LibCore: Expose processor id where a thread last ran 2020-07-01 12:07:01 +02:00
Andreas Kling
b191f24f05 LibCore: Remove some debug spam in Local{Server,Socket} 2020-06-22 21:21:38 +02:00
Andreas Kling
32dfde746a LibCore: Put safe_syscall() debug spam behind #ifdef 2020-06-22 21:19:10 +02:00
Andreas Kling
6bc40b20b8 LibCore: Add API for taking over an accepted socket from SystemServer
Core::LocalSocket::take_over_accepted_socket_from_system_server() now
allows you to construct a Core::LocalSocket for a pre-accepted socket
when using SystemServer's new AcceptSocketConnections mode.
2020-06-21 21:54:30 +02:00
Sergey Bugaev
d89843f96f LibCore: Add File::read_link() :^)
This is a convenient wrapper around readlink() that hides away the details
of buffers and buffer sizes, and simply returns a String. The best part is it
doesn't rely on PATH_MAX :D

It comes in two versions, for Serenity, where we can pass non-null-terminated
strings to syscalls, and where sys$readlink() returns the total link size, and
for other systems, where we have to copy out the string, and always have to do
two syscalls.
2020-06-17 15:02:03 +02:00
Matthew Olsson
e8e728454c AK: JsonParser improvements
- Parsing invalid JSON no longer asserts
    Instead of asserting when coming across malformed JSON,
    JsonParser::parse now returns an Optional<JsonValue>.
- Disallow trailing commas in JSON objects and arrays
- No longer parse 'undefined', as that is a purely JS thing
- No longer allow non-whitespace after anything consumed by the initial
  parse() call. Examples of things that were valid and no longer are:
    - undefineddfz
    - {"foo": 1}abcd
    - [1,2,3]4
- JsonObject.for_each_member now iterates in original insertion order
2020-06-13 12:43:22 +02:00
Andreas Kling
d54ace5f04 LibCore: Add Core::File::real_path_for()
A slightly convenient wrapper around realpath(3).
2020-06-12 21:29:01 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
940fbea3a7 LibCore: Fix typo in Forward.h 2020-06-11 22:44:54 +02:00
Andreas Kling
7bb4f3764c LibCore: Add Timer::restart() convenience API
This simply restarts the timer with the existing millisecond interval.
2020-06-11 22:35:37 +02:00
Sergey Bugaev
89004a3a40 LibCore: Make sure to disable notifiers when closing a socket
RefPtr<Notifier> doesn't work quite like it appears to, since the notifier
is also a "child" of the socket, in Core::Object sense. Thus we have to both
remove it from the parent (socket) and drop the additional RefPtr<Notifier> for
it to actually go away.

A proper fix for this would be to untangle parent-child relashionship from
refcounting and inspectability.

This fixes use-after-close of client file descriptors in IPC servers.
2020-06-08 13:58:32 +02:00
Andreas Kling
59adccb987 LibCore: Put some annoying debug spam behind EVENTLOOP_DEBUG 2020-06-02 12:46:52 +02:00
Sergey Bugaev
b4ca45b5ec LibCore: Update Core::ArgsParser to the new error message format 2020-05-30 15:01:18 +02:00
Marcin Gasperowicz
9a4ee9aa1a Lagom: Adjust AK, LibCore and LibTLS to build on MacOS 2020-05-30 00:36:13 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Sergey Bugaev
ec4902d1dd LibCore+Inspector: Move RPC sockets to /tmp/rpc
We have a hierarchical filesystem, let's make use of it :^)
2020-05-29 07:53:30 +02:00
Sergey Bugaev
8afcf0d87a LibCore: Do not assert that we can start the RPC server
Now that the Shell uses Core::EventLoop, we can't afford to just crash if /tmp
is unwritable.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Marcin Gasperowicz
c21dc21f36
Build: Make Lagom build under macOS (#2341)
Lagom now builds under macOS. Only two minor adjustments were required:

* LibCore TCP/UDP code can't use `SOCK_{NONBLOCK,CLOEXEC}` on macOS,
use ioctl() and fcntl() instead

* LibJS `Heap` code pthread usage ported to MacOS
2020-05-23 15:31:30 +02:00
Andreas Kling
4b202a3c79 LibCore+LibTLS: Don't keep a "ready to write" notifier on all Sockets
The "ready to write" notifier we set up in generic socket connection is
really only meant to detect a successful connection. Once we have a TCP
connection, for example, it will fire on every event loop iteration.

This was causing IRC Client to max out the CPU by getting this no-op
notifier callback over and over.

Since this was only used by TLSv12, I changed that code to create its
own notifier instead. It might be possible to improve TLS performance
by only processing writes when actually needed, but I didn't look very
closely at that for this patch. :^)
2020-05-18 20:16:52 +02:00
AnotherTest
1c4f38749e LibCore: Allow ArgsParser::parse() to not exit on failure
This allows its use in places where multiple calls to
ArgsParser::parse() are needed, such as Shell builtins.
2020-05-17 11:58:08 +02:00
AnotherTest
16ba0b39f3 LibCore: Reset getopt's state when starting parse()
This way, a program can use ArgsParser multiple times, potentially with
multiple different options.
2020-05-17 11:58:08 +02:00
Andreas Kling
c3379e3734 LibCore: Always wait_for_events() when pumping the event loop
This fixes an issue where continuously posting new events to the queue
would keep the event loop saturated, causing it to ignore notifiers.

Since notifiers are part of the big select(), we always have to call
wait_for_events() even if there are pending events. We're already smart
enough to select() without a timeout if we already have pending events.
2020-05-16 22:06:33 +02:00
Sergey Bugaev
345fbd1fc1 LibCore: Fix timer expiration processing
The previous code did not account for the case when there are timers present,
but none are enabled, and used a zero polling timeout.

Fixes https://github.com/SerenityOS/serenity/issues/2222
2020-05-15 17:41:54 +02:00
AnotherTest
3485613f4a LibCore: Make IODevice::can_read_line() const
This also makes LibHTTP's Job::can_read_line() const, as IODevice was
keeping that from being const.
Fixes #2219
2020-05-15 09:50:48 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Nicholas Hollett
b7810a31c3 LibDesktop: Switch to LaunchServer for DesktopServices::open
Moves DirectoryServices out of LibCore (because we need to link with
LibIPC), renames it Desktop::Launcher (because Desktop::DesktopServices
doesn't scan right) and ports it to use the LaunchServer which is now
responsible for starting programs for a file.
2020-05-09 15:13:32 +02:00
Hüseyin ASLITÜRK
a3367cf4fa LibCore: DesktopServices, open fonts with FontEditor 2020-05-08 09:49:41 +02:00
AnotherTest
d051fffe25 LibCore: Add a primitive comparison function to DateTime
This should go away when we get the ability to parse strings to
DateTime's.
2020-05-07 10:23:58 +02:00
Linus Groh
9dbab2d05e Misc: Replace "String(string_view)" with "string_view.to_string()"
StringView::to_string() was added in 917ccb1 but not actually used
anywhere yet.
2020-05-06 19:28:59 +02:00
Andreas Kling
76dd1e3284 LibCore: Add a standard downloads directory (~/Downloads) 2020-05-05 23:56:57 +02:00
AnotherTest
06cf9d3fb7 ProtocolServer: Implement and handle download progress
Also updates `pro` to display download progress and speed on stderr
2020-05-03 12:59:26 +02:00
AnotherTest
7670e5ccf0 LibCore+LibHTTP: Move out the HTTP handler and add HTTPS 2020-05-02 12:24:10 +02:00
AnotherTest
7eb72c72e8 LibCore: Mark Socket::{common_,}connect() virtual and add a on_write 2020-05-02 12:24:10 +02:00
Sergey Bugaev
b319aca81a LibCore: Do not assert that NonnullRefPtr is non-null
Clang complains about this; with the change the next commit is going
to make to ASSERT() internals, GCC is going to start to complain as well.
2020-04-30 11:30:27 +02:00
Andreas Kling
36a5e0be4b LibCore: Don't continue in forked child if exec() fails
Fixes #1854.
2020-04-30 09:52:07 +02:00
AnotherTest
8d419c1915 LibCore: Trim decompressed Gzip output to size
Prior to this commit, we would (re-)allocate the output buffer aligned
to 1024 bytes, but never trim it down to size, which caused
Gzip::decompress to return uninitialised data.
2020-04-28 09:32:33 +02:00
Hüseyin ASLITÜRK
e7b9e03285 LibCore: Open gif files with QuickShow 2020-04-26 18:44:20 +02:00
Brendan Coles
edd8abc4cf LibCore: read_bool_entry parse "true" / "false" strings in config files
`read_bool_entry()` can now interpret both integers (1 or 0) and
Boolean strings ("true" or "false") in configuration files.

All values other than "1" or "true" are considered false.
2020-04-23 11:04:25 +02:00
Brendan Coles
c3b2bfabfe DesktopServices: Add irc URL protocol handler 2020-04-23 09:50:19 +02:00
Andreas Kling
a19690170f LibCore: Make Core::File::open() return a Result<NNRP<File>, String>
It was impractical to return a RefPtr<File> since that left us no way
to extract the error string. This is usually needed for the UI, so the
old static open() got basically no use.
2020-04-21 16:19:18 +02:00
Andreas Kling
c45e16f605 LibCore: Add StandardPaths thing to retrieve various standard locations
Fixes #1853.
2020-04-19 19:57:05 +02:00
Sergey Bugaev
50c139e61c LibCore: Check for fork() failure
For those good boy points :^)
2020-04-19 11:14:26 +02:00
Sergey Bugaev
f8b2a7b4a7 LibCore+LibGUI: Move DesktopServices to LibCore 2020-04-19 11:14:26 +02:00
Andreas Kling
a53cf81374 LibCore: Add Core::Timer::create_single_shot()
This is just a convenience function for creating single-shot timers.
2020-04-07 23:01:43 +02:00
Andreas Kling
20e58c5513 AK: Make dbgprintf() and dbgputstr() go to stderr on non-Serenity hosts 2020-04-06 10:49:27 +02:00
AnotherTest
d8e944e899 LibCore: Fix UDPServer up to properly receive data
Prior to this, UDPServer was using listen/accept, which does not make
sense in the context of UDP.
2020-04-04 12:25:33 +02:00
Andreas Kling
eeec1c1293 LibCore: Don't replay last handled event when leaving nested event loop
The event that triggered the exit from an inner event loop would always
get re-delivered in the outer event loop due to a silly off-by-one
mistake when transferring pending events between loops.
2020-04-03 22:55:48 +02:00
Andreas Kling
0df15823b5 LibCore: Add a static Core::File::open() convenience function
This helper opens a file with a given name, mode and permissions and
returns it in a RefPtr<File>. I think this will be a bit nicer to use
than having to go through Core::File::construct() every time.
2020-03-30 12:08:25 +02:00
Andreas Kling
290ea11739 LibCore: Tweak DateTime.cpp so it compiles on Linux + drive-by bug fix 2020-03-23 13:13:36 +01:00
Shannon Booth
83425b1ac0 LibCore: Wrap commented out debug messages in a preprocessor define
We can also remove an outdated FIXME as dbg() does now support unsigned
longs :^)
2020-03-22 08:51:40 +01:00
Liav A
7268499c76 LibCore: Use monotonic time when handling timers 2020-03-19 15:48:00 +01:00
rhin123
08a30a4961 LibCore: Moved cal.cpp functions to DateTime 2020-03-18 08:17:01 +01:00
Shannon Booth
5dc5b8a2b6 LibCore: Rename Udp classes to UDP
The kernel was already using the UDP prefix, and the TCP LibCore classes
are also uppercased. Let's rename for consistency.

Also order the LibCore Makefile alphabetically, because everywhere else
seems to be doing that :)
2020-03-14 23:56:12 +01:00
Alex Muscar
81c6f72134
EventLoop: Don't destroy ID allocator (#1403)
The ID allocator is destroyed before a timer in HackStudio is
is unregistered leading to an access violation.

Fixes #1382.
2020-03-10 11:31:37 +01:00
Andreas Kling
37fc6c117c Userspace: Add missing #includes now that AK/StdLibExtras.h is smaller 2020-03-08 13:06:51 +01:00
Andreas Kling
b1058b33fb AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it
possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-08 13:06:51 +01:00
howar6hill
10e0d4a196
LibCore: Add format option for DateTime::to_string() (#1358) 2020-03-08 11:35:26 +01:00
Shannon Booth
57f1c919df LibCore: Remove all remaining C prefix references
LibCore's GZip is also moved into the Core namespace with this change.
2020-03-07 01:33:53 +01:00
Andreas Kling
42f2696355 LibCore: Add a way to set an individual Core::Object property remotely 2020-03-05 15:50:22 +01:00
Andreas Kling
d16f8214d8 LibCore: Allow RPC clients to specify the currently inspected object
Add a SetInspectedObject call that tells us which Core::Object a remote
client is currently looking it. Objects get notified when they gain
their first inspector, and when they lose their last one.
2020-03-05 14:40:47 +01:00
Andreas Kling
028c011760 LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can
simply vend a ChildType&. This allows us to use "." instead of "->"
at the call site, which is quite nice. :^)
2020-03-04 21:04:06 +01:00
Andreas Kling
22d0a6d92f AK: Remove unnecessary casts to size_t, after Vector changes
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
2020-03-01 12:58:22 +01:00
Jesse Buhagiar
22cdf12ec4 LibCore: Allow ConfigFile::read_num_entry to handle negative numbers
Previously, this function was using `AK::String::to_uint()`, which is
wrong considering the function returns type `int`. This also means that
configuration files would revert to the default value on negative
values.
2020-02-26 11:48:53 +01:00
howar6hill
35024154cc DateTime: Fix a typo 2020-02-26 09:31:43 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Andreas Kling
d9e459293b LibCore: Add Core::Object::add<T> helper for creating child objects
Consider the old pattern for creating a Core::Object parent and child:

    auto parent = Core::Object::construct(...);
    auto child = Core::Object::construct(..., parent);

The above was an artifact of the pre-reference-counting Object era.
Now that objects have less esoteric lifetime management, we can replace
the old pattern with something more expressive:

    auto parent = Core::Object::construct(...);
    auto child = parent->add<Core::Object>(...);

This reads a lot more naturally, and it also means we can get rid of
all the parent pointer arguments to Core::Object subclass constructors.
2020-02-23 11:10:52 +01:00
Andreas Kling
28f1486627 LibCore: Log a more helpful message when Socket::connect() fails
Fixes #1272.
2020-02-22 16:41:31 +01:00
Andreas Kling
82fd09e8fe LibCore: Fix wrong return value in Core::Socket::destination_address() 2020-02-22 16:38:10 +01:00
Andreas Kling
88b9fcb976 AK: Use size_t for ByteBuffer sizes
This matches what we already do for string types.
2020-02-20 13:20:34 +01:00
Shannon Booth
42399167b3 LibCore: Add DirIterator::next_full_path() 2020-02-16 02:19:22 +01:00
Shannon Booth
6764b77788 LibCore: Add SkipParentAndBaseDir flag in DirIterator
Sometimes we may want to iterate over dotfiles but not include the
parent or base directory
2020-02-15 11:40:05 +01:00
Shannon Booth
3879d75219 LibCore: Simplify some of DirIterator's code
The main changes are in advance_next() where we flatten some of the
nesting to improve readability
2020-02-15 11:40:05 +01:00
Andreas Kling
0e3a9d8e9d LibCore: Reduce header dependencies of EventLoop 2020-02-15 02:09:00 +01:00
Andreas Kling
3866e0d4d4 LibCore: Move LogStream::operator<< overloads into cpp files 2020-02-15 00:58:52 +01:00
Andreas Kling
2a41bff329 LibCore: Remove a bunch of unnecessary forward declarations
Now that we get LibCore forward declarations from <LibCore/Forward.h>,
we don't need to declare things manually.
2020-02-15 00:32:33 +01:00
Andreas Kling
a368cf7d51 LibGfx: Replace manual forward declarations with <LibGfx/Forward.h> 2020-02-15 00:10:34 +01:00
Andreas Kling
8f7333f080 LibCore: Add a forward declaration header
This patch adds <LibCore/Forward.h> and uses it in various places to
shrink the header dependency graph.
2020-02-14 23:31:18 +01:00
Andreas Kling
3cba9c3c25 LibCore: Add Core::MimeData class
This object contains zero or more { mime_type, data } entries and will
be used for clipboard data as well as drag & drop.
2020-02-14 13:17:26 +01:00
Andreas Kling
90fec9c732 LibCore: Add "static bool Core::File::exists(filename)" 2020-02-12 21:17:00 +01:00
Andreas Kling
8f89cc85d1 LibCore: Add DateTime::from_timestamp(time_t) 2020-02-11 19:48:46 +01:00
Andreas Kling
b8cf83926a LibCore: Add a basic Core::DateTime class
This is just to have a pleasant way to print the current time for now:

    dbg() << Core::DateTime::now();

Or if you want it as a string:

    Core::DateTime::now().to_string();
2020-02-11 19:43:29 +01:00
Andreas Kling
3713d31750 LibCore: TCP and UDP servers should parent Notifiers to themselves
This makes things look a little more neat in Inspector. :^)
2020-02-10 14:15:56 +01:00
Andreas Kling
6cbd72f54f AK: Remove bitrotted Traits::dump() mechanism
This was only used by HashTable::dump() which I used when doing the
first HashTable implementation. Removing this allows us to also remove
most includes of <AK/kstdio.h>.
2020-02-10 11:55:34 +01:00
Andreas Kling
67ccdbe384 LibCore: Add File::is_directory() helpers 2020-02-09 14:15:55 +01:00
Andreas Kling
3a7e49fe07 LibCore: Allow constructing a Core::HttpRequest from a raw HTTP request
This patch adds a very simple HTTP request parser that can be useful
for implementing say.. a web server. :^)
2020-02-09 14:15:55 +01:00
Andreas Kling
258d798b34 LibCore: Merge the CSyscallUtils namespace into Core 2020-02-06 15:04:57 +01:00
Andreas Kling
d17e23bd27 LibCore: Remove leading C from filenames 2020-02-06 15:04:03 +01:00
Andreas Kling
9ac94d393e LibGfx: Rename from LibDraw :^) 2020-02-06 12:04:00 +01:00
joshua stein
dac07a5d76 LibCore: CEventLoop: If timeval_sub makes tv_sec negative, use 0 2020-02-05 18:39:45 +01:00
joshua stein
f6a8b1b69a LibCore: Fix building with clang 2020-02-05 18:39:45 +01:00
Andreas Kling
2d39da5405 LibCore: Put all classes in the Core namespace and remove the leading C
I've been wanting to do this for a long time. It's time we start being
consistent about how this stuff works.

The new convention is:

- "LibFoo" is a userspace library that provides the "Foo" namespace.

That's it :^) This was pretty tedious to convert and I didn't even
start on LibGUI yet. But it's coming up next.
2020-02-02 15:15:30 +01:00
Andreas Kling
5b47b0d867 LibGUI: Make GAction scoped to its CObject parent (widget or window)
Unparented GActions are still parented to the application like before,
making them globally available.

This makes it possible to have actions that work whenever a specific
window is active, no matter which widget is currently focused. :^)
2020-02-02 02:03:39 +01:00
Andreas Kling
6ab9dc4ff4 LibCore: is<CObject>(object) should not default to true
Otherwise we'll lie about anything that doesn't implement is<T>() and
think it's indeed a T.
2020-02-02 02:03:39 +01:00
Andreas Kling
d0c230855d LibCore: Fix CArgsParser build on my host machine 2020-02-01 20:18:53 +01:00
Sergey Bugaev
9276582535 LibCore: Rewrite CArgsParser
This is a complete reimplementation of CArgsParser with a different API.

Now, CArgsParser properly supports and distinguishes between:
* Positional arguments (required or not)
* Options

Options can be short and/or long.

The API allows you to add custom option and argument types. A few types are
pre-implemented for convenience:
* Boolean options (take no value)
* String and integer options (take a required value)
* String and integer arguments
* Vector-of-string arguments

This commit doesn't include changes for all the users of CArgsParser (see next
commit for that).
2020-01-28 13:50:18 +01:00
Andreas Kling
3c129172d4 LibCore: Add UDP socket and server classes 2020-01-26 14:45:07 +01:00
Andreas Kling
8e7e502f37 LibCore: CSocket::set_blocking() was backwards 2020-01-26 14:29:33 +01:00
Andreas Kling
b0192cfb38 Meta: Remove some copyright headers added in error 2020-01-25 10:34:32 +01:00
Andreas Kling
a93f35ac71 LibCore: Remove redundant check in CObject::dispatch_event() 2020-01-23 21:33:15 +01:00
Andreas Kling
72d68b4025 LibCore: Fix broken "stay_within" mechanism in event dispatch
The "stay_within" parameter to CObject::dispatch_event() optionally
specifies a node in the CObject parent chain where event dispatch
should stop bubbling upwards.

Since event dispatch is done recursively, this was not working right,
as we would simply return from the innermost dispatch loop, leaving
the event un-accepted, which meant that the penultimately inner
dispatch loop would pick up the event and keep bubbling it anyway.

This made it possible for events to jump across window boundaries
within an application, in cases where one window was a CObject ancestor
of another window. This is typically the case with dialog windows.

Fix #1078.
2020-01-21 21:55:25 +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
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Sergey Bugaev
cee597a728 LibCore: Make CIODevice::read_all() actually read all data
It used to only read the data it could get without blocking. Andreas says this
was intentional, but it's counterintuitive and no code that uses read_all()
actually expects it to return only a part of the data. So change it to always
read data until an EOF (or an error) is received.
2020-01-17 21:49:58 +01:00
DrewStratford
2a8de4cdec LibCore: Fix segfault in CArgsParser (#1072)
CArgsParser::parse_next_param did not properly ensure that, when
a param required a following argument, there were enough parameters left to
complete the parse. This meant that params_left could become negative,
avoiding parse_next_param's termination condition, and cause a segfault
when reading from argv with an out of bounds index.

This fixes the check to ensure that we do in fact have the right amount
of parameters and also adds an assertion to ensure that params_left does
not become negative.
2020-01-13 14:52:25 +01:00
Andreas Kling
ec1ae37f69 SystemMonitor+LibCore: Show process pledges in SystemMonitor :^) 2020-01-11 21:33:12 +01:00
Conrad Pankoff
84f0be37f0 LibCore: Fix a typo in CConfigFile.h 2020-01-07 12:46:02 +01:00
Andreas Kling
04b734501a LibCore: Oops, we were forgetting to destroy disconnected RPC clients 2020-01-05 17:54:48 +01:00
Shannon Booth
861f40f014 AK+LibCore: Add an IDAllocator and use to allocate timer ids 2020-01-05 09:00:05 +01:00
Andreas Kling
70a41420a9 LibCore: Fix crash on RPC client disconnect
The RPC client management was not updated for the changes that made
CObject reference-counted it seems. :^)
2020-01-03 20:27:48 +01:00
Andreas Kling
e76e533a69 LibCore: Stop making the RPC sockets go=rw
Now that we can fchmod() on a pre-bind() socket, use that to lock down
the RPC sockets we publish in all CEventLoop-driven programs.
2020-01-03 20:21:39 +01:00
joshua stein
288fa07d85 LibCore: CSocketAddress: pull in netinet/in.h 2020-01-02 04:09:56 +01:00
Andreas Kling
50677bf806 Kernel: Refactor scheduler to use dynamic thread priorities
Threads now have numeric priorities with a base priority in the 1-99
range.

Whenever a runnable thread is *not* scheduled, its effective priority
is incremented by 1. This is tracked in Thread::m_extra_priority.
The effective priority of a thread is m_priority + m_extra_priority.

When a runnable thread *is* scheduled, its m_extra_priority is reset to
zero and the effective priority returns to base.

This means that lower-priority threads will always eventually get
scheduled to run, once its effective priority becomes high enough to
exceed the base priority of threads "above" it.

The previous values for ThreadPriority (Low, Normal and High) are now
replaced as follows:

    Low -> 10
    Normal -> 30
    High -> 50

In other words, it will take 20 ticks for a "Low" priority thread to
get to "Normal" effective priority, and another 20 to reach "High".

This is not perfect, and I've used some quite naive data structures,
but I think the mechanism will allow us to build various new and
interesting optimizations, and we can figure out better data structures
later on. :^)
2019-12-30 18:46:17 +01:00
Andreas Kling
1b2c6e8f41 LibCore: Use JsonObject::get_ptr() in CProcessStatisticsReader
This removes a bunch of JsonValue copying from the hot path in thread
statistics fetching.

Also pre-size the thread statistics vector since we know the final size
up front. :^)
2019-12-30 14:51:34 +01:00
Andreas Kling
411d293961 LibCore+LibGUI: Don't fire timers in non-visible windows by default
LibCore timers now have a TimerShouldFireWhenNotVisible flag which is
set to "No" by default.

If "No", the timer will not be fired by the event loop if it's within
a CObject tree whose nearest GWindow ancestor is currently not visible
for timer purposes. (Specificially, this means that the window is
either minimized or fully occluded, and so does not want to fire timers
just to update the UI.)

This is another nice step towards a calm and serene operating system.
2019-12-29 16:03:36 +01:00
Andreas Kling
c74cde918a Kernel+SystemMonitor: Expose amount of per-process clean inode memory
This is memory that's loaded from an inode (file) but not modified in
memory, so still identical to what's on disk. This kind of memory can
be freed and reloaded transparently from disk if needed.
2019-12-29 12:45:58 +01:00
Andreas Kling
0d5e0e4cad Kernel+SystemMonitor: Expose amount of per-process dirty private memory
Dirty private memory is all memory in non-inode-backed mappings that's
process-private, meaning it's not shared with any other process.

This patch exposes that number via SystemMonitor, giving us an idea of
how much memory each process is responsible for all on its own.
2019-12-29 12:28:32 +01:00
Stefano Cristiano
1222b94ab8 LibCore: Allow LibCore to be compiled on macOS host
Compiling LibCore on macOS is needed if one wants to compile host tools
(like IPCCompiler) on a non Linux host.
These changes could be possibly reverted once "event loop" functionality
and "base library" (Vector, String etc.) will be split in two separate libraries,
updating all relevant projects.
2019-12-27 02:19:55 +01:00
Stefano Cristiano
aab412bd85 LibCore: Fix errors when compiling LibCore using clang instead of gcc 2019-12-27 02:19:55 +01:00
joshua stein
2aeae2aea9 LibCore: compile puff.c as a separate object 2019-12-25 10:11:09 +01:00
Andreas Kling
411058b2a3 WindowServer+LibGUI: Implement basic color theming
Color themes are loaded from .ini files in /res/themes/
The theme can be switched from the "Themes" section in the system menu.

The basic mechanism is that WindowServer broadcasts a SharedBuffer with
all of the color values of the current theme. Clients receive this with
the response to their initial WindowServer::Greet handshake.

When the theme is changed, WindowServer tells everyone by sending out
an UpdateSystemTheme message with a new SharedBuffer to use.

This does feel somewhat bloated somehow, but I'm sure we can iterate on
it over time and improve things.

To get one of the theme colors, use the Color(SystemColor) constructor:

    painter.fill_rect(rect, SystemColor::HoverHighlight);

Some things don't work 100% right without a reboot. Specifically, when
constructing a GWidget, it will set its own background and foreground
colors based on the current SystemColor::Window and SystemColor::Text.
The widget is then stuck with these values, and they don't update on
system theme change, only on app restart.

All in all though, this is pretty cool. Merry Christmas! :^)
2019-12-23 20:33:01 +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
6b71250d1a LibCore: Silence some aggressive CSocket and CHttpJob debug spam 2019-12-14 11:30:18 +01:00
Andreas Kling
bcffe31d3a LibCore: Bump the CHttpJob receive buffer size from 4KB to 64KB
4KB gets pretty mmap/munmap heavy when downloading larger files,
so bump this a bit to reduce time spent in memory allocation.

This can be improved in various ways, but I'm not sure what the
best way forward is at the moment.
2019-12-14 10:01:20 +01:00
Andreas Kling
40b7d814c3 LibCore: Make CHttpJob::response() return a CHttpResponse*
We know that the CNetworkResponse inside a CHttpJob is always going to
be a CHttpResponse, so we can return a casted pointer to be nice. :^)
2019-12-10 20:46:33 +01:00
Andreas Kling
92b46d9814 SystemMonitor: Show information about purgeable memory
This patch exposes some fields about purgeable memory regions.
We now also show total purgeable volatile and non-volatile memory in
the big process table.
2019-12-09 19:16:58 +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
Andrew Kaster
e09a02ad3f SystemMonitor: Show thread name instead of process name
Add the thread name to CThreadStatistics and display it in the
system monitor's process model instead of the process name.
2019-12-08 14:09:29 +01:00
Andreas Kling
5d4ee0f58a LibIPC: Move IPC client/server connection templates to LibIPC
Move over the CoreIPC::Server and CoreIPC::Client namespace stuff
into LibIPC where it will soon becomes LibIPC-style things.
2019-12-02 11:11:05 +01:00
Andreas Kling
272d65e3e2 WindowServer: Port to the new IPC system
This patch introduces code generation for the WindowServer IPC with
its clients. The client/server endpoints are defined by the two .ipc
files in Servers/WindowServer/: WindowServer.ipc and WindowClient.ipc

It now becomes significantly easier to add features and capabilities
to WindowServer since you don't have to know nearly as much about all
the intricate paths that IPC messages take between LibGUI and WSWindow.

The new system also uses significantly less IPC bandwidth since we're
now doing packed serialization instead of passing fixed-sized structs
of ~600 bytes for each message.

Some repaint coalescing optimizations are lost in this conversion and
we'll need to look at how to implement those in the new world.

The old CoreIPC::Client::Connection and CoreIPC::Server::Connection
classes are removed by this patch and replaced by use of ConnectionNG,
which will be renamed eventually.

Goodbye, old WindowServer IPC. You served us well :^)
2019-12-02 11:11:05 +01:00
Andreas Kling
5a45376180 Kernel+SystemMonitor: Log amounts of I/O per thread
This patch adds these I/O counters to each thread:

- (Inode) file read bytes
- (Inode) file write bytes
- Unix socket read bytes
- Unix socket write bytes
- IPv4 socket read bytes
- IPv4 socket write bytes

These are then exposed in /proc/all and seen in SystemMonitor.
2019-12-01 17:40:27 +01:00
Andreas Kling
2ece61fa1f LibCore: Improve logging of errors in safe_syscall() somewhat 2019-12-01 16:47:28 +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