#Nyaux

1 messages Β· Page 36 of 1

edgy pilot
#

iopb btw

silver yarrow
#

yeah

#

mb

#

like if u set offset to zero, arent u saying that the 104 bytes of tss are actually iopb

silver yarrow
#

yeah thats what I do

#

basically saying there is zero bytes in iopb

#

because the limit is 104

surreal path
#

okay but

#

i dont get how this relates to all the UB

#

going on

silver yarrow
#

it probably doesnt but im intrigued

surreal path
#

FAIR LOL

#

whoosp caps lock

edgy pilot
surreal path
#

but adding it causes this

#

πŸ€·β€β™‚οΈ

edgy pilot
#

then something else is the problem

surreal path
#

most likely

silver yarrow
#

iobp base == 0 would be a bit of a security issue no? because u are prolly allowing some portio in userspace by accident

surreal path
#

its fine

edgy pilot
silver yarrow
#

fair

#

ok ill get back to debugging @surreal path

surreal path
#

ill try to also debug as well

#

thanks for the help btw

silver yarrow
#

wait

#

where do u even load the tss

surreal path
#

gdte.asm

silver yarrow
#

ah

#

thats... undocumented

#

lol

surreal path
#

lol

flat nymph
#

uint16_t sizeoftss = sizeof(struct TSS) - 1;?

surreal path
#

i mean

#

it fits in a uint16

silver yarrow
#

lol

surreal path
#

also - 1

#

yea

silver yarrow
#

its the limit

surreal path
#

so what lol

surreal path
silver yarrow
#

whats the last commit that works

surreal path
#

uhhhh that one

silver yarrow
#

lmao aight

flat nymph
#

I give it sizeof(TSS)

#

Without -1

silver yarrow
#

dont do that

#

oh wait

#

no I do that

#

now I gotta figure out whos right

#

sec

flat nymph
#

What does SDM say on the matter

#

sizeof(TSS) -1 doesn't crash my kernel

#

But I'm setting granularity bit

#

Yeah it's working

#

uint64_t constructedlow = ((uint64_t)base_low << 16) | ((uint64_t)base_mid << 32) | ((uint64_t)base_midhi << 56) | ((uint64_t)access_byte << 40) | sizeoftss;

#

Base mid

#

why << 32

#

Ok it's right nvm

surreal path
#

because

flat nymph
#

Somehow everything looks right to me

surreal path
#

lmao

silver yarrow
#

I am still trying to figure out whether the limit is -1

#

lol

#

I assume it isnt

flat nymph
#

Have you tried aligning struct TSS?

#

To 4

#

Not sure it will change anything

#

since it's after lapic_id

surreal path
#

i dont think it will

#

tbf

flat nymph
#

Now

#

When does it crash

#

In init_gdt()?

surreal path
#

i told u its random each boot

flat nymph
#

Are you sure it's because of TSS?

surreal path
#

i dont know

#

genuinely

flat nymph
#

How do I build this thing

silver yarrow
#

do u have nix

flat nymph
#

error: 'cc-runtime' is not a Git repository

flat nymph
surreal path
#

remember

silver yarrow
#

L

#

this is consitently the fail

#

with one cpu

surreal path
#

cd into cc-runtime

#

mkdir .git

silver yarrow
#

I am pretty convinced this has absolutely nothing to do with the tss

surreal path
#

yea same

surreal path
silver yarrow
#

OK @surreal path WTF

surreal path
silver yarrow
flat nymph
#

0xd

silver yarrow
#

what in the fuck is this

flat nymph
kind root
surreal path
#

its unfinsihed

finite summit
finite summit
surreal path
flat nymph
#
0: v=0d e=0048 i=0 cpl=0 IP=0028:ffffffff80087878 pc=ffffffff80087878 SP=0030:ffff800007b0efb8 env->regs[R_EAX]=0000000000000048
RAX=0000000000000048 RBX=0000000000000000 RCX=ffffffff800efc60 RDX=01000099802c0000
RSI=0000000000000000 RDI=ffffffff800efc00 RBP=ffff800007b0efe0 RSP=ffff800007b0efb8
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff80087878 RFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
CS =0028 0000000000000000 00000000 00209b00 DPL=0 CS64 [-RA]
SS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
DS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
FS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
GS =0030 ffff800001998018 00000000 00009300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     ffffffff800efc10 00000057
IDT=     0000000000000000 00000000
CR0=80010011 CR2=0000000000000000 CR3=000000000005a000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000001ffff0000 CCD=00000000ffff8000 CCO=SARQ
EFER=0000000000000d00
check_exception old: 0xd new 0xd
     1: v=08 e=0000 i=0 cpl=0 IP=0028:ffffffff80087878 pc=ffffffff80087878 SP=0030:ffff800007b0efb8 env->regs[R_EAX]=0000000000000048
