Commit Graph

2128 Commits

Author SHA1 Message Date
Hediadyoin1
fdef6e5f76 AK: Add FixedPoint arithmetic helper
Co-authored-by: Hendiadyoin1 <leon2002.la@gmail.com>
Co-authored-by: kleines Filmröllchen <malu.bertsch@gmail.com>
2021-08-31 17:03:55 +04:30
Timothy Flynn
587d4663a3 AK: Return early from swap() when swapping the same object
When swapping the same object, we could end up with a double-free error.
This was found while quick-sorting a Vector of Variants holding complex
types, reproduced by the new swap_same_complex_object test case.
2021-08-30 19:42:40 +01:00
Andreas Kling
9fd58fd6d8 AK: Use get_random() in IDAllocator
Also generate a new random ID on collision, instead of using
the old ID + 1. :^)

SonarCloud: https://sonarcloud.io/project/security_hotspots?id=SerenityOS_serenity&hotspots=AXuVPBMNk92xXUF3qWZd
2021-08-30 18:35:36 +02:00
Brian Gianforcaro
1f68b1f768 AK: Add operator delete stub to all AK_MAKE_ETERNAL objects
Static analysis correctly flags that we are missing an implementation
for `operator delete` for all classes which are annotated with
AK_MAKE_ETERNAL. To appease static analysis define an implementation
which asserts to make sure no one ever calls delete on the object.
2021-08-30 16:44:16 +02:00
Brian Gianforcaro
f0b3aa0331 Everywhere: Pass AK::Format TypeErasedFormatParams by reference
This silences a overeager warning in sonar cloud, warning that
slicing could occur with `VariadicFormatParams` which derives from
`TypeErasedFormatParams`.

Reference:
https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPBO_k92xXUF3qWsm&open=AXuVPBO_k92xXUF3qWsm
2021-08-30 15:50:00 +04:30
kleines Filmröllchen
f99e6507ee AK: Add Traits for Enums
Enums can be hashed as their underlying integral type. This allows enum
keys in hash maps etc.
2021-08-27 23:35:27 +04:30
Timothy Flynn
262e412634 AK: Implement method to convert a String/StringView to title case
This implementation preserves consecutive spaces in the orginal string.
2021-08-26 22:04:09 +01:00
Ali Mohammad Pur
355c2eef57 AK: Make explode_byte depend on sizeof(FlatPtr) instead of ARCH(...)
The assumption that FlatPtr is 64-bit on every platform except i686 is
not correct, and also makes the definition of explode_byte() less nice
to look at.
2021-08-26 22:00:17 +02:00
Andreas Kling
c915174563 Userland: Remove IRC Client
The IRC Client application made some sense while our main communication
hub was an IRC channel. Now that we've moved on, IRC is just a random
protocol with no particular relevance to this project.

This also has the benefit of removing one major client of the single-
process Web::InProcessWebView class.
2021-08-24 16:37:28 +02:00
Hendiadyoin1
607bddac96 AK: Use explode_byte for pointer sanitization 2021-08-23 12:30:29 +04:30
Andreas Kling
dea93a8bb9 Kernel: Rename Processor::id() => current_id()
And let id() be the non-static version that gives you the ID of a
Processor object.
2021-08-23 00:02:09 +02:00
Richard Wurth
4b2953125b AK: Use POSIX specified types for Time::to_timespec and to_timeval
The previous implementation assumed 64-bit time_t and 32-bit long,
which is not true on some 32-bit systems
2021-08-22 17:07:11 +02:00
Jesse Buhagiar
2fe5f1528f AK: Use __builtin_bit_cast if available
We now use the compiler's buitin version of bitcast if it's available
instead of just resorting to using the builtin `memcpy`.
2021-08-21 13:48:59 +04:30
Timothy Flynn
fd8ccedf2b AK: Add GenericLexer API to consume an escaped Unicode code point
This parsing is already duplicated between LibJS and LibRegex, and will
shortly be needed in more places in those libraries. Move it to AK to
prevent further duplication.

This API will consume escaped Unicode code points of the form:
    \\u{code point}
    \\unnnn (where each n is a hexadecimal digit)
    \\unnnn\\unnnn (where the two escaped values are a surrogate pair)
2021-08-19 23:49:25 +02:00
Timothy Flynn
02e3633b7f AK: Move FormatParser definition from header to implementation file
This is primarily to be able to remove the GenericLexer include out of
Format.h as well. A subsequent commit will add AK::Result to
GenericLexer, which will cause naming conflicts with other structures
named Result. This can be avoided (for now) by preventing nearly every
file in the system from implicitly including GenericLexer.

