#Nyaux

1 messages Β· Page 25 of 1

surreal path
#

making sure no one starves

finite summit
#

might not be that bad of an idea...

surreal path
#

exactly

#

i call this design

finite summit
#

now do the same thing

surreal path
#

the nyaux thread design

rigid fable
#

this represents @finite summit:

  1. Write a VMM
  2. Work on the rest of the ker-
  3. Rewrite the VMM - if it fails 4
  4. Rewrite the kernel
finite summit
#

with 60 threads

surreal path
#

will stress test after finishing writing sched

finite summit
#
  • write vmm
  • rewrite vmm
  • do other kernel shit
  • rewrite vmm
  • do toher kernle shit
#

what I do is

#

in my thread ready function

elder shoal
surreal path
finite summit
#

I ignore cpu cache

#

if you don't like my memory accesses

#

fuck u

surreal path
#

^^^

finite summit
elder shoal
# surreal path how

If you keep moving between cpus youre gonna have to read everything into the cache in the new cpu

finite summit
surreal path
#

say 3

#

what abt that

#

yea im imagining it in my brain

#

i think that works well

elder shoal
#

My scheduler is gonna do something like this to figure out what cpu to run on (inspired by ule):

Cpu it has a hard target for, always picks it
Last cpu it ran on if it can run immediately
Going up from the last cpu to see if any can run it immediatelly
Go to the least loaded cpu in the system

#

With load being nr of threads in the queue

rigid fable
#

nevermind. I updated discord and it's still fucking UI message passing somehow

#

or whatever

#

I literally cannot see the threads

surreal path
#
#[no_mangle]
pub fn schedule_task(regs: Registers) -> Option<Registers> {
    let addr_to_info = rdmsr(0xC0000101);
    if addr_to_info == 0 {
        return None;
    }
    let info = core::ptr::with_exposed_provenance_mut(addr_to_info as usize) as *mut perthreadcpu;
    unsafe {
        if (*info).run_queue.len() == 0 {
            return None;
        }
        if let Some(mut r) = (*info).next.take() {
            let thr = (*info).run_queue.pop_front().unwrap();
            (*r).run_queue.push_back(thr);
        }
        if (*info).run_queue.len() == 0 {
            return None;
        }
        let mut thr = (*info).run_queue.pop_front().unwrap();
        if let Some(mut cur_thr) = (*info).cur_thread.take() {
            (*cur_thr).content.frame = regs;

            (*info).cur_thread = Some(Box::from(thr));
            (*info).run_queue.push_back(*cur_thr);
        }
        if (*info).run_queue.len() == 0 {
            todo!()
        }

        todo!()
    }
}
#

what ive got so far

#

actually

#

nvm this wont work

#

fuck

#

hmmm

#

@finite summit the problem is

#

the gs_base is stored in thread

#

and is making things difficut

#

idk what to do

finite summit
surreal path
finite summit
#

if you are switching to a thread currently in kernel mode then you ignore gsbase when switching to its context

#

otherwise

#

you want to swapgs then set gsbase to whatever the thread's context says it is

surreal path
#

no thats not what im talking abt

#

ugh

#
struct process {}
#[repr(C, packed(8))]
pub struct perthreadcpu {
    kernal_stack_ptr: *mut u8,
    user_stack_ptr: Option<*mut u8>,
    run_queue: VecDeque<Thread>,
    next: Option<Box<perthreadcpu>>,
    cur_thread: Option<Box<Thread>>,
}
struct Thread {
    name: String,
    tid: usize,
    gs_base: *mut perthreadcpu,
    fs: usize,
    content: cpu_ctx,
    process: Option<Arc<Mutex<process>>>,
}
#

this is how i define everything atm

#
#[repr(C, packed(8))]
pub struct perthreadcpu {
    kernal_stack_ptr: *mut u8,
    user_stack_ptr: Option<*mut u8>,
    run_queue: VecDeque<Thread>,
    next: Option<Box<perthreadcpu>>,
    cur_thread: Option<Box<Thread>>,
}
finite summit
#

yes

surreal path
#

my problem is like

#

how to set gs_base to the right perthreadcpu

#

oh wait

finite summit
#

wrmsr(GS_BASE, foo)

surreal path
#

.next exists

surreal path
finite summit
#

also doing this in a linked list

#

seems useless

#

when you can do it in a linear array