RAX=0000000000000048 RBX=0000000000000000 RCX=ffffffff800efc60 RDX=01000099802c0000
RSI=0000000000000000 RDI=ffffffff800efc00 RBP=ffff800007b0efe0 RSP=ffff800007b0efb8
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff80087878 RFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
CS =0028 0000000000000000 00000000 00209b00 DPL=0 CS64 [-RA]
SS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
DS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
FS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
GS =0030 ffff800001998018 00000000 00009300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     ffffffff800efc10 00000057
IDT=     0000000000000000 00000000
CR0=80010011 CR2=0000000000000000 CR3=000000000005a000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000001ffff0000 CCD=00000000ffff8000 CCO=SARQ
EFER=0000000000000d00
check_exception old: 0x8 new 0xd
kind root
#

Most stable part of nyaux

surreal path
silver yarrow
#

surprise surprise when I commented out the unfinished part it works

surreal path
#

does removing that line solve anything

#

insane

silver yarrow
#

that and this

surreal path
#

i still need to load the kernel registers into a kstack

#

and then load the userspace registers

flat nymph
#

It's crashing in ltrw still

surreal path
#

oh

surreal path
#

πŸ’₯

#

nooo *

flat nymph
#

No

#

We are fixing TSS

#

sorry not sorry

silver yarrow
#

oh wait

#

I did another fix

#

let me see if I remoev that

surreal path
silver yarrow
#

hm

#

no it still works for me

surreal path
#

huh

#

weird

silver yarrow
#

@flat nymph

#

does it work if u just run one core

flat nymph
#

Btw this

TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
seems half-sus

flat nymph
#

When he's loading other cores

#

I guess

silver yarrow
#

lmao

#

alright lemme put in a couple more cores

#

ah yeap

flat nymph
#

How do I change how many cores it has

surreal path
silver yarrow
#

makefile

#

the top level one

flat nymph
#

Oh

#

SMP 20

silver yarrow
#

yeap

#

very debug friendly

flat nymph
#

It page faults

surreal path
#

fun

silver yarrow
#

a lot

surreal path
#

more UB

flat nymph
#

In memcpy

silver yarrow
#

per_cpu_data is NULL

#

so thats

#

eh

surreal path
#

it shouldnt be

silver yarrow
#

OH REALLY?

surreal path
#

yea

finite summit
#

Lmfao

flat nymph
#

In create kentry

finite summit
silver yarrow
#

well ubsan is screaming

finite summit
#

You've no one but yourself to blame

silver yarrow
#

so he's not all that wrong

#

though he definitely created the ub

finite summit
#

Just come work on obos with me

surreal path
kind root
surreal path
#

im not giving up on my kernel

surreal path
silver yarrow
#

on the BSP

finite summit
silver yarrow
#

do u even create the local data

finite summit
#

uEC

silver yarrow
#

I cant pinpoint where u do

surreal path
kind root
surreal path
#

check sched.c

finite summit
kind root
#

Nooby

silver yarrow
#

no the fuck its not

#

where

surreal path
silver yarrow
#

lol

#

where

surreal path
#

look

silver yarrow
#

look WHERE

surreal path
#

sched/sched.c

finite summit
#

That looks like per cpu data to me

silver yarrow
#

oh wtf

#

jesus

surreal path
#

wdym

#

@flat nymph told me to do it

#

for the bsdp

#

bsp*

silver yarrow
#

no its just in between a bunch of funcs

#

so where exactly do you write it into gs

surreal path
#

hold on

#

for creating it

#

for other cpus

#

that arent the bsdp

#

bsp*

silver yarrow
#

yes ik

finite summit
#

Whatever happened to normal variable names...

silver yarrow
#

there u write that into the msr

#

where do u write the msr for the bsp

surreal path
#

i dont

silver yarrow
#

oh and we have arrived at the fucking ub

surreal path
#

have we????

silver yarrow
#

sec

finite summit
#

He returns &bsp if he's on the bsp

#

In get cpu local

silver yarrow
#

oh jesus

flat nymph
silver yarrow
#

thats so cooked

silver yarrow
#

but its fine

finite summit
flat nymph
silver yarrow
flat nymph
#

It does

silver yarrow
#

doesnt

surreal path
#

but wheres the ub wux

#

u said u arrived

flat nymph
silver yarrow
#

that doesnt get called for the bsp

surreal path
#

check limine spec @flat nymph

