#EvalynOS

1 messages ¡ Page 3 of 1

hazy saddle
#

But we should be all good

devout path
#

yeah yeah

hazy saddle
#

How did this not break 😭

devout path
#

i have 0 clue LMAO

#

do u have commands like hexdump and stuff so we can try breaking it :))

hazy saddle
devout path
#

kernel

#

oh wait that runs on

hazy saddle
#

Sadly no

devout path
#

oh

#

aw

hazy saddle
#

i only have bad apple

hazy saddle
# hazy saddle

i should be able to make this take arguments when starting the thread right?

devout path
#

i am not entirely sure

hazy saddle
#

or i can have some external vars you fill in and then start it

#

and then mutex it so it can only be changed once its consuimed it

#

i do it with the other vars

#

i could have args there

#

and then have a var that gets written to once its safe to start another thread and change thoes args

devout path
#

yea actually

#

yea yea

hazy saddle
#

And if it’s not ready spin because it won’t take that long

#

Like fuckin maybe 500 cycles of spinning at worst

devout path
#

xD

hazy saddle
#

Can always make it a hlt spin anyways

#

Maybe

#

May not even need any locking if it’s sequential too

#

No no it is a thread

#

Ehhh whatever

hazy saddle
#

I have to pass data from one thread to another

hazy saddle
#

And a shared varrible with a spin lock is quick and dirty especially for somthing like this

hazy saddle
#

But it also makes me get infra for mutexes and other things

#

Which is good

#

And it’s not the most cursed thing

hazy saddle
#

So args might be a pita

devout path
#

pita?

hazy saddle
#

Pain in the ass

devout path
#

XD

devout path
hazy saddle
#

That’s how making the thread works

#

and all user threads are kernel threads in a trenchcoat

devout path
#

is

#

kinda not safe

hazy saddle
hazy saddle
#

And then it’s always running inside of user space

devout path
#

oh

hazy saddle
devout path
#

this confuses me a little XD

#

yeah

#

hmmmmmmmmmmmmmmmmmmm

hazy saddle
#

I can probslt strip run once with a infinite loop or having it signal to free itself

#

Wait is there a way to make a new instance of a static function to call?

#

Because I don’t think freeing would work with this if the thread it’s self don’t know which thread it is

devout path
#

hmmmmmmmmmmmmmmm

hazy saddle
#

@devout path maybe I can pass a pointer to it that has a structure of all the data it needs?

#

But how do I construct the stack for that

#

Wouldn’t that be a register argument in SYS-V too?

#

Which I have to put into the right thing on the stack

#

Because the zeros I set I think are the registers

devout path
#

hmm

#

im tryna find a solution myself too

hazy saddle
#

this should be the stuff popped off the stack into registers

    for (int i = 0; i < 15; i++) {
        *--stack = 0x0 + i;
    }
#

so i could slide a pointer into here

devout path
hazy saddle
devout path
devout path
hazy saddle
#

it uses the crafted stack to jump to the entry point

devout path
#

like u can use kmalloc containing the args, pass the pointer there and the thread reads the data?

hazy saddle
devout path
hazy saddle
devout path
#

yes

hazy saddle
#

the crafted stack has all of that stuff

devout path
#

oooh

hazy saddle
#

the GPRs and RFLAGS

#

So I should just be able to slide in that sneaky pointer to pass in the function

sudden mirage
devout path
hazy saddle
#

Just put in in RDI I assume

devout path
#

would u like me to explain it in tech jargon or in simple terms

sudden mirage
hazy saddle
hazy saddle
sudden mirage
# hazy saddle The stack is useful here no?

yea its pretty useful after i read your code, the only risk is bad code which causes a program to use a ton of stack which means if the memory below the stack is not mapped you get a #PF when switching threads

devout path
hazy saddle
sudden mirage
#

the pros of using the stack method is that i only need to store rsp in a program's PCB

devout path
hazy saddle
devout path
hazy saddle
#

I mean when crafting the stack

#

Where RDI should be in the push and pops

#

I put in that pointer instead of a 0

hazy saddle
#

And then you can detect that

devout path
#

i don't have much context

#

wait gimme a moment to read

hazy saddle
hazy saddle
#

I set them to 0

#

So when I execute ret it fills the registers properly right

#

If I make the one that equals RDI to the pointer

#

According to the sysV abi

#

That’s the first argument

#

Which means when it starts up and that gets pushed into the stack it should be given to the kernel thread

#

Let me do a demo

#

i will make them all 1s

#

and it wont crash

devout path
#

im actually braindead rn i completely forgot that you made that

#

my bad

