Commit Graph

709 Commits

Author SHA1 Message Date
Andrew Kaster
c24fe710d7 AK: Turn off demangler in userland
For some reason, the default CXXFLAGS and such don't get us the
__cxa_demangle symbol in userland.
2020-01-01 17:48:41 +01:00
Andreas Kling
a88d409c74 AK: Use stack buffers in String::number() to avoid some malloc() calls 2019-12-30 14:52:27 +01:00
Andreas Kling
7011dba98e AK: Add JsonObject::get_ptr() for copy-free lookup
This variant of get() returns a const JsonValue* instead of a JsonValue
and can be used when you want to peek into a JsonObject's member fields
without making copies.
2019-12-30 14:49:45 +01:00
Andreas Kling
821484f170 AK: Fix JSON parser crashing when encountering UTF-8
The mechanism that caches the most recently seen string for each first
character was indexing into the cache using a 'char' subscript. Oops!
2019-12-29 22:20:21 +01:00
Shannon Booth
24bc674d94 AK: Add StringView::ends_with function 2019-12-29 22:04:22 +01:00
Andreas Kling
80556e6111 AK: Unbreak Tests Makefile. Turns out this newline was effectful :^) 2019-12-28 21:41:32 +01:00
joshua stein
0b501335f5 Build: wrap make invocations with flock(1)
Lock each directory before entering it so when using -j, the same
dependency isn't built more than once at a time.