flat nymph
flat nymph
surreal path
#

its ignored for the bsp

flat nymph
#

Oh bsp

#

But still

#

It's never set

finite summit
#

Nyaux challenge: Don't have people get confused as shit when they read it's code, level impossible

silver yarrow
#

real

finite summit
#

Tbf reading obos' code can give brain cancer

#

At one point I started adding "Abandon all hope, ye who enter here" to the beginning of some files

flat nymph
silver yarrow
#

speaking of

finite summit
#

lmao

flat nymph
#

Yes

surreal path
#

lol

finite summit
#

obos code is bad

#

but not THAT bad\

surreal path
#

but wux wheres the UBu said u found it?

#

??

silver yarrow
#

no I thought I did

surreal path
#

ohhh

#

okay

silver yarrow
#

apparently u do some cursed shit with the bsp local

#

not sure why it wouldnt work like every other cpu local but it is Nyaux so

surreal path
#

fair

flat nymph
#

It casually pagefaults in if (cpu->run_queue == NULL && cpu->start_of_queue == NULL)

silver yarrow
#

yes ubsan catches it

flat nymph
#

What if I actually set msr in BSP? roundnthonk

silver yarrow
flat nymph
#

asserts everywhere really help with that btw

surreal path
#

that makes no sense

#

at all

silver yarrow
#

yes

surreal path
#

yes u agree with me

silver yarrow
#

sure do

flat nymph
#

Could rdmsr be casually broken?

#

It failed on all 20 cores

silver yarrow
#

LMAO

flat nymph
#

Although that makes no sense

flat nymph
#

Or wrmsr

#

Because wtf

silver yarrow
#

nah they're fine

#

checked em

flat nymph
#

Because idk

#

He writes msr

#

I've printfed it

#

Then reads 0 back from it

#

Like how

surreal path
#

THAT SHOULD NOT HAPPEN

flat nymph
#

Your swapgs is broken

#

lemmy try something

surreal path
#

how

#

how are u so sure

flat nymph
#

je

#

I need bochs

#

or gdb

#

Nope

#

what the f

surreal path
#

on the foruth day of christmas nyaux gave to me

#

5 billion bugs

#

and the sixth day of christmas nyaux gave to me

flat nymph
#

Give up

surreal path
#

an extra memory bug under the tree

surreal path
#

wtf

#

that is not nice

#

tf

flat nymph
#

I don't get the pattern

surreal path
#

what pattern

flat nymph
#

What is going on with your kernel

#

Some cores have cpu local data

#

Some don't

surreal path
#

ill solve it

#

but first

#

we need to solve these bugs

#

@silver yarrow i see everyone is struggling with the cursedness of nyaux lol

surreal path
#

that is weird

#

that shouldnt happen

#

tf

surreal path
#

cause otherwise none of this would happen

#

it has to be memory corruption or something

finite summit
#

obos only has minor memory corruption, come work on it instead

surreal path
#

some bug in the slab or vmm

finite summit
surreal path
#

it will never happen

finite summit
#

It is joke

surreal path
#

ik

finite summit
#

Chill

surreal path
flat nymph
#

how does this even happen

surreal path
#

u chill

finite summit
kind root
#

Still waiting for suspend article on osdev wiki

surreal path
#

may allah help me figure out these bugs

#

i hope allah will help

finite summit
#

Yeah only prayer can help you now

surreal path
#

pretty much 😭

kind root
#

You know what else can help

surreal path
#

what

kind root
#

Working on obos instead

surreal path
#

lmao

#

@flat nymph can u maybe join vc

#

i wanna see the bugs for myself

#

if ur free ofc

flat nymph
#

Ok

surreal path
#

okay

finite summit
#

Actually not oberrow approved, he will curse obos

#

you might be saying to yourself, "obos is already cursed though"

kind root
#

Or u can uncurse nyaux

finite summit
#

it pales in comparison to nyaux

finite summit
#

no thanks

kind root
#

Lol

#

Mr beast should make a video about hiring every Microsoft engineer to work on nyaux

#

Can all ms engineers decurse nyaux

finite summit
#

no

#

they can rewrite it

surreal path
#

impossible task

kind root
#

No rewrites

finite summit
#

they would end up rewriting it in the end meme

#

the diff would be -10000 +10000

kind root
#

Lol

finite summit
#

speaking of diff lapfedmoment

#

Can’t automatically merge.
nooo

kind root
#

Commit message: fix all memory corruption bugs in obos

surreal path
#

we found the issue

#

its the asm

#

in load and save ctx

#

and the thing for kstack

kind root
#

Lol

finite summit
#

master hasn't had code pushed to it since september

