Commit Graph

905 Commits

Author SHA1 Message Date
AnotherTest
7d0bf9b5a9 Kernel+AK: Separate out MACAddress and move it into AK 2020-04-05 09:50:48 +02:00
Tibor Nagy
1bf93d504f AK: Break on end of input in JsonParser::consume_quoted_string
Fixes #1599
2020-04-04 10:31:01 +02:00
AnotherTest
df7062aac5 AK: Add an overwrite API to ByteBuffer
Since ByteBuffer is a Buffer, it should allow us to overwrite parts of
it that we have allocated.
This comes in useful in handling unsequenced writes like handling
fragmented ip packets :^)
2020-04-03 09:42:13 +02:00
Emanuel Sprung
d0d093fef5 AK: Remove relative path in AK testsuite
With relative filenames in the executable code, the executable is basically not
relocatable. This makes out-of-source builds unneccesery hard. This patchset moves
the relative link into the filesystem: that can be handled much easier :^)
2020-04-03 09:07:19 +02:00
Emanuel Sprung
b995a499d3 AK: Add equals method to JsonValue to semantically compare two values.
This patchsets adds the semantic check of two values. One first approach
was to compare the (generated) json strings of the two values. This works
out in the most cases, but not with numbers, where "1.0" and "1" in JSON
format are semantically the same. Therefore, this patch adds deep (recursive)
check of two JsonValues.
2020-04-01 22:12:19 +02:00
Emanuel Sprung
2577712a1c AK: Add String::replace() functionality
This adds a replace functionality that replaces a string that contains
occurences of a "needle" by a "replacement" value. With "all_occurences"
enabled, all occurences are being replaced, otherwise only the first
occurence is being replaced.
2020-04-01 21:47:23 +02:00
Andreas Kling
806d3d8e79 AK: Add adopt_own() to create a NonnullOwnPtr<T> from a T& 2020-04-01 21:05:35 +02:00
Emanuel Sprung
c54855682c AK: A few JSON improvements
* Add double number to object serializer

* Handle negative double numbers correctly

* Handle \r and \n in quoted strings independently
  This improves the situation when keys contain \r or \n that currently
  has the effect that "a\rkey" and "a\nkey" in an JSON object are the
  same key value.
2020-03-31 13:42:39 +02:00
Emanuel Sprung
c925aaceb2 AK: Print double numbers with printf
This patchset allows double numbers to be printed with the printf function.
The fraction will always be printed as 6 digit number. This can be improved :^)
2020-03-31 13:42:39 +02:00
Itamar
6b74d38aab Kernel: Add 'ptrace' syscall
This commit adds a basic implementation of
the ptrace syscall, which allows one process
(the tracer) to control another process (the tracee).

While a process is being traced, it is stopped whenever a signal is
received (other than SIGCONT).

The tracer can start tracing another thread with PT_ATTACH,
which causes the tracee to stop.

From there, the tracer can use PT_CONTINUE
to continue the execution of the tracee,
or use other request codes (which haven't been implemented yet)
to modify the state of the tracee.

Additional request codes are PT_SYSCALL, which causes the tracee to
continue exection but stop at the next entry or exit from a syscall,
and PT_GETREGS which fethces the last saved register set of the tracee
(can be used to inspect syscall arguments and return value).

A special request code is PT_TRACE_ME, which is issued by the tracee
and causes it to stop when it calls execve and wait for the
tracer to attach.
2020-03-28 18:27:18 +01:00
Andreas Kling
95cc4c7e74 AK: Add some string comparison operators
Some of these are very inefficient. It's nice to have some optimization
opportunities in the future though. :^)
2020-03-28 09:11:13 +01:00
Sergey Bugaev
5bb18bf548 AK: Use print_string() for %c formatting
Instead of simply outputting the character. This way, we get proper padding
support and other niceties strings enjoy.
2020-03-26 08:01:16 +01:00
Andreas Kling
e34fe556ca AK: Fix JsonParser kernel build (no floats/doubles in kernel code) 2020-03-24 22:37:24 +01:00
Emanuel Sprung
bca5762542 AK: Add parsing of JSON double values
This patch adds the parsing of double values to the JSON parser.
There is another char buffer that get's filled when a "." is present
in the number parsing. When number finished, a divider is calculated
to transform the number behind the "." to the actual fraction value.
2020-03-24 22:20:07 +01:00
Emanuel Sprung
45921328e4 AK: Add get_or() method to JsonObject
This allows to retrieve a default value for items thare are not
available in the json object.
2020-03-24 22:20:07 +01:00
Andreas Kling
404de10a15 AK: Add FlyString::is_null() 2020-03-24 16:14:10 +01:00
Andreas Kling
7d862dd5fc AK: Reduce header dependency graph of String.h
String.h no longer pulls in StringView.h. We do this by moving a bunch
of String functions out-of-line.
2020-03-23 13:48:44 +01:00
Andreas Kling
c4a6d6ae9f AK: Add FlyString::to_lowercase() and LogStream operator<<(FlyString) 2020-03-22 19:07:02 +01:00
Andreas Kling
26bc3d4ea0 AK: Add FlyString::equals_ignoring_case(StringView)
And share the code with String by moving the logic to StringUtils. :^)
2020-03-22 13:07:45 +01:00
Andreas Kling
0efa47b7ef AK: Run clang-format on StringUtils.{cpp,h} 2020-03-22 13:04:04 +01:00
Andreas Kling
4f72f6b886 AK: Add FlyString, a simple flyweight string class
FlyString is a flyweight string class that wraps a RefPtr<StringImpl>
known to be unique among the set of FlyStrings. The class is very
unoptimized at the moment.