This doesn't get full -j parallelism though, since one make child
will be sitting idle waiting for flock to receive its lock and
continue making (which should then do nothing since it will have
been built already).  Unfortunately there's not much that can be
done to fix that since it can't proceed until its dependency is
built by another make process.
2019-12-28 21:09:33 +01:00
Valtteri Koskivuori
5d1acdda82 AK: Fix unused parameter bug in SinglyLinkedList (#928) 2019-12-27 10:29:28 +01:00
Conrad Pankoff
fe3311d458 AK: Simplify const T& versions of append/insert in SinglyLinkedList 2019-12-27 02:15:45 +01:00
Conrad Pankoff
13cf7e76b9 AK: Add insert_{before,after}(iterator, value) to SinglyLinkedList 2019-12-27 02:15:45 +01:00
Andreas Kling
f607cab235 AK: Add NeverDestroyed<T>, for things that should never be destroyed
This template allows you to define static globals without having them
destroyed on exit.
2019-12-26 22:12:45 +01:00
Andreas Kling
11d49aedd8 AK: Add Vector::remove_all_matching() 2019-12-22 18:29:12 +01:00
Andreas Kling
96cfddb3ac AK: Add IntrusiveList::take_first() 2019-12-22 12:38:01 +01:00
Andrew Kaster
aa0ee0e407 AK: InlineLinkedListIterator operator-> should return m_node directly
Little typo here. Don't think many people use this iterator :)
2019-12-22 09:07:47 +01:00
Andreas Kling
44bc4008b7 Build: Get rid of the USERLAND define
Let's simplify things. There is now only KERNEL.
To see if you're on Serenity, check if __serenity__ is defined.
2019-12-20 22:59:11 +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
Hüseyin ASLITÜRK
86c6fec890 AK: Add Vector::find_first_index(const T&) 2019-12-19 10:34:33 +01:00
Andreas Kling
e3c0e75055 AK: Add String::equals_ignoring_case(StringView) 2019-12-18 12:43:53 +01:00
Andreas Kling
fe874bc455 JsonValue: Fix wrong return type of as_u32() and friends 2019-12-12 21:17:26 +01:00
Andreas Kling
9641f74310 AK: Teach URL::complete_url() how to resolve URL's starting with "/" 2019-12-10 21:13:00 +01:00
Andreas Kling
7248c34e35 AK: SinglyLinkedList::size_slow() should return size_t 2019-12-09 17:51:21 +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
1726c17d0d AK: Handle LogStream operator<<(size_t)
This has been an annoyingly missing feature for some time.
2019-12-09 17:51:21 +01:00
William McPherson
aa8b40dce6 Shell: Cache PATH for faster tab completion
This patch reduces the O(n) tab completion to something like O(log(n)).
The cache is just a sorted vector of strings and we binary search it to
get a string matching our input, and then check the surrounding strings
to see if we need to remove any characters. Also we no longer stat each
file every time.

Also added an #include in BinarySearch since it was using size_t. Oops.

If `export` is called, we recache. Need to implement the `hash` builtin
for when an executable has been added to a directory in PATH.
2019-12-05 17:09:22 +01:00
Sergey Bugaev
cf7910fc1e AK: Implement %n printf specifier
This is a special specifier that does not output anything to the stream,
but saves the number of already output chars to the provided pointer.

This is apparently used by GNU Nano.
2019-12-05 12:29:11 +01:00
Andreas Kling
8f80879676 AK: StringView::lines() should keep empty lines 2019-12-02 20:41:15 +01:00
Andreas Kling
61f298faf3 AK: Add DoublyLinkedList::prepend()
Also make it possible to remove() with a value-type Iterator.
2019-12-02 18:36:10 +01:00
William McPherson
d7177212fd AK: Add a BinarySearch template implementation
binary_search takes a haystack, a size, a needle and a compare function.
The compare function should return negative if a < b, positive if a > b
and 0 if a == b. The "sane default" compare function is integral_compare
which implements this with subtraction a - b.
binary_search returns a pointer to a matching element, NOT necessarily
the FIRST matching element. It returns a nullptr if the element was not
found.

This patch includes tests for binary_search.
2019-12-02 15:30:45 +01:00
Tommy Nguyen
2eb5793d55 LibMarkdown: Handle CRLF line endings
Previously, MDDocument only split on Unix-style line endings. This adds
a new function to StringView which handles LF, CR and CRLF.
2019-12-02 13:52:42 +01:00
Andreas Kling
7aaea085de AK: Allow BufferStream to serialize/deserialize floats 2019-12-02 09:19:56 +01:00
Andreas Kling
f75a6b9daa Kernel: Demangle kernel C++ symbols correctly again
I broke this while implementing module linking. Also move the actual
demangling work to AK, in AK::demangle(const char*)
2019-11-29 14:59:15 +01:00
Andreas Kling
a91c17c0eb AK: Add a query string component to URL
It's missing query string parsing from new URLs, but you can set the
query string programmatically, and it will be part of the URL when
serialized through to_string().
2019-11-25 21:21:27 +01:00
Andreas Kling
0405ab91aa LibHTML+AK: Move URL completion from Document to AK::URL
Completing a relative URL based on a base URL seems like generally
useful functionality.
2019-11-19 17:46:36 +01:00
Andreas Kling
39e2b69153 AK: Atomic.h needs <stddef.h> for ptrdiff_t 2019-11-16 12:18:25 +01:00
Andreas Kling
e89cdd504c AK: Fix leak in WeakPtr(WeakPtr&&) and WeakPtr::operator=(WeakPtr&&)
We were forgetting to adopt the WeakLink, causing a reference leak.
This ended up costing us one allocation per exec(), with this stack:

    kmalloc_impl()
    Inode::set_vmo()
    InodeVMObject::create_with_inode()
    Process::do_exec()
    Process::exec()
    Process::sys$execve()

This was a pain to track down, in the end I caught it by dumping out
every live kmalloc pointer between runs and diffing the sets. Then it
was just a matter of matching the pointer to a call stack and looking
at what went wrong. :^)
2019-11-15 16:07:39 +01:00
Andreas Kling
d016d5e365 HackStudio: Start fleshing out the GUI for a GUI designer :^)
I'll be reconstructing parts of the VisualBuilder application here and
then we can retire VisualBuilder entirely once all the functionality
is available in HackStudio.
2019-11-09 00:41:00 +01:00
Andreas Kling
870be9d71e AK: Add Vector::take(index)
This removes an item from the vector and returns it.
2019-11-07 20:38:33 +01:00
Andreas Kling
68e23bca3f AK: Delete operator!() and operator bool() from the Nonnull pointers
Since NonnullRefPtr and NonnullOwnPtr cannot be null, it is pointless
to convert them to a bool, since it would always be true.