surreal path
#

nvm

#

we didnt find it

#

still some UB

#

this is mega duper super duper cringe

edgy pilot
#

UB is the nyauxmaster equivalent of gremlins

surreal path
#

its 1am

#

ive been at this for nearly 6hours

#

maybe ill js sleep

#

okay so instead of just sleeping

#

im gonna debug nyaux all night

#

maybe ill find something

surreal path
#

at this point there has to be some memory corruption going o

#

n

#

i want to mcmcmc

#

end my life

finite summit
#

don't

surreal path
#

someone on the forums js told me this

#

what if i

#

add a lock on memory

finite summit
#

did you not before concern

surreal path
#

no

#

wait

#

did adding a lock make the behavior consisent

#

it has!!!

finite summit
#

I wonder why

#

@kind root this man didn't lock his malloc

surreal path
#

lmao

#

im still having page faults

#

but the behavior is consisent now

#

ubsan is telling me this

#

so thats weird

#

BUT HEY

#

BEHAVIOR IS CONSISENT NOWW!!!

#

WE GOT CLOSER!!!

surreal path
finite summit
#

I know

surreal path
#

ive made the behavior consisent

#

by putting a lock on kmalloc

flat nymph
#

Race condition

surreal path
#

yep

flat nymph
#

Nice

surreal path
#

smp is pain

#

anyways we still have this issue

flat nymph
#

The shittest thing to debug

surreal path
#

literarly

surreal path
#

well now we know nyaux code is not impossiblely cursed

#

just

#

yk

#

always put a lock on ur allocators guys!!!

#

if any function is gonna be access and written to by multiple cpus

#

put a lock

#

please

flat nymph
#

Lock free structures are fun

surreal path
#

The Rules Of Nyaux:

  1. Zero Out Your Pages.
  2. Put locks on things that will be accessed and written to by multiple cpus.
  3. thy variable names shall make zero sense
  4. have the worst most cursed formatting possible
#

anyways

surreal path
cinder plinth
#

so whats happening now

#

did you fix it

surreal path
#

my brain is absolutely fried

#

from no sleep

#

no my problem solving is probs shit rn

#

ngl

cinder plinth
#

time for redbull

surreal path
#

lol

cinder plinth
#

when I have a bug thats hard to resolve and it's late i just give up and spend the next day fixing it

cinder plinth
surreal path
#

something funky is going on

#

but at least its consisent for once

silver yarrow
#

ello

#

sorry something came up

#

where we at

surreal path
#

ALL GOOD

#

WUX WE HAVE GOODNEWS

#

AND SOME ISH NEWS

#

GOOD NEWS WE FIXED THE WEIRD INCONSISENTCY

#

IT WAS THE FACT WE DIDNT HAVE A LOCK ON KMALLOC

#

BAD NEWS STILL HAVING ISSUES WITH PER CPU DATA BEING NULL

silver yarrow
#

latest in gh?

surreal path
#

yep

silver yarrow
#

alright

#

oh motherfucker

#

99% sure I figured it out

#

yeap I got it @surreal path

finite summit
#

Bros doing miracles

#

That is indeed your problem

cinder plinth
#

yeah I knew it

surreal path
#

remove that i suppose

finite summit
#

I have had this kind of problem before

cinder plinth
#

I just didnt want to spoonfeed

surreal path
#

bro im not getting spoonfed

#

stop with these jokes not funny

cinder plinth
#

I'm trolling lol

surreal path
#

about me getting spoonfed

#

ik

cinder plinth
#

well

#

would you have fixed it on your own is the question

#

but yeah I'll stop

surreal path
#

plus i wouldnt have thought of that

finite summit
#

If it were my kernel I would have thought of it

#

Because I fixed a problem like that one day ago

silver yarrow
#

to be clear the only data segment u need to load is ss

surreal path
#

thanks

silver yarrow
#

ds can be zero

surreal path
silver yarrow
#

fs, gs u never touch

finite summit
#

I am not tho

#

I only have a year and a half

cinder plinth
surreal path
#

so @silver yarrow

#

just ss and ds

#

or only ds?

cinder plinth
#

no need for ds

#

ds is useless

silver yarrow
#

just ss

surreal path
#

okay

finite summit
#

Don't forget cs

silver yarrow
#

zero in ds and es

cinder plinth
#

idk why you would call it reload_CS

surreal path
#

okay put zero in ds and cs

cinder plinth
#

if you dont do CS stuff there

#

no

#

not CS

#

CS is important

surreal path
#

es*

#

sorry

silver yarrow
#

its the label for far jmp

finite summit
cinder plinth
#

ah

finite summit
#