Other changes in this commit are to add the GenericLexer include to
files where it is missing.
2021-08-19 23:49:25 +02:00
Timothy Flynn
e331656bb9 AK: Add GenericLexer to forwarding header 2021-08-19 23:49:25 +02:00
Idan Horowitz
95bc8e4641 LibCore: Make DateTime's members signed
Core::DateTime is essentially a C++ wrapper of the tm struct, so we
should support the same signed range as the underlying tm.
2021-08-19 19:15:00 +01:00
Brian Gianforcaro
8e41d96618 AK: Enable IntrusiveList self reference to be optimized out when empty
If a member is an empty class, the standard normally stats that it needs
to have a size of at least 1 byte in order to guarantee that the
addresses of distinct objects of the same type are always distinct.

However as of c++20, we can use [[no_unique_address]] to instruct the
compiler that if the member has an empty type, it may optimize it to
occupy no space.
2021-08-19 08:07:45 +04:30
Brian Gianforcaro
e9d8f158a1 AK+Kernel: StringView hash map Traits should not set peek type to String
This typo / bug in the Traits<T> implementation for StringView caused
AK::HashMap methods to return a `String` when looking up values out of
a hash map of type HashTable<StringView,StringView>.

This change fixes the typo, and fixes the only consumer, the kernel
Commandline class.
2021-08-18 10:21:19 +02:00
Timothy Flynn
c4ee576531 AK: Add Utf8View::byte_offset_of overload for code point index lookups 2021-08-18 09:47:09 +04:30
sin-ack
8269e1a197 AK: Add adopt_nonnull_own_or_enomem
This is basically a complement to adopt_nonnull_ref_or_enomem, and
simplifies boilerplate for try_create functions which just return ENOMEM
or the object based on whether it was able to allocate.
2021-08-15 15:41:02 +02:00
Lenny Maiorani
c27abaabc4 AK: Stop publishing detail namespaced functions
Problem:
- `AK::Detail::integer_sequence_generate_array` is published via a
  `using` directive in the `Array.h` header, but this is a `Detail`
  function.

Solution:
- Remove the `using` declaration.
2021-08-15 15:14:19 +02:00
Andreas Kling
90c7307c6c AK: Pull RefCountedBase into the global namespace 2021-08-15 12:44:35 +02:00
Brian Gianforcaro
a2a5cb0f24 AK: Add Time::is_negative() to detect negative time values 2021-08-15 12:20:38 +02:00
Brian Gianforcaro
3cbc2364a8 AK: Annotate AK::Time APIs as [[nodiscard]] 2021-08-15 12:20:38 +02:00
Brian Gianforcaro
dae17ce7e3 AK: Add Time::now_<clock_id> functions for obtaining the current time
In the quest of removing as timespec / timeval usage in the Userland as
possible, we need a way to conveniently retrieving the current clock
time from the kernel and storing it in `AK::Time` format.
2021-08-15 12:20:38 +02:00
sin-ack
134dbe2607 AK: Add adopt_nonnull_ref_or_enomem
This gets rid of the ENOMEM boilerplate for handling memory allocation
failures in the kernel.
2021-08-15 02:27:13 +02:00
Lenny Maiorani
077e78a8d7 IntrusiveRedBlackTree: Remove redundant subtraction of 0
Problem:
- ToT clang will not build due to casting `nullptr` to `u8*`. This is
  redundant because it casts to get a `0` then subtracts it.