When to use FlyString:

- When you want O(1) string comparison
- When you want to deduplicate a lot of identical strings

When not to use FlyString:

- For strings that don't need either of the above features
- For strings that are likely to be unique
2020-03-22 13:03:43 +01:00
Andreas Kling
4eef3e5a09 AK: Add StringBuilder::join() for joining collections with a separator
This patch adds a generic StringBuilder::join(separator, collection):

    Vector<String> strings = { "well", "hello", "friends" };
    StringBuilder builder;
    builder.join("+ ", strings);
    builder.to_string(); // "well + hello + friends"
2020-03-20 14:41:23 +01:00
howar6hill
e07f50c398 AK: Add begin() and end() to String and StringView
Now it's possible to use range-based for loops with String and StringView.
2020-03-10 10:25:21 +01:00
Andreas Kling
b956e2d939 AK: Remove all the AK .host.o files on "make clean" in AK/Tests
This is a bit hackish, but sometimes these files stick around and mess
up rebuilds.
2020-03-08 21:40:40 +01:00
howar6hill
6da131d5db AK: Reduce code duplication in StringBuilder 2020-03-08 17:08:18 +01:00
howar6hill
d8df9c510c AK: Improve the API of StringBuilder 2020-03-08 17:08:18 +01:00
Liav A
0433c0780d AK: Use default constructor of Optional if an unset bit is not found 2020-03-08 14:13:30 +01:00
Andreas Kling
32f15f3c45 AK: Remove unused InlineLRUCache template
This was not used by anyone. If we ever need it, we can bring it back.
2020-03-08 13:13:34 +01:00
Andreas Kling
900f51ccd0 AK: Move memory stuff (fast memcpy, etc) to a separate header
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h.
This will break a ton of things that were relying on StdLibExtras.h
to include a bunch of other headers. Fix will follow immediately after.

This makes it possible to include StdLibExtras.h from Types.h, which is
the main point of this exercise.
2020-03-08 13:06:51 +01:00
Andreas Kling
35d88f536c AK: Use __builtin_memset() and such to reduce header dependencies
We can use __builtin_memset() without including <string.h>.
This is pretty neat, as it will allow us to reduce the header deps
of AK templates a bit, if applied consistently.