Or rather far return

#

But whatever

surreal path
#

wait its fine

#

i dont load cs

#

so its fine

#

dunno why i call it .reloadcs

silver yarrow
#

u literally do

finite summit
#

The people at AMD decided it would be a good idea to remove far jumps

silver yarrow
#

the retfq

surreal path
#

it does reload the cs

#

my bad its nearly 4am

silver yarrow
#

lol

surreal path
silver yarrow
#

im in the states for christmas rn so only 7pm for me

finite summit
#

I'm in Canada for the living

#

So it's 10 30 pm

silver yarrow
silver yarrow
#

no

finite summit
#

No

surreal path
#

okay not worrying abt it

silver yarrow
#

does it matter to my ocd brain? yeap

surreal path
#

yes this solved the issue

#

thanks chat

silver yarrow
#

but ur entire kernel makes my brain want to shutdown for a year to begin with

surreal path
#

😭

finite summit
#

I was here to insult motivate

#

So yw

#

Now when nyaux on real he

#

*wh

#

**hw

#

Damn it I can't type on me phone

silver yarrow
#

skill issue

surreal path
#

but after i fix up the scheduler with yk

#

before that however im gonna nap

#

sleep*

#

goodnight

silver yarrow
#

night

finite summit
#

I'm sleeping too

cinder plinth
#

it's only 10:30pm

#

come on

#

you gotta grind

surreal path
#

😭

finite summit
#

Brain is shutting down

#

Debugging EC drivers does that to a person

#

Especially when you do it from 7 am to 9 pm

#

Drives you nuts

surreal path
#

tried impling this

#

not so great time

#

thats load ctx into kstack

#

which runs fine

surreal path
# surreal path
do_savekstackandloadkstack: ; rdi has thread old and rsi has thread new
    push rbp
    push rax
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15
    test rdi, rdi
    jz .skipstore
    mov [rdi + 0xB0], rsp ; store into kernel stack ptr the value of rsp
    .skipstore
    mov rsp, [rsi + 0xB0] ; load from kernel stack ptr into rsp
    mov rdi, rsp
    call change_rsp0 
    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx
    pop rax
    pop rbp
    ret
#

thats my do_savekstack_andloadkstack

#

dunno whats going on i know im supposed to be asleep ngl

#

its 4am

#

i cannot slerep

#

😭

flat nymph
#

You only have to save the saved registers

flat nymph
#

thonk or maybe not

#

You have to push the return address into there

surreal path
#

morning

surreal path
surreal path
flat nymph
#

No

#

You need to set kernel stack return address as well

surreal path
#

to what exactly

#

and does that mean i have to pop those registers out as well??

flat nymph
#

Add label right after call syscall whatever

surreal path
#

i dont have syscalls yet

#

again

flat nymph
#

In syscall instruction handler

surreal path
#

i dont have a syscall instruction handler

#

lol

flat nymph
#

Or some interrupt handler

surreal path
#

why do i need to add a label

#

also thats not how u spell label

flat nymph
#

How do your interrupts handlers look

surreal path
#
isr_stub_%1:
    ; Push a dummy error code if a 2nd parameter has been passed to the macro
%if %0 == 2
    push %2                  ; Push dummy error code
%endif
    test byte [rsp + 16], 0x3; Are lower 2 bits(priv lvl) of CS selector 0?
    jz .skipswapgs1          ; If they are 0 (kernel mode) then skip swap
    swapgs                   ; Otherwise swapgs in user mode
.skipswapgs1:
    push rbp
    push rax
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15

    ; push gs                  ; Save previous state of segment registers
    ; push fs


    push %1                  ; Push the interrupt number
    mov rdi, rsp ; put value of stack pointer into paramter 1 of c interrupt handler
    mov rax, [idt_handlers + %1 * 8]
                             ; Get the registered handler to call
    cld                      ; Required by the 64-bit System V ABI
    call rax
    mov rsp, rax
    add rsp, 8               ; skip int number
              ; Restore previous state of segment registers
    ; pop fs
    ; pop gs

    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx
    pop rax
    pop rbp

    test byte [rsp + 16], 0x3; Are lower 2 bits(priv lvl) of CS selector 0?
    jz .skipswapgs2          ; If they are 0 (kernel mode) then skip swap
    swapgs                   ; Otherwise swapgs in user mode
.skipswapgs2:
    add rsp, 8               ; Skip error code
    iretq
%endmacro
#

like this]

#

and also i realized why it page faults

#

because theres still values that wern't popped off the kstack

flat nymph
#

No

surreal path
#

yea

flat nymph
surreal path
surreal path
flat nymph
#