This patch makes it an error to null-check one of these pointers.
2019-11-07 18:00:05 +01:00
Andreas Kling
6a8695e759 AK: Add Vector::prepend(T&&) 2019-11-07 10:35:13 +01:00
Andreas Kling
9a5e065229 AK: Always rebuild unit tests if AK headers change
This is a hack to avoid failing AK unit tests because it didn't even
try to rebuild.
2019-11-06 19:14:34 +01:00
Andreas Kling
e33bbdb6ba AK: Remove unused AK::not_implemented()
Whatever this was supposed to be, it was ironically... not implemented.
2019-11-06 13:58:08 +01:00
Andreas Kling
49635e62fa LibELF: Move AK/ELF/ into Libraries/LibELF/
Let's arrange things like this instead. It didn't feel right for all of
the ELF handling code to live in AK.
2019-11-06 13:42:38 +01:00
Andreas Kling
2ad0ec325a AK: Get rid of TStyle (output styling helper for LogStream)
This didn't end up getting used, so let's get rid of it.
2019-11-06 11:37:03 +01:00
Andreas Kling
4623811ec3 AK: Let's just log unimplemented printf() format strings
It's too dang frustrating that we actually crash whenever we hit some
unimplemented printf specifier. Let's just log the whole format string
and carry on as best we can.
2019-11-04 20:48:30 +01:00
Andreas Kling
8c45891c80 AK: Allow overriding the Queue segment size with a template parameter 2019-11-03 12:33:51 +01:00
Andreas Kling
78a744da77 AK: Add Queue::head()
This returns a const T& for the first element in the queue, without
dequeuing it.
2019-11-03 12:09:19 +01:00
Andreas Kling
a1ea3754a3 AK: Handle '%llu' in printf() (unsigned 64-bit integer)
I got a warning when using '%Q' since that's non-standard. This patch
makes our printf family accept '%llu'.
2019-11-02 10:35:08 +01:00
Andreas Kling
014f8ca8c4 AK: Allow JsonValue to store 64-bit integers internally
Add dedicated internal types for Int64 and UnsignedInt64. This makes it
a bit more straightforward to work with 64-bit numbers (instead of just
implicitly storing them as doubles.)
2019-10-29 16:36:50 +01:00
Andreas Kling
01c6088789 AK: Add String::contains(String)
This is just a wrapper around strstr() for now. There are many better
ways to search for a string within a string, but I'm just adding a nice
API at the moment. :^)
2019-10-28 19:08:48 +01:00
Andreas Kling
93dff5df34 AK: Add JsonArray::ensure_capacity()
This is helpful for anyone who knows up-front how many items are gonna
be appended to the JsonArray.
2019-10-23 14:55:21 +02:00
Andreas Kling
0cea80218d AK: Make it possible to store complex types in a CircularQueue
Previously we would not run destructors for items in a CircularQueue,
which would lead to memory leaks.