Solution:
- Remove it since subtracting `0` doesn't do anything.
2021-08-13 17:39:33 +04:30
Ali Mohammad Pur
15f95220ae AK+Everywhere: Delete Variant's default constructor
This was exposed to the user by mistake, and even accumulated a bunch of
users that didn't blow up out of sheer luck.
2021-08-13 17:31:39 +04:30
Brian Gianforcaro
f2d684fc24 AK: Annotate String.count as [[nodiscard]] 2021-08-13 11:08:11 +02:00
Ali Mohammad Pur
0f1425c895 AK: Avoid OOB access in UniformBumpAllocator::destroy_all()
Otherwise we would end up calling T::~T() on some random memory right
after our mapped block, which is most likely a pretty bad thing to do :P
2021-08-13 04:42:34 +04:30
Ali Mohammad Pur
c6a137dbac AK: Add a IsSpecializationOf<T, Template> type trait 2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
dcf795085b AK: Don't zero Variant data in the move constructor
There's no reason to zero the data that will be immediately overwritten.
2021-08-12 21:03:53 +02:00
Jean-Baptiste Boric
7a9d05c24c AK: Add contains(char) method to String 2021-08-12 00:41:13 +02:00
Timothy Flynn
daf559c717 AK: Add a formatter overload for Utf16View 2021-08-10 23:07:50 +02:00
Timothy Flynn
c16aca7abf AK+Kernel: Add StringBuilder::append overload for UTF-16 views
Currently, to append a UTF-16 view to a StringBuilder, callers must
first convert the view to UTF-8 and then append the copy. Add a UTF-16
overload so callers do not need to hold an entire copy in memory.
2021-08-10 23:07:50 +02:00
Timothy Flynn
5978caf96b AK: Convert StringBuilder to use east-const 2021-08-10 23:07:50 +02:00
Daniel Bertalan
d000ca1ec3 AK: Add typename keyword for dependent types
This was made optional in C++20 in most cases, but Clang doesn't support
omitting it yet. See P0634R3.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
1472f6d986 AK: Add formatting for infinity and NaN
Without this patch, we would end up printing garbage values when we
encountered floating point infinity or NaN values, and also triggered
UBSAN with Clang. This added code models `std::format`'s behavior: the
sign is added the same way as with normal values and the strings 'nan'
and 'inf' are printed.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
5d32f543ec AK: Handle partial remainders
On x86, the `fprem` and `fmprem1` instructions may produce a 'partial
remainder', for which we should check by reading a FPU flag. If we don't
check for it, we may end up using values that are outside the expected
range of values.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
653d22e21f LibSanitizer+AK: Add float cast overflow handler
This is not enabled by default in GCC, but is in Clang.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
301cab188c AK: Use explode_byte in BumpAllocator.h
When compiling this code with Clang, both branches of the ternary
operator get evaluated at compile-time, triggering a warning about a
narrowing implicit conversion. We can use `explode_byte` instead.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
efd1aea969 AK: Make InputMemoryStream::read_LEB128_* templated
On i686, reading integers larger than `2^32 - 1` would fail as the
32-bit `size_t` parameter would overflow. This caused us to read too few
bytes in LibDebug's DWARF parser. Making this method templated solves
this issue, as we now can call this API with a `u64` parameter.
2021-08-08 10:55:36 +02:00
Andreas Kling
3609ac4cf9 AK: Use kmalloc_array() where appropriate 2021-08-08 00:03:45 +02:00
Andreas Kling
2189524cb3 AK: Add kmalloc_array() to trap multiplication overflows
This pattern is no good:

    kmalloc(elements * sizeof(T));

Since it silently swallows any multiplication overflow.
This patch adds a simple kmalloc_array() that stops the program if
overflow occurs:

    kmalloc_array(elements, sizeof(T));
2021-08-08 00:03:45 +02:00
Andreas Kling
c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
Andreas Kling
eb60cb156d AK: Bring Singleton into the global namespace with using 2021-08-08 00:03:45 +02:00
sin-ack
a2a553b286 AK: Add RecursionDecision
Similar to IterationDecision, this can be returned from callbacks passed
to recursive traversal functions to signal how to proceed.
2021-08-07 15:21:58 +02:00
Timothy
62af82f494 AK: Use east const in MappedFile 2021-08-07 12:48:22 +02:00
Timothy
bc75ca4fe5 AK: Add method to create MappedFile from fd 2021-08-07 12:48:22 +02:00
Jean-Baptiste Boric
786036820b AK: Introduce IntrusiveListRelaxedConst
This container is the same as IntrusiveList, except that it allows
modifications to the elements even if the reference to the
IntrusiveList itself is const, by returning mutable iterators. This
represents a use-case where we want to allow modifications to the
elements while keeping the list itself immutable.

This behavior is explicitely opt-in by using IntrusiveListRelaxedConst
instead of IntrusiveList. It will be useful later on when we model
shared/exclusive locks with the help of const and mutable references.
2021-08-07 11:48:00 +02:00
Lenny Maiorani
2e6fc13b1e AK: Implement any_of using common implementation
Problem:
- `any_of` is implemented in 2 different ways, one for the entire
  container and a different implementation for a partial container
  using iterators.

Solution:
- Follow the "don't repeat yourself" (DRY) idiom and implement the
  entire container version in terms of the partial version.