Where

surreal path
#

arch_create_frame

finite summit
surreal path
finite summit
#

wut

flat nymph
#

What do those functions doo

finite summit
#

you literally pop those

surreal path
surreal path
finite summit
#

bru

surreal path
#
#if defined(__x86_64__)
struct StackFrame arch_create_frame(bool usermode, uint64_t entry_func, uint64_t stack)
{
    if (usermode)
    {
        struct StackFrame meow = {.rip = entry_func,
                                  .rsp = stack,
                                  .cs = 0x40 | (3),       // USER CODE
                                  .ss = 0x38 | (3),       // USER DATA
                                  .rbp = stack,
                                  .rflags = 0x202};
        return meow;
    }
    else
    {
        struct StackFrame meow = {.rip = entry_func,
                                  .rsp = stack,
                                  .cs = 0x28,     // USER CODE
                                  .ss = 0x30,     // USER DATA
                                  .rbp = stack,
                                  .rflags = 0x202};
        return meow;
    }
}
#endif

flat nymph
flat nymph
surreal path
#

.rip is setting the stackframes shi

#

rip

#

its entire frame is then pushed

flat nymph
#

That's not it

surreal path
#

wdym

flat nymph
#

You have isr stub

#

It calls to some functions

surreal path
#

yea

flat nymph
#

Which calls to function which I can't find

#

To switch tasks

surreal path
#

yea

flat nymph
#

What do you have on stack?

#
  • userspace rip, rsp, cs, ss, rflags
  • userspace registers (rax - r15)
    ======
  • a bunch of C shit which calls do_savekstackandloadkstack
    ======
  • return address which called do_savekstackandloadkstack
  • kernel registers which you save
flat nymph
surreal path
flat nymph
flat nymph
surreal path
flat nymph
surreal path
#

debug purposes

flat nymph
#

First ```x86asm
do_savekstackandloadkstack: ; rdi has thread old and rsi has thread new
; do_savekstackandloadkstack(Thread *old, Thread *new)
push rbx
push rbp
push r12
push r13
push r14
push r15
mov [rdi + 0xB0], rsp ; store into kernel stack ptr the value of rsp
mov rsp, [rsi + 0xB0] ; load from kernel stack ptr into rsp
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
ret

surreal path
#

what about it

#

lol;

thorn bramble
#

that looks okay tho

#

assuming 0xb0 is the address of the kernel stack

surreal path
#

mhm

flat nymph
#

Second ```c
const size_t saved_stack_size = sizeof(long)*6;

void load_ctx_into_kstack(struct thread_t t, struct StackFrame userctx)
{
t->kernel_stack_ptr -= sizeof(struct StackFrame);
(struct StackFrame)t->kernel_stack_ptr = user_ctx;
t->kernel_stack_ptr -= sizeof(void
);
(void)t->kernel_stack_ptr = return_from_kernel_in_new_thread;
t->kernel_stack_ptr -= saved_stack_size
}```

surreal path
#

mishakov

flat nymph
#

third ```x86asm
return_from_kernel_in_new_thread:
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
pop rbp

test byte [rsp + 16], 0x3; Are lower 2 bits(priv lvl) of CS selector 0?
jz .skipswapgs2          ; If they are 0 (kernel mode) then skip swap
swapgs                   ; Otherwise swapgs in user mode

.skipswapgs2:
add rsp, 8 ; Skip error code
iretq

surreal path
#

this is the defination of stackframe

flat nymph
surreal path
#

those values

flat nymph
#

Well, add it

surreal path
#

return_from_kernel_in_new_thread is that function address?

flat nymph
#

Yes

flat nymph
#

But you can do it from C

surreal path
#

so ur not exactly saving the kernel stack garbage in load_ctx_into_kstack

flat nymph
#

What

surreal path
#

as in\

flat nymph
surreal path
#

krnctx

surreal path
#

i know this

#

im saying something else

surreal path
flat nymph
#

I mean in TSS

surreal path
#

yea ofc

surreal path
flat nymph
#

Idk

surreal path
surreal path
#

that makes sense

#

hold on while i implement this stuff

surreal path
#

and why are we
t->kernel_stack_ptr -= sizeof(void*);

flat nymph
#

Because you push a pointer

surreal path
#

oh yesh makes sensee

#

but why saved stack size

#

whats that purpose for

flat nymph
#

For 6 registers that you push

surreal path
#

why not more

#

yk what im not gonna question

flat nymph
surreal path
surreal path
flat nymph
#

Change it to be the same as what you have in your structs

surreal path
#

ik i did

flat nymph
#

Like of you push interrupt number and error code, pop those