This patch fixes that, and also adds a basic unit test for the class.
2019-10-23 12:27:43 +02:00
Andreas Kling
835496375f URL: https:// URLs should default to port 443 2019-10-21 17:19:17 +02:00
Andreas Kling
9c434d8c6a JsonObject: Add JsonObject::has(key) 2019-10-21 14:47:18 +02:00
Andreas Kling
b74a433809 URL: Unbreak the serialization test
http:// URLs no longer include ":80" when serialized, since port 80 is
implied by the protocol. Non-standard ports are still serialized.
2019-10-21 14:46:36 +02:00
Andrew Kaster
138abb9098 ELF: Fail layout when program header hooks return nullptr (#673)
ELFLoader::layout() had a "failed" variable that was never set. This
patch checks the return value of each hook (alloc/map section and tls)
and fails the load if they return null.

I also needed to patch Process so that the alloc_section_hook and 
map_section_hook actually return nullptr when allocating a region fails.

Fixes #664 :)
2019-10-20 16:24:42 +02:00
Drew Stratford
67041f3a8c AK: Add CircularDeque.
This class inherits from CircularQueue and adds the ability dequeue
from the end of the queue using dequeue_end().

Note that I had to make some of CircularQueue's fields protected to
properly implement dequeue_end.
2019-10-20 10:51:12 +02:00
Andreas Kling
96f9e6a64f String: Define operator>(String) 2019-10-19 20:54:47 +02:00
Andreas Kling
f4e6dae6fe UTF-8: Add Utf8CodepointIterator::codepoint_length_in_bytes()
This allows you to retrieve the length (in bytes) of the codepoint the
iterator is currently pointing at.
2019-10-18 22:49:23 +02:00
Andreas Kling
ab9e6166e8 AK: Add String::hash() 2019-10-18 17:17:47 +02:00
Andreas Kling
f1f928670e URL: Parse URLs that lack a path (e.g "http://serenityos.org") 2019-10-17 23:39:31 +02:00
Tom
b0773a8ea6 AK: Add Atomic.h
Use gcc built-in atomics
2019-10-12 19:30:59 +02:00
Andreas Kling
bf5a65d934 URL: No need to include ":80" when serializing http:// URLs 2019-10-10 22:06:25 +02:00
Andreas Kling
a7f538fb63 AK: Make String compile on platforms where size_t==u32
This kind of thing is a bit annoying. On Serenity, size_t is the same
size as u32, but not the same type. Because of "long" or whatever.
This patch makes String not complain about duplicate overloads.
2019-10-07 10:56:44 +02:00
Andreas Kling
d64c054d25 AK: URL should support file:// URL's
Also add some setters since this class was very setter-less.
2019-10-05 10:14:42 +02:00
Andreas Kling
9e7560fae9 AK: Make Bitmap constructors public to allow make<Bitmap>()
I don't love this, but I also don't love the Bitmap class in general.
2019-10-01 19:58:07 +02:00
Andreas Kling
4bfd4dc6c7 AK: Remove empty files JsonArray.cpp and JsonObject.cpp 2019-10-01 11:24:54 +02:00
Andreas Kling
8f45a259fc ByteBuffer: Remove pointer() in favor of data()
We had two ways to get the data inside a ByteBuffer. That was silly.
2019-09-30 08:57:01 +02:00
Andreas Kling
99fc7033b5 AK: Add StringBuilder::length() and trim(int)
Sometimes you want to trim a byte or two off the end.
2019-09-29 16:20:09 +02:00
Sergey Bugaev
08d9883306 AK: Add StringBuilder::string_view() and StringBuilder::clear()
The former allows you to inspect the string while it's being built.
It's an explicit method rather than `operator StringView()` because
you must remember you can only look at it in between modifications;
appending to the StringBuilder invalidates the StringView.

The latter lets you clear the state of a StringBuilder explicitly, to
start from an empty string again.
2019-09-28 18:29:42 +02:00
Sergey Bugaev
127d168def AK: Add a keep_empty argument to String[View]::substring{_view} 2019-09-28 18:29:42 +02:00
Andreas Kling
7f9a33dba1 Kernel: Make Region single-owner instead of ref-counted
This simplifies the ownership model and makes Region easier to reason
about. Userspace Regions are now primarily kept by Process::m_regions.

Kernel Regions are kept in various OwnPtr<Regions>'s.

Regions now only ever get unmapped when they are destroyed.
2019-09-27 14:25:42 +02:00
Andreas Kling
9c3c117f05 ELF: Make code a little more buildable on other platforms
Patch from Anonymous.
2019-09-27 13:30:23 +02:00
Andreas Kling
0c72e0c09f AK: Add AK_MAKE_NONMOVABLE 2019-09-22 00:17:29 +02:00
Andreas Kling
1c692e87a6 Kernel: Move kmalloc() into a Kernel/Heap/ directory 2019-09-16 09:01:44 +02:00
Andreas Kling
9f99e285d1 Utf8View: Don't print potentially unterminated string in debug message 2019-09-15 15:46:40 +02:00
Andreas Kling
09e89cc55d Revert "AK: Made Strings reversible"
This reverts commit 26e81ad574.

We forgot to consider UTF-8 here. String is UTF-8 and we need to be
careful about things like this.
2019-09-13 14:37:25 +02:00
Jesse Buhagiar
26e81ad574 AK: Made Strings reversible
`AK::String` can now be reversed via AK::String::reverse(). This makes
life a lot easier for functions like `itoa()`, where the output
ends up being backwards. Very much not like the normal STL
(which requires an `std::reverse` object) way of doing things.

A call to reverse returns a new `AK::String` so as to not upset any
of the possible references to the same `StringImpl` shared between
Strings.
2019-09-13 13:54:07 +02:00
MinusGix
a574e1ab84 TestStringView: Add test for starts_with 2019-09-13 09:22:30 +02:00
MinusGix
05f641a5a9 StringView: Add starts_with method 2019-09-13 09:22:30 +02:00
Andreas Kling
81caf95136 printf: %w, %b, and %p should be zero-padded but not left-padded
This fixes the goofy issue with %p coming out as "     0x123" instead
of "0x00000123".
2019-09-11 20:08:11 +02:00
Andreas Kling
1427c20f6a AK: Add LogStream operator<< for ByteBuffer 2019-09-11 19:35:14 +02:00
Andreas Kling
5cd04a6ad8 AK: Add String::number(size_t) overload 2019-09-11 18:58:33 +02:00
Sergey Bugaev
1fb6a7d893 AK: Fix buffer overrun in Utf8CodepointIterator::operator++
The old implementation tried to move forward as long as the current
byte looks like a UTF-8 character continuation byte (has its two
most significant bits set to 10). This is correct as long as we assume
the string is actually valid UTF-8, which we do (we also have a separate
method that can check whether it is the case).

We can't, however, assume that the data after the end of our string
is also valid UTF-8 (in fact, we're not even allowed to look at data
outside out string, but it happens to a valid memory region most of
the time). If the byte after the end of our string also has its most
significant bits set to 10, we would move one byte forward, and then
fail the m_length > 0 assertion.

One way to fix this would be to add a length check inside the loop
condition. The other one, implemented in this commit, is to reimplement
the whole function in terms of decode_first_byte(), which gives us
the length as encoded in the first byte. This also brings it more
in line with the other functions around it that do UTF-8 decoding.
2019-09-08 17:45:10 +02:00
Conrad Pankoff
9273589c5e AK: Pad %b and %w to two and four places in printf 2019-09-08 08:49:29 +02:00
Andreas Kling
ec6bceaa08 Kernel: Support thread-local storage
This patch adds support for TLS according to the x86 System V ABI.
Each thread gets a thread-specific memory region, and the GS segment
register always points _to a pointer_ to the thread-specific memory.

In other words, to access thread-local variables, userspace programs
start by dereferencing the pointer at [gs:0].

The Process keeps a master copy of the TLS segment that new threads
should use, and when a new thread is created, they get a copy of it.
It's basically whatever the PT_TLS program header in the ELF says.
2019-09-07 15:55:36 +02:00
Andreas Kling
bcfdf9ffa7 AK: Add a useful align_up_to(value, power_of_two) function 2019-09-07 15:39:26 +02:00
Andreas Kling
d10ca2b010 AK: When printf assert on unsupported specifier, specify which one!
We were asserting without saying why. That's a bit unhelpful. :^)
2019-09-06 20:27:58 +02:00
Andreas Kling
73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Andreas Kling
fb39e46d3d Utf8View: Try fixing the travis-ci build
There's some overload ambiguity when doing Utf8View("literal")
2019-09-05 19:06:39 +02:00
Sergey Bugaev
55197ed4ef AK: Log UTF-8 validation errors 2019-09-05 16:37:39 +02:00
Sergey Bugaev
c379f43d2a AK: Add some more utility methods to Utf8View 2019-09-05 16:37:39 +02:00
Andreas Kling
cc98ea1956 Json: Add serializer fast-path for string values
Passing these through the generic JsonValue path was causing us to
instantiate temporary JsonValues that incurred a heap allocation.
This avoids that by adding specialized overloads for string types.
2019-09-04 14:40:11 +02:00
Conrad Pankoff
87808e535a AK: Fix printf %x padding and %p length 2019-09-03 15:23:13 +02:00
Conrad Pankoff
40daefd3dc AK: Abort on unknown printf formatting characters
Right now if we encounter an unknown character, printf (and its related
functions) fail in a really bad way, where they forget to pull things off
the stack. This usually leads to a crash somewhere else, which is hard to
debug.

This patch makes printf abort as soon as it encounters a formatting
character that it can't handle. This is not the optimal solution, but it
is an improvement for debugging.
2019-09-02 08:29:21 +02:00
Conrad Pankoff
a92939b766 AK: Support %i as an alias for %d in printf 2019-09-02 08:28:31 +02:00
Conrad Pankoff
4a4e66b2d0 Kernel/AK: Add is_zero helpers for IP and MAC addresses 2019-08-29 06:25:06 +02:00
Sergey Bugaev
5d3696174b AK: Add a Utf8View type for iterating over UTF-8 codepoints
Utf8View wraps a StringView and implements begin() and end() that
return a Utf8CodepointIterator, which parses UTF-8-encoded Unicode
codepoints and returns them as 32-bit integers.

This is the first step towards supporting emojis in Serenity ^)
https://github.com/SerenityOS/serenity/issues/490
2019-08-28 13:46:02 +02:00
Conrad Pankoff
970e0147f7 AK: Make printf %x actually work properly
When printing hex numbers, we were printing the wrong thing sometimes. This
was because we were dividing the digit to print by 15 instead of 16. Also,
dividing by 16 is the same as shifting four bits to the right, which is a
bit closer to our actual intention in this case, so let's use a shift
instead.
2019-08-28 06:43:04 +02:00
Sergey Bugaev
216b7b3b80 JSON: Port JsonArray and JsonObject serialization to serializers
This way, primitive JsonValue serialization is still handled by
JsonValue::serialize(), but JsonArray and JsonObject serialization
always goes through serializer classes. This is no less efficient
if you have the whole JSON in memory already.
2019-08-27 14:56:09 +02:00
Sergey Bugaev
56f5c14d86 JSON: Add JSON serializers
These are two new types that allow serializing JSON on-the-fly
as it's generated, without building the whole JSON in memory
first.
2019-08-27 14:56:09 +02:00
Andreas Kling
e29fd3cd20 Kernel: Display virtual addresses as V%p instead of L%x
The L was a leftover from when these were called linear addresses.
2019-08-26 11:31:58 +02:00
Andreas Kling
8f50d75184 AK: Make HashTable.h compile inside the SDL2 port 2019-08-25 17:47:48 +02:00
Andreas Kling
d38bd3935b AK: Add StringView::hash()
This grabs the hash from the underlying StringImpl if there is one,
otherwise it's computed on the fly.
2019-08-25 06:45:31 +02:00
Andreas Kling
bb32fd8bfa AK: Add HashMap::find() with customizable finder callback
This will allow clients to search the map without having to instantiate
a key value.
2019-08-25 06:45:27 +02:00
Andreas Kling
cd8278e489 AK: Add String::operator==(StringView)
Comparing a String to a StringView would instantiate a temporary
String just for the comparison. Let's not do that. :^)
2019-08-25 06:45:19 +02:00
Andreas Kling
a00419ed77 AK: Optional::operator bool() should consume the Optional
We use consumable annotations to catch bugs where you get the .value()
of an Optional before verifying that it's okay.