hazy saddle
#

but i can add some logging

#

LMAO

devout path
#

gimme a moment to reread this LMAO

devout path
#

this is exactly what i was thinking

#

man i swear

hazy saddle
#

what the fuck

devout path
#

aight my badlmao

devout path
hazy saddle
devout path
#

uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuh

hazy saddle
#

with a zero

#

its consistent

devout path
#

wdym?

hazy saddle
#

its always off by 5

#

time for advanced investigation

#

because im fuckin lost

devout path
#

i

#

am

#

HUH

#

WAT

#

this aint the thing that im gonna investigate at 2:40 am

hazy saddle
#

every register should be becoming that value

devout path
#

LMAO

hazy saddle
#

leme do a panic for a register dump

devout path
#

like the value itself when you set it?

hazy saddle
#

the value i set on the stack

devout path
#

oh

hazy saddle
#

my reg dump may not be accurate mmLol

devout path
#

heh

hazy saddle
#

because i aint either rn

#

i have a headache

devout path
#

heh

#

err it's working no?

#

don't question stuff when it's working :))

hazy saddle
#

no

#

its not working'

#

the argument isnt passing right

devout path
#

where is rdi again?

#

wait lemme backread

hazy saddle
#

im setting all regs

#

all the way

#

to be safe

devout path
#

xd

#

waht if

#

hear me out

#

what if we don't use the loop XD

hazy saddle
#

wait

#

no

#

im so stupid

#

oh my fucking god

devout path
#

wat

hazy saddle
#

do you see it

devout path
#

was it about hte rdi

hazy saddle
#

PLUS I

#

😭

devout path
#

B

#

R

#

U

#

H

#

LMAOA

hazy saddle
#

that was a reminant of debugging ages ago

devout path
#

heh xd

hazy saddle
#

i do need to fix my reg dumps tho heh

#

here we go

hazy saddle
#

@devout path it diddnt send this here

#

But we are all good

devout path
#

noice

hazy saddle
#

Now I can malloc a structure and get it passed in there

devout path
#

yeaaaaaaaaaah

hazy saddle
#

And then it can operate on that to know how to do things

#

Like telling the scheduler to end its self

devout path
#

heh

hazy saddle
#

Or even then pass this on to userspace for a sub set of things

#

But the system call handler can probslt check the current thread

#

So that won’t need this

devout path
#

yeaah

hazy saddle
#

Programming be like

#

Over three fucking charaters XD

devout path
#

LMAO

#

ngl

#

for some weird reason

#

i love programming on crt monitors more than my oled screens

hazy saddle
#

Apparently text is ass on OLEDs?

#

That’s what IPS can do better

devout path
#

oh damn

hazy saddle
#

@devout path

devout path
#

WAT DA HEEELL

hazy saddle
#

I’d maybe pickup a decent 75hz bussness IPS display for coding?

devout path
#

i THOUGHT I NEED GLASSES BUT THAT'S JUST BAD LMAO

hazy saddle
#

And keep the oled for gaming

devout path
#

yeaah

hazy saddle
#

It’s what like 100 200 bucks for a decent one?

devout path
#

yup

hazy saddle
#

Cheaper than glasses heh

devout path
#

actually glasses here are cheaper LMAO

hazy saddle
#

LMAO

devout path
#

u can get a decent built glasses for 40 dollars

#

in usd

hazy saddle
#

Dang

#

But yeah plus it can’t hurt to have an extra monitor

#

I have three

devout path
#

imma just add my old crt monitor on my desk atp

hazy saddle
#

I really wana get a CRT to play deltarune

#

The game is a pixel art RPG and it’s 4:3

devout path
#

u can get one for idk 20 dollars secondhand online XD

hazy saddle
#

And I’ve seen videos of it played on CRT and holy shit it’s good

devout path
#

even for free if ppl are decluttering

#

yeaah

hazy saddle
#

I want that steam controller

#

Looks so nice for pc gaming

devout path
#

the new one with the pads?

#

i have no idea how that's comfy but eh

hazy saddle
devout path
#

ooh

#

fair enough

hazy saddle
#

@devout path teehee

#

working on the second user app

#

a mandlebrot

hazy saddle
#

@devout path it seems to crash when running both at once

#

its triggering a page fault

#

if they run alone thry work though

hazy saddle
#

If I run mandelbrot first

#

And then bad apple

#

Bad Apple won’t execute

#

But mandelbrot restarts

hazy saddle
#

My kernel may be dead

#

I dunno how to fix it

hazy saddle
#

Well I managed to fix some other things

#

They both now “properly” fault when executing them because a bad variable name