2021-08-06 23:57:48 +02:00
Andreas Kling
a1d7ebf85a Kernel: Rename Kernel/VM/ to Kernel/Memory/
This directory isn't just about virtual memory, it's about all kinds
of memory management.
2021-08-06 14:05:58 +02:00
TheFightingCatfish
4e8e1b7b3a AK: Improve the parsing of data urls
Improve the parsing of data urls in URLParser to bring it more up-to-
spec. At the moment, we cannot parse the components of the MIME type
since it is represented as a string, but the spec requires it to be
parsed as a "MIME type record".
2021-08-06 10:45:17 +02:00
Ali Mohammad Pur
3829bf115c AK: Make StringBuilder::join() use appendff() instead of append()
`append()` is almost never going to select the overload that is desired.
e.g. it will append chars when you pass it a Vector<size_t>, which is
definitely not the right overload :)
2021-08-06 01:14:03 +02:00
Timothy Flynn
70080feab2 AK+LibJS: Implement String.from{CharCode,CodePoint} using UTF-16 strings
Most of String.prototype and RegExp.prototype is implemented with UTF-16
so this is to prevent extra copying of the string data.
2021-08-04 11:18:24 +02:00
Timothy Flynn
dae7674ca9 AK: Allow configuring the BumpAllocator chunk size 2021-08-04 11:18:24 +02:00
Timothy Flynn
510bbcd8e0 AK+LibRegex: Add Utf16View::code_point_at and use it in RegexStringView
The current method of iterating through the string to access a code
point hurts performance quite badly for very large strings. The test262
test "RegExp/property-escapes/generated/Any.js" previously took 3 hours
to complete; this one change brings it down to under 10 seconds.
2021-08-04 11:18:24 +02:00
sin-ack
bed51d856a AK+Kernel: Print TODO when a TODO() is executed
Previously we would just print "ASSERTION FAILED: false", which was
kinda cryptic and also didn't make it clear whether this was a TODO or
an unreachable condition. Now, we actually print "ASSERTION FAILED:
TODO", making it crystal clear.
2021-08-04 11:01:16 +02:00
Brian Gianforcaro
2dd6d2121a AK: Mark Time::max() / Time::min() / Time::zero() as constexpr
No reason for these static helper functions to not be constexpr.
2021-08-03 18:44:01 +02:00
Lenny Maiorani
97bd13264a Everywhere: Make use of container version of all_of
Problem:
- New `all_of` implementation takes the entire container so the user
  does not need to pass explicit begin/end iterators. This is unused
  except is in tests.

Solution:
- Make use of the new and more user-friendly version where possible.
2021-08-03 10:46:43 +02:00
Timothy Flynn
011514a384 AK: Fix declaration of {String,StringView}::is_one_of
The declarations need to consume the variadic parameters as "Ts&&..."
for the parameters to be forwarding references.
2021-08-02 21:02:09 +04:30
Ali Mohammad Pur
b034fa9f1f AK: Add a simple bump allocator 2021-08-02 17:22:50 +04:30
Ali Mohammad Pur
a08870cc19 AK: Correct Tuple's constructor signatures
Tuple previously required rvalue references, this commit makes it accept
forwarding references instead (which was the intention all along).
2021-08-02 17:22:50 +04:30
sin-ack
05c3755e62 AK: Add formatters for BigEndian and LittleEndian
This allows printing out BigEndian and LittleEndian values without
having to perform a static_cast first.
2021-08-02 00:25:11 +02:00
Sam Atkins
e54531244f LibWeb: Define proper debug symbols for CSS Parser and Tokenizer
You can now turn debug logging for them on using `CSS_PARSER_DEBUG` and
`CSS_TOKENIZER_DEBUG`.
2021-07-31 00:18:11 +02:00
Andreas Kling
58b5a8f3c0 AK: Update mmap name for MappedFiles on SerenityOS
Looking at process memory maps is a lot nicer when you can see the paths
of MappedFile mappings.
2021-07-29 15:01:47 +02:00
Brian Gianforcaro
0bb3d83a48 AK: Add copy_to span method for AK::MACAddress 2021-07-27 01:23:37 +04:30
brapru
7e40c17460 AK: Create MACAddress from string
Previously there was no way to create a MACAddress by passing a direct
address as a string. This will allow programs like the arp utility to
create a MACAddress instance by user-passed addresses.
2021-07-25 17:57:08 +02:00
Lenny Maiorani
2cf4781d14 AK: Reimplement all_of in terms of find_if
Problem:
- Now that a generic free-function form of `find_if` is implemented
  the code in `all_of` is redundant.

Solution:
- Follow the "don't repeat yourself" mantra and make the code DRY by
  implementing `all_of` in terms of `find_if`.
- One tricky part is that since captures are not permitted in
  `constexpr` lambdas, the lambda created to negate the predicate
  needs to be created by a function which does not capture and takes
  the predicate at run-time instead. This allows `all_of` to continue
  to work in a `constexpr` context.