The bug here was that only has_value() would set the consumed state,
even though operator bool() does the same job.
2019-08-25 06:45:09 +02:00
Andreas Kling
56eaf9b033 AK: Make FileSystemPath better at handling relative paths
Relative paths now canonicalize into a string starting with "./"
Previously, "foo" would be canonicalized as "/foo" which was clearly
not right.
2019-08-23 19:58:16 +02:00
Andreas Kling
a5cdd0afa5 NonnullPtrVector: Add ptr_at() getters for accessing the NonnullPtr
Normally you want to access the T&, but sometimes you need to grab at
the NonnullPtr, for example when moving it out of the Vector before
a call to remove(). This is generally a weird pattern, but I don't have
a better solution at the moment.
2019-08-19 19:04:52 +02:00
Andreas Kling
5465795dc3 AK: The printf family was mixing up case and alternate form settings 2019-08-18 16:14:21 +02:00
Andreas Kling
e3f3c980bf IntrusiveList: Make Iterator::operator* return a T&
This makes iteration a little more pleasant :^)
2019-08-17 11:25:32 +02:00
Andreas Kling
5122caf9a8 LogStream: Prefix userspace dbg() output with "ProcessName(PID): "
Using the new get_process_name() syscall, we can automatically prefix
all userspace debug logging.

