Commit graph

359 commits

Author SHA1 Message Date
Érico Nogueira Rolim
a8f0e489a4
LibCore: Rename identifiers that can clash with libc macros (#4127)
POSIX allows the default streams (stdin, stdout and stderr) to be
macros, which means that on such systems (musl libc is one) building
Lagom will fail due to the File::std*() names.

Also fix any files that use these identifiers.
2020-12-22 23:37:11 +01:00
Tom
5f51d85184 Kernel: Improve time keeping and dramatically reduce interrupt load
This implements a number of changes related to time:
* If a HPET is present, it is now used only as a system timer, unless
  the Local APIC timer is used (in which case the HPET timer will not
  trigger any interrupts at all).
* If a HPET is present, the current time can now be as accurate as the
  chip can be, independently from the system timer. We now query the
  HPET main counter for the current time in CPU #0's system timer
  interrupt, and use that as a base line. If a high precision time is
  queried, that base line is used in combination with quering the HPET
  timer directly, which should give a much more accurate time stamp at
  the expense of more overhead. For faster time stamps, the more coarse
  value based on the last interrupt will be returned. This also means
  that any missed interrupts should not cause the time to drift.
* The default system interrupt rate is reduced to about 250 per second.
* Fix calculation of Thread CPU usage by using the amount of ticks they
  used rather than the number of times a context switch happened.
* Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it
  for most cases where precise timestamps are not needed.
2020-12-21 18:26:12 +01:00
Brendan Coles
27a5c51f3f LibCore: UDPServer::bind: Replace bind failure assert() with perror() 2020-12-18 19:20:30 +01:00
Conrad Pankoff
bb4e4921c0 LibCore: Expose some Socket properties to make then inspectable 2020-12-16 17:12:13 +01:00
Itamar
0b0c09e647 LibCore: Add DirectoryWatcher
DirectoryWatcher is a wrapper around watch_file, and can be used to
watch for changes in directories.
2020-12-14 23:05:53 +01:00
Itamar
efe4da57df Loader: Stabilize loader & Use shared libraries everywhere :^)
The dynamic loader is now stable enough to be used everywhere in the
system - so this commit does just that.
No More .a Files, Long Live .so's!
2020-12-14 23:05:53 +01:00
Andreas Kling
b9b7b2b28a LibCore: Make IODevice::read_line() return a String
Almost everyone using this API actually wanted String instead of a
ByteBuffer anyway, and there were a bunch of slightly different ways
clients would convert to String.