2021-07-24 13:11:13 +04:30
Timothy Flynn
0e6375558d AK+LibRegex: Partially implement case insensitive UTF-16 comparison
This will work for ASCII code points. Unicode case folding will be
needed for non-ASCII.
2021-07-23 23:06:57 +01:00
Timothy Flynn
2e45e52993 AK: Add UTF-16 helper methods required for use within LibRegex
To be used as a RegexStringView variant, Utf16View must provide a couple
more helper methods. It must also not default its assignment operators,
because that implicitly deletes move/copy constructors.
2021-07-23 23:06:57 +01:00
Andreas Kling
3f9e018d9a CrashDaemon: Remove BACKTRACE_DEBUG debugging code
This thing seems to work fine, no need to hang on to old debug code.
2021-07-22 23:34:33 +02:00
Hendiadyoin1
1d74742c29 AK: Add char SIMD types
These are used in intrinsics, which do not recognize any signed version
of the char type
2021-07-22 23:33:21 +02:00
Ali Mohammad Pur
73fc2b3748 AK: Rewrite {AnyOf,AllOf,Find}.h to use the IteratorPairWith concept
This makes it so these algorithms are usable with arbitrary iterators,
as opposed to just instances of AK::SimpleIterator.
This commit also makes the requirement of ::index() in find_index()
explicit, as previously it was accepting any iterator.
2021-07-22 22:56:20 +02:00
Ali Mohammad Pur
2dc31c503e AK: Convert AnyOf/AllOf to east-const style 2021-07-22 22:56:20 +02:00
Ali Mohammad Pur
d40d10aae7 AK: Implement {any,all}_of(IterableContainer&&, Predicate)
This is a generally nicer-to-use version of the existing {any,all}_of()
that doesn't require the user to explicitly provide two iterators.
As a bonus, it also allows arbitrary iterators (as opposed to the hard
requirement of providing SimpleIterators in the iterator version).
2021-07-22 22:56:20 +02:00
Ali Mohammad Pur
f879e04133 AK: Add a concept for iterable containers
This concept describes a type with a begin()/end() pair that can
function as an iterator, given the following criteria:
- The return type of begin() is comparable with the return type of
  end(), and the comparison (with operator!=) yields a bool
- The object returned from begin() can be pre-incremented
- The iterator has an operator*() implementation
2021-07-22 22:56:20 +02:00
Ali Mohammad Pur
2891dca0cd AK: Add a deduction guide to Vector
Note that this does not generate a vector with inline capacity.
2021-07-22 22:56:20 +02:00
Ali Mohammad Pur
6c9ef20010 AK: Add a CommonType<Ts...> type trait
Also adds a simple-ish test for CommonType.
2021-07-22 22:56:20 +02:00
Linus Groh
42b6bffbf2 AK: Make TypeBoundsChecker<UnsignedIntegralT, FloatingPointT> work
By replacing MakeUnsigned<Source> in this specific specialization with a
simple negativity check this now works for floating point source types.
Previously it would attempt a comparison of the destination type and
void.
2021-07-22 21:19:40 +01:00
Timothy Flynn
9b83cd1abf AK: Add Utf16View for decoding UTF-16 strings
Also includes a way to transcode from and to UTF-8 strings.
2021-07-22 09:10:44 +02:00
Gunnar Beutner
bcf5e5ee5a AK: Disable clang-format for AK/Time.h
clang-format >=12 format this file incorrectly/differently.
2021-07-22 08:57:01 +02:00
Gunnar Beutner
11e02f222d AK: Add a getter to JsonValue to get machine-native addresses 2021-07-22 08:57:01 +02:00
Andreas Kling
8ea029405f AK: Sprinkle [[nodiscard]] on AK::Array 2021-07-21 18:22:10 +02:00
Andreas Kling
4b0498e38b AK: Convert Array to east-const style 2021-07-21 18:21:15 +02:00
Andreas Kling
a940a8bf37 AK: Remove unused private HashTable::lookup_for_reading() 2021-07-21 18:18:51 +02:00
Andreas Kling
f65b039c44 AK: Sprinkle [[nodiscard]] on HashMap and HashTable 2021-07-21 18:18:29 +02:00
Andreas Kling
583d6741ed AK: Sprinkle [[nodiscard]] on AK::Bitmap 2021-07-21 18:09:01 +02:00
Andreas Kling
a5c9a31001 AK: Remove unused HashMap::remove_one_randomly() 2021-07-21 18:08:11 +02:00
Hendiadyoin1
ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Hendiadyoin1
c5f6ba6e71 AK: Introduce Math.h
This is to implement constexpr template based implementations for
mathematical functions

This also changes math.cpp to use these implementations.

Also adds a fastpath for floating point trucation for values smaller
than the signed 64 bit limit.
2021-07-19 16:34:21 +04:30
Andrew Kaster
64aac345d3 AK: Use new Formatter for each element in Formatter<Vector<T>>
The state of the formatter for the previous element should be thrown
away for each iteration. This showed up when trying to format a
Vector<String>, since Formatter<StringView> was unhappy about some state
that gets set when it's called. Add a test for Formatter<Vector>.
2021-07-19 05:17:05 +04:30
Andrew Kaster
4842c8c902 AK: Use StringView literals in Format to avoid strlen
We don't want to be constructing StringViews at runtime if we don't have
to in Formatter code.
2021-07-19 05:17:05 +04:30
Ali Mohammad Pur
a245ea1743 AK: Add the at()/operator[]() getter to Utf32View
This is trivial, and makes it easier to get the code point compared to
the previous `.code_points()[index]` (which was not actually checked
for in-bounds length).
2021-07-18 21:10:55 +04:30
Ali Mohammad Pur
55fa51b4e2 AK: Add a is_null() method to Utf{8,32}View
Both of these can be null as well as empty, and there's a difference.
2021-07-18 21:10:55 +04:30
Ali Mohammad Pur
0060fa48d4 AK: Don't return a null Utf32View when a zero-length one is requested
There is still an offset to consider, a zero-length view is very
different from a nonexistent string :P

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2021-07-18 21:10:55 +04:30
Gunnar Beutner
7e94b090fe Kernel: Introduce basic pre-kernel environment
This implements a simple bootloader that is capable of loading ELF64
kernel images. It does this by using QEMU/GRUB to load the kernel image
from disk and pass it to our bootloader as a Multiboot module.