Hopefully this is more helpful than annoying. We'll find out! :^)
2019-08-15 20:55:45 +02:00
Andreas Kling
d64e698bf1 AK: Add a simple TriState type
enum class TriState : u8 { False, True, Unknown };
2019-08-15 20:53:12 +02:00
Andreas Kling
2349dc1a21 StringView: Add StringView::operator==(StringView)
Previously we'd implicitly convert the second StringView to a String
when comparing two StringViews, which is obviously not what we wanted.
2019-08-15 14:09:27 +02:00
Andreas Kling
eaa9cf58f5 AK: Use int_hash() to generate less idiotic hashes for {Nonnull,}OwnPtr 2019-08-14 21:21:15 +02:00
Andreas Kling
1ac963b5c8 JsonParser: "" is an empty string, not a null value 2019-08-14 15:01:42 +02:00
Andreas Kling
fdcff7d15e AK: Make it possible to use HashMap<K, NonnullOwnPtr>::get()
Add the concept of a PeekType to Traits<T>. This is the type we'll
return (wrapped in an Optional) from HashMap::get().

The PeekType for OwnPtr<T> and NonnullOwnPtr<T> is const T*,
which means that HashMap::get() will return an Optional<const T*> for
maps-of-those.
2019-08-14 11:47:38 +02:00
Andreas Kling
f75b1127b2 OwnPtr: Add a way to turn an OwnPtr into a NonnullOwnPtr
Okay, so, OwnPtr<T>::release_nonnull() returns a NonnullOwnPtr<T>.
It assumes that the OwnPtr is non-null to begin with.