#

And I got AVX and other things working to accelerate the code

#

For the userspace apps

devout path
#

oops

#

i feel

#

asleep

hazy saddle
sudden mirage
sudden mirage
hazy saddle
#

It’s inaccurate

hazy saddle
sudden mirage
hazy saddle
#

My registers are color coded and I can read it fine and it also dumps into the serial port on QEMU

sudden mirage
# hazy saddle Why

you are writing one byte to the stack and C treats 0x1 without a cast as a normal int unless you end it with ULL or UL or something like this

sudden mirage
hazy saddle
#

I am meant to be pushing 8 byte values

#

They are the registers

sudden mirage
hazy saddle
#

Part of building the stack

sudden mirage
#

0xFULL means (uint64_t)0xF

hazy saddle
#

It’s meant to set them to zero

#

Let me read this again

#

The stack is cast to a uint64 already

#

So when I operate on it it should be 8 byte values no

#

the 0x1 is a debug value to set registers too

#

like the + i was

#

but if this wasnt working all threads would be fucked

#

not just user threads

#

and one user thread works

hazy saddle
#

its one px it seems

sudden mirage
sudden mirage
hazy saddle
hazy saddle
sudden mirage
hazy saddle
#

an all the stuff comes on seriel

sudden mirage
#

or do you take it with qemu windowed?

hazy saddle
#

i know how to make it full screen but that dosnt matter?

sudden mirage
hazy saddle
sudden mirage
hazy saddle
#

yes the qemu window gets a new resolution

#

but the guest os dosnt

#

it would have to request the new video mode

#

or have some kind of guest additions things

sudden mirage
#

ig its usually handled with a gpu driver

hazy saddle
#

even with a GPU driver it might not know etc

sudden mirage
hazy saddle
#

uhuh. if i were to open a linux vm it probaly wouldnt change unless i change it in video settings

#

maybe it was changed

sudden mirage
#

makes sense you cant stretch a monitor irl meme

hazy saddle
#

Look are you here to talk pedantics about font sizes and qemu screenshotting and giving bad advice about stuff when you don’t have the full code context or are you here to talk about this project in a meaningful way to have it actually progress?

sudden mirage
hazy saddle
#

Because I don’t think this convo is going anywhere

hazy saddle
#

The font works for me

#

And you can easily change it in the source code if you wanted to work on it

sudden mirage
#

it was just a suggestion

hazy saddle
#

I can even make it a compile option for the font

#

-DBIGGER_FONT

#

I think there are bigger issues afoot than the font?

#

The font that’s working

#

There is the case of the userspace failing spectacularly

devout path
#

what did i just come back to

hazy saddle
hazy saddle
#

Anyways @devout path how’s it going

#

I just wrapped up one of the parts of another project while you talked here

devout path
#

finals exam week so haven't been doin anythin

hazy saddle
#

Ooo

hazy saddle
#

Honestly my os might go on hold until I can fix this slongesab

#

But I am working on some cool thing for my internal services and might be good for others

#

Making some proofs of concept for the major 3 bits I need to mix

#

My threadpool works nice

#

And it can generate this fractal using all my cores in 12 seconds

devout path
#

ooh noice

hazy saddle
#

but i found the problem

#

my stack pointer was being set to zero

#

i think i am setting up user threads poorly

#

i should make a better bootstrap function for them in the firstplace

#

that sets up a proper stack etc for userspace

#

@devout path i think i got this

#

i dont think anything is wrong with my switching logic

global thread_switch
global thread_switch_user
global switch_to_user

section .text
thread_switch:
    pushfq
    push rax
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi
    push rbp
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15

    mov [rdi], rsp
    mov rsp, rsi

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

    ret

USER_STACK_TOP equ 0x0000000080000000

switch_to_user:
    mov ax, 0x33
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax

    push 0x33
    mov rax, USER_STACK_TOP
    push rax
    pushfq
    pop rax
    or rax, 0x200
    push rax
    push 0x2B
    push 0x4000
    iretq
viral bison
hazy saddle
viral bison
#

you only need like 6 regs

hazy saddle
#

Hmm

#

I may be dumb

viral bison
#

the other regs are discarded

viral bison
#

hmm, why push 0x4000?

#

and why 0x33?

hazy saddle
#

I have a fixed load address in userspace for programs start function and a fixed stack address top

viral bison
#

0x33 seems so strange there

hazy saddle
viral bison
#

show your gdt

hazy saddle
viral bison
#

my gdt is:
null
kcode
kdata
ucode32
udata
ucode64

hazy saddle
#