surreal path
#
#[no_mangle]
pub fn schedule_task(regs: Registers) -> Option<Registers> {
    let addr_to_info = rdmsr(0xC0000101);
    if addr_to_info == 0 {
        return None;
    }
    let info = core::ptr::with_exposed_provenance_mut(addr_to_info as usize) as *mut perthreadcpu;
    unsafe {
        if (*info).run_queue.len() == 0 {
            return None;
        }
        if let Some(mut r) = (*info).next.take() {
            let mut thr = (*info).run_queue.pop_front().unwrap();
            thr.gs_base = (*info).next.take().unwrap().as_mut();
            (*r).run_queue.push_back(thr);
        }
        if (*info).run_queue.len() == 0 {
            return None;
        }
        let thr = (*info).run_queue.pop_front().unwrap();
        if let Some(mut cur_thr) = (*info).cur_thread.take() {
            (*cur_thr).content.frame = regs;
            let fs = rdmsr(0xC0000100);
            (*cur_thr).fs = fs as usize;
            (*cur_thr).gs_base = info;
            (*info).cur_thread = Some(Box::new(thr));
            (*info).run_queue.push_back(*cur_thr);
        } else {
            (*info).cur_thread = Some(Box::new(thr));
        }

        let thr = (*info).cur_thread.take().unwrap();
        wrmsr(0xC0000100, thr.fs as u64);
        wrmsr(0xC0000102, thr.gs_base as u64);
        return Some(thr.content.frame);
    }
}

#

this function

#

is the most

#

disgusting code ive ever wrote

#

but lets hope it works 🀞

#

ima gonna hook this up to the lapic

#

try this on 1 core

#

2

#

or 18

#

im gonna try to add a thread

#

fun

#

fault

#

and of course attaching gdb makes @molten grotto 's uacpi crate say i have no kernel api

#

oh wait

#

i just realized

#

okay it works now

#

yep ticks now

surreal path
#

okay something very cursed is happening

#

like its able to get the registers

#

but then it stops

#

and its stuck

#

the lapic is firing

#

strange

#

okay

#

this is dumb

#

im afraid

#

im going sleep and after that im gonna read some things on scheduler design

surreal path
#

im awake

#

but

#

idfk

#

i dont think its a good idea to store the cpu queue in gs base

#

this complicates things

#

it'd be better to have a static variable the cpu index's with its lapic id

molten grotto
surreal path
# molten grotto why?

it just gets difficult for me to manage cause like the thread stores its gs_base but i have to save and load the gs base and like the actual cpu queue is INSIDE the gs_base and i dont know how to setup the cpu queues when there are no threads

#

unless you have a better approach to this

#

cause im rlly confused tbh

molten grotto
#

and a thread always has a pointer to the cpu it runs on

thorn bramble
#

the first thing you do before you do anything is set up threading primitives

#

aka per cpu data

#

you can just statically allocate it for obvious reasons

#

like for example no memory manager or allocator being available

cinder plinth
#

I store the current thread in gs

#

And get the cpu using a pointer inside the thread

surreal path
thorn bramble
surreal path
thorn bramble
#

explain what?

#

now i am confused lol

#

you just put them in .data/.rodata

#

aka statically allocate

#

"allocate"

finite summit
#
struct thread
{
    // ...
    cpu_local* master;
    // ...
};```
thorn bramble
#

a global variable

finite summit
#

you said you stored yoru

#

sorry

surreal path
#

my brain has exploded

thorn bramble
#

yeah so what

finite summit
#

you said you stored the cpu being ran on

thorn bramble
#

you can still take a pointer to it

finite summit
#

in the thread struct

thorn bramble
#

and stash it in gs base

surreal path
#

ooohhh

thorn bramble
#

OHHH

#

IT CLICKED

#

HUH

surreal path
#

you can store the current thread in gs base, then you can have a pointer to a static cpu struct

#

i seee

#

or wait that might be stupid

#

i might be stupid

thorn bramble
#

uh im not sure if we're on the same page

#

but what i was talking about is

cinder plinth
#

You don't actually store it in gs base

surreal path
cinder plinth
#

You store a pointer

thorn bramble
#

you set up per cpu data (cpu info + current thread pointer) as soon as possible

#

and to avoid having an allocator up to do that

#

you can just have it as static variables for the bootstrap cpu

#

and properly heap allocate it for other cpus

cinder plinth
#

Yea

finite summit
#

idk what's so hard to understand about

struct cpu_local
{
    thread* curr;
    // other shit
};
struct cpu_local bsp_cpu;
// ...
// setup cpu struct
bsp_cpu.curr = ...;
// write to gs base
wrmsr(GS_BASE, &bsp_cpu);```
#

then when setting up other cpus

#

you do the same but you use a heap allocator to allocate the cpu_local struct

surreal path
#

cant i just do something like this

struct cpu_local {
  lapic_id: usize,
  cur_thread: // ptr to thread,
  
}
static blah: Once<Vec<cpu_local>> = Once::new();

// in smp.rs
fn init() {
  ...
  blah.run_once(|| // setup cpu structs
  return vec
  );
  ...
}

fn schedule_task() {
  ...
  let id = get_lapic_id();
  let cpu_struct = blah.get()[id]
}
#

is this bad or

finite summit
#

looks fine

#

actually

surreal path
finite summit
#

NO

surreal path
#

oh lol

finite summit
#

for the most part it is fine

#

BUT you store a pointer