Note that this removes the value from the OwnPtr, as there can only be
a single owner.
2019-08-14 11:04:19 +02:00
Conrad Pankoff
06743932b8 AK: Support width/alt/caps/padding modifiers for %x in printf 2019-08-13 18:15:58 +02:00
Andreas Kling
2c7b0b8893 Vector: Use memcpy to implement remove() for trivial types
This is a lot faster than the generic code path.
Also added some unit testing for this.
2019-08-12 11:07:31 +02:00
Andreas Kling
fb636389d6 URL: Add some convenience constructors 2019-08-10 19:31:37 +02:00
Andreas Kling
ed43770b2f AK: Add a basic URL class to help us handle URL's
We're gonna need these as we start to write more networking programs.
2019-08-10 17:30:35 +02:00
Sergey Bugaev
79f867238a printf: Support dynamic fill widths
The printf formatting mini-language actually allows you
to pass a '*' character in place of the fill width specification,
in which case it eats one of the passed in arguments and uses it
as width, so implement that.
2019-08-10 08:46:22 +02:00
Andreas Kling
865a1b913c AK: Add Optional<T>(const U&)
This replaces Optional<T>(U&&) which clang-tidy complained may hide the
regular copy and move constructors. That's a good point, clang-tidy,
and I appreciate you pointing that out!
2019-08-08 18:34:59 +02:00
Andreas Kling
bb9909548b AK: Add an iterator class for InlineLinkedList
This makes it possible to iterate over these with range-for. :^)
2019-08-08 13:39:40 +02:00
Andreas Kling
9889d170b9 JsonValue: Add as_string_or(String)
Return the contained string if the value *is* a string, otherwise it
returns the alternative string passed in the parameter.
2019-08-07 22:03:25 +02:00
Andreas Kling
f6998b1817 JSON: Templatize the JSON serialization code
This makes it possible to use something other than a StringBuilder for
serialization (and to produce something other than a String.) :^)
2019-08-07 21:29:32 +02:00
Andreas Kling
43ec733b61 AK: Add a basic unit test for FileSystemPath
Just to make sure that things are on the up-and-up.
2019-08-07 21:07:02 +02:00
Andreas Kling
2e416b1b87 Vector: Add a test for growing a Vector beyond its inline capacity 2019-08-07 20:43:13 +02:00
Andreas Kling
5096eaa845 AK: Add a FixedArray<T> container
This is a simple array wrapper that knows its size. It has begin/end
so you can use range-for. It also has a resize() that reallocates.
2019-08-07 20:05:36 +02:00
Andreas Kling
5487f81b5d Vector: Use memcpy when dynamically growing Vectors of trivial types 2019-08-07 15:35:23 +02:00
Andreas Kling
6da6ca64d2 Vector: Use TypedTransfer in more parts of Vector
Make more Vector-of-trivial-type operations go fast :^)
2019-08-07 15:25:34 +02:00
Andreas Kling
e8e85f5457 Vector: Use memcmp for comparing two vectors with trivial elements 2019-08-07 15:05:10 +02:00
Andreas Kling
6d97caf124 JsonParser: Scan ahead to find the first special char in quoted strings
This allows us to take advantage of the now-optimized (to do memmove())
Vector::append(const T*, int count) for collecting these strings.

This is a ~15% speedup on the load_4chan_catalog benchmark.
2019-08-07 11:57:51 +02:00
Andreas Kling
b48b6c0caa Vector: Use memmove() for moving trivial types around more
This can definitely be improved with better trivial type detection and
by using the TypedTransfer template in more places.

It's a bit annoying that we can't get <type_traits> in Vector.h since
it's included in the toolchain compilation before we have libstdc++.
2019-08-07 11:55:20 +02:00
Andreas Kling
60c25228ee AK: Fix -Wconsumed warnings in Optional move-ctor and move-assign
Our protocol says we have to call has_value() before release_value().
The code was already safe, but the compiler had no way of knowing that.
2019-08-07 07:17:52 +02:00
Andreas Kling
2abfab2892 ELFLoader: Remove an uninteresting debug log message
This is showing up at the boundary between kernel and userspace stack
frames in backtraces, and looks silly.
2019-08-06 20:49:36 +02:00
Conrad Pankoff
73c998dbfc Kernel: Refactor TCP/IP stack
This has several significant changes to the networking stack.