I don’t have any kind of 32 bit at all

viral bison
#

you have to have that segment anyway

#

for syscalls

hazy saddle
#

But I have null kcode kdata tss ucode udata

viral bison
#

oh

#

tss in the middle

hazy saddle
#

Is that bad

viral bison
#

well, you have to swap ucode and udata

viral bison
rancid viper
hazy saddle
rancid viper
#

it doesnt

viral bison
#

syscall msrs

rancid viper
#

they dont use syscall

viral bison
#

it does

#

well, in the future

rancid viper
#

yes but its irrelevant here

hazy saddle
hazy saddle
# hazy saddle

This patch when applied to my repo should get you to where I am at btw

#

I am quite vexed

viral bison
#

@hazy saddle maybe the missing [] here?

hazy saddle
viral bison
#

i think it gets the value from the pointer

rancid viper
#

basically deref

hazy saddle
#

Aswell wouldn’t this brick kernel threads too

rancid viper
#

and no you shouldnt deref it

#

you are passing the rsp

#

not a pointer to it

hazy saddle
#

yes

#

thread_switch(&previous_thread->rsp, current_thread->rsp);

#

btw @viral bison you on my source tree from github or the patchset

viral bison
#

yes

#

yours+

#

pagefault seems to be caused by this

#

hmm

hazy saddle
#

why tf is IP even there

#

is that under CPL3 or 0

viral bison
#

idk

#

btw, all user code starts at 0x4000?

hazy saddle
#

yes

viral bison
#

hmm

#

that might give you problems later

hazy saddle
#

it gets loaded here
fs_read("/badapple.bin", (void *)0x4000, num_pages * page_size);

hazy saddle
#

would be easy too

viral bison
#

i use r15 to pass it

#

when i set the first thread stack

hazy saddle
#

il do static elf loading later

#
ENTRY(main)

SECTIONS
{
  . = 0x4000;

  .text :
  {
    KEEP(*(.entry))
    *(.text)
  }

  .rodata :
  {
    *(.rodata)
  }

  .data :
  {
    *(.data)
  }
}
viral bison
#

k

#

why no .bss?

hazy saddle
#

it gets hoisted like this

hazy saddle
#

when fs read is told to read more bytes than there are in the file it dumps nulls

#

eg 0