surreal path
#

but

#

what about syscalls

flat nymph
#

What about them

surreal path
#

if we are iretq'ing

#

are we iretqing back into a new thread

flat nymph
#

Yes

#

What do you want to do

surreal path
#

okay

#

sorry

#

nvm

flat nymph
#

You can return to C which could do some extra shit

surreal path
#

no its okay

#

all good

#

dw

#

okay im running it

#

it died

#

when calling change_rsp0???

#

no nvm its not even consisent

#

this is my asm code

#
global return_from_kernel_in_new_thread
return_from_kernel_in_new_thread:
    add rsp, 8 ; skip int num
    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx
    pop rax
    pop rbp

    test byte [rsp + 16], 0x3; Are lower 2 bits(priv lvl) of CS selector 0?
    jz .skipswapgs3          ; If they are 0 (kernel mode) then skip swap
    swapgs                   ; Otherwise swapgs in user mode
.skipswapgs3:
    add rsp, 8               ; Skip error code
    iretq
do_savekstackandloadkstack: ; rdi has thread old and rsi has thread new
    push rbx
    push rbp
    push r12
    push r13
    push r14
    push r15 ; dont ask why these 6 registers only, mr miskakov never bothered explaining
    test rdi, rdi
    jz .skipstore
    mov [rdi + 0xB0], rsp ; store into kernel stack ptr the value of rsp
    .skipstore
    mov rsp, [rsi + 0xB0] ; load from kernel stack ptr into rsp
    mov rdi, rsp
    call change_rsp0 
    pop r15
    pop r14
    pop r13
    pop r12
    pop rbp
    pop rbx
    ret
#

my schedd code

#

g

#

it wont let me post the code snipped

#

cringe

#

thats load ctx

#

that is schedd

#

i dont get why its dying ngl

#

im doing everything right?

#

😭

#

uhh any idea @flat nymph ?

#

i got none

flat nymph
#

What's the point of skipstore?

surreal path
#

but thats besides the point

#

seems to be failing somewhere

flat nymph
# surreal path

Your kernel_stack_ptr should probably point to the top of the stack

#

Not to the stored location

#

Same in rsp0

surreal path
#

where the stack pointer is rn?

surreal path
flat nymph
#

No

surreal path
flat nymph
surreal path
#

makes sense

#

ill have to make 2 pointers in my thread

#

one for the base

#

one for the current ptr for yk

flat nymph
flat nymph
surreal path
#

yea

flat nymph
#

or you can put thread on stack

surreal path
#

hold on

flat nymph
#

and for syscall

surreal path
#

yeayea

#

thats 0xC0

#

and also

#

its not 0xb0

#

its 0xb8

flat nymph
#

You can also probably do call change_rsp0 from C

surreal path
#

its good

#

okay im testing now

#

IT FUCKING WORKS

#

IT FUCKINS WORKS @flat nymph

#

AND IT WORKS PERFECTLY??

#

YOOOO

flat nymph
#

Why wouldn't it

surreal path
#

WELL THANK YOU MISHKAVO

#

NOW I HAVE A PROPER

#

YK

#

PROPER SCHEDULER IG

#

OLD NYAUX NEVER HAD THIS BTW

#

AND THAT RAN BASH

#

SO

#

😎

#

also

#

even tho i got my voice back

#

i still havent talked

#

should i talk

#

it feels so weird to talk

#

i havent in like 4 days now

surreal path
# surreal path IT FUCKING WORKS

@kind root @finite summit 😎 proper saving and loading context that the very first nyaux kernel (which ran bash btw never had)

#

ANYWAYS

#

vfs time chat?

#

the fun part now

#

oh wait

#

before that

#

interrupt controller like APIC

#

i need to get working

#

i also might need a hashmap

#

i will port a library

#

somehow

surreal path
#

in all previous nyaux schedulers

#

there was no actual switching out of rsp0, or saving kernel registers and stuff. it was just *stackframe = thread->frame

#

now we actually have proper shit

#

as all schedulers have

finite summit
#

with every new nyaux feature comes 50 bugs

surreal path
#

lmao

finite summit
#

(per each line of code written)

surreal path
#

real

finite summit
#

and 5 days of debugging

surreal path
#

lmao fr

finite summit
#

(per single bug)

#

and +1000 messages in the nyaux thread

surreal path
#

πŸ’€

finite summit
#

just for some nerd to tell him he did it wrong

#

and it should be done this way

#

and not that way

surreal path
#

anyways

#

i will port a hashmap library after i play some roblox

#

because is christmas

finite summit
#

if you want

finite summit
#

but why does the lapic need a hashmap??

surreal path
#