The bootloader then parses the ELF image and sets it up appropriately.
The kernel's entry point is a C++ function with architecture-native
code.

Co-authored-by: Liav A <liavalb@gmail.com>
2021-07-18 17:31:13 +02:00
Sahan Fernando
217415226e AK: Add helper type for serializing structures into buffer 2021-07-18 19:58:17 +04:30
Timothy Flynn
06ddfcde89 AK: Allow setting both width and precision when formatting a string 2021-07-18 02:57:49 +02:00
Timothy Flynn
87848cdf7d AK: Track byte length, rather than code point length, in Utf8View::trim
Utf8View::trim uses Utf8View::substring_view to return its result, which
requires the input to be a byte offset/length rather than code point
length.
2021-07-17 16:59:59 +01:00
Brian Gianforcaro
a2a5af9745 AK: Restrict timespec comparison operator overloads in AK::Time
The previous implementation was too generic, and would cause conflicting
operator overload errors when included in certain code paths. Fix this
by restricting the template parameters to types which have the same
member names as `struct timespec`.
2021-07-17 17:39:12 +04:30
Brian Gianforcaro
6059d69249 AK: Mark RedBlackTree functions as [[nodiscard]] 2021-07-17 13:02:09 +02:00
Brian Gianforcaro
af65c4d8b7 AK: Mark AK::IntrusiveRedBlackTree as final 2021-07-17 13:02:09 +02:00
Brian Gianforcaro
9a6e065b36 AK: Mark AK::IntrusiveList Non copyable and movable 2021-07-17 13:02:09 +02:00
Brian Gianforcaro
deda32628a AK: Mark RedBlackTree as final 2021-07-17 13:02:09 +02:00
Brian Gianforcaro
86b02a678c AK: Mark RedBlackTree find APIs as [[nodiscard]] 2021-07-17 13:02:09 +02:00
Daniel Bertalan
3099a6bf2a Kernel+AK: Generate compile-time error for non-sized delete
This is a much more ergonomic option than getting a
`VERIFY_NOT_REACHED()` failure at run-time. I encountered this issue
with Clang, where sized deallocation is not the default due to ABI
breakage concerns.

Note that we can't simply just not declare these functions, because the
C++ standard states:
> If this function with size parameter is defined, the program shall
> also define the version without the size parameter.
2021-07-16 20:51:13 +02:00
Timothy
9715311837 AK+Kernel: Implement and use EnumBits has_any_flag()
This duplicates the old functionality of has_flag and will return true
when any flags present in the mask are also in the value.
2021-07-16 11:49:50 +02:00
Timothy
03b76e4ba0 AK: Change EnumBits has_flag() to check all flags in mask are present
Co-authored-by: Brian Gianforcaro <b.gianfo@gmail.com>
2021-07-16 11:49:50 +02:00
Daniel Bertalan
4566387ba5 AK: Add workaround for clang-format 12 problems with concepts 2021-07-15 09:26:19 +02:00
Andreas Kling
980f409003 AK: Allow getting the key from a RedBlackTree iterator 2021-07-15 01:48:10 +02:00
Andreas Kling
4ff35c23d3 AK: Make RedBlackTree non-copyable and non-movable 2021-07-15 01:48:09 +02:00
Ali Mohammad Pur
5d170810db AK: Make JsonParser correctly parse unsigned values larger than u32
Prior to this, it'd try to stuff them into an i64, which could fail and
give us nothing.
Even though this is an extension we've made to JSON, the parser should
be able to correctly round-trip from whatever our serialiser has
generated.
2021-07-15 01:47:35 +02:00
Idan Horowitz
e94dfb7355 AK: Expose RedBlackTree allocation failures via try_insert
This should help with using the RedBlackTree in a more OOM-safe way in
the kernel.
2021-07-15 00:49:41 +02:00
Timothy Flynn
d9c2447999 AK: Add free function to wrap around __atomic_is_lock_free built-in
Note: this exact implementation is needed for __atomic_is_lock_free to
link with both GCC (for the SerenityOS build) and Clang (for the Fuzzer
build). The size argument must be a compile-time constant, otherwise it
fails to link with both compilers. Alternatively, the following
definition links with GCC but fails with Clang:

    template<size_t S>
    static inline bool atomic_is_lock_free(volatile void* ptr = nullptr)
    {
        return __atomic_is_lock_free(S, ptr);
    }