#
int main() __attribute__((section(".entry")));
int main() {
#

this hoists my main function to the start if the binary

#
gcc -ffreestanding -fPIC -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector -c badapple.c -o badapple.o
ld -nostdlib -T badapple.ld -o badapple.elf badapple.o
objcopy -O binary badapple.elf badapple.bin

cp ./badapple.bin ../../initramfs
cd ../../../
viral bison
#

that RIP happens when i press enter

hazy saddle
#

and this will extract the binary

hazy saddle
viral bison
hazy saddle
#

how

viral bison
#

idk

#

it crashes there for me

hazy saddle
#

did my diff generate / apply right

#

did you change anything

viral bison
#

i did git apply <patch>

#

and edited a sec this

hazy saddle
#

i used git diff > whatever.patch

viral bison
#

that's to generate the patch

hazy saddle
#

yeah so it should be good

viral bison
#

ok it somewhat got fixed

#

how do i trigger your crash?

hazy saddle
#

run badapple

#

and then run it again

viral bison
#

how do i stop it XDD

hazy saddle
#

crash it with badapple again or run panic

viral bison
#

no i mean

#

how do i stop it from playing the first time

#

lol

hazy saddle
#

wdym?

viral bison
#

i can't run it the second time if i don't stop it from playing, no?

#

ah wait

#

i can

hazy saddle
#

the shell should still work

#

that running debug is a lil broken

viral bison
#

ye

#

it crashed at 4207

hazy saddle
#

That’s what I somewhat expect

#

Well I shouldn’t expect it

#

But yeah

#

This is using FPU code btw

viral bison
#

where is badapple compiled to

hazy saddle
#

But it will crash the same way if you have an infinite while loop

#

So it won’t do anything

hazy saddle
viral bison
#

found, thx

hazy saddle
#

That gets called by another shell script that’s executed by the makefile

#

Also I lowkey wana use some c++ in my kernel for instantiating classes for some drivers to be easier

viral bison
#

oof, i can't addr2line the .bin

hazy saddle
#

Should be able to objdump it and spesify x86-64

viral bison
#

how?

hazy saddle
#

You need to tell it it’s x86-64

#

Because it’s a binary blob

#

No headers

viral bison
#

and how do i tell it?

hazy saddle
#

Leme look it up

#

-m i386:x86-64

viral bison
#

still says not recognised

hazy saddle
#

Maybe drop the -S

viral bison
#

nope

hazy saddle
#

objdump -b binary -m i386:x86-64 -D ./badapple.bin this works now

#

207: 48 8b 45 f0 mov -0x10(%rbp),%rax

#

it dosnt know the offset so subtract 0x4000

viral bison
#

that's strange

#

why would it only happen the second time

hazy saddle
#

Why would I know 😭

viral bison
#

wait a sec

#

you never map the user pages

#

in the thread pagemap

#

you only map to the kernel pagemap here

#

@hazy saddle

hazy saddle
#

Fuuuuuuuuuuckkkkk

#

how should i handle passing this in there

viral bison
#

i save the currently executing thread pointer in my cpu struct

#

so i can access it on the local cpu

#

the thread then contains a ref to its process

hazy saddle
#

what if i pass the pagemap pointer as an argument to the thread?

viral bison
#

and the process contains the pagemap

viral bison
hazy saddle
#

huh

viral bison
hazy saddle
#

but the actual thread dosnt have that

viral bison
hazy saddle
#

i need to get it passed in here?

viral bison
#

you need to get the thread struct there

hazy saddle
viral bison
#

or well, thread pointer

hazy saddle
#

yeah i can do that

viral bison
#

i write the cpu struct pointer to KGSBAS

#

so i can read it whenever i want

hazy saddle
#

which one on the stack should the pointer be again

viral bison
#

wdym

#

just use msrs

hazy saddle
#

when cracfting the stack

viral bison
#

it's way easier

hazy saddle
#

what

viral bison
#

write the cpu struct to the kernel GS base msr

#

so you can use it in other places too

hazy saddle
#

i dont have a CPU struct

viral bison
#

make one

hazy saddle
#

not rn

viral bison
#

well, then write the thread pointer there

#

it'll just be a temporary thing for now

hazy saddle
#

nah i got this

viral bison
#

you could use an unused register then

hazy saddle
#

ive been awake like more than 24 hours i need to just do this easily

viral bison
#

using the msr is the easiest way tbh

hazy saddle
#

nahhh fuck it we ball

viral bison
#

XD

#

why like that

hazy saddle
hazy saddle
viral bison
#

you write it 15 times?

#

lol

hazy saddle
#

to every register

viral bison
#

bruh

hazy saddle
#

so i cant possbily be wrong

viral bison
#

that is a bad idea

hazy saddle
viral bison
#

just write it to like r15

hazy saddle
#

i need to conform to SYS-V

viral bison
#

i use r15 and r14 to pass data to the newly created thread

#

tho i can use some more

hazy saddle
#

this is what it used to be

#

its somthing like index 6 right

viral bison
#

in theory you should just need to set 6 registers

viral bison
hazy saddle
#

scherdular.c

viral bison
#

found

#

wait what

#

why pass task quit?

hazy saddle
#

if the thread exits it returns there and loops

viral bison
#

hmm

#

idk if that works like that

hazy saddle
#

still fucked

viral bison
#

well, are you mapping the memory?

hazy saddle
#

i need to sleep lowkey but i cant sleep knowing its broke

viral bison
#

changing 1 reg there means nothing if you don't use it

hazy saddle
#

i am

viral bison
#

show the updated mapping code

hazy saddle
viral bison
#

bruh

hazy saddle
#

what did i do this time yaaar

viral bison
#

what reg did you pass the thread to?

hazy saddle
#

RDI

viral bison
#

hmm

#

can you check if it's not 0?

#

the function arg i mean

hazy saddle
hazy saddle
viral bison
#

yeah, that's very strange

#

it shouldn't even execute

#

bc that mem is not even mapped

hazy saddle
#

it is mapped tho

viral bison
#

before i meant

#

ok, well, i see 1 problem there

#

the 0x0 to 0x4000 is mapped to the kernel

#

it doesn't have the user flag

#

so it will throw a pagefault

#

tho i'm not even sure that's the cause

hazy saddle
#

because thoes pahes shouldnt be used rightr

viral bison
#

then why map those at all?

hazy saddle
#

and idk why tf it is mapped tbh

#

my entire VMM is stolem

#

i dont think anything SHOULD EVEN BE MAPPING IT

viral bison
#

wait, in create_thread, i see you are using malloc to create the stack

hazy saddle
#

yes

viral bison
#

but do you then map that stack to add the user flag or no?

hazy saddle
#

That’s the kernel stack right

hazy saddle
viral bison
#

oh ok

#

there is an easier way for this btw

hazy saddle
#

Probslt

#

But most of my code is written in seep depreciation

viral bison
hazy saddle
#

Which I am having right now

#

And I’m about to falls sleep

#

Is there anything else you need

#

Because I dunno what to do

viral bison
#

maybe try to debug a bit

hazy saddle
#

Idk what I should even be debugging

viral bison
#

i think i'm starting to get somewhere, wait

#

nope

hazy saddle
#

I dunno what the heck is going on

rancid viper
#

I think text messages is too inefficient to debug this lmao

#

yall need to do some pair programming

hazy saddle
#

Setup one of those stupid IDEs that lets you edit code at the same time together too lmao

#

And honestly I’m so fucking burnt out from this one bug

rancid viper
#

zed editor

#

its my primary editor

#

: )