#

to the current CPU's

#

CPU LOCAL STRUCT IN GS_BASE

#

AHHHHHHHHHH]

surreal path
#

okay store a ptr in gs_base

#

got it

finite summit
#

if it's per-cpu run queues

#

otherwise it's a global variable protected by a global lock

surreal path
finite summit
#

if you plan on modifying this queue

#

from other cpus

#

you would probably want to lock it

#

otherwise just having interrupts disabled while modifying it should be fine

surreal path
#

so gs_base points to per cpu data -> per cpu data has the run queue, the current cpu and kernel stack ptr and if usermode user stack ptr

finite summit
#

yeah sure

#

whatever you need to put in there

#

you put in there

#

it's your kernel, not mine

surreal path
#

and what about deciding when to get a thread to another run queue

#

hows that logic

finite summit
#

magic

surreal path
#

bru

finite summit
#

I mean if you're just doing round robin

#

you simply

curr = curr->next;
if (!curr) curr = queue.head```
#

on schedule

#

then switch to the new thread

surreal path
#

i mean

#

when do u decide

#

to give a thread to another cpu

finite summit
#

whenever you want

cinder plinth
#

Don't care about load balancing or work stealing

#

For now

#

Just assign CPUs in a round robin fashion

surreal path
#

okay

#

what about if gs_base points to a cpu_local struct and that cpu_local struct points to the run queue, and gs_base is stored in the thread itself and the msr is written to from the thread itself, and your still in that same run queue

wont you be stuck on the same cpu_local struct

cinder plinth
#

You setup a different gs_base for every cpu

surreal path
#

otherwise it doesnt make sense

#

how to explode brain 101 !!

finite summit
#

except when swapgsing

#

when coming from/returning to

#

userspace

finite summit
#

you swapgs then write the user thread's stored gsbase

#

but in kernel mode you ignore the thread's gsbase field in its context

surreal path
#

and why do u only write to gs base when going / coming out of a user thread now im even more confused 😭

finite summit
#

you know how in your ISR handlers

#

you swapgs on teh condition that you were interrupted in user mode

#

*the

surreal path
#

yea

finite summit
#

in your thread context switch function

#

if you are going to a user thread

#

you do the same

#

swapgs
then you write gsbase to whatever the user thread had it at before

#
    test qword [rdi+16+0xB8], 0x3 ; cs & 0x3 (is user mode?)
    je .restore_fs_base
    swapgs
    mov eax, [rdi]
    mov edx, [rdi+4]
    mov ecx, 0xC0000101
    wrmsr```
surreal path
#

okay but like

#

why do we even store the current cpu struct in gs base in the first place

#

if we swapgs

#

or whatev

finite summit
#

and sometimes necessary

surreal path
#

and on sched init when u setup the cpus

#

do u write the gs_base?

#

to set the cpu_local struct?

finite summit
#

What.

#

Bro this is not that hard 😭

surreal path
#

im sorry bro 😭 my brain dies

finite summit
#

OK forget everything
you have a CPU local struct

#

you initialize it

#

you store a pointer to it inside of gs_base

surreal path
#

in the thread struct right

finite summit
#

no

surreal path
#

oh

finite summit
#

you store a pointer to the cpu local struct

#

in gsbase

#

and for each CPU the value of gsbase differs

surreal path
#

okay but do u write to gs base the ptr right

#

yes or no

finite summit
#

reword that

#

I failed to parse that sentence

surreal path
#

when u setup the cpus -> do you create the cpu_local_struct, wrmsr to gs base a ptr to the cpu_local struct on whatever cpu

am i understanding this correctly or do i have severe brain rot

finite summit
#

you do do that

surreal path
#

oh okay makes sense

#

is it GS_BASE or KERNEL_GS_BASE which msr?

finite summit
surreal path
#

okay

finite summit
#

KERNEL_GS_BASE is for swapgs stuff

surreal path
#

now the reason we swapgs is because usermode likes to store stuff in gs right?

finite summit
#

yup

surreal path
#

makes sense, and for getting the cpu_local struct on schedule_task() we read the GS_BASE msr correct?

finite summit
#

@junior solstice who dis?

finite summit
#

and you can use gs-relative accesses in assembly

surreal path
# finite summit yes

if we are returning/coming to usermode we write to kernel_msr_base whatever is in gs_base the usermode thread struct