2021-07-14 22:13:15 +01:00
Gunnar Beutner
d92548c5b0 AK: Avoid pagefaults when repeatedly enqueing/dequeing items in a Queue
When repeatedly enqueing and dequeing a single item in a Queue we end
up faulting in all the pages for the underlying Vector. This is a
performance issue - especially where the element type is large.
2021-07-14 23:03:36 +02:00
Gunnar Beutner
3ff0a3aa4b AK: Avoid allocations for the Queue class
Previously the Queue class used a SinglyLinkedList to manage its queue
segments. This changes the Queue class to use the IntrusiveList class
instead which saves us one allocation per segment.
2021-07-14 23:03:36 +02:00
Hendiadyoin1
d761c5024b AK: Generalize ByteReader
Also use it instead of CPU.h's possibly_unaligned_data interface
2021-07-14 11:26:34 +04:30
Andreas Kling
be83b3aff4 AK: Make Bitmap::set() non-const 2021-07-13 22:40:25 +02:00
kleines Filmröllchen
1e1fa4eac4 AK: Add Formatter for Vector
For debugging purposes, it is very useful to look at a Vector in a
simple list representation. Therefore, the new Formatter for Vector
provides a string representation of the following form:

```
[ 1, 2, 3, 4, 5 ]
```

This requires the content type of Vector to be formattable with default
arguments.

The current implementation ignores width and precision, which may be
accounted for later or passed down to the content formatter.
2021-07-13 17:40:07 +02:00
ngc6302h
3b81ba7c4f HashMap: Rename finders with a more accurate and self-descripting name 2021-07-13 17:31:00 +02:00
ngc6302h
213e2af281 HashTable: Rename finders with a more accurate and self-descripting name 2021-07-13 17:31:00 +02:00
ngc6302h
de7831153f Vector: Homogenize type and parameter names for predicates 2021-07-13 17:31:00 +02:00
Ali Mohammad Pur
8776f424ac AK: Make Traits<T*> use ptr_hash() and not assume 32-bit pointers
As a nice bonus, it also simplifies the code quite a bit.
2021-07-12 23:49:59 +04:30
Ali Mohammad Pur
ad328f852b AK: Replace all explicit specialisations of Traits with a single one
This commit un-confuses the many specialisations of AK::Traits, and
makes it work correctly for all integral types.
Prior to this, `AK::Traits<size_t>` would've been instantiating the
base Traits implementation, not `Traits<u32>` or `Traits<u64>`.
2021-07-12 23:49:59 +04:30
Idan Horowitz
141c46feda AK: Add a DateTimeLexer
This is an AK::GenericLexer that exposes helper methods for parsing
date and time related literals (years, months, days, hours, minutes,
seconds, fractional seconds & more)
2021-07-12 19:05:17 +01:00
Idan Horowitz
39a9cf4bb4 AK: Add a retreat(count) method to GenericLexer
This method can be used to rewind a constant amount backwards in the
source instead of one by one with retract()
2021-07-12 19:05:17 +01:00
Andrew Kaster
fac4eab415 AK: Add load64 and load_pointer to AK::ByteReader
This lets us load misaligned 64 bit integers, and misaligned pointers
in a platform agnostic way.
2021-07-12 18:42:45 +04:30
Andrew Kaster
1455604b13 AK+Meta: Remove unused AUTOCOMPLETE_DEBUG flag 2021-07-12 12:26:52 +02:00
Andreas Kling
373b8d7cfa AK: Add FixedArray::span() 2021-07-11 17:42:31 +02:00
Andreas Kling
88c8451973 AK: Bring back FixedArray<T>
Let's bring this class back, but without the confusing resize() API.
A FixedArray<T> is simply a fixed-size array of T.

The size is provided at run-time, unlike Array<T> where the size is
provided at compile-time.
2021-07-11 17:42:31 +02:00
Andreas Kling
5087b2b32f AK: Don't forget to kfree_sized() in ByteBuffer 2021-07-11 15:15:57 +02:00
Andreas Kling
25e850ebb1 Kernel: Remove krealloc()
This was only used by a single class (AK::ByteBuffer) in the kernel
and not in an OOM-safe way.

Now that ByteBuffer no longer uses it, there's no need for the kernel
heap to burden itself with supporting this.
2021-07-11 14:14:51 +02:00
Andreas Kling
966880eb45 AK: Don't use realloc() in AK::ByteBuffer
This class is the only reason we have to support krealloc() in the
kernel heap, something which adds a lot of complexity.