Note that this is an enabling change for an upcoming #include removal.
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
Andreas Kling
b98d8ad5b0 AK: Add a Conditional<condition, TrueType, FalseType> template
This allows you to select a type based on a compile-time condition.
2020-03-08 13:06:51 +01:00
Andreas Kling
b866582d98 AK: Fix all the warnings in the AK tests 2020-03-06 11:22:23 +01:00
Andreas Kling
8bb361889c AK: Remove Optional::operator bool()
This was causing some obvious-in-hindsight but hard to spot bugs where
we'd implicitly convert the bool to an integer type and carry on with
the number 1 instead of the actual value().
2020-03-06 10:32:58 +01:00
Andreas Kling
dc039fdc7e AK: Simplify JsonObject and JsonArray API a little bit
Instead of set(const JsonValue&) and set(JsonValue&&), just do
set(JsonValue) and let callers move() if they want. This removes some
ambiguity and the compiler is smart enough to optimize it anyway.
2020-03-06 08:51:22 +01:00
Andreas Kling
783c99516a AK: LogStream should handle being passed a null const char* 2020-03-04 21:04:06 +01:00
Andreas Kling
686ade6b5a AK: Make quick_sort() a little more ergonomic
Now it actually defaults to "a < b" comparison, instead of forcing you
to provide a trivial less-than comparator. Also you can pass in any
collection type that has .begin() and .end() and we'll sort it for you.
2020-03-03 16:02:58 +01:00
Liav A
9440c45d6e AK: Add support for Kernel Log Stream 2020-03-02 22:23:39 +01:00
Andreas Kling
214f934465 Meta: Adjust some copyright dates by Fei Wu 2020-03-02 14:24:25 +01:00
Andreas Kling
f5b78c2a1c AK: Add missing copyright headers to StringUtils.{cpp,h} 2020-03-02 14:23:11 +01:00
howar6hill
d75fa80a7b
AK: Move to_int(), to_uint() implementations to StringUtils (#1338)
Provide wrappers in String and StringView. Add some tests for the
implementations.
2020-03-02 14:19:33 +01:00
howar6hill
055344f346 AK: Move the wildcard-matching implementation to StringUtils
Provide wrappers in the String and StringView classes, and add some tests.
2020-03-02 10:38:08 +01:00
howar6hill
2a30a020c1
AK: Add enqueue_begin() for the CircularDeque class (#1320)
Also add tests for CircularDeque.
2020-03-02 09:50:43 +01:00
howar6hill
4ed2ba264d
AK: Remove superfluous explicit in Bitmap (#1337) 2020-03-02 09:50:22 +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
Andreas Kling
dcd619bd46 Kernel: Merge the shbuf_get_size() syscall into shbuf_get()
Add an extra out-parameter to shbuf_get() that receives the size of the
shared buffer. That way we don't need to make a separate syscall to
get the size, which we always did immediately after.
2020-02-28 12:55:58 +01:00
Andreas Kling
a1514369d7 LibC: Move shbuf_* API's to <serenity.h> 2020-02-28 12:55:58 +01:00
Andreas Kling
f72e5bbb17 Kernel+LibC: Rename shared buffer syscalls to use a prefix
This feels a lot more consistent and Unixy:

    create_shared_buffer()   => shbuf_create()
    share_buffer_with()      => shbuf_allow_pid()
    share_buffer_globally()  => shbuf_allow_all()
    get_shared_buffer()      => shbuf_get()
    release_shared_buffer()  => shbuf_release()
    seal_shared_buffer()     => shbuf_seal()
    get_shared_buffer_size() => shbuf_get_size()

Also, "shared_buffer_id" is shortened to "shbuf_id" all around.
2020-02-28 12:55:58 +01:00
howar6hill
a19967d5c3 Tests: Fix a typo inTestRefPtr 2020-02-27 21:16:02 +01:00
William McPherson
121e7306c3 AK: Expose SinglyLinkedListIterator constructor
This commit replaces SinglyLinkedListIterator::universal_end() with an
empty SinglyLinkedListIterator(). Piano needs this in order to
initialize a member array of iterators without 84 lines of
universal_end().
2020-02-27 10:21:13 +01:00
howar6hill
a57f074187 CircularQueue: Move construct a T object instead of copy constructing it 2020-02-26 15:22:45 +01:00
Andreas Kling
6824cb17a6 AK: Have AK/kmalloc.h #include <new> on other platforms
This should make stuff like placement new work correctly when building
outside of Serenity. This stuff is a bit delicate due to the weirdly
staged toolchain build at the moment. Hopefully we can unify this stuff
in the future.
2020-02-25 15:58:24 +01:00
Andreas Kling
00e744c263 AK: Provide a ptr_hash(const void*) overload 2020-02-25 15:37:07 +01:00
joshua stein
7e6ac544f7 AK: Add ptr_hash to use int_hash or u64_hash depending on pointer size 2020-02-25 15:32:58 +01:00
Andreas Kling
960cae924a AK: Some more int => size_t in Bitmap 2020-02-25 15:11:15 +01:00
Andreas Kling
fbe4081f4b AK: Make Queue use size_t for its size 2020-02-25 14:55:04 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Emanuel Sprung
074d935c6e AK, LibGfx, LibGUI: Initialize various variables to zero.
The not initialized variables can lead to compiler warnings that
become errors with the -Werror flag.
2020-02-25 10:18:46 +01:00
Andreas Kling
17846dd063 AK: Zero-initialize the internal storage of Optional 2020-02-24 10:22:27 +01:00
Andreas Kling
0763f67043 AK: Make Bitmap use size_t for its size
Also rework its API's to return Optional<size_t> instead of int with -1
as the error value.
2020-02-24 09:56:07 +01:00
Andreas Kling
b813b2f871 AK: Make HashTable and HashMap use size_t for size and capacity 2020-02-24 09:42:52 +01:00
Shannon Booth
ba9313111f AK: Add StringBuilder::is_empty() 2020-02-22 21:36:54 +01:00
Shannon Booth
854f0b9e1a AK: Add StringView::starts_with(char) & StringView::ends_with(char)
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
2020-02-22 21:36:54 +01:00
Andreas Kling
c4c1ad2289 Toolchain: Build demangling into LibC except during toolchain build 2020-02-21 18:54:57 +01:00
Andreas Kling
7592f9afd5 AK: Use size_t for CircularQueue and CircularDeque 2020-02-20 13:20:34 +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
Andreas Kling
23a54636ea AK: Fix bug where "%s" with field width would print too many characters
I introduced this while implementing "%.*s", oops.
2020-02-19 23:02:15 +01:00
Andreas Kling
151467b569 AK: Support "%.*s" in format strings
Work towards #623.
2020-02-19 22:08:13 +01:00
Liav A
01ae3e9c85 AK: Use endianness flags to determine if conversion is necessary 2020-02-19 16:08:28 +01:00
Andreas Kling
a7dbb3cf96 Kernel: Use a FixedArray for a process's extra GIDs
There's not really enough of these to justify using a HashTable.
2020-02-18 11:35:47 +01:00
Sergey Bugaev
bf8dacf0c1 Kernel: Add placement new[] operator 2020-02-18 11:23:27 +01:00
Andreas Kling
48f7c28a5c Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now
Thread::current and Process::current respectively. :^)
2020-02-17 15:04:27 +01:00
Andreas Kling
a6e69bda71 AK: Add basic Traits for RefPtr
This allows RefPtr to be stored in a HashTable<RefPtr<T>> :^)

It's unfortunate about the const_casts. We'll need to fix HashMap::get
to play nice with non-const Traits<T>::PeekType at some point.
2020-02-16 21:58:17 +01:00
Andreas Kling
02e199a9cb AK: Don't construct a String every time we LogStream<< a number 2020-02-16 12:48:58 +01:00
Kaif Mavani
fa21c7e8bf
AK: Fixed a typo in NeverDestroyed.h (#1228) 2020-02-16 09:32:18 +01:00
Andreas Kling
e61cdf5c39 AK: Add HashMap, HashTable and Traits to Forward.h 2020-02-16 02:01:18 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
d42f0f4661 AK: Add missing include in CircularQueue.h 2020-02-16 01:27:25 +01:00
Andreas Kling
f27a646bf5 AK: Don't bring in LibBareMetal's kstdio.h in userspace 2020-02-15 19:18:56 +01:00
Andreas Kling
b515ea454f AK: Make sure that Weakable always has the same memory layout
Weakable objects ended up with differing memory layouts in some ports
since they don't build with the DEBUG macro defined.

Instead of forcing ports to define DEBUG, just put this behind a custom
WEAKABLE_DEBUG macro and leave it always-on for now.
2020-02-15 14:49:57 +01:00
Andreas Kling
175cd4d9c2 AK: Fix broken #include statement 2020-02-15 13:28:33 +01:00
Andreas Kling
dc417ada6d AK: Add BufferStream to Forward.h 2020-02-15 12:10:48 +01:00
Shannon Booth
9920d17342 AK: Add String starts_with(char) & ends_with(char)
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
2020-02-15 11:40:05 +01:00
Andreas Kling
d85b09893d AK: Add Utf8View to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
22b41a0fa3 AK: Add LogStream and DebugLogStream to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
184475d45a AK: Add SharedBuffer to Forward.h 2020-02-14 23:31:18 +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
3bbf4610d2 AK: Add a forward declaration header
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.

Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
2020-02-14 23:31:18 +01:00
Andreas Kling
3e486f75ff AK: Move escape_html_entities() from LibHTML to AK
This sort of thing can be useful to things that don't want to link with
all of LibHTML.
2020-02-13 08:46:00 +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
Liav A
8bdb08c354 AK: Apply changes for the Bootstrapper environment 2020-02-09 19:38:17 +01:00
Andreas Kling
80b1af2352 AK: Make StringBuilder::to_string() non-destructive
This was an artifact of an earlier design of StringBuilder where I had
attempted to preserve the same allocation from build to final String.
2020-02-09 14:15:55 +01:00
Andreas Kling
745ea2a0ef AK: Add JsonObjectSerializer::add(key, bool) overload
Without this, bools will get implicitly converted to integers, which is
usually not what we want.
2020-02-08 02:48:27 +01:00
Andreas Kling
a7e72f78cd AK: Make PrintfImplementation treat %lld as 64-bit 2020-02-08 01:43:05 +01:00
Andreas Kling
28a5e33134 AK: Add LogStream overloads for long and long long 2020-02-08 01:41:43 +01:00
Andreas Kling
9afda55d73 AK: Add some missing "inline" keywords in JsonObject.h 2020-02-06 19:32:17 +01:00
Andreas Kling
939a605334 AK: Add missing StdLibExtras.h include in Optional.h 2020-02-06 11:55:19 +01:00
Andreas Kling
0cff25ac78 AK+IPCCompiler: Get rid of BufferStream overloads for size_t
Since BufferStream is about creating specific binary stream formats,
let's not have a flaky type like size_t in there. Instead, clients of
BufferStream can cast their size_t to the binary size they want to use.

Account for this in IPCCompiler by making String lengths always 32-bit.
2020-02-05 19:13:44 +01:00
Andreas Kling
be0034d2ca AK: Break LogStream::operator<< overloads into i/l/ll and u/ul/ull 2020-02-05 19:13:44 +01:00
Andreas Kling
90b1dafeff AK: Break String::number() overloads into i/l/ll and u/ul/ull
Now that we're trying to be more portable, we can't only rely on using
i32/u32 and i64/u64 since different systems have different combinations
of int/long/long long and unsigned/unsigned long/unsigned long long.
2020-02-05 19:13:44 +01:00
joshua stein
0c4c5b5eb7 AK: Support 64-bit integers in BufferStream 2020-02-05 18:39:45 +01:00
joshua stein
dc93ed4368 AK: Add support for 64-bit size_t 2020-02-05 18:39:45 +01:00
Andreas Kling
c600280dde AK: The <cxxabi.h> header is not available during Toolchain build
This will need some refinement, but basically since we build LibC
during the toolchain build, we don't have libstdc++ headers yet.
2020-02-03 06:27:54 +01:00
Andreas Kling
8ccf0e16a9 AK: Turn demangling back on for userspace
This didn't work at some point, but now it apparently works again. :^)
2020-02-02 20:15:58 +01:00
Andreas Kling
ab57db2bf1 AK: #ifdef out the contents of SharedBuffer on other platforms 2020-02-01 20:18:53 +01:00
Andreas Kling
268000e166 AK: Always inline StringView(const char*)
Also use strlen() instead of manually walking the string. This allows
GCC to optimize away the strlen() entirely for string literals. :^)
2020-02-01 13:54:13 +01:00
Andreas Kling
276b6a4372 AK: Add some integer overloads to JsonObjectSerializer
This avoids constructing a temporary JsonValue just to append an int.
2020-02-01 10:56:17 +01:00
William McPherson
ddefb95b21 AK: Add FixedArray::data() 2020-01-31 13:13:04 +01:00
Marios Prokopakis
da296f5865 Ext2FS: allocate_blocks allocates contiguous blocks (#1095)
This implementation uses the new helper method of Bitmap called
find_longest_range_of_unset_bits. This method looks for the biggest 
range of contiguous bits unset in the bitmap and returns the start of
the range back to the caller.
2020-01-26 09:48:24 +01:00
Andreas Kling
603bf6fb4a Build: Remove -fno-sized-deallocation -Wno-sized-deallocation
Add sized variants of the global operator delete functions so we don't
have to use these GCC options anymore.
2020-01-25 16:59:21 +01:00
Andreas Kling
003d52ce6e AK: Vector::is_null() should always return false
This is only used by the somewhat dubious templated String::copy().
An empty Vector should generate an empty String when copied, never
a null String.
2020-01-25 12:14:59 +01:00
Andreas Kling
3f52cee595 AK: Assert if trying to create a WeakPtr to an object being destroyed
Trying to make_weak_ptr() on something that has begun destruction is
very unlikely to be what you want. Let's assert if that scenario comes
up so we can catch it immediately.
2020-01-25 10:34:32 +01:00
Sergey Bugaev
c0b32f7b76 Meta: Claim copyright for files created by me
This changes copyright holder to myself for the source code files that I've
created or have (almost) completely rewritten. Not included are the files
that were significantly changed by others even though it was me who originally
created them (think HtmlView), or the many other files I've contributed code to.
2020-01-24 15:15:16 +01:00
Andreas Kling
ca413a5b50 AK: Use swap-based assignment in OwnPtr
Also provide a specialized swap(OwnPtr, OwnPtr) that allows swapping
an OwnPtr with itself.
2020-01-24 09:35:55 +01:00
Andreas Kling
3de5439579 AK: Let's call decrementing reference counts "unref" instead of "deref"
It always bothered me that we're using the overloaded "dereference"
term for this. Let's call it "unreference" instead. :^)
2020-01-23 15:14:21 +01:00
Andreas Kling
d66bbc21ce AK: Unbreak FileSystemPath after String::split() changes
FileSystemPath(".") should not have a title(). This was caught by the
unit test for FileSystemPath, yay! :^)
2020-01-22 22:35:12 +01:00
Sergey Bugaev
6a64077ed7 AK: Also add a keep_empty argument to String::split[_limit]()
Just like String[View]::split_view() has already.
2020-01-22 21:22:23 +01:00
Andreas Kling
f38cfb3562 Kernel: Tidy up debug logging a little bit
When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.

This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
2020-01-21 16:16:20 +01:00
Andreas Kling
2309029cb4 AK: Allow clamp() with min==max 2020-01-20 13:49:05 +01:00
Andreas Kling
e07b34b9b8 Kernel+AK: Add/fix uintptr_t and intptr_t definitions
We should move towards using uintptr_t instead of u32 for pointers
everywhere, to prepare for an eventual 64-bit port.
2020-01-20 13:13:03 +01:00
Shannon Booth
de74458f13 AK: Add clamp() function
This function can be used to more cleanly write the common operation of
clamping a value between two values.
2020-01-20 10:35:12 +01:00
Andreas Kling
d394267f50 AK: Add NonnullOwnPtr::swap() as well for symmetry 2020-01-19 16:03:57 +01:00
Andreas Kling
ad3f931707 Kernel: Optimize VM range deallocation a bit
Previously, when deallocating a range of VM, we would sort and merge
the range list. This was quite slow for large processes.

This patch optimizes VM deallocation in the following ways:

- Use binary search instead of linear scan to find the place to insert
  the deallocated range.

- Insert at the right place immediately, removing the need to sort.

- Merge the inserted range with any adjacent range(s) in-line instead
  of doing a separate merge pass into a list copy.

- Add Traits<Range> to inform Vector that Range objects are trivial
  and can be moved using memmove().

I've also added an assertion that deallocated ranges are actually part
of the RangeAllocator's initial address range.

I've benchmarked this using g++ to compile Kernel/Process.cpp.
With these changes, compilation goes from ~41 sec to ~35 sec.
2020-01-19 13:29:59 +01:00
Andreas Kling
502626eecb AK: Teach Vector::insert() to use memmove() for trivial types 2020-01-19 12:15:43 +01:00
Andreas Kling
109727082c AK: Support '+' qualifier in printf() to force sign for positive %d's 2020-01-19 11:00:02 +01:00
Andreas Kling
39b3c0ef7e AK: Make it possible to swap() a NonnullRefPtr with itself
The generic swap() is not able to swap a NonnullRefPtr with itself,
due to its use of a temporary and NonnullRefPtr asserting when trying
to move() from an already move()'d instance.
2020-01-19 10:33:26 +01:00
Andreas Kling
604c5cb98e AK: Add some missing "inline" keywords in StdLibExtras.h 2020-01-19 10:33:26 +01:00
Andreas Kling
7ea264a660 AK: NonnullRefPtr should allow assigning owner to ownee
Given the following situation:

    struct Object : public RefCounted<Object> {
        RefPtr<Object> parent;
    }

    NonnullRefPtr<Object> object = get_some_object();
    object = *object->parent;

We would previously crash if 'object' was the only strongly referencing
pointer to 'parent'. This happened because NonnullRefPtr would unref
the outgoing pointee before reffing the incoming pointee.

This patch fixes that by implementing NonnullRefPtr assignments using
pointer swaps, just like RefPtr already did.
2020-01-18 14:40:04 +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
Andreas Kling
c6e552ac8f Kernel+LibELF: Don't blindly trust ELF symbol offsets in symbolication
It was possible to craft a custom ELF executable that when symbolicated
would cause the kernel to read from user-controlled addresses anywhere
in memory. You could then fetch this memory via /proc/PID/stack

We fix this by making ELFImage hand out StringView rather than raw
const char* for symbol names. In case a symbol offset is outside the
ELF image, you get a null StringView. :^)

