#Nyaux
1 messages ยท Page 23 of 1
it was also fun
it was fun for different reasons tho
it was fun to like, implement String and shit from scratch
I implemented whole std::string from scratch
with sso and stuff
(I don't remember exactly but I think I copied some stuff from libc++ libstdc++ and msvc++)
i copied serenity's array stuff (those stuff are pretty simple, their String is much more complicated) and String was just a glorified array of characters with helper shit
modern gcc, you just --disabled-hosted-libstdcxx or something like htat
and it will just work
I'm just planning to use libstdc++ for that in my kernel
i will be using exceptions in this mock kernel i am putting together to make fun of hackernews
I've just removed exceptions from mine
here: https://github.com/ilobilo/string
it's not terrible
I believe it supports almost all C++23 stuff
I haven't encountered any bugs yet
you just need freestanding-cxx-headers and <memory> with std::allocator implemented
I suggest you do at least some userspace C++ first
You can just look at how I'm doing it and do it the other way around 
boring
how is that a problem
because I said it is
if you know what you're doing yeah
just don't allocate any memory in them if you are going to run them before you have an allocator
???
say you initialzie the allocator in there
Aren't they static?
but also allocate memory in another global constructor

you might assume a specific order
just call them after the allocator is available
that
I don't know how they work, but I assumed it's just a pointer to a static table at the beginning of the object
then you have to be careful about not using any of them before you have an allocator available tho or else you are going to get screwed
yeah I just took some random thing
global constructors are just an array of function pointers you have to call in order to initialize global objects
I had that issue two days ago lol
I just chose the option of not allocating memory in them as you usually don't need to
Are we talking about global constructors or vtables?
I don't use global constructors
i was confused at first too
I use frg::manual_box
vtables are fine too
like everything is fine
u just need to know
the fucking language
I use that kind of thing for objects which do need to allocate or which depend on other things
but for things like the log eh
jsut use constexpr/consteval constructors ๐ฏ
Global constructors are absolutely fine
consteval operator new/delete coming to a c++26 near you soon
and are irrelevant
The wiki is just very outdated as usual
yeah no they dont do anything on their own
apart from maybe being slower
what will they do
yea
it's just an abstraction over a bunch of function pointers
you can do it manually in C
I kinda get it
yes
or you can ask the language to do it for you using virtual
but virtual functions will be slower to call
imaginary memory in the compiler
you can allocate memory at compile time
yes
not really
it's necessary for stuff liek vfs anyway
they have one more indirection vs inlining the vtable inside the object
it's like calling a function pointer
yes but in any C++ program where you need absolute performance you shouldnt use virtual classes
yeah sure but we are talking about a hobby kernel
yes
the performance hit is basically non existent
it basically compiles to class->vtable[off_myvirtualfunc](parameters);
yeah mine is just a bunch of virtual classes
so its like calling a function pointer
yes
its Not That Bad
I never said it was
you should really start worrying about performance of trivial things like this, only when you can't do anything else to optimize your stuff
"It's not a performance problem until you can prove it."
inline call isn't a call
can't do that with my std::function impl 
its like 2.1 times slower than a regular call
just dont do oop and have a giant switch statement ez

genious
it's not an issue unless you're calling those functions millions of time per second
and you'll probably never do that in a hobby kernel
"A virtual function call first needs to load the vtable pointer from the object. This can result in a data cache miss. Then it loads the function pointer from the vtable which can result in another data cache miss. Then it calls the function which can result in an instruction cache miss like a non-virtual function."
nowadays it's def not an issue
i know your comment is sarcastic but for the record, it's basically the same
for 1. hobby kernels and 2. fast cpus
Just use final where appropriate?
?
well branching + static calls do have a performance advantage at least when there aren't too many cases
yeah the performance is comparable
an OOP project could gain a lot of cases in the relevant switch so it'd probably just use a jump table
yeah that's why I said with a small number of cases
"The time it takes to call a virtual member function is a few clock cycles more than it takes to
call a non-virtual member function, provided that the function call statement always calls the
same version of the virtual function. If the version changes then you may get a misprediction
penalty of 10 - 20 clock cycles. The rules for prediction and misprediction of virtual function
calls is the same as for switch statements,"
So that virtual functions can be called directly or inlined in some cases
what is final
class that can't be inherited from anymore
what's the point
or a function
what's the point of override
Sometimes not?
so the programmer doesn't make a mistake
or you need to expose that class to the user
Like in some situations I think inheritance is more convenient that having a bunch of unions or whatever
and less error-prone
But it you store a pointer to the derrived object, then it makes virtual functions free
clang complains if you don't add it
it isn't
i thought override was needed
nop
I think gcc doesn't care
I use clang
if you use it on at least one method, then it complains
ah
'func' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
or yk what
ill just learn rust properly even if it takes months
guess nyaux will be suspended for 2-3 months maybe
its sad but
its the unfortunate truth
i will see you all in 2-3 months
and when im back i should be compitent enough to write an os
why do you even want to use rust
it sucks for osdev
if you still want fancy abstractions use C++
you heard it from the rust compiler itself
i mean rust is fine for osdev
just
when you use rust
don't fight the borrow checker
it's like the defining feature of rust
Write a linked list 
that's also fine
with unsafe it's fine
or that
or in C
well, yeah, but unsafe is simply required in some cases
it is also a feature of the language
Just use Ada
or actually
ill just use C++ but without most of the C++ features, only like the classes
just not rn tho
i need to sleep
in a few hours ill setup stuff
ill get there
im a little tired tho
night night
RAII is great
now do on demand allocation
what's that
if page fault, map?
yeah
how I do it is on the first page fault on an anonymous range, I map a shared zero page and then do copy on write on it if nescessary
NVM IT STILL ISNT PAGE FAULTING THAT WAS SOME OTHER BUG

WTF
WHY WONT IT UNMAP
RAHHH
back to C
NO
THIS SEEMS TO BE A LOGIC BUG
of some kind
switching a dif language wont help
that's kinda smart
I just allocate it on-demand
rustc
what
no
check the mapped pages in qemu monitor
yea thats what im gonna do
Are you flushing TLB?
i am invlpging yea
info tlb shows its not mapped
i will now not dealloc it and check info tlb again
if it is mapped then
this is not my problem to deal with
could be some rust quirk idfk
btw info tlb has nothing to do with the tlb
wym
it's just printing the mappings page by page
as opposed to in a range format when you do info mem
how do i view the tlb
fun
okay this is getting weird
even not unmamping it
its not showing up
umm
lol
oh wait
flags i forgor
still not showing up?
yea this weird lmao
should i even care if unmap works or not
i mean
im doing everything correct
self.unmap(i.base + (f * 0x1000));
assert_eq!(
None,
Self::find_pte(self.rootpagetable as usize, i.base + (f * 0x1000))
);
ill do something like this to verify
if it fails
bug
if it doesnt
idk tlb hates me lol
tlb can kiss my booty
idc then
yea no problems with the assert
so it did work
just tlb does NOT care
๐ญ
ummm
why is there no invlpg instruction
HELLO
RUST???
๐ญ
this is dev mode
and its like
not there
yall gotta be kidding me
Instead of having to explicitly use volatile, volatile is the default and you have to opt-out if you want using pure. This is done to prevent forgetting to use volatile when you need to.
does anyone here work with rust no whats going on
good idea
yoinky splunky
ummm still objdumping no exist
WHWHY RUST HATE ME
RAHH
OKAY YK WHAT I DONT CARE IMA MOVE ON
werent u rewriting it yesterday
nah i realized it was a bug
probably because you dont know how to write correct rust code
stupid me
bro im using references now
๐ก
use C
yeah
nah look im just gonna ignore whats going on, rust is not compiling invlpg in but it doesnt rlly matter DOES IT
nah
day n of waiting for nyaux to switch to C
it does
day n of waiting for nyaux to burn out because of rust issues and speedrunning os instead of learning it
im not speedrunning tho
i know what im doing
its not even speedrunning
lol
ur trying to speedrun
really.
but u get stuck every minute
cause of issues with dumb me
(dunning kruger effect)
bru
High level details rather
No
wym no?
i know how to implement a gdt and a idt and a vfs and a vmm and a pmm and a scheduler and such
Ur not dumb ur just lacking the patience to do anything right
explain further
Not learning rust properly, then proceeding to use it for a thing that requires insanely advanced rust knowledge, not researching the component that you're writing and instead doing it willy nilly
wdym "the component"
Vmm, pmm, scheduler, whatever ur doing right now
moral of the story: use C
or learn to program first in general
the rust safety rules are incredibly complex
i know this concept
if i didnt know to program i wouldnt be writing an os
chat can we just stop trying to roast me into a roasted chicken
this is rlly like yall trying to bring down my moral or smthin 
sorry but clearly not enough
-# I came into osdev not knowing how to make a linked list, and didn't know a thing about most data structures
what
i know how to make a linked list wtf
he said
I came into osdev not knowing how to make a linked list, and didn't know a thing about most data structures
now I do though
i knwo what he said ๐ญ
are u saying abt urself
yes
dont worry at least its not rust
I
aka "you cant make a safe doubly linked list" lang
no cause pitust thinks i "dont know how to program"
thats kinda mean to be honest
ok sorry
maybe there are gaps in my knowledge sure, but im learning them and im improving. im not trying to speedrun im not trying to not learn i am trying to learn and understand to the best i can
@surreal path hi fellow rust osdever
hi
I just got my basic scheduler working
nice
sleep is not there yet because I'm still not happy with my timer stuff
@kind root this is my response to you as well infy
i need a non-arch specific api for that
but otherwise sleep is easyy
there's something related to clobbering memory
it is useful
check the asm! docs
if memory is clobbered llvm/rustc won't reorder or drop anything
okay so i need to make it clobbered?
idk check the docs
i know it exists
i used it in clang but i don't know the syntax for rust asm!
using cloober_abi solved nothing
no not that
ok let me check the docs
worst case, use llvm_asm! maybe they don't have such an option in asm!
ok in asm! it is enabled by default
ignore everything i said
bru
unless you pass options(nomem)
echo -e 'bits 64\nglobal invlpg\ninvlpg:\n\tinvlpg [rdi]\n\tret\n' > invlpg.asm
it does what you want it to do
i lit did
and rust still optimized it out lmao
this is something unrelated
rust skill issue
i don't know the issue but i don't think it's a rust skill issue
rust's asm! is just a different syntax over llvm's
why tf would rust optimize out a function call that it knows nothing about
he said he also used a function call
can rust even do that
Yeah it's the same as calling c functions I guess
wait since when has that been a thing
I'VE ALWAYS USED global_asm!(include_str!()) AAAAAA
srry i mean
yes
global_asm
idk what's wrong with this server and hate on rust but yea rust has external linking lmao
i have an idea
It's not hate it's just no one knows it
I don't hate rust, I despise it /j
i guess
how is that hating on rust
the way everyone uses rust for osdev is shit
even doing this
let mut fake: usize;
core::arch::asm!(
"invlpg [{0}]",
"mov {1}, 5",
in(reg) va,
out(reg) fake,
options(nostack)
);
println!("{}", fake);
It's a simple question
did you objdump?
yea
and no mention of invlpg?
yep
can you send the binary
sure
everyone on this server (maybe except me but I don't have my stuff public
people on the rust server are not bad osdevers
there's serious stuff going on there :3
lemme look at that
The only good rust os is aero
consider: ableos
No idea what that is
damn no invlpg
bruh
osdev on the rust server is basically riscv shilling at this point
not even osdev
heyy that's not true it's basically all people following phil-opp's blog
czapek@raptor-wsl:~/wow$ rustc -o test.o test.rs --target x86_64-unknown-none
czapek@raptor-wsl:~/wow$ objdump -d test.o
test.o: file format elf64-x86-64
czapek@raptor-wsl:~/wow$ cat test.rs
#![no_std]
#![no_main]
pub extern "C" fn _start() -> ! {
unsafe {
core::arch::asm!("invlpg [rax]");
}
loop {}
}
#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
loop {}
}```
what is rustc doing
my and repnop are the only risc-v rust osdevers that I am aware of
or what am i doing...
what's the function name where you use invlpg
yeah im wrong hold up
wait
unmap
i dont think i can objdump an object file like that
PageMap::unmap
idk invlpg but is that at&t syntax or intel syntax?
idk ๐ญ
Is that release mode
doubt
this wouldn't be optimised out in dev mode
idfk ???
why doesn't unmap exist in my objdump
is invlpg different in at&t and intel syntax?
are optimisations disabled
intel syntax
maybe the assembler shits
it is running devmode
rust asm uses intel syntax
so optimizations should be disabled
is that correct intel syntax for invlpg
yes
yes
extremely rare rust W
invlpg takes a memory operand
good question
so [reg] should be fine
and #[test]
oki
@surreal path can I see your linker script
now it DOES invlpg
NyauxKT::PageMap::unmap doesn't exist either
i fixed it
what was it
czapek@raptor-wsl:~/sources/zig-kernel$ objdump -d kernel/zig-out/bin/kernel | grep invlpg
ffffffff80000040: 0f 01 3c 25 00 00 00 invlpg 0x0```
yay good language
asm volatile("invlpg 0");```
last time I had symbols not appearing it was my linker script discarding it
i see why it doesnt page fault lmao
(assembly)
What'd you change
i wrote the pte to be 0
??
yea stupid ik
?????????????
"rustc bug" smh
๐
lmao
lmao
this guy makes me wanna quit life
yea as normal it's just a human error
why you mean :c
this was me 3 years ago on my first osdev attempt
ill name drop u on my goodbye note
don't be mean to them
/s
they will improve
my first osdev attempt was just following phil-opp's blog
then I wrote stuff for ableos
its kinda shit
my first osdev attempt was... questionable
yea
it is shit but
the work done around that community (the rust-osdev github org
its basically like
is not actually bad
"go use this crate lololol"
"shout out to nyauxmaster for helping me speedrun life"
like thanks to them x86_64-unknown-none is stabilised
they were attempting real mode rust at some point
all the ${cpu_architecture} crates are inspired by their x86_64 crate
and they are good crates
wait shouldnt u set the pte to 0? i know this is wrong but i am not understanding WHY its wrong, ur setting everything to 0?
including the present bit
so shouldnt the mmu not complain
wtf is it complaining about to u
tlb exists
but its not mapped anyone
but if it exists in the tlb it will still be "mapped"
did you set cr3 if you're creating a new page table
yes
and did you do the invalidation stuff correctly
yep
pub fn unmap(&self, va: usize) {
let him = unsafe { Self::find_pte(self.rootpagetable as usize, va) };
if let Some(h) = him {
*h = 0;
unsafe {
let mut fake: usize;
core::arch::asm!(
"invlpg [{0}]",
"mov {1}, 5",
in(reg) va,
out(reg) fake,
options(nostack)
);
println!("{}", fake);
};
} else {
println!("not found");
}
}
sorry I don't remember x86 enough
; after unsafe block makes me cry
lmao yes
that fake variable makes me cry
yea so why isnt it unmapping hmmmm
It is unmapping
the INSTRUCTION
probably
is EXECUTED
you should really learn to use a debugger
wow it magically fixed itself
rustc goated
okay we'll see
ill pull up my debugger
gdb or lldb
i use gdb
i know how to use a debugger
nah he uses ida pro
i don't even know how to use a debugger beyond breakpoints and reading memory
pro
the totally legit copy of IDA Professional 9.0โข๏ธ
step/stepi/next/nexti/finish/br/delete breakpoints/i/p
same but without the second part
all you need to know tbh
then what's the problem
idfk ??
move on
if there's no problem, why are you still debugging it
if it isnt page faulting
why
infy or pitust can u tell u why
maybe add a sleep() or a few pauses between invlpg and trying to write
what does that even do
idk maybe it needs some time to think lmao
ah yes 
okay im not gonna worry and move on
im doing everything correct so
if the cpu chooses to listen or not
not my business
anyways gonna add vmm_region_alloc into my global allocator and yea
anyways vmm done
he has been trying to for the last week
yes finally
uacpi integration time
no
why
you don't need it yet
why do you need it
uhhhh
exactly
you don't
then what should i do next
interrupts
i already have
I mean timer and a scheduler
no drivers yet lol
lol
so?
too early for that
scheduler THIS early?
well not too late
scheduling is like
the most important part
of any kernel
fair
a wise man told me to have a scheduler asap when I start my kernel
i started with a memory manager
scheduler is what I do after I do memory management
you just have to not have the scheduler depend on the memory manager
the problem?
funny
i don't have an allocator (I use someone else's allocator) and I have a scheduler lmao
bru
yeah taht will be fun to untangle later 
I didn't have an allocator until a week after I start dev on my current kernel
what my kernel does rn
parse fdt
scheduler
pmm
has code for mapping pages but unused
but I had a scheduler within the first 5 days
pub export fn _start() callconv(.C) noreturn {
arch.disableInterrupts();
arch.serial.initialize(0x3f8);
const hhdm_response = hhdm_request.response.?;
const kernel_address_response = kernel_address_request.response.?;
const memory_map_response = memory_map_request.response.?;
const smp_response = smp_request.response.?;
bsp_cpu_info = .{
.arch_cpu = arch.cpu.ArchCpuInfo.init(smp_response.bsp_lapic_id),
.idle_thread = &bsp_idle_thread,
};
bsp_cpu_info_block = .{
.cpu_info = &bsp_cpu_info,
.current_thread = &bsp_idle_thread,
};
arch.cpu.setCpuInfoBlock(&bsp_cpu_info_block);
arch.cpu.initializeCpuEarly(&bsp_cpu_info);
// ...
}```
literally what my kernel does at the start
iretq im in ur walls
hi
nahj u stay in there

what my kernel does at the start is initializes the gdt and idt, then initailizes the scheduler
my walls are paper thin
astral does this
void kernel_entry() {
cpu_set(&bsp_cpu);
logging_init();
logging_sethook(arch_e9_putc);
arch_gdt_reload();
arch_idt_setup();
arch_idt_reload();
dpc_init();
pmm_init();
term_init();
logging_sethook(term_putchar);
arch_mmu_init();
vmm_init();
alloc_init();
cmdline_parse();
acpi_early_init();
arch_apic_init();
timekeeper_early_init(0);
cpu_initstate();
arch_apic_timerinit();
sched_init();
my initializeCpuEarly sets up gdt and idt
im going to steal ur cat then by grabbing it via the walls
or the floorboards
after that i initialize my memory manager and start up other cores
although the scheduler is cooperative until the scheduler timer is initialized
mathew what is adpc
#[no_mangle]
unsafe extern "C" fn _start() -> ! {
HHDM_OFFSET.store(HHDM_REQUEST.get_response().unwrap().offset() as usize, Ordering::Relaxed);
crate::memory::alloc::init(INITIAL_KERNEL_HEAP_START, INITIAL_KERNEL_HEAP_SIZE);
crate::memory::pmm::init(MM_REQUEST.get_response().unwrap().entries());
// Get a DTB and parse it, then discover devices
// This also sets the serial console.
let dtb_response = DTB_REQUEST.get_response().unwrap();
let dtb = dtb_response.dtb_ptr();
let fdt = fdt::Fdt::from_ptr(dtb.cast()).unwrap();
crate::fdt::discover_devices(&fdt);
log::info!("Hello serial console!");
// CHECK FOR LIMINE RESPONSES
log::info!("Initialising hart context");
// ALLOCATE 4 PAGES FOR KERNEL STACK
// HART CONTEXT INITIALIZE
log::info!("Initialising trap handler");
trap::init();
log::info!("Initialising scheduler");
crate::scheduler::init();
THREAD1 = crate::scheduler::create_kernel_thread(thread1);
crate::scheduler::create_kernel_thread(thread2);
log::info!("Enabling interrupts");
interrupts::enable();
loop {
wfi();
}
}
static mut THREAD1: *mut crate::thread::Thread = core::ptr::null_mut();
fn thread1() {
log::info!("hello from thread1 :S");
log::info!("blocking thread1 :O");
crate::scheduler::block(crate::thread::ThreadState::Paused);
log::info!("hello again from thread1 :3");
log::info!("terminating thread1 UwU");
crate::scheduler::terminate();
}
fn thread2() {
log::info!("hello from thread2 >:3");
log::info!("unblocking thread1 from thread2 LoL");
unsafe {
crate::scheduler::unblock(THREAD1);
}
log::info!("terminating thread2 OwO");
crate::scheduler::terminate();
}
dpc*
basically the entirety of my kernel
deferred procedure call
ah yes makes total sense
I had to cut some code and replace it with comments tho
A Deferred Procedure Call (DPC) is a Microsoft Windows operating system mechanism which allows high-priority tasks (e.g. an interrupt handler) to defer required but lower-priority tasks for later execution.
what it does is it defers code execution until a later point in the kernel at a lower interrupt priority
i see
in obos they run at IRQL_DISPATCH
when irql goes < IRQL_DISPATCH
linux definitely has an equivalent
OBOS_NO_UBSAN OBOS_NO_KASAN void Core_LowerIrqlNoThread(irql to)
{
Core_LowerIrqlNoDPCDispatch(to);
if (to < IRQL_DISPATCH && CoreS_GetCPULocalPtr())
{
CoreS_SetIRQL(IRQL_DISPATCH, to);
*Core_GetIRQLVar() = IRQL_DISPATCH;
CoreH_DispatchDPCs();
*Core_GetIRQLVar() = to;
CoreS_SetIRQL(to, IRQL_DISPATCH);
}
}```
its basically a per-cpu work queue
linux is windows comfirmed
i see
this thread is eating my brain
OBOS_NO_UBSAN OBOS_NO_KASAN void CoreH_DispatchDPCs()
{
// Run pending DPCs on the current CPU.
for (dpc* cur = LIST_GET_HEAD(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs); cur; )
{
dpc* next = LIST_GET_NEXT(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs, cur);
LIST_REMOVE(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs, cur);
cur->cpu = nullptr;
cur->handler(cur, cur->userdata);
cur = next;
}
}```
im gonna leave
softint
i knew it :^)
don't ping me it makes me follow the thread
discord fix your app why can you ping random people and force them to follow the thread
i will use nixstrap if u stay
@discord fix
ok
tasklets to be more specific it seems
so u will stay?
yes
pro gamer
๐
blackmail my favourite past time activity
anyways
time for scheduler
or whatever tf
ill do that after i eat me hungy
yes
ok gonna clean shit up
please don't; use nixstrap
u dont ev en know fucking nix
this guy will never finish a project
istg
i will
chill
also how do u know i dont use nix
i lit used nixos a bunch of times lmao
tf
i still doubt you know nix
you doubt everything lmao
i do too but
a user for nixstrap = i will learn what other people want it to do and it's not just a gearbox (my kernel) thing
cant wait for the 10 daily pings @ sanana
pinging sanana

๐ก
tho i would not suggest using nixstrap with rust as your first attempt at using nixstrap
rust + nix + custom targets and build-std don't really add up well
it does work don't get me wrong
it takes a bunch of effort
there's a rust template available already tho
let's update my disko fork
that seemed to work
It can't, deal with it
(my kernel still doesn't do tlb invalidation properly)
๐ก
oh yeah sorry im taking a break for like until weekend cause school is getting more stressful
sorry chat
but this is to avoid burn out
cya in two months
It's the worst type of bugs if you don't get it right...
its not funny anymore at this point
thank you
cya on saturday
You got this
Lucky
honestly i back infy on this
i bet you're going to disappear for months now
it has already happened like 3 times
idk why this one would be different
prove us wrong, i guess :p
nope im here
ill prove yall wrong
lmao
im currently outside rn ill be back in a few hours eta 5pm irish time to work on nyaux
alright
ready to start some work
im gonna do the uacpi first because i believe its just better to do so, i know yall disagree but its fine
good heap stress test anyway
okay very fun
so after integrated uacpi
we got some issues
with the heap
okay more bugs
fun
this just happened
wtf is going on
now
lol
memory corruption!!
even tho im being "safe"
CR2=ffffffff80001320
hmmm
fn slab_allocsearch(&mut self) -> Option<usize> {
let mut h = &mut self.slabs;
'outer: loop {
println!("{:?}", h);
if let Some(fre) = h.as_mut().unwrap().freelist.take() {
h.as_mut().unwrap().freelist = fre.next.take();
return Some(fre as *mut KTNode as usize);
} else {
if h.as_ref().unwrap().next_slab.is_none() {
println!("breaking out");
break 'outer;
} else {
println!("{:#?}", h.as_ref().unwrap().next_slab);
}
h = &mut h.as_mut().unwrap().next_slab;
}
}
println!("HELLLO???");
let new = slab_header::init(self.size);
let o = h.as_mut().unwrap().next_slab.take();
println!("suc");
if let Some(g) = o {
new.next_slab = Some(g);
h.as_mut().unwrap().next_slab = Some(new);
} else {
h.as_mut().unwrap().next_slab = Some(new);
}
let gethim = h.as_mut().unwrap().next_slab.take().unwrap();
println!("{:#?}", gethim.freelist);
gethim.freelist = gethim.freelist.as_mut().unwrap().next.take();
let gg = gethim.freelist.as_mut().take().unwrap();
return Some(*gg as *mut KTNode as usize);
}
make a scheduler first, then uacpi
no this is good to stresstest my heap
im gonna redo my slab allocator
with MaybeUnIt<T>
struct slab_header {
...
freelist: MaybeUninit<Option<&'static KTNode>>
...
}
because otherwise its ub
and the compiler can do whatever the hell it wants
it optized prev out
causing dumb issue
lol
thanks to @glossy walrus for the suggestion
tho i dont think theres anything wrong with the 'static lifetime
the ktnode is going to live for the entirety of the kernel when its in the freelist
okok my brain is dying
trying to figure out how to right this slab allocator properly
hmm
the mad lads at rust community server told me to use raw pointers
in this context it is SAFE
Option<NonNull<T>>
they told me to do
raw pointers are always safe they obey the same rules as references
just you're supposed to uphold those rules instead of the compiler
the unsafe part is reading from and writing to the raw pointers
i get you
sigmas know i'm skibidi now
slab allocator nearly done
just working on the last few functions then
we will have slab allocator that isnt UB
thanks to the RUST server for guiding me on how to create no UB
fn slab_allocsearch(&mut self) -> Option<*mut u8> {
let mut h = &mut self.slabs;
for i in h.iter_mut() {
unsafe {
if let Some(friend) = (*i.as_ptr()).freelist {
(*i.as_ptr()).freelist = (*friend.as_ptr()).next;
return Some(friend.as_ptr().cast::<u8>());
}
}
}
None
this is good rust code according to them lol
lol
i have tracked down the issue to my slab_header init
solved it
enabling strict provence is the best thing ive ever done
no more UB
cause the compiler errors out if theres some ptr to int to ptr cast
๐
@finite summit what is ur opinion on this information
๐
fun
uacpi page faults on kvm
and non kvm runs out of memory
why does the curse always follow me
why tf is parent 0x0
why is out_obj 0x0
why is args 0x0
wtf
the cause is wrong also
wdym
LOAD_CAUSE_INIT is whats passed
UACPI_TABLE_LOAD_CAUSE_LOAD_OP
yea
wtf is happening

UACPI_TABLE_LOAD_CAUSE_INIT
fucking hell
yea
all the addresses i give to uacpi
their sizes too
could it be my vmm region
i mean
it looks fine

WHY AM I ALWAYS CURSED
RAHHHH
changing between dev and release mode doesnt change anything, in tcg it works fine (only runs out of memory cause i didnt make free function yet) but kvm it page faults
cr2 is 0
as u'd except
I'm used to a lot more verbose debugging sessions
nyaux thread almost at 23000
yea i know
anyways i think i found the function at fault
slab_allocsearch is doing something rlly weird
i just need to find where
and we gucci
crazy !!!! ik
anyways i have school tmrw
i must sleep now
goodnight chat
good night nyaux :3
IM AT SCHOOL ๐ญ
they dont allow devices here
also
school nearly finished but i have tennis practice after this
ill be back around 8pm
im back
@kind root im back to work
im gonna write some unit tests
maybe it'll show me whats going on
nice
its fucking hell trying to setup them up ๐ญ
which language are you using now
still rust

one thing i found out
its not an alignment issue
i cant get unit tests working
so
im just gonna ball and not care
actually wait
i can do something brb
wait
i will read the source code of linux about this
@kind root ```rs
running 1 test
thread 'mem::pmm::h' panicked at src/mem/pmm.rs:348:9:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0xffffffffffffffff
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass --lib
Caused by:
process didn't exit successfully: /home/rayan/NyauxKT/kernel/target/x86_64-unknown-linux-gnu/debug/deps/NyauxKT-207c79480958aa03 (signal: 6, SIGABRT: process abort signal)
look what i found
extern crate std;
extern crate libc;
assert_eq!(1, 1);
let data: *mut u8 = unsafe {
libc::mmap(0 as *mut c_void, 4096, libc::PROT_READ
| libc::PROT_WRITE, libc::MAP_ANONYMOUS, 0, 0) as *mut u8
};
let it = NonNull::new(unsafe {
data
as *mut slab_header
}).unwrap();
unsafe {
(*it.as_ptr()).obj_size = 16;
}
let obj_amount = (4096 - size_of::<slab_header>()) / 16;
let start = unsafe {it.add(1).cast::<um>()};
let mut prev = start;
for i in 1..obj_amount {
unsafe {
let new = start.byte_add(i * 16);
(*new.as_ptr()).next = None;
(*prev.as_ptr()).next = Some(new);
prev = new;
}
}
unsafe {
(*it.as_ptr()).freelist = Some(start);
}
unsafe {
if let Some(friend) = (*it.as_ptr()).freelist {
(*it.as_ptr()).freelist = (*friend.as_ptr()).next;
let bro = friend.as_ptr().cast::<u8>();
}
}
my test
allocator bug?
i think
or maybe i have the wrong thigns to mmap
hey: 0xffffffffffffffff
oh
let data: *mut u8 = unsafe {
libc::mmap(0 as *mut c_void, 4096, libc::PROT_READ
| libc::PROT_WRITE, libc::MAP_ANONYMOUS, 0, 0) as *mut u8
};
mmap is giving me
0xfff
why???
๐
WHY TF DID IT FAIL
๐ญ
nvm i solved it
it works fine
@kind root
it failed !
congrats
well another step closer @kind root
we can debug this further tomrw
i have to sleep i have school

Good luck
Why is this functions name just the letter h ๐ญ
h
chat i dont think i can code today i have an exam to study for