apic*

#

but

#

i have a way of doing isa -> GSI

#

using hashmaps

finite summit
#

ioapic or lapic?

surreal path
#

ioapic

#

i already have lapic

#

lmao

finite summit
#

oh

finite summit
surreal path
#

how else am i getting my timer interrupts??

finite summit
#

idfk

surreal path
finite summit
finite summit
#

you register a GSI once in a blue moon

surreal path
#

is funny trl

#

anyways i go play roblox, ugh the smell of pizza CAN SOMEONE JS TAKE MY PIZZA LIKE SERIOUSLY

#

WHY DOES MY DAD WANT IT IN MY EROOM

#

IF IM NOT GONNA EAT IT TIL TMRW

#

πŸ’€

#

bro i get hes trying to get me to eat more but

#

come on

finite summit
finite summit
#

good

surreal path
#

what else am i talking about??

#

lmao

finite summit
#

what you said

#

ISA->GSI IRQs

#

thought you were gonna do some cursed thing

surreal path
#

no????

#

lmao

finite summit
#

you're nyauxmaster, you do the most cursed stuff sometimes

surreal path
#

fair

#

nyaux will one day run portal 2 co-op

finite summit
#

aim high

surreal path
#

so omar will be forced to play portal 2 co-op with me

#

because obos will also be able to run it

finite summit
surreal path
#

i think half life 2's source code is leaked

#

so u can probs compile that and somehow port that

#

maybe one day

molten grotto
surreal path
#

so i can port it

#

😑

finite summit
#

smh

molten grotto
#

just use a glibc compatible libc

finite summit
#

you need to get 1-1 binary compatibility

molten grotto
#

like hzlibc

surreal path
molten grotto
#

its not binary compatible with glibc tho

finite summit
surreal path
finite summit
#

you need to make nyaux linux

surreal path
#

i am not using some obsecure libc tho

molten grotto
#

hzlibc troll

finite summit
surreal path
surreal path
finite summit
#

you won't

surreal path
#

no i wont

#

that is torture chamber

#

port glibc to obos

molten grotto
finite summit
#

lies

surreal path
#

prove it

molten grotto
#

anyway you could port wine

surreal path
#

probs

finite summit
#

with hzlibc's plentiful 20 commits

#

over a period of 5 months

surreal path
#

lol

molten grotto
#

it does run factorio tho

finite summit
#

There are a lot of functions still to be implemented

surreal path
#

okay qwinci

#

make hzlibc more active

molten grotto
surreal path
#

make it easy to port

surreal path
#

thats not happening tho

molten grotto
#

yeah likely no with the amount of sysdeps it requires

finite summit
#

so if I port it to obos, I get factorio?

surreal path
#

yea

finite summit
surreal path
#

who is this guy

#

in the white shirt

#

not me

#

bro thinks hes pro

molten grotto
surreal path
molten grotto
#

about stuff like xorg I am not sure, I should do LFS with it again and get that far

surreal path
#

u could probs get factrio on mlibc

#

ngl thop

#

someone get linux on mlibc

#

to test this

#

do lfs with mlibc trl

molten grotto
surreal path
#

wdym

cinder plinth
surreal path
cinder plinth
#

chromium ran on mlibc linux first

surreal path
#

yes!!!

molten grotto
surreal path
#

peak roblox gameplay

surreal path
finite summit
surreal path
molten grotto
#

in the compat layer?

#

or hzlibc

finite summit
#

yes

#

hzlibc

#

sysdeps

molten grotto
#

I mean some of them are for implementing linux specific libc fns

#

but then there is just posix stuff that mlibc also has sysdeps for

cinder plinth
#

I will try porting glibc stuff eventually

#

through linux compat

#

imagine factorio on your OS meme

surreal path
#

on nyaux trl

#

it will be

#

pro

finite summit
surreal path
#

then @elder shoal can waste his time doing factrio in nyaux instead of doing astral work

molten grotto
#

with llvmpipe

haughty kite
#

oh damn

#

thats barely playable but still

#

waiting for i915 tho

surreal path
#

imagineu

#

udrm

#

on nyaux with factrio

cinder plinth
molten grotto
#

you can def get more out of llvmpipe, on linux I got like double that (I don't exactly remember how much tho, might also have been slightly more than that)

haughty kite
#

lmfao

#

managarm moment

molten grotto
#

nvm it was 9 on managarm, I think on linux it was like 40

haughty kite
#

is the perf still shitty if you turn off vsync

silver yarrow
#

Nyax with factorio before gta 6

haughty kite
#

also, what do the profiles look like

surreal path
#

:sk

#

πŸ’€