finite summit
#
mov eax, gs:0x8```
surreal path
surreal path
#

oh

finite summit
#

if you are going to/coming from usermode

#

you would swapgs

surreal path
#

mhm

finite summit
#

when you are going to usermode

#

that puts the user's GS base value in GS_BASE and the kernel's GS base inside of KERNEL_GS_BASE

#

and when you are coming from user mode it does the opposite

#

the user's gs base value goes in KERNEL_GS_BASE

#

and the kernel's goes in GS_BASE

#

because what swapgs does is swap the values of the KERNEL_GS_BASE and GS_BASE msrs

surreal path
#

and im guessing the kernels gs base (not talking abt the msr)

#

is the one that stores the cpu local struct

finite summit
#

yes

#

and the user's stores whatever

#

the user's GS base can really have anything it wants

#

the kernel doesn't give a shit about what is in it

#

it only gives a shit about making sure both user code and kernel code have the GS base they expect

surreal path
#

okay so

if cs was coming from usermode:
get cpu local from gs_base
do run queue stuff
and if going to usermode:
write to msr kernel_gs_base value of gs_base from thread
going to kernel mode:
do not write anything

if cs was coming from kernel mode:
get cpu local from gs_base
do run queue stuff
and if going to usermode:
write to msr kernel_gs_base value of gs_base from thread
or if going to kernel_mode
no writing

#

do i understand?

finite summit
#

you never write to kernel_gs_base

#

directly

surreal path
#

oh

finite summit
#

if cs was coming from usermode
swapgs
do shit
swapgs (on return)

#

if cs is coming from kernel mode
do shit

surreal path
#

okay and

#

for getting the cpu local struct

#

what do u do

#

if ur coming from usermode or coming from kernel mode

#

and for writing the value of gs_base if ur going to usermode

#

what msr do u write to

#

like make it like an if statement ill probs understand lmao

#

😭

finite summit
surreal path
#

mhm

elder shoal
#

swapgs

finite summit
#
if (frame->cs & 0x3)
    swapgs
// do IRQ shit
if (frame->cs & 0x3)
    swapgs
iretq```
surreal path
#

i understand the swapgs part

finite summit
#

well depends

#

are you going to usermode from an irq handler

#

if so then swapgs handled it for you

#

if it's in a thread context switch

#

then you can write to KERNEL_GS_BASE then swapgs

surreal path
#

not the irq handler

#

😭

finite summit
#

or you can swapgs then write to GS_BASE

surreal path
#

and if ur NOT going to usermode

#

no writing

#

right

finite summit
#

write

#

*right

#

bruh

surreal path
#

so

if coming from usermode:
swapgs
rdmsr gs_base to get cpu local struct
do shit
if going to usermode
writemsr kernel_gs_base value of thread gs_base
swapgs
iretq
else
do nothing and dont swapgs then iretq

if comfing from kernel mode:
no swapgs
rdmsr gs_base to get cpu_local struct
if going to usermode
writemsr kernel_gs_base value of thread gs_base
swapgs
iretq
else
do nothing and dont swapgs then iretq

#

yea that actually

#

sounds rlly

#

easy

#

😭

#

why didnt i understand it first try

#

πŸ’€

#

its lit the same shit

#

@finite summit thank you for making me understand

#

:D

#

now is funny scheduling time muheheheh

finite summit
#

np

surreal path
#

also rust community told me to use an AtomicPTR for the cur thread or whatever

finite summit
surreal path
finite summit
surreal path
finite summit
#

A raw pointer type which can be safely shared between threads.

#

This type has the same size and bit validity as a *mut T.

Note: This type is only available on platforms that support atomic loads and stores of pointers. Its size depends on the target pointer’s size.

surreal path
#

okay i see

surreal path
#

stacks themselves

finite summit
#

ask him why

surreal path
#

okay askimng

#

lol

finite summit
#

idk why you would need atomic accesses for stack bases

#

for syscalls

#

considering the syscall handler is in assembly

#

idek what difference that makes

surreal path
#

yea i agree

#

to be honest

finite summit
#

in my syscall handlers, scheduler preemption is disabled

#

but you can still be preempted by other IRQs

finite summit
surreal path
#

time to open vscode

finite summit
#

it simply swapgss first thing then switches to a kernel stack stored in the per-cpu struct

surreal path
#

run_queue can just be the head or smthin

#

of the run queue

#

ok ez

finite summit
#

it doesn't

surreal path
#

what if the syscall meows

#

:3

finite summit
#

shit it does

finite summit
surreal path
#

😑

finite summit
#

they can

surreal path
#

!!!

finite summit
elder shoal
#

Smh oberrow

surreal path
#

smh mathew

#

SYSCALLS CAN MEOW

#

GRRR

#

@finite summit how big of a kernel stack should i alloc

#

256k?

finite summit
#

very

#

set it to some small value

#

when it runs out make it bigger

surreal path
#

ill just set it to 256k :)

#

thats like

#

63 pages

#

ish

finite summit
#

note that it will be allocated for each user thread

cinder plinth
surreal path
#

jason spotted

finite summit
#

memory usage be like:

surreal path
#

oh

#

then how will i know

#

the stack runs out

#

???

#

????

cinder plinth
#

my user stacks are like 2mib

edgy pilot
#

mine too

#

and 64kib for the kernel

surreal path
#

oh ok

cinder plinth
#

yeah same

#

exactly

surreal path
#

