summaryrefslogtreecommitdiff
path: root/Kernel/KBuffer.h
AgeCommit message (Collapse)Author
2021-07-03Kernel: Fix always-true comparison warningsDaniel Bertalan
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-05-29Kernel: Make KBuffer APIs OOM safeBrian Gianforcaro
2021-05-28Kernel: Use KString for Region namesAndreas Kling
Replace the AK::String used for Region::m_name with a KString. This seems beneficial across the board, but as a specific data point, it reduces time spent in sys$set_mmap_name() by ~50% on test-js. :^)
2021-05-13Kernel: Make KBuffer::try_create_with* APIs OOM safeBrian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-10Kernel: Add non-const KBuffer::impl() getterAndreas Kling
2021-03-08Kernel: Make MemoryManager API type-safe for Region::Access enumBrian Gianforcaro
Increase type-safety moving the MemoryManager APIs which take a Region::Access to actually use that type instead of a `u8`. Eventually the actually m_access can be moved there as well, but I hit some weird bug where it wasn't using the correct operators in `set_access_bit(..)` even though it's declared (and tested). Something to fix-up later.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-15Kernel: Mark KBuffer and its getters as [[nodiscard]]Brian Gianforcaro
There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-14Kernel: Assert if rounding-up-to-page-size would wrap around to 0Andreas Kling
If we try to align a number above 0xfffff000 to the next multiple of the page size (4 KiB), it would wrap around to 0. This is most likely never what we want, so let's assert if that happens.
2021-02-14Kernel: Remove user/kernel flags from RegionAndreas Kling
Now that we no longer need to support the signal trampolines being user-accessible inside the kernel memory range, we can get rid of the "kernel" and "user-accessible" flags on Region and simply use the address of the region to determine whether it's kernel or user. This also tightens the page table mapping code, since it can now set user-accessibility based solely on the virtual address of a page.
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2021-01-03Kernel: Improve ProcFS behavior in low memory conditionsTom
When ProcFS could no longer allocate KBuffer objects to serve calls to read, it would just return 0, indicating EOF. This then triggered parsing errors because code assumed it read the file. Because read isn't supposed to return ENOMEM, change ProcFS to populate the file data upon file open or seek to the beginning. This also means that calls to open can now return ENOMEM if needed. This allows the caller to either be able to successfully open the file and read it, or fail to open it in the first place.
2021-01-02Kernel: Allocate profiling memory upfrontTom
We need to allocate all pages for the profiler right away so that we don't trigger page faults in the timer interrupt handler to allocate them. Fixes #4734
2021-01-01Kernel: Merge PurgeableVMObject into AnonymousVMObjectTom
This implements memory commitments and lazy-allocation of committed memory.
2020-12-23Kernel: Make KBuffer::try_create_with_bytes() actually copy the bytesAndreas Kling
KBuffers created with this API were actually just zero-filled instead of being populated with the provided bytes. Fixes #4493.
2020-12-18Kernel: Add KBuffer::try_create_with_bytes()Andreas Kling
Here's another fallible KBuffer construction API that creates a KBuffer and populates it with a range of bytes.
2020-12-18Kernel: Add KBuffer::try_create_with_size()Andreas Kling
We need to stop assuming that KBuffer allocation always succeeds. This patch adds the following API: - static OwnPtr<KBuffer> KBuffer::create_with_size(size_t); All KBuffer clients should move towards using this (and handling any failures with grace.)
2020-08-11Kernel: Make Inode::read_entire() return a KBuffer (not ByteBuffer)Andreas Kling
ByteBuffer is backed by kmalloc heap memory which is a scarce resource. This fixes an OOM panic when traversing a large directory.
2020-03-23AK: Reduce header dependency graph of String.hAndreas Kling
String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line.
2020-03-08Kernel: Add missing #includes now that <AK/StdLibExtras.h> is smallerAndreas Kling
2020-02-23Kernel: Commit the entire region up front in KBuffer::copy()Andreas Kling
Since we know exactly how much physical memory we'll need, we might as well commit it up front instead of letting page faults drive it.
2020-02-21Kernel: Expose the underlying Region of a KBufferAndreas Kling
2020-02-16Kernel: Add forward declaration headerAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-01-20Kernel: Allow naming KBuffersAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
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.
2019-12-25Kernel: Make kernel memory regions be non-executable by defaultAndreas Kling
From now on, you'll have to request executable memory specifically if you want some.
2019-09-27Kernel: Make Region single-owner instead of ref-countedAndreas Kling
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-08-24KBuffer: capacity() should return internal capacity, not internal sizeAndreas Kling
KBuffer is just meant to be a dumb wrapper around KBufferImpl. With this change, we actually start to see KBuffers with different size and capacity, which allows some reallocation-avoiding optimizations.
2019-08-06Kernel: Make KBuffer lazily populatedAndreas Kling
KBuffers are now zero-filled on demand instead of up front. This means that you can create a huge KBuffer and it will only take up VM, not physical pages (until you access them.)
2019-08-06KBuffer: Add set_size() and LogStream operator<<Andreas Kling
It will be useful to be able to set the "public" size of a KBuffer. It can still have a different amount of memory allocated internally.
2019-08-05Kernel: Use KBuffers for ProcFS and SynthFSAndreas Kling
Instead of generating ByteBuffers and keeping those lying around, have these filesystems generate KBuffers instead. These are way less spooky to leave around for a while. Since FileDescription will keep a generated file buffer around until userspace has read the whole thing, this prevents trivially exhausting the kmalloc heap by opening many files in /proc for example. The code responsible for generating each /proc file is not perfectly efficient and many of them still use ByteBuffers internally but they at least go away when we return now. :^)
2019-08-05Kernel: Add a little comment header about KBufferAndreas Kling
2019-08-05Kernel: Make KBuffer a value-type wrapper around a KBufferImplAndreas Kling
A KBuffer always contains a valid KBufferImpl. If you need a "null" state buffer, use Optional<KBuffer>. This makes KBuffer very easy to work with and pass around, just like ByteBuffer before it.
2019-08-04Kernel: Add KBuffer, a simple byte buffer backed by kernel-only memoryAndreas Kling
This memory is not accessible to userspace and comes from the kernel page allocator, not from the kmalloc heap. This makes it ideal for larger allocations.