hazy saddle
#

Is it on Linux?

#

And it’s that one that shills AL yaaar

#

AI

rancid viper
#

fuck windows

#

is all Ill say

#

but they did recently start shipping windows binaries I believe too

rancid viper
#

they have great agent features

#

I dont use them personally

hazy saddle
#

I get a bad taste in my mouth from anything that wants to integrate Ai

#

If I want AI il goto AI

rancid viper
#

so...

#

everything

hazy saddle
#

I don’t want it inside my editor

#

KATE dosnt do stuff like that

rancid viper
#

xd

hazy saddle
#

I use KATE

rancid viper
#

I mean u can turn off the agent panel with one setting if you wish

#

unfortunately today its basically expected to have AI stuff builtin

hazy saddle
#

If they are going to bend to the will of AI I don’t wana use it

#

I should be switching to libre wolf soon too because of the Firefox crap

#

Even fucking VIM has a sponsor for AI

#

JFC

rancid viper
#

it is futile to escape it

#

I just pick the best editor for me

#

an extra feature I turn off doesnt hurt me

hazy saddle
#

But yeah anyways

#

@viral bison wana VC and pair program later when I wakeup

rancid viper
hazy saddle
#

We got this

#

Somthing somthing this gif

viral bison
hazy saddle
#

When I sleep im out cold

#

8 to 12. Hours probably

viral bison
#

XD

#

idk if i'll still be awake then

#

it's already 4pm here

hazy saddle
#

My parents try and wake me up and they think I’m dead 💀

viral bison
#

XD

viral bison
#

huuh

#

@hazy saddle

#

i might have found exactly where it crashes

#

the second or third execution of this loop

#

when calling allocate_page

devout path
#

how are u

#

dam i was outside earlier

hazy saddle
#

But perhaps closer

hazy saddle
#

thats from my friends code

#

maybe its running out of pages to give?

#

but hm

#

and if i give the PMM more bitmap pages and give it from 512mb to 2gb memory it still shits its self

hazy saddle
hazy saddle
#

So it’s giving “valid pages”

#

I know the code is doing some integer division

#

Could it be accidentally giving physical pages that already have been allocated

viral bison
#

It's simpler and better than bitmap

hazy saddle
viral bison
#

@hazy saddle what ide do you use to code?

hazy saddle
#

KATE

hazy saddle
#

And not make things explode like they are

viral bison
#

If you were on vscode we could code at the same time

#

Or on CLion

hazy saddle
#

I can probably get it on cachyOS

#

The flatpak should be fine too anyways if I have a terminal open elsewhere

viral bison
#

K

hazy saddle
#

It is 2am rn tho

viral bison
#

Oh

#

Lol

hazy saddle
#

What would happen if I replace it with a bump allocator maybe

viral bison
#

8Am here

hazy saddle
#

And see if that will keep it working?

hazy saddle
#

Just to see if that’s the real issue

hazy saddle
viral bison
#

tho i don't even think it's a pmm issue

#

try to add a check if it returns a null

hazy saddle
#

My friend said the VMM was fucked

#

But every time I made a VMM it always caused issues

viral bison
#

so it's already at the first time that it returns a null page??

#

but somehow it still works

#

@hazy saddle how do i make your printf print an address in hex?

hazy saddle
#

Should be the same as standard normal printf

viral bison
#

FUUUCK

#

wait what

#

oh i'm stupid

hazy saddle
#

I am using nanoprintf

viral bison
#

k, i was using > instead of <

#

lol

#

ok, alloc_page is out

#

it returns a valid page

hazy saddle
#

Hmmmm

#

I mean I should redo that later anyways to maybe a buddy allocator

viral bison
#

buddy might be better for malloc

#

i think freelist is the best one for pmm

hazy saddle
#

Ahhh

#

How does a free list work

viral bison
#

virtually no mem needed, and it's instant

#