i will do the same then

cinder plinth
#

the kernel stacks are preallocated

#

user stacks are on-demand

surreal path
#

how

#

tho

#

how does that work lol

edgy pilot
#

you allocate user stack whenever a thread is created

surreal path
#

mhm

#

what next

edgy pilot
#

and optionally increase its size (?)

surreal path
#

what

cinder plinth
#

no

edgy pilot
#

good to know

cinder plinth
#

the stack is just an anon mapping like any other

#

they're allocated lazily

#

i.e. on page fault

surreal path
#

oh and i have to implement that...

#

fuck

#

:c

edgy pilot
#

mmap

cinder plinth
#

demand paging is very easy

edgy pilot
#

^

cinder plinth
#

CoW is where it gets a bit trickier and requires a bit of thinking

surreal path
#

how does it work

#

demand paging

cinder plinth
#
on page fault:
  if cr2 was mmap-ed && fault == non_present:
    map_page(faulted_page, alloc())
edgy pilot
#

When you map, you don't actually map but store that information somewhere
whenever a process tries to access an unmapped page, it page faults and you map it

edgy pilot
#

wdym what

surreal path
#

store that information where

edgy pilot
#

you implement that

cinder plinth
#

in some kind of struct

#

I keep it in a Vm::Space

#

kinda

surreal path
#

i dont know how to implement this im dead inside nooo

cinder plinth
#

which is per process

cinder plinth
#

64kib user stacks

#

that's the shitty but works way

surreal path
#

ok

cinder plinth
#

the good way is growing the stack as needed

#

linux stacks can get to 8mib iirc

edgy pilot
elder shoal
#

Yeah linux has a pretty big user stack

surreal path
#

im just gonna

#

64kib user stack

#

i just want a working os anyway like nooo

elder shoal
#

This iteration of astral only had demand allocation at first but then I expanded it to copy on write and proper file mappings with page cache etc

edgy pilot
edgy pilot
#

yes but it's simple

surreal path
#

trust

#

:)

cinder plinth
#

use rbtree!!!! (/s kinda)

edgy pilot
#

I have never actually used rbtree

cinder plinth
#

or any datastructure that allows for better searching

surreal path
#

if kernel explodes due to stack size being too small just increase stack size

#

memory usage?

#

pfft

#

whats that

cinder plinth
#

idk how good that would be

#

probs sucks space-wise

edgy pilot
#

yes

cinder plinth
edgy pilot
#

does rust have a built in hash map
like Vec

surreal path
#

anyways @finite summit ive created the cpu local structs written them to gs base, now how do i decide which thread do i give to which cpu for the kernel entry thread or whatevs

cinder plinth
#

in the standard library yea

surreal path
#

i use hashmaps

edgy pilot
surreal path
#

in my kernel

#

:)

cinder plinth
cinder plinth
elder shoal
cinder plinth
#

yeah

elder shoal
#

I still use it in astral

cinder plinth
#

realistically a process wont mmap 1000 times

edgy pilot
cinder plinth
#

you'd need to keep it sorted

#

then

edgy pilot
#

oh yeah
just insert sorted :D

finite summit
#

not using C?

#

or just don't wanna

cinder plinth
#

because ew C!!

cinder plinth
#

I'm currently in the process of phasing out frigg

surreal path
#

do i just give it to the buttstrap cpu

edgy pilot
cinder plinth
#

now where my vmm sucks is the amap

#

I use a linked list for that too

edgy pilot
#

amap?

#

anon?

surreal path
#

someone pin this

#

best joke ever

cinder plinth
edgy pilot
#

yes

cinder plinth
#

basically you have one entry per page

surreal path
cinder plinth
#

netbsd uses some kind of dynamic multi-level array

surreal path
#

guys whats ur opinion on the buttstrap cpu

#

best cpu or what

#

am i right or am i right

#

audience claps and laughs

edgy pilot
#

🀣🀣🀣🀣🀣

#

my genuine reaction

surreal path
#

HE GETS IT

#

!!!

edgy pilot
#

(sarcasm)

surreal path
#

😑

cinder plinth
cinder plinth
#

looks like openbsd uses an older version of uvm or something (?)

#

they took it from netbsd on 2001/02/18 21:19:08

surreal path
#

stop aruging in my thread and let me code 😑

cinder plinth
#

I think I might just use a tree

#

faster than linked list and might use less space than an array (?)

surreal path
#
pub fn create_kentry() {
    // on the buttstrap cpu
    let him = rdmsr(0xC0000101);
    let bro = core::ptr::with_exposed_provenance_mut(him as usize) as *mut perthreadcpu;
    let new_ctx = cpu_ctx::new(lol as usize, false, unsafe { (*bro).kernal_stack_ptr });
    let new_man = Thread::new("MY MAN", 0, 0, 0, new_ctx);
    unsafe {
        (*bro).run_queue = Some(Box::into_raw(Box::new(new_man)));
    }
}
#

