Commit Graph

627 Commits

Author SHA1 Message Date
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