Test: Kernel/elf-symbolication-kernel-read-exploit.cpp
2020-01-16 22:11:31 +01:00
Andreas Kling
575664cda3 AK: Add Vector::unstable_remove(index)
This removes an item at an index without preserving the sort order of
the Vector.

This enables constant-time removal from unsorted Vectors, as it avoids
shifting all of the entries following the removed one.
2020-01-15 19:25:58 +01:00
Sergey Bugaev
499612482b AK: Fix String[View]::split_view() returning an extra empty part
If the last character was the separator and keep_empty is true, the
previous if statement would have already appended the last empty part,
so no need to do this again.

This was even more problematic, because the result of split_view() is
expected to consist of true substrings that are usable with the
StringView::substring_view_starting_*_substring() methods, not of
equal strings located elsewhere.

Fixes https://github.com/SerenityOS/serenity/issues/970
See https://github.com/SerenityOS/serenity/pull/938
2020-01-14 12:24:19 +01:00
Sergey Bugaev
7ad9bfbc68 AK: Don't return null from String[View]::substring_view()
We expect the result to be usable with the
StringView::substring_view_starting_*_substring() methods.

See https://github.com/SerenityOS/serenity/pull/938
2020-01-14 12:24:19 +01:00
Andrew Kaster
9681d41bf0 AK: Add ArmedScopeGuard, a scope guard that can be disarmed 2020-01-13 13:03:30 +01:00
Andreas Kling
61e6b1fb7c AK: Run clang-format on Atomic.h
Also use <AK/Types.h> instead of <stddef.h>
2020-01-12 18:45:13 +01:00
Andreas Kling
c48acafcba AK: Add assertions to FixedArray::operator[]
Let's catch ourselves if we ever index out of bounds into one of these.
2020-01-07 14:49:33 +01:00
Conrad Pankoff
c7fd39f3b1 AK: Add dirname() to FileSystemPath 2020-01-07 12:36:30 +01:00
Shannon Booth
4a6605bbe5 AK: Fix test compile warnings
These warnings are pretty harmless, but warnings nonetheless.
2020-01-06 10:43:00 +01:00
Shannon Booth
d4fa8e4b00 AK+Demos+Libraries: Remove executable permissions from {.cpp,.h} files 2020-01-06 10:43:00 +01:00
Andreas Kling
1da31ce8ae LibCore: IDAllocator should never vend ID 0
This was tripping up CObject which interprets timer ID 0 as "no timer".
Once we got ID 0 assigned, it was impossible to turn it off and it
would fire on every event loop iteration, causing CPU churn.
2020-01-05 15:13:55 +01:00
Shannon Booth
861f40f014 AK+LibCore: Add an IDAllocator and use to allocate timer ids 2020-01-05 09:00:05 +01:00
Shannon Booth
d5fea1b235 AK: Add a u64 Trait type
This allows u64s to be used in HashMaps.
2020-01-05 09:00:05 +01:00
Andreas Kling
6dec88c7fa AK: Allow copying a Vector from a Vector with different inline capacity 2020-01-04 10:57:30 +01:00
joshua stein
d61131945d Build: HOST_CXX -> USE_HOST_CXX
Allow HOST_CXX to be passed to make which will be the actual host
C++ compiler used, such as 'make HOST_CXX=clang++'.
2020-01-02 21:03:53 +01:00
joshua stein
f06d0da39f Build: AK/Tests: use Makefile.common 2020-01-01 22:21:50 +01:00
Andreas Kling
fc86460134 AK: Move the userspace SharedBuffer from LibC to AK
This always felt out-of-place in LibC.
2020-01-01 18:53:34 +01:00
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