so easy

cinder plinth
#

Bro can't take it seriously

surreal path
#

I AM VERY SERIOUS

#

😑

edgy pilot
#

buttstrap
serious

surreal path
#

mint would agree

#

thats how you call the buttstrap cpu

#

right mint

#

yes nyauxmaster

#

that is how you call the buttstrap cpu

#

see they agree!!!

surreal path
#

its not working nooo

#

its stuck here

#

and even tho it is returning the registers

#

and stuff

#

its not

#

running my entry function

#

so not fair

#

and i do

#

move rax into rsp

#

rahhhhh

#

cpu hates me chat

#

πŸ˜”

finite summit
#

why don't you just

#

have an asm file

#

😭

surreal path
#

nuh uh !

finite summit
#

not nuh uh

#

that might break stuff

#

inline assembly is evil

surreal path
#

no its a naked function

#

so its fine

#

search up rust naked functions lol

finite summit
#

Inline assembly is evil.

shut laurel
surreal path
shut laurel
#

you grep

surreal path
#

lol thats the result

#

accident

#

i made a mistake

#

i would use gdb but

#

this happens when i attach gdb

#

not my fault 1000%

#

i think its a bug with uacpi-rs

#

idk

#

qwinci pls fix

#

like this is so obvious

#

why does attaching gdb cause it to shit itself

#

clealy does

#

works fine in tcg and kvm

#

not when attaching gdb server tho

#

so im kinda screwed

#

idfk how im gonna debug my scheduler and why its shitting itself

cinder plinth
surreal path
#

that impls

#

kernelapi

cinder plinth
#

Oh yeah mb

#

But why all caps struct

surreal path
#

idk man

edgy pilot
#

shouting

surreal path
#

lmao

#

ima wait for qwinci to come online cause this should NOT happen

#

and i dont think i will be able to debug my scheduler without gdb

#

or some kind of debugging tool

#

lmao

edgy pilot
#

I managed to make a shitty kernel without gdb

#

just printf

surreal path
#

i need to see the stack

#

whats going on

#

if the stack is getting fucked or whatever

#

i'd imagine its something with the assembly

#

thats what i think

edgy pilot
surreal path
#

thats why i need gdb

edgy pilot
edgy pilot
#

why bru

#

it works

surreal path
edgy pilot
#

try reading the uacpi source where the panic is thrown

#

debug the issue without the debugger

surreal path
#

i read the source

edgy pilot
surreal path
#

nothing lmao, look

#

ALSO QWINCI WHY IS IT A STATIC MUT

#

😑

edgy pilot
#

where does it panic

surreal path
#

line 183

edgy pilot
#

show me the line 183

surreal path
edgy pilot
#

Where is it called from

edgy pilot
surreal path
#

called when uacpi::init

edgy pilot
#

and where is it called from?

surreal path
#

my acpi::init function

edgy pilot
#

can you show it to me

surreal path
#

yea

#

thats it

edgy pilot
#

common rust L

surreal path
#

its not a rust L

edgy pilot
#

what is it then

#

user L?

surreal path
#

idk man

#

i rlly dont know

#

maybe rust is optizming the struct out?

#

cause theres no data in it

#

idk why it'd do that tho

edgy pilot
surreal path
#

considering it works fine on release mode with kvm or tcg

#

without the gdb server

surreal path
edgy pilot
#

so when does it not work

surreal path
#

when attaching gdb

#

with qemu

edgy pilot
#

gdb L then

surreal path
#

maybe

#

making the struct contain data changes nothing

finite summit
surreal path
surreal path
#

it clearly is context switching

#

wtf???

surreal path
#

further debugging shows invalid opcode

surreal path
#

_print is causing 0x6?

#

invalid op code?

#

maybe UB?

kind root
#

Call cannot produce 0x6

#

U sure thats the instruction pointer?

surreal path
#

i dunno but it is what is says before it triple faults

kind root
#

Does it say 7c0

surreal path
kind root
#

Then why are u looking at something else

surreal path
#

7c0

#

which is

#

my print function

kind root
#

Broooo

#

Ur looking

#

At things

#

Calling it

#

Not at the address itself

surreal path
#

yea im trying to look for it

#

wait

spice yarrow
#

x/10i 0xffffffff000007c0

surreal path
#

but ill try again

spice yarrow
surreal path
spice yarrow
#

Or even just objdump -Mintel -d kernel

#

And then find the address

surreal path
#

weirdly it just doesnt wanna show me whats going on

#

im unsure why

kind root
#

So its just push rbp

#

Why is it calling itself tho

surreal path
#

idfk

#

wait no

#

nvm