Let's just cut out all the confusion and make it return String. :^)
2020-12-13 11:54:11 +01:00
Ben Wiederhake
52a8062084 LibCore: Offer to display a general description 2020-12-06 00:06:53 +01:00
Tom
e0e26c6c67 LibCore: Don't wait for negative amount of time 2020-11-30 13:17:02 +01:00
Andreas Kling
13c32e0607 LibCore: Reduce debug spam from successful gzip decoding 2020-11-29 22:20:27 +01:00
AnotherTest
129a58a2e5 LibCore: Do not try to null-terminate a ByteBuffer in read_line()
That's just silly :)
Also fix that one use of read_line() which assumes it will
null-terminated in mount.cpp (this would've blown up if the IODevice was
at EOF and had a line with the same size as max_size).
2020-11-29 20:32:10 +01:00
AnotherTest
8066a623d9 LibCore: Make `guess_mime_type_based_on_filename()' recognise CSV files 2020-11-24 21:38:13 +01:00
Andreas Kling
adabcf24ec Everywhere: Add missing <AK/ByteBuffer.h> includes
All of these files were getting ByteBuffer.h from someone else and then
using it. Let's include it explicitly.
2020-11-15 13:11:21 +01:00
Lenny Maiorani
1643fa2223 InputFileStream: Incorrectly defaulted constructor
Problem:
- The default constructor is is deleted because NonnullRefPtr has no
  default constructor and there is a member variable of that type, but
  the function is set as `= default`.

Solution:
- Remove the code because the function is actually deleted implicitly.
2020-11-12 10:19:52 +01:00
Tom
75f61fe3d9 AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.

Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.

In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-11-10 19:11:52 +01:00
asynts
3b3edbc4d2 AK: Rename new_out to out and new_warn to warn. 2020-11-09 16:21:29 +01:00
AnotherTest
6d1e47e7dd LibGUI+WindowServer: Make DragOperation hold a MimeData instance
...instead of maybe bitmap + a single mime type and its corresponding data.
This allows drag&drop operations to hold multiple different kinds of
data, and the views/applications to choose between those.
For instance, Spreadsheet can keep the structure of the dragged cells,
and still provide text-only data to be passed to different unrelated editors.
2020-11-08 21:46:13 +01:00
Andreas Kling
6d841f2628 LibCore: Run clang-format on ArgsParser.cpp 2020-11-07 21:13:56 +01:00
Nico Weber
b143e604d7 LibCore: Add an ArgsParser::add_option() overload for doubles 2020-11-07 18:28:35 +01:00
Andreas Kling
387607503c LibCore: IODevice::can_read_line() should succeed for newline-less file
If the first call to populate_read_buffer() hits EOF but something did
get buffered, we can indeed read a line.
2020-10-25 14:38:07 +01:00
Linus Groh
82956a08b3 LibCore: Rename File::ShouldCloseFile{Description => Descriptor}
From https://youtu.be/YNSAZIW3EM0?t=1474:

"Hmm... I don't think that name is right! From the perspective of
userspace, this is a file descriptor. File description is what the
kernel internally keeps track of, but as far as userspace is concerned,
he just has a file descriptor. [...] Maybe that name should be changed."

Core::File even has a member of this enum type... called
m_should_close_file_descriptor - so let's just rename it :^)
2020-10-25 13:59:41 +01:00
Andreas Kling
5043c4a3e5 LibCore+WebServer+LibWeb: Make MIME type guesser take a StringView
This reverts my previous commit in WebServer and fixes the whole issue
in a much better way. Instead of having the MIME type guesser take a
URL (which we don't actually have in the WebServer at that point),
just take a path as a StringView.

Also, make use of the case-insensitive StringView::ends_with() :^)
2020-10-21 21:16:20 +02:00
asynts
c9ca897a45 LibCore: Use new format functions in some places. 2020-10-17 23:20:31 +02:00
asynts
56cf272ed5 LibCore: Add formatter for Object. 2020-10-17 23:20:31 +02:00
Nico Weber
4153a99ae1 LibCore: Make Object::m_all_objects_list_node private 2020-10-17 23:19:14 +02:00
Itamar
fec4152220 LibCore: Add ensure_parent_directories to LibCore::File
Moved the implementation in SystemServer/Service.cpp to LibCore.
2020-09-30 21:46:59 +02:00
Andreas Kling
62785b7872 LibCore: Expose origin timestamp of Core::ElapsedTime 2020-09-29 18:22:53 +02:00
Andreas Kling
f88a7cd4e1 LibCore: Make TCPServer::listen() report failure instead of asserting 2020-09-28 22:14:23 +02:00
Ben Wiederhake
ede5dbd7b3 Meta+LibC through LibHTTP: Make clang-format-10 clean
Why break at LibHTTP? Because "Meta+Libraries" would be insanely large,
and breaking between LibHTTP and LibJS makes the commits roughly evenly large.
2020-09-25 21:18:17 +02:00
Peter Elliott
3d34724d37 LibCore: Add Core::Account for login management.
Core::Account abstracts login semantics like password checking and
switching uid/gid.
2020-09-21 20:18:05 +02:00
asynts
a9f7b576a4 LibCore: Add missing .characters() for String::format. 2020-09-16 20:52:30 +02:00
asynts
3283f5bb5d LibCore: Add find_executable_in_path. 2020-09-16 19:39:17 +02:00
Tom
d67553e128 LibCore: Add Notifier::close
If a file descriptor is being closed, we need to permanently disable
any Notifier and remove it from the event loop. This method removes
the notifier and disables it so that the EventLoop does not use a
invalid file descriptor.
2020-09-16 17:50:43 +02:00
Andreas Kling
e2f32b8f9d LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing
a pretty asymmetric job of implementing the various properties, let's
add a bit of structure here.

Object properties are now represented by a Core::Property. Properties
are registered with a getter and setter (optional) in constructors.
I've added some convenience macros for creating and registering
properties, but this does still feel a bit bulky. We'll have to
iterate on this and see where it goes.
2020-09-15 21:46:26 +02:00
Itamar
7b66469ab3 LibCore: Add command() utility functions
Add utility functions for executing commands and getting their output.
2020-09-15 21:43:29 +02:00
asynts
96edcbc27c AK: Lower the requirements for InputStream::eof and rename it.
Consider the following snippet:

    void foo(InputStream& stream) {
        if(!stream.eof()) {
            u8 byte;
            stream >> byte;
        }
    }

There is a very subtle bug in this snippet, for some input streams eof()
might return false even if no more data can be read. In this case an
error flag would be set on the stream.

Until now I've always ensured that this is not the case, but this made
the implementation of eof() unnecessarily complicated.
InputFileStream::eof had to keep a ByteBuffer around just to make this
possible. That meant a ton of unnecessary copies just to get a reliable
eof().

In most cases it isn't actually necessary to have a reliable eof()
implementation.

In most other cases a reliable eof() is avaliable anyways because in
some cases like InputMemoryStream it is very easy to implement.
2020-09-14 20:58:12 +02:00
Andreas Kling
aa3c28957a LibCore: Include object names in Object::dump_tree() output 2020-09-14 16:16:36 +02:00
pkotzbach
072e94caa2
LibCore: Fixed DeferredInvoke debug message (#3456) 2020-09-11 18:41:50 +02:00
AnotherTest
c3dbe77024 LibCore: Add 'notify_forked()' to tear down the eventloop in forked child
This makes the forked process capable of constructing a new event loop,
should it choose to.
2020-09-09 20:35:21 +02:00
Simon Danner
05be6481b7 LibWeb: make it possible to directly load .svg files
Make LibWeb load svg files by guessing the svg mime type from the file
extension and parsing it with the HTML parser.
2020-09-08 13:57:18 +02:00
Andreas Kling
6d8c4af9c2 LibCore+top: Use pid_t for pgid/pgrp/sid numbers 2020-09-06 19:04:47 +02:00
Andreas Kling
35b844ba4c LibCore: Add Core::IODevice::truncate()
This is just a wrapper around ftruncate(). Today I also learned that
ftruncate() does not reset the file descriptor offset. :^)
2020-09-06 16:09:26 +02:00
asynts
6de63782c7 Streams: Consistent behaviour when reading from stream with error.
The streaming operator doesn't short-circuit, consider the following
snippet:

    void foo(InputStream& stream) {
        int a, b;
        stream >> a >> b;
    }

If the first read fails, the second is called regardless. It should be
well defined what happens in this case: nothing.
2020-09-06 12:54:45 +02:00
asynts
b9a6c07bb7 LibCore: FileStream.h: Fix infinite loop when trying to read past end-of-file. 2020-09-06 12:54:45 +02:00
asynts
612c1bc84d Userland: Use Buffered<T> in gunzip. 2020-09-06 12:54:45 +02:00
asynts
9ce4475907 Streams: Distinguish recoverable and fatal errors. 2020-09-01 17:25:26 +02:00
Sergey Bugaev
852454746e Everywhere: Port to String::copy_characters_to_buffer() 2020-08-30 17:35:27 +02:00
Nico Weber
9ad5a261f7 LibCore: Let DateTime::create()/set_time() take summer time into account
DateTime::create() takes a date/time in local time, but it set
tm_isdst to 0, which meant it was in local winter time always.
Set tm_isdst to -1 so that times during summer time are treated
in summer time, and times in winter time are treated as winter
time (when appropriate). When the time is adjusted backward by
one hour, the same time can be in winter time or summer time,
so this isn't 100% reliable, but for most of the year it should
work fine.

Since LibJS uses DateTime, this means that the Date tuple
ctor (which creates a timestamp from year/month/day/hours/etc
in local time) and getTime() should now have consistent (and
correct) output, which should fix #3327.

In Serenity itself, dst handling (and timezones) are unimplemented
and this doens't have any effect yet, but in Lagom this has an effect.
2020-08-30 16:56:47 +02:00
asynts
9664453739 LibCore: Add InputFileStream and OutputFileStream. 2020-08-30 09:56:10 +02:00
Ben Wiederhake
9f7ec33180 Meta: Force semi-colon after MAKE_AK_NONXXXABLE()
Before, we had about these occurrence counts:
COPY: 13 without, 33 with
MOVE: 12 without, 28 with

Clearly, 'with' was the preferred way. However, this introduced double-semicolons
all over the place, and caused some warnings to trigger.

This patch *forces* the usage of a semi-colon when calling the macro,
by removing the semi-colon within the macro. (And thus also gets rid
of the double-semicolon.)
2020-08-27 10:12:04 +02:00