basically you add blocks (that represent free pages) in a linked listr

#

you store those blocks inside the free pages

#

then, when a block is used, if a block is multiple pages wide, you just shrink that

#

else, you nuke that block from the list and overwrite the data on that page

#

so it basically uses no mem

hazy saddle
#

So a link list of free page ranges?

viral bison
#

yes

hazy saddle
#

When I take pages I break off from it

viral bison
#

yes

hazy saddle
#

And when I free pages I add to it

viral bison
#

at the start

hazy saddle
#

And it kind of just works?

#

Do I have to go through the entire linked list?

viral bison
#

not if you don't require more than you have on the first block

#

when you find a block of the size you need, you stop

#

that's why you add freed pages at the start

hazy saddle
#

And I can take a block and a part of another?

viral bison
#

well, it depends

#

if you need them contiguous no

#

else yes, you can

hazy saddle
#

Why would I need it to be contiguous?

viral bison
#

DMA sometimes need it like that

hazy saddle
#

Ahh

#

I need to make myself a generic linked list helper tbh 🥀

viral bison
#

want mine?

#

it's pretty good

hazy saddle
#

What’s it licensed under?

viral bison
#

huuh

#

my os is under GPL

hazy saddle
#

I’m on MIT

viral bison
#

idc really

#

i might change the license too

hazy saddle
#

You could cc0 the linked list stuff

#

I’m planning on having a repo with a bunch of small shit I made to be public domain

viral bison
#

i tought gpl was good, will prob change it

#

it's made with c++

#

so you might have to adapt it

hazy saddle
hazy saddle
viral bison
#

even with permission?

hazy saddle
#

Technically but it can get messy I think?

#

Also slongesab templates

viral bison
#

sec, lemme go and change that

viral bison
hazy saddle
#

Yeah

#

MIT still needs credit for when the source is open

#

But it’s a lot more flexible

viral bison
#

oh cool

hazy saddle
#

Also dosnt a linked list need a malloc

viral bison
#

well, yes

#

tho it can be made without

#

the one i sent was made to work with malloc

#

but if you go in my PMM file

#

you see the implementation without

viral bison
hazy saddle
#

Not yet rn

viral bison
#

k

#

tho rn we need to find what is nuking badapple

hazy saddle
#

Or rather any extra threads

viral bison
#

wdym

hazy saddle
#

User*

#

It will be nuked even if two different user apps were to be loaded

viral bison
#

also, how does the ctx switch work

#

like, the thread queue

hazy saddle
#

It should push all GPRs switch stacks and then restore GPRs

#

Works for kernel threads

hazy saddle
#

It cycles through all of them

viral bison
#

yeah i saw, but i don't see it looping i think?

#

when it reaches the end of the queue it will take a nullptr, no?

hazy saddle
#

I’m pretty sure the list is setup so the last element links to the top

viral bison
#

hmm

#

prob

#

ok yeah, it should

hazy saddle
#

@viral bison I wonder if it’s possible to gdb the user apps too?

viral bison
#

it is

#

tho idk if it will load the symbols

#

if they are not elfs

hazy saddle
#

I assume you can have external symbols generated

#

It will compile the elf too

#

But it dosnt load the elf

#

It’s elf -> binary blob

viral bison
#

hmm

#

let's hope the addresses are the same

hazy saddle
#

The linker says the load address

#

So it should be fine

#

Linker script says 0x4000 I put it there

viral bison
#

k yes, it recognised it

hazy saddle
#

Also for not using malloc on the PMM

#

What if I used a bootstrap bump allocator? Once I have malloc working I can then use that properly

viral bison
#

no need for that

#

you can make a linked list without malloc

#

look at mine

hazy saddle
#

Or I just reserve the first page for the PMM?

viral bison
#

yep, you reserve the first page

#

and point the first pointer to that

#

or well

#

first page of every mem region

#

limine gives you a memmap

#

use that

#

oh wait

#

debugging the app is useless rn

#

it never even reaches that point

#

lol

hazy saddle
#

Isn’t the page fault under CPL3 mode?

viral bison
#

how do i see that

hazy saddle
#

I dump the bits of the error code

viral bison
#

error is 0x111

hazy saddle
#

For a page fault when bit3 is set it means CPL3 right

viral bison
#

idk

hazy saddle
#

Eg 0b111

viral bison
#

oh yeah

#

srry

hazy saddle
#

That’s pretty useful for debugging though innit?

viral bison
#

how tf is it failing on CPL3 if it never even reaches main

hazy saddle
viral bison
#

seems like it's skipping main entirely

hazy saddle
#