#
ffffffff800007c0 <NyauxKT::term::_print>:
ffffffff800007c0:       55                      push   rbp
ffffffff800007c1:       48 89 e5                mov    rbp,rsp
ffffffff800007c4:       48 83 ec 10             sub    rsp,0x10
ffffffff800007c8:       48 89 fa                mov    rdx,rdi
ffffffff800007cb:       b1 01                   mov    cl,0x1
ffffffff800007cd:       0f 1f 00                nop    DWORD PTR [rax]
ffffffff800007d0:       31 c0                   xor    eax,eax
ffffffff800007d2:       f0 0f b0 0d 6e 11 04    lock cmpxchg BYTE PTR [rip+0x4116e],
#

found it

#

looks fine ummm

#

this is weird, flanterm doesnt even use my allocator so

#

hmm

#

push rbp is not an invalid instruction

#

i even have a double fault handler so

#

this is very weird

kind root
#

Dump memory contents at the time of crash

surreal path
spice yarrow
#

Dump using the qemu monitor

surreal path
#

k will do

spice yarrow
#

It's not as good as gdb, but it's still useful

surreal path
#

yep i just cannot use gdb

#

weird UB

#

happens

spice yarrow
#

Well you should definitely fix that sometime

surreal path
#

memory map

surreal path
#

this is the same problem

surreal path
spice yarrow
#

info tlb

surreal path
#

k

spice yarrow
#

it's not actually the tlb but every memory mapping

#

idk why it's called that

surreal path
spice yarrow
#

That's weird, I thought it combined sequential entries

surreal path
#

page table bug hmm

#

no not rlly

spice yarrow
#

Question, what if you report your kernel entry point with loop { asm!("out 0xe9, {}", in("al")b'!') }

#

try to see if you can get gdb to connect to that

surreal path
spice yarrow
#

yeah

surreal path
#

kk

#

mr sharkie

#

this you?

#

face reveal

#

exposed

spice yarrow
#

how did you find outβ€½

surreal path
#

magic

#

gdb connected

#

whats next

#

btw im NOT running a mac swear

#

😭 πŸ™

#

what next

spice yarrow
surreal path
#

okay

#

no recongized

#

"gdb"

#

in type: "gdb"

spice yarrow
#

Install gdb

#

Oh wait you need the extension, just a sec

#

Also the executable path should be NyuaxKT for you

surreal path
#

okay

surreal path
spice yarrow
surreal path
#

ok done

spice yarrow
#

What I find gdb super useful for is getting backtraces

surreal path
#

okay got gdb now @spice yarrow

#

do i remove the uh

#

asm thing or what

#

and how do i run commands to gdb via the debug console in vscode

spice yarrow
#

yeah, remove it and see if you can step through everything

spice yarrow
spice yarrow
#

If you want to manually run gdb commands then launch gdb in your bash shell

#

if you want a nice gui use vscode

surreal path
#

nah its fine ill just

#

use it

#

wheres the

#

invalid opcode fault

#

wtf

spice yarrow
#

okay you might be able to do -exec command in the debug console

spice yarrow
surreal path
#

in uacpi-rs

#

and it has invalid opcode otherwise

spice yarrow
#

No like open the file and ss it

surreal path
spice yarrow
#

okay so it's returning an error, fix however your calling uacpi

surreal path
#

bro

#

???

spice yarrow
#

you aren't getting invalid opcodes anymore

surreal path
#

WHEN NOT ATTAHCING GDB

#

😭

#

AND IM DOING EVERYTHING CORRECT

spice yarrow
#

wait so it still does different stuff with gdb attached?

surreal path
#

yep

spice yarrow
#

wtf

surreal path
#

I KNOW!!!

#

😭

#

qwinci says its my allocator so clearly somethings wrong idfk

#

difficult to debug without gdb

#

im screwed maybe

#

im just gonna ask the rust gods @spice yarrow in their os-dev channel

#

maybe they might know

#

idfk

#

cause i lit have no option

cinder plinth
surreal path
#

its showing wsl as that icon for some reason

cinder plinth
#

what

surreal path
#

yea

#

idfk

cinder plinth
#

There's a remote desktop title on the top left

surreal path
#

idfk but its wsl

cinder plinth
#

Is that heavily customized windows or what

surreal path
#

im not using "rdp"

surreal path
cinder plinth
#

And a top bar thing

surreal path
#

part of the dock

cinder plinth
#

So the GUI apps are remote

surreal path
#

we have more information

#

!!!

#

commenting out

#

everything

#

related to writing to the limine terminal

#

it page faults here

#

CR2=0xffffffffffffff84

#

error code is 0

#

in here

#

cr2 is actually this

#

interesting

#

it is most likely a rust skill issue im afraid

#

asking rust peopel for help

finite summit
#

Please do not tell me you used the feature request

elder shoal
#

Probably meant flanterm?

surreal path
#

flanterm

#

also i have been sleeping all day

#

😭

#

might not get any work done today

#

i have a lot of homework

#

maybe tmerw

surreal path
#

ok back

#

lets um

#

fix this

surreal path
#

still going back and forth with the