* Significant refactoring of the TCP state machine. Right now it's
  probably more fragile than it used to be, but handles quite a lot
  more of the handshake process.
* `TCPSocket` holds a `NetworkAdapter*`, assigned during `connect()` or
  `bind()`, whichever comes first.
* `listen()` is now virtual in `Socket` and intended to be implemented
  in its child classes
* `listen()` no longer works without `bind()` - this is a bit of a
  regression, but listening sockets didn't work at all before, so it's
  not possible to observe the regression.
* A file is exposed at `/proc/net_tcp`, which is a JSON document listing
  the current TCP sockets with a bit of metadata.
* There's an `ETHERNET_VERY_DEBUG` flag for dumping packet's content out
  to `kprintf`. It is, indeed, _very debug_.
2019-08-06 16:21:17 +02:00
Andreas Kling
151e6a1818 AK: Fix leak in Optional(Optional&&)
We were *copying* the other Optional's value and then marking it as not
having a value. This prevented us from ever destroying the original.
2019-08-05 22:27:47 +02:00
Andreas Kling
9553ecfe01 AK: Optional::operator=(Optional&&) should clear movee's has_value bit
We were forgetting to clear m_has_value in the Optional being moved
from when using operator=(Optional&&).
2019-08-05 21:47:36 +02:00
Sergey Bugaev
55d7810fab AK: Do not keep an open FD in MmappedFile
We only need an open FD while establishing the mapping,
and can close it immediately after mmap() call.
2019-08-05 16:04:31 +02:00
Andreas Kling
0d0230ab10 JsonParser: Fold extract_while() into parse_number()
It wasn't unsed anywhere else anyway, and this is actually ~1% faster
on the load_4chan_catalog benchmark.
2019-08-04 20:23:46 +02:00
Andreas Kling
a846ee76ea AK: Add VectorIterator::index()
A simple helper function that extracts the index of an iterator.
Note that the index is not valid if the iterator is end().
2019-08-04 20:18:18 +02:00
Andreas Kling
2a89bb2ac4 Vector: Add find() and some iterator improvements
Vector now has find() just like HashTable. I also made the iterator
comparison functions const-correct.
2019-08-04 19:21:08 +02:00
Andreas Kling
539985f4fe HashTable: Use the Bucket type in some places over SinglyLinkedList<T>
This is just for consistency, and we might want to switch to another
bucket type some day.
2019-08-04 19:20:20 +02:00
Andreas Kling
72b69b82bb JsonParser: Oops, fix build. 2019-08-04 18:59:06 +02:00
Andreas Kling
4e004a664f JsonParser: Cache the last seen string starting with each possible char
Keep a 256-entry string cache during parse to avoid creating some new
strings when possible. This cache is far from perfect but very cheap.
Since none of the strings are transient, this only costs us a couple of
pointers and a bit of ref-count manipulation.

The cache hit rate on 4chan_catalog.json is ~33% and the speedup on
the load_4chan_catalog benchmark is ~7%.
2019-08-04 18:41:24 +02:00
Andreas Kling
3eb1a7f8f8 AK: Add a benchmark for parsing 4chan catalog JSON
I was able to get parsing time down to about 1/3 of the original time
by using callgrind+kcachegrind. There's definitely more improvements
that can be made here, but I'm gonna be happy with this for now. :^)
2019-08-04 11:57:32 +02:00
Andreas Kling
b62a12c687 JsonParser: Some minor optimizations
- Return more specific types from parse_array() and parse_object().
- Don't create a throwaway String in extract_while().
- Use a StringView in parse_number() to avoid a throwaway String.
2019-08-04 11:47:21 +02:00
Andreas Kling
93596dc00d JsonObject: Add move constructors for JsonObject(Json{Array,Object}&&)
This also helps avoid JsonValue copying during parse.
2019-08-04 11:46:31 +02:00
Andreas Kling
82826104e0 Json: Add efficient copy and move constructors for Json{Array,Object}
This helps avoid copying JsonValues during parsing.
2019-08-04 11:45:16 +02:00