Merge restart into main #21

Closed
asleepymoon wants to merge 0 commits from restart into main
Owner

Let's do it!!

Let's do it!!
asleepymoon added 409 commits 2023-01-08 14:38:45 +00:00
write seems to work fine, read just hangs there, waiting.
Since we're using Rust-style integer types already, why not go all in?
I am now officially a big-boy OS developer, I read the Intel manuals for this!! (Not that the OSDev wiki doesn't have the information, but it was missing descriptions for some more obscure exceptions)
This helper returns true if the Result contains a value, or false if it doesn't.
Additionally, if it has a value, it sets the passed reference to it.
AFAIK, this is the proper naming scheme. "Pages" are virtual, and "frames" physical.
To make it clearer that this API is only intented for mapping contiguous frames of physical memory (for MMIO perhaps?)
This is the first time I've actually dropped liballoc in favor of writing my own implementation.
Usually, malloc() and such looked so complicated that I preferred to let a nice external library do the job.
But I've decided to try writing my own allocator, and now we have heap memory without any 3rd party code!
And remove a lot of testing code as well.
Those are there only for common stuff (in the Luna library) that needs an environment-agnostic way of allocating memory.
new and delete are standard, thus we should use those.
Here's one advantage of Rust over C++:
Immutability by default. In Rust, you have to mark a variable as mutable, whereas in C++ you have to mark it as immutable.

What's the problem here? Usually, most variables don't need mutability. Thus we end up with const all over the place.
*facepalm*

This was causing page faults when having two blocks and the first one (oldest one) being freed first.
Much better now!!
Can be used to append an item after another one instead of at the end of the list.
With doubly linked lists, this is extremely easy to achieve (O(1)).
Serial and TextConsole always succeed, no need to act as if they could fail
Not all of them, but if you're measuring a size it's more appropriate to use usize than u64.
Reviewed-on: 
For real this time, turns out me, being dumb, added it to Luna instead of the kernel.
If you want to return an error without meaning, use Option.
Reviewed-on: 
This avoids copying + we don't need to destroy the item if we move it, since it either gets emptied by moving it or doesn't have anything to destroy.
Let's make sure we explicitly tell new that we don't want exceptions
A managed String which uses RAII to free its contents. It's not a proper string though, since it's read-only.
So it's a StringView... but an owned one.

Can't be copied automatically, must be either moved or copied manually by calling clone() on it.
Why can printing to the serial port or format onto a string fail?
Even if cstyle_format returns Result<usize>, we shouldn't always follow suit.
No one was noticing because everyone using OwnedStringView included Result.h before it
Let's not confuse String.h with a managed string class, it's in fact the equivalent of the C stdlib's <string.h>
If we cannot fail to output, it doesn't make sense to propagate errors. So if you're SURE there are no errors, use pure_cstyle_format().
If, however, output can fail, use cstyle_format().

This has a drawback of adding quite a bit of code duplication to Format.cpp.
Some of it is dealt using templates, but some code still remains duplicate.
Not much support, since the font only covers codepoints from U+0000 to U+00FF,
(Basic Latin & Latin Extended-A), but unprintable code-points are rendered as ONE box per code-point,
instead of multiple garbage characters.
So it's Unicode-aware, even if it can't print most characters.
I think this can go in CString.h, no need to create a separate CWChar.h or something
We now have Utf8StringEncoder and Utf8Encoder (no state this time)
Invented function to memcpy() with a specific size, but add a null terminator.
As long as it's in memory, we can use it :)
Yes, we're using the physical address. Not optimal, this is only for demo purposes.
Too bad if it isn't.
Let's set the default (unlocked) value of Spinlock's underlying atomic to 0, so even if the constructor is not called it stays like that.
For when you want to lock a resource if possible but not get blocked if it is locked by another thread.
This is a special way of iterating over the list which permits removing items while iterating.
If your memory is all 0xacacacac there is a big probability you haven't initialized it.
These can't fail from UTF-8 decoding errors.
This function allocates a continuous range of VM and maps the physical frames passed to said VM range.
It's also mapped into virtual memory instead of directly going into the physical location!!
This enables NX before we actually use it.
Wasn't causing problems with KVM on, but crashed with KVM off with a 'reserved bit set' page fault.
Instead of showing a generic "Option::value() called on an empty Option" with no useful source location,
you will get something like "check failed: m_start_node at LinkedList.h:139"
At some point, this should be done inside LinkedList itself, but we have no such thing as break in for_each().
It's iterate over everything or nothing.

This also requires operator= in Option, might be also added to Result in the future.
This reduces calls to kmalloc() since segment data is heap-allocated, and the segments loaded will be deleted when deleting the page directory.
This function mirrors unmap_owned_and_free_vm(), but using weak unmapping (does not free the underlying physical memory)
From a TarStream. Not optimal, but OK for the moment.
User processes need to do something, amirite?
Putting it all together, we have a user process that successfully calls sys_exit() w/o crashing.
A bit crude, should be replaced by a strdup_from_user() helper to avoid touching userspace memory directly.
But it'll do for now.
Not good for W^X, but the compiler decides to squash everything into a single program header :(
Looks like these are now provided by the compiler.
Of course, using <luna/Format.h> makes it so simple. No need for duplicate code!
The cool POSIX kids use clock_gettime() now because it has NANOSECONDS (and different clocks!),
but ANSI C prefers this function.

We can still implement it based on clock_gettime(), we just have to discard the NANOSECONDS.
My bad :(
Fix inspired by: https://github.com/serenityos/serenity/pull/16345
CI will fail, it's normal. Wait for me to build a new toolchain for it.
Still tied to x86_64, but because there's no other platform implemented.

Also making this commit just to test CI with the new toolchain.
asleepymoon self-assigned this 2023-01-08 14:39:01 +00:00
Author
Owner

Had to merge manually because conflicts.

Had to merge manually because conflicts.
asleepymoon closed this pull request 2023-01-08 14:46:33 +00:00
asleepymoon deleted branch restart 2023-01-08 14:47:48 +00:00
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing

Pull request closed

Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: asleepymoon/Luna#21
No description provided.