#

rust community rn

#

cause my page table just always never works

#

chat im going to cry

#

its UB

#

always ub

#

fucking ub

#

i hate ub

#

with a venginence

#

aaaa

#

nyaux try not get stuck with rust skill issue #5012616 @finite summit am i right or am i right

#

if i started with C

#

we could have signals by now

#

im genuinely like

#

im so tired

#

writing a rust kernel

#

has been an absolute nightmare for me

surreal path
#

c++ has iterators

#

and stuff

finite summit
#

C++ is fun for osdev

#

Just don't do anything stoobid (global constructors)

surreal path
#

think about switching

#

cause im actually

#

so annoyed

#

with rust now

#

drives me insane

cinder plinth
#

nice now I'm cold

cinder plinth
finite summit
#

like not the too cold

#

the cozy cold

#

thanks to canada, I get ~0 degree weather in the middle of autumn

cinder plinth
#

same

#

wait ur canadian

#

which province

finite summit
#

not canadian, but have lived in canada my entire (short) life

finite summit
cinder plinth
#

ah so probs warmer than here

finite summit
#

I've heard you're in quebec?

cinder plinth
#

yea

finite summit
#

from misc sources

#

cool

#

my friend once went to quebec and the first thing he said was "hon hon oui oui baguette"

finite summit
cinder plinth
#

well not rlly

#

but like

#

as soon as you enter the airport you'll hear english

finite summit
#

we're the only two osdevs in canada (not)

#

any osdevers in canada?

cinder plinth
#

brian kernighan is canadian

#

idk if he counts

finite summit
finite summit
#

and idk who that is lol

cinder plinth
#

bro

finite summit
#

some old guy it seems

cinder plinth
#

the K in K&R

finite summit
#

ohhhhh

cinder plinth
#

designed go?

finite summit
#

that guy

cinder plinth
#

the k in AWK too

finite summit
#

I forgor what that command does

#

pattern scanning

#

and text processing language

cinder plinth
#

it's a language

#

btw he literally coined hello, world

#

so idk I think he had atleast a little impact meme

finite summit
#

nah not that much /j

#

literally did nothing but invent C

#

like why didn't he invent rust instead

cinder plinth
#

nah ritchie invented C

#

kernighan helped write the book

finite summit
#

same thing

cinder plinth
#

idk if he helped design GO tho, he did write the book

finite summit
#

I need to read up on programming history tbh

cinder plinth
#

also designed m4

finite summit
#

m4 carbine?

cinder plinth
#

kinda crazy we still use 1970s scripting languages

spice yarrow
cinder plinth
#

no the script configuration thing

#

macro processing language

#

I've never used it but it's used in e.g autotools

finite summit
#

autotools is delusional

cinder plinth
#

ah it's kinda like a preprocessor

finite summit
#

I'd sudo apt remove it if I didn't need it for building gcc n' stuff

cinder plinth
#

autotools is nice for some stuff

finite summit
#

not stuff that I do

#

CMake my beloved

spice yarrow
cinder plinth
#

autotools is dead simple to cross-compile with

#

./configure --target=blabla

finite summit
cinder plinth
#

C has no restrictions

finite summit
#

didn't you used to be clang

cinder plinth
#

clang I am no more

finite summit
#

I 3> implicitly casting void* to int*

#

when I allocated a short

#

(never happened)

#

I am sorry, why is there a pregnant man emoji on discord

#

unless I'm missing something that is impossible

#

unless it's like, trans man pregnant

cinder plinth
#

yeah maybe

finite summit
#

anyway I have a handle system to fix

#

damn thing doesn't like my handles

spice yarrow
cinder plinth
#

I have no idea what that means

finite summit
#

maybe has something to do

#

with

#

invariant stuff

#

stuff that do not vary

#

wtf

#

rust my behated

finite summit
#

I get blanket and be back

#

back

spice yarrow
cinder plinth
#

how

elder shoal
#

Rust should just define every single possible behaviour and become the first language without ub

finite summit
#

rsut should just make your programs for you

#

OH WAIT

spice yarrow
#

You can never have two &mut at the same time

finite summit
#

It already does

cinder plinth
#

oh right you're borrowing two times

surreal path
#

i want to cry

spice yarrow
#

There's also the fact that thread::spawn can never capture non-static lifetimes, even if the thread is killed when it's dropped

surreal path
#

because im such a shitty programmer

finite summit
#

don't say that

#

and use C

cinder plinth
#

do you even know C++

surreal path
#

no

#

not rlly

spice yarrow
#

you wouldn't have to worry about rust's crazy invariants

cinder plinth
#

I've been using C++ for a while and I still get confused over stuff like std::forward

spice yarrow
#

which is what seems to be your main struggle

cinder plinth
#

(wtf does it do?)

#

(ok I know what it does but it's still confusing)

surreal path
#

hashmaps are so useful

finite summit
#

it does tho