So what the fuck is going on

viral bison
#

that's what we need to understand

#

well, now we know why it is pagefaulting

#

WAIT

hazy saddle
#

What

viral bison
#

oh no

#

tought you were loading the new pagemaps too erarly

#

bc what if it's not the new thread thta's pagefaulting

#

but the old one

#

this would make more sense

hazy saddle
#

But I only run on one core tho

hazy saddle
viral bison
#

try

hazy saddle
#

Sorry

viral bison
#

?

#

k

#

pinpointed the fail location

#

2nd time it runs allocate_page()

hazy saddle
viral bison
#

i'm stepping into it with gdb

#

ok

#

it fails before doing free_pages--

hazy saddle
#

the exact part it fails on

viral bison
#

hmm, then my breakpoint isn't triggering

#

what is the RIP?

hazy saddle
#

and if i make it use less pages it does the same

#
Interrupt Frame:
IP=0x0000000000004203 SP=0x000000007fffffa0
SS=0x0000000000000033 CS=0x000000000000002b
FLAGS : 00000000 00000001 00000010 10000111 
viral bison
#

ok wtf

#

where exactly is that log

hazy saddle
#

this is my panic log

#

to the serial

viral bison
#

no, i mean the alloc page one

#

show the line

hazy saddle
viral bison
#

how the fuck is it failing in 0x4000

hazy saddle
#

userspace code ig 😭

#

wtf is this mapping here

#

this is before bad apple

viral bison
#

wtf

hazy saddle
#

and then running bad apple once

#

and then after once more

hazy saddle
#

this dosnt apear in serial

viral bison
#

race condition prob

hazy saddle
#

FT and sterial output is the same tho

viral bison
#

that's strange

#

something might be nuking the FB too?

hazy saddle
#

somthing may be up with the VMM?

#

thats what she said and its her VMM code

viral bison
#

vmm seems ok

#

it's not even failing there

hazy saddle
#

but what if its settings things wrong

hazy saddle
#

with qemu debugs info mem

#

the memory map is bad

#

@viral bison we may need an expert to help us?

#

this is so fuckin strange

viral bison
#

ye

#

we need someone else

hazy saddle
#

fresh set of eyeballs

#

@viral bison who should we get

viral bison
#

idk

#

someone that is available rn

#

something is trying to access a phys address

#

i think i'm getting close

#

it happens only when i run badapple

hazy saddle
#

interwsting

#

i cannot thank you enough

#

i dunno if i could of even debugged this far without you

viral bison
#

to get that error, i fixed this function:

#

this should also remove the garbage from the new pagemap

hazy saddle
#

it now page faults after running bad apple once

#

but i can repro the error

viral bison
#

yes

hazy saddle
#

but we are clean

#

i wonder what was causing the non clean bits of it

viral bison
#

they are in the kernel pagemap

hazy saddle
#

ig its some kind of just random non zero memory?

viral bison
#

but you zero it

hazy saddle
#

but i never should be putting anything in tjere hmmCat

#

but how is this put there then

viral bison
#

also, that a address

hazy saddle
#

huh

viral bison
#

this here

#

something was mapping it

#

and it's where it is pagefaulting now

hazy saddle
#

thats the frame buffer

#

uint64_t frameBufferBase = 0x00000000A0000000;

viral bison
#

oh, where are you allocating it

hazy saddle
#

FUCK

viral bison
#

yep

#

fuck

#

that's why it is pagefaulting now XD

#

and that's what i think is breaking the second badapple

hazy saddle
#

should i have that just grab the current thread from the schedular

viral bison
#

yes

#

IT WORKS

hazy saddle
#

ITS DOING IT

viral bison
#

i'll pass you the code i have

hazy saddle
#

the XMM registers arent preserved

viral bison
#

it has some more fixes

hazy saddle
#

so they kinda sync up

viral bison
hazy saddle
#

but it works

viral bison
#

you aren't doing xsave

#

nor fxsave

#

so that's kinda normal

hazy saddle
#

i forgor how to do that ngl

viral bison
#

it's a bit of a pain

#

well, simd is not even enabled in your os

hazy saddle
#

SIMD is

#

bad apple does use SIMD

#

i can convert to integer divison rq

viral bison
#

where do you enable it

hazy saddle
#

wait i may of nuked that code

#

i may be only doing x87?

viral bison
#

prob

#

i don't see any simd init

hazy saddle
#

wait im not using any FPU

#

still works with this

#

i think they all run tho

#

leme add a systemcall to DENGEROUSLY print a string

#

umm hmmCat

#

the threads need to know thier ID maybe

viral bison