Let's move towards a simpler path and do malloc+memset in the
ByteBuffer code (where we know the sizes anyway.)
2021-07-11 14:14:51 +02:00
Andreas Kling
c1e902acd9 AK: Use kfree_sized() in AK::Vector 2021-07-11 14:14:51 +02:00
Andreas Kling
c68c3fa69c AK: Use kfree_sized() in AK::StringImpl 2021-07-11 14:14:51 +02:00
Andreas Kling
3aabace9f5 AK: Use kfree_sized() in AK::HashTable 2021-07-11 14:14:51 +02:00
Andreas Kling
05a00c3978 AK: Use kfree_sized() in AK::ByteBuffer 2021-07-11 14:14:51 +02:00
Andreas Kling
6950dd220b AK: Use kfree_sized() in AK::Bitmap 2021-07-11 14:14:51 +02:00
Andreas Kling
875afb35c3 AK: Make kfree_sized() forward to kfree() in non-kernel code for now 2021-07-11 14:14:51 +02:00
Gunnar Beutner
3e53f4a3de AK: Remove unused NO_RETURN macro 2021-07-10 01:41:57 +02:00
Jan de Visser
a034774e3a LibSQL+SQLServer: Build SQLServer system service
This patch introduces the SQLServer system server. This service is
supposed to be the only process/application talking to database storage.
This makes things like locking and caching more reliable, easier to
implement, and more efficient.

In LibSQL we added a client component that does the ugly IPC nitty-
gritty for you. All that's needed is setting a number of event handler
lambdas and you can connect to databases and execute statements on them.

Applications that wish to use this SQLClient class obviously need to
link LibSQL and LibIPC.
2021-07-08 17:55:59 +04:30
Daniel Bertalan
2ee39ed5f0 AK: Fix UFixedBigInt not building with Clang
Clang does not like that we are trying to refer to our own size while
our declaration is not yet complete, and fails to compile this file.
This is fixed by introducing a function which returns the correct
sizeof. This only gets evaluated in the `requires` clause after the
whole class has been parsed, so it will compile fine.
2021-07-08 10:11:00 +02:00
Daniel Bertalan
714bd011e1 Everywhere: Use the correct literal suffixes
When performing arithmetic with long doubles/floats, we want to avoid
floating point promotion and narrowing.
2021-07-08 10:11:00 +02:00
Daniel Bertalan
c6fafd3e90 AK+Userland: Add generic AK::abs() function and use it
Previously, in LibGFX's `Point` class, calculated distances were passed
to the integer `abs` function, even if the stored type was a float. This
caused the value to unexpectedly be truncated. Luckily, this API was not
used with floating point types, but that can change in the future, so
why not fix it now :^)

Since we are in C++, we can use function overloading to make things
easy, and to automatically use the right version.

This is even better than the LibC/LibM functions, as using a bit of
hackery, they are able to be constant-evaluated. They use compiler
intrinsics, so they do not depend on external code and the compiler can
emit the most optimized code by default.

Since we aren't using the C++ standard library's trick of importing
everything into the `AK` namespace, this `abs` function cannot be
exported to the global namespace, as the names would clash.
2021-07-08 10:11:00 +02:00
Daniel Bertalan
62f84e94c8 AK+Kernel: Fix perfect forwarding constructors shadowing others
If a non-const lvalue reference is passed to these constructors, the
converting constructor will be selected instead of the desired copy/move
constructor.

Since I needed to touch `KResultOr` anyway, I made the forwarding
converting constructor use `forward<U>` instead of `move`. This meant
that previously, if a lvalue was passed to it, a move operation took
place even if no `move()` was called on it. Member initializers and
if-else statements have been changed to match our current coding style.
2021-07-08 10:11:00 +02:00
Max Wipfli
f0fcbb7751 AK: Replace usages of ctype.h with CharacterTypes.h
This replaces all remaining usages of ctype.h in AK with
CharacterTypes.h.
2021-07-07 14:05:56 +02:00
Daniel Bertalan
a482a3e609 AK: Declare operators new and delete as global functions
This fixes a build issue introduced in 23d66fe, where the compiler
statically detected that that mismatching new and delete operators were
used.

Clang generates a warning for this, for the reasons described in the
comment in `AK/kmalloc.cpp`, but GCC does not.

Besides moving the allocator functions into a `.cpp` file, declarations
in `AK/kmalloc.cpp` were reordered to have imports at the top, in order
to make the code more readable.
2021-07-05 20:23:42 +02:00
Hendiadyoin1
9b7e48c6bd Kernel: Replace raw asm functions with naked ones 2021-07-05 16:40:00 +02:00