#Nyaux

1 messages Β· Page 3 of 1

surreal path
#

if its in C

finite summit
#

probably

surreal path
#

i will c+c c+v

#

but its not

#

πŸ˜”

finite summit
#

actually

#

use liballoc

surreal path
#

lib alloc?

finite summit
#

allocator library (in C) made to be easily portable

surreal path
cinder plinth
#

i use liballoc and use my vmm to allocate virtually contiguous pages to map physically separate pages

daring juniper
#

Yuck! Virtual Memory.

finite summit
#

booo

surreal path
#

allocator

#

☠️

finite summit
#

Same

#

and I found a way to work around it

#

I assume slab relies on vmm

cinder plinth
#

you need a virtual memory allocator

surreal path
cinder plinth
#

no

#

it doenst

surreal path
#

vmm region struct

cinder plinth
#

heres my virtual memory allocator

surreal path
#

sorry i have school rn

#

which is why

#

i didnt do anything yet

#

when i come back from school ill keep researching about slab allocators so i can implment one that DOESNT fault

ionic jetty
#

Is this turning into obos thread KEKW ?

surreal path
surreal path
#

ok back from school

#

time to learn abouts slabs

#

more

surreal path
#

i just fell asleep watching a lecture about slabs

#

and slept for

#

3 hours

#

nah thats crazy

ionic jetty
#

damn

#

what did you learn?

#

give me a short explanation about slabs

surreal path
# ionic jetty give me a short explanation about slabs

a slab allocator works like this

you have a cache that has a pointer to the current slab being used, a list of slabs that are full and list of slabs that arent full but arent empty either.

when we run out of memory on a slab we switch to ones that are in the partial list, if there arent any then we allocate a new one to switch to.

in linux the kmalloc function is implmented by having caches from the pow2

ionic jetty
#

I think linux doesn’t only have pow2 caches

#

But yeah that’d be easiest to implement

surreal path
#

yea

#

i guess the next thing to do

#

is to start implmenting this now

#

i think i understand it to a point

#

i can implment it

shut laurel
ionic jetty
#

I don’t know about the others but slub defines non pow2 ones too, and this becomes apparent when cat-ing /proc/slabinfo

#

Theres like 192 byte generic ones

#

(For specific slabs like dentries there are more specific sizes too)

shut laurel
#

yup, couldnt check

surreal path
#

isnt that so kawaii

#

.<

haughty kite
#

not particularly

surreal path
#

u tell me how to make it kawaii then

#

mr know it all

haughty kite
#

dont?

#

lmao

#

that isnt a goal of an os for like

#

99% of people

surreal path
haughty kite
kind root
#

yeah memeing the kernel log, or using trash variable names is just you making fun of yourself at your own expense

cinder plinth
#

I had the same type of logs but on vga

surreal path
#

!!!

surreal path
kind root
#

idk man this is just sad

surreal path
kind root
#

you should respect your work more

surreal path
#

look i reverted it u happy?

surreal path
#

cause my code is shit !

kind root
#

yes im very happy because your kernel now uses ok instead of whatever shit it was before

surreal path
#

ok im gonna work on slab

kind root
surreal path
#

i will treat it like amazing

kind root
#

no just treat it as a reflection of yourself, and actually put in effort to make it look good

#

then it will be good

surreal path
#

anyways i feel like store size in header as well

#

idk

#

im just thinking of like

#

how itll work when freeing and allocing

#

i think this looks correct

#

header is 16 bytes

surreal path
#

why am i even doing that

#

yea i dont think i need to do that

#

that just wastes space

#

lmao

#

we can fit 510 objects in the page

#

cool

#

i think this is valid?

#

i feel so scared typing each line of code

#

i feel like im gonna instant fuck up the page or something

#

lmao

#

i think this is good

kind root
#

Looks good

surreal path
kind root
#

No idea

surreal path
#

long function

#

huh

kind root
#

Add an if addr == 0 return

surreal path
#

well it seems to work

#

keyword

#

seems

kind root
#

Cool

#

I doubt it will survive uACPI init

tawdry mirage
#

what a hater

#

:^)

kind root
#

Lmao

surreal path
kind root
#

Because that would mean you're better than oberrow

surreal path
#

huh

#

then it page faults

#

in nano printf

kind root
#

Yeah im sorry it didn't survive KEKW

surreal path
kind root
#

Its unrelated

cinder plinth
#

why so many memory allocator skill issues recently

kind root
#

The memory is corrupted

cinder plinth
#

literally just use liballoc if u cant write your own

surreal path
surreal path
kind root
#

Yes

cinder plinth
kind root
#

Either you allocated more, or allocated less, or returned the same block twice, or freed it early

surreal path
#

oh cause it tries to allocate 2

kind root
#

Also enable debug uACPI log for better tracing

surreal path
kind root
#

In the init replace trace with debug

surreal path
kind root
#

I would also recommend printfs to trace what memory you're returning

surreal path
#

everything looks right

kind root
#

The oberrow curse is upon you now

surreal path
surreal path
#

I GIVE IT CORRECT MEMORY WHY IS IT FKN DANGLING

#

😠

kind root
#

I dont see u logging any addresses

surreal path
#

ok wait

#

THEY LOOK VALID

#

like wtf

#

and it page faults in nano printf???? like sorry wtf is going on

kind root
#

Yeah that probably means you're trashing the memory from somewhere

kind root
#

Overwriting

surreal path
#

when i free i dont memzero

#

is that a problem

#

should i memzero the memory before i like

#

yk

#

i also dont memzero

#

when i give the block

#

@kind root

#

do i need to memzero?

kind root
#

In calloc yes

#

In alloc no

surreal path
#

oh then i need to memzero it

#

☠️

#

i dont memzero in calloc

kind root
#

Yes

surreal path
kind root
#

void *I_have_no_self_respect

surreal path
#

😠

#

FRICK U FRICK U FRICK U

kind root
#

Lol

surreal path
#

I MEMZERO'D AND I GOT CLOSER

surreal path
#

I MEMZERO'D IM CLOSER

#

😭

kind root
#

Yea

#

But you're getting there

surreal path
#

probs cause the cache i gave was 051i20958190258190285019285125

#

so bro requested 528

#

wtf is going on

kind root
#

Round up to next power of two?

surreal path
surreal path
#

do that

kind root
#

Yup

surreal path
#

ummm

#

why is the memory address 30000000

#

why tf

#

I DONT FUCKING KNOW

#

WHY THE ADDRESS IS 30000000

#

why is it pointing

#

to 3000000

#

why

#

fuck me

#

why

#

NO ONE IS OVERWRITING THE HEADER

#

ITS CORRECT

#

SO WHY IS IT GETTING tHIS STUPID NUMBER

#

WHY IN THE WHY

#
void init_cache(struct cache *cache, size_t size)
{
    char shit[64] = "";
    cache->size = size;
    void *page = pmm_alloc_singlep();
    struct Header *h = page + hhdm_request.response->offset;
    h->size = size;
    cache->slabs = (uint64_t)h;
    
    size_t obj_amount = (4096 - sizeof(struct Header)) / (size);
    write_color(ctx, "Slab: Creating Cache of Object Count: ", 0);
    write(ctx, itoa(shit, obj_amount));
    write(ctx, " and Size: ");
    write(ctx, itoa(shit, size));
    write(ctx, "\n");
    struct pmm_node *start = (uint64_t)h + sizeof(struct Header);
    h->freelist = start;
    struct pmm_node *prev = start;
    for (int i = 1; i < obj_amount; i++)
    {
        struct pmm_node *new = (uint64_t)start + (i * size);
        prev->next = new;
        prev = new;
    }
    write_color(ctx, "Slab: Cache Created!\n", 0);
}

struct Header *make_slab(size_t size)
{
    void *page = pmm_alloc_singlep();
    struct Header *h = page + hhdm_request.response->offset;
    h->size = size;
    size_t obj_amount = (4096 - sizeof(struct Header)) / (size);
    struct pmm_node *start = (uint64_t)h + sizeof(struct Header);
    h->freelist = start;
    struct pmm_node *prev = start;
    for (int i = 1; i < obj_amount; i++)
    {
        struct pmm_node *new = (uint64_t)start + (i * size);
        prev->next = new;
        prev = new;
    }
    return h;
}

like i create the caches correctly

#

i allocate and free everything correctly

#

so why is bro pointing to address 3000000

#

its not from the free function thats causing this

#

triple checked

#

not from the making of a new slab either

#

gotcha

#

i got u now

#

interesting

#

oh wait

#

itoah

#

not itoa

#
struct Header *make_slab(size_t size)
{
    char shit[64] = "";
    void *page = pmm_alloc_singlep();
    struct Header *h = page + hhdm_request.response->offset;
    h->size = size;
    size_t obj_amount = (4096 - sizeof(struct Header)) / (size);
    struct pmm_node *start = (uint64_t)h + sizeof(struct Header);
    h->freelist = start;
    struct pmm_node *prev = start;
    for (int i = 1; i < obj_amount; i++)
    {
        struct pmm_node *new = (uint64_t)start + (i * size);
        prev->next = new;
        prev = new;
    }
    return h;
}

somethings wrong in this function

#

the page is valid

#

dumped the addresses

#

all valid

#

I SOLVED IT BUT NOW I TRIPLE FAULT nooo

#

guys new address just dropped!

#

!!!

#

this is weird

#

it general protection faulted here

#

tf

#

@finite summit i understand how u feel now

#

this is straight up

#

torture

#

This thread is like my prison

#

and I’m yapping to the cell wall

#

WHY R U POINTING THERE

#

😭

#

HOW DOES IT EVEN GET THIS ADDRESS

finite summit
#

Actually debatable

surreal path
#

i have prints every where

#

i cant figure out

#

where its getting this address

#

im dying

#

omar help me

#

this is pain

#

i cant find

#

this stupid issue

#

where is it making up this address

finite summit
#

sudo pacman -S gdb

surreal path
#

😠

finite summit
#
> gdb kernel
> target remote :1234
> breakpoint slab_alloc
> c
surreal path
#

okay wiat

#

wait

finite summit
#

It'll help more than with prints

surreal path
#

since slab_alloc is getitng called

#

thousands of times

#

by uacpi

#

i cant really find the instance where it gets this fake ah address

#

what the fuckkkk

#

do the register values looked fucked

#

i dont know why this is happening

wide nexus
surreal path
wide nexus
#

based ass value ngl

surreal path
#

fr

#

to the point its driving me insane!

#

at this point i dont know what to do

#

i've printed every address

#

everything

#

wtf

#

okay so its attempting to free memory that seems to have corrupted our header

#

i dont do anything but somehow this is um

#

i dont know

#

maybe one of you guys spot something i didnt idk

#

im going to sleep i have school trrw

finite summit
#

@surreal path Take a look into this test function I made for allocators to allow to track the allocation easier

#

All you'd need to do is break when i == (the allocation that crashes' index) and see what it does

ionic jetty
#

Hell yeah, another completely failing allocator : )

surreal path
#

it’s not my fault

#

My code is simply so pro 😎

surreal path
#

im in hell

#

im in hell help me

#

i even brung my laptop to school

#

to keep trying to debug the code

#

I STILL CANNOT FIND IT

#

i dont get why tf

#

and my teacher kept asking

#

me

#

"did u find the issue yet"

#

☠️

ionic jetty
#

Whats happening again

#

Memory corruption right

surreal path
#

i think

#

but i cannot find the issue in my code

ionic jetty
#

Debug the exact location of WHERE memory is WHEN corrupted

#

You could try finding out where and then watch that address with gdb

surreal path
#

ill tell u the output

surreal path
#

actually im gonna go to the store real quick

#

brb

rigid fable
#

why do not just use printfs (or whatever) to get the values to see if they are what you expect and use infinite loops to find where it crashes

surreal path
#

okay back

rigid fable
#

oh nvm

surreal path
rigid fable
surreal path
rigid fable
#

yes that is not relevant

surreal path
#

yea okay

rigid fable
#

so where is it crashing?

surreal path
#

this specfic value 2-smthin i dont have the value in my clipboard but its a value that doesnt make sense, its the same value that causes the crash

#

every run

elder shoal
#

Do you have an assert macro

surreal path
#

the stack trace looks like this

rigid fable
surreal path
surreal path
#

it makes zero sense

rigid fable
# surreal path ?

it is a macro which prints the line number of where it is used on a certain condition

elder shoal
#

To make sure everything is going fine and so you can know when and where something goes wrong

#

I have a bunch of them around my slab implementation and it has saved me a lot of headaches before

surreal path
#

that is just pointing tape on the issue

#

putting*

#

not fixing it

#

something is causing this value

#

someone is like overwritting something where they shouldnt

#

@kind root its probs memory corruption right?

kind root
#

yea

rigid fable
#

if it does not work it is because you are doing something wrong

surreal path
# kind root yea

but like ive read through the damn slab allocator code a billion times i dont see the issue where it could be overrwriting something

kind root
#

well look harder

surreal path
kind root
#

it took oberrow two weeks

ionic jetty
#

Have you written userspace test @surreal path

surreal path
#

i dont know how to do that

ionic jetty
#

You dont know how to what

#

Write a program in userspace?

surreal path
#

no

#

i mean

#

i dont know how to write a test

#

for this allocator

#

in userspace

ionic jetty
#

You copy everything you did

#

But malloc on some big array

#

Instead of your physical memory

surreal path
ionic jetty
#

In your kernels allocator you operate on your ram

#

In your userspace testing program you do everything the same but just operate on fake ram / an array

surreal path
#

all valid

#

it HAS to be some kind of memory fuckery

ionic jetty
#

Are you writing to the allocated blocks

surreal path
ionic jetty
#

Are you writing to the blocks returned by kmalloc

surreal path
ionic jetty
#

You should try to reproduce your allocator in userspace

surreal path
#

its not me whos making the allocations, its uacpi

#

so whatever its doing

ionic jetty
ionic jetty
surreal path
#

void *uacpi_kernel_alloc(uacpi_size size)
{
    char shit[64] = "";
    if (size < 1024)
    {
        return kmalloc(size);
    }
    else
    {
        return vmm_region_alloc(align_up(size, 4096), NYA_OS_VMM_PRESENT | NYA_OS_VMM_RW);
    }

}
void *uacpi_kernel_calloc(uacpi_size count, uacpi_size size)
{
    char shit[64] = "";
    
    if (count * size < 1024)
    {
        void *man = kmalloc(count * size);
        memset(man, 0, count * size);
        return man;
    }
    else
    {
        return vmm_region_alloc(align_up(count * size, 4096), NYA_OS_VMM_PRESENT | NYA_OS_VMM_RW);
    }
}

just letting u know that i do memset the allocations when uacpi calls calloc as required

surreal path
#

ill try to make a userspace program of my slab allocator i suppose

kind root
#

You can run both uACPI and your allocator in userspace

#

Oberrow did that and found the bug almost instantly

surreal path
#

?????

kind root
#

Wdym

surreal path
#

why does uacpi run in userspace just fine

#

that makes zero sense

#

lmao

kind root
#

Why wouldn't it

#

Obviously all io is emulated

#

Other than that no difference

surreal path
kind root
#

You give it the blob with a virtual address

#

Look at my tests

#

Tests_runner.cpp

#

And interface_impl.cpp

ionic jetty
#

Only your api functions do

#

So you just β€žfakeβ€œ them

ionic jetty
# kind root Yup

Do you have userspace tests for like acpi events and whatever stuff there is too

kind root
#

Uh no because that needs interrupts

surreal path
kind root
#

But I have bytecode tests of course

surreal path
#

do i just malloc(4096) or somethin

ionic jetty
#

Yes

#

Or page_alloc i dont know your apis

surreal path
#

was my printf statements

#

okay so it loads

#

okay how do i setup uacpi to test @kind root

ionic jetty
#

look into the uacpi repo into tests ig?

kind root
#

yup

#

i literally mentioned the files to look at

surreal path
#

do i have to define

#

a kernel api

#

@kind root

kind root
#

Yes??

#

interface_impl.cpp

surreal path
#

thanks

kind root
#

Np

surreal path
# kind root Np

im trying to compile this but like its saying the functions i made dont exist even tho i add the slab.c to the cmakelists thing

#

i import the header as well

kind root
#

No idea

rigid fable
surreal path
rigid fable
#

how are you differetiating the compiler between different extension source files?

#

gcc compiles as C++ by default, it is just that in most cases C code is valid C++ code

surreal path
rigid fable
#

ah

#

seems you do see the code as C. But maybe you have not passed the flag

surreal path
#

even tried

rigid fable
#

can you upload to github the test code and share a link?

rigid fable
rigid fable
#

what compiler are you using? g++?

surreal path
#

i dont know what compiler its using

rigid fable
surreal path
rigid fable
#

see how to specify a compiler

#

(I have no idea how cmake works)

#

can you share the github repo?

surreal path
#

I FIXED IT

#

@kind root what does this mean

rigid fable
surreal path
rigid fable
#

that should tell you you have serious build problems

surreal path
#

how im getting the header in kfree?

#

so how im getting the header

#

thats removing the 12 bit page offset tho?

#

???

#
=================================================================
==949491==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000005000 at pc 0x5578c1810218 bp 0x7ffe8e9bed10 sp 0x7ffe8e9bed00
READ of size 8 at 0x621000005000 thread T0
    #0 0x5578c1810217 in kfree /home/rayan/Programming/fard/uACPI/tests/runner/slab.c:109
    #1 0x5578c17a4103 in uacpi_kernel_free /home/rayan/Programming/fard/uACPI/tests/runner/interface_impl.cpp:226
    #2 0x5578c188f42e in uacpi_free_resources /home/rayan/Programming/fard/uACPI/source/resources.c:2018
    #3 0x5578c17c77ab in run_resource_tests() /home/rayan/Programming/fard/uACPI/tests/runner/resource_tests.cpp:2226
    #4 0x5578c179a016 in main /home/rayan/Programming/fard/uACPI/tests/runner/test_runner.cpp:181
    #5 0x7f0a14752d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #6 0x7f0a14752e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #7 0x5578c1797244 in _start (/home/rayan/Programming/fard/uACPI/tests/runner/test-runner+0x146244)

0x621000005000 is located 256 bytes to the left of 4096-byte region [0x621000005100,0x621000006100)
allocated by thread T0 here:
    #0 0x7f0a1536e887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x5578c180ef98 in init_cache /home/rayan/Programming/fard/uACPI/tests/runner/slab.c:8
    #2 0x5578c1810983 in init_slabs /home/rayan/Programming/fard/uACPI/tests/runner/slab.c:164
    #3 0x5578c179a011 in main /home/rayan/Programming/fard/uACPI/tests/runner/test_runner.cpp:180
    #4 0x7f0a14752d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/rayan/Programming/fard/uACPI/tests/runner/slab.c:109 in kfree

dont understand what any of this means

surreal path
#

0x621000005000 is located 256 bytes to the left of 4096-byte region

kind root
#

slab.c 109

#

Is bugged

surreal path
#
if (kmalloc_cache[i].size == h->size)
kind root
#

Yes

surreal path
#
struct Header *h = (uint64_t)addr & ~0xFFF;
    struct cache *rightcache = NULL;
    for (int i = 0; i < 8; i++)
    {
        if (kmalloc_cache[i].size == h->size)
        {
            rightcache = &kmalloc_cache[i];
        }
    }
kind root
#

Debug it

surreal path
#

is it how im getting the header????

#

like huh???

#

faults whenever i access it too

wicked loom
#

idk if we're debugging the same thing

#

i have spent the past 2 days trying to figure out why the Vinix slab allocator don't worky

wicked loom
#

the Vinix slab is very similar to the Lyre slab so if you took inspiration from either of those, i am so sorry for you

surreal path
#

idk

#

no it was qwinci

wicked loom
#

yeah we do the same

#

we as in Lyre and Vinix collectively

#

i need to shelve Lyre because honestly keeping track of 2 mostly-the-same-but-sometimes-a-bit-different OSes gets confusing

surreal path
wicked loom
#

Vinix

surreal path
#

why so?

wicked loom
#

Lyre was translated for the most part from V to C and not by me, so there are certain copying mistakes and sometimes design alterations which make it hard for me to approach it

#

meanwhile Vinix is mostly made solely by me

#

the only things that aren't are segregated into driver code for specific shit and not much else in the way of design or other core stuff

surreal path
#

ah okay

#

well anyway time to spend the next 24 hours of my life trying to figure out why tf addr & ~0xFFF no worky

wicked loom
#

if i figure anything out i'll let you know

surreal path
#

please do

#

im in severe chronic pain

wicked loom
#

understandable

surreal path
#

this bug gives me a brain tumor

wicked loom
#

btw, a tangential point, but if you take prejudice against V out of the picture, V is a really comfy language for writing a kernel in

#

at least to me

kind root
wicked loom
#

not saying you should use it or anything of course, just reporting my experience with the funny vman language

surreal path
elder shoal
#

Constants in x86-64 C are 32 bit unless specified

#

Yeah thats the issue I think

wide nexus
#

been wanting to code in something different for a bit now

surreal path
wide nexus
#

but every language out there has some stuff that C just does better

wicked loom
elder shoal
wicked loom
#

btw if you use V for osdev though keep in mind that you need to beat it into submission a bit

#

it's not very plug-and-play

rigid fable
#

@surreal path why are you still in voice 0?

surreal path
#

i am alone πŸ˜”

surreal path
wide nexus
elder shoal
surreal path
#

didnt work

wicked loom
#

btw for me

#

the problems really only show up if i free the slab allocations

#

and the funny part is that the corruption garbage written seems to come from a page frame allocator free

#

which doesn't really check out in any obvious way

surreal path
#

yea

#

ik

#

its weird

wicked loom
#

is it the same for you?

surreal path
#

the issue only really showed up

#

when i took uacpi and my slab allocator to userspace

#

and ran the test

#

which showed

#

that kfree

#

is the issue

#

which like doesnt make any sense

wicked loom
#

what is kfree?

surreal path
#

it just doesnt make any sense like at all

#

function for freeing address back into the correct cache slab freelist

wicked loom
#

do you trash the memory on free?

#

because for me, even if i do, it still works, as long as i don't try to readd the page to the slab linked list

surreal path
wicked loom
#

as in

#

overwrite with 0xaa or some random garbage

#

to catch use-after-free and friends

surreal path
#

no

wicked loom
#

try doing it

#

in your kfree

#

without actually "freeing" the allocation back to the slab allocator linked list

#

i keep saying page

#

i mean allocation

surreal path
#

so just overwrite the address or the header?

wicked loom
#

like

#

overwrite whatever is written at the allocation that you're trying to free

#

say X tells you to free count bytes at ptr, then memset(ptr, 0xaa, count) before actually freeing the allocation

#

but don't actually free it

#

i wanna see if that works for you as well

surreal path
#

alrt

#

sec

wicked loom
#

because if it does we may literally have the same bug which would be kinda funny

surreal path
#

i did that and like it didnt care until i wanted to try getting the header

wicked loom
#

odd

elder shoal
#

Once I thought I had a slab bug but it turned out to be in my pmm because I used a 32 bit int somewhere instead of a 64 bit onw

#

That was fun to debug

wicked loom
#

i don't think my pmm is wrong because using it instead of the slab as the kernel allocator makes everything workℒ️ (at least in appearence)

#

the problem really just arises when using the slab allocator, and only when freeing

ionic jetty
#

I hate nothing more than stuff that appears to be working

#

but isnt

wicked loom
#

same lol

surreal path
#

same

wicked loom
#

you have to learn to live with it at some point though

#

as a programmer

ionic jetty
#

yup

surreal path
#

yea

wicked loom
#

unless you go and formally verify everything

surreal path
ionic jetty
#

I funnily implemented a slab allocator a few days back becuase I wanted to prove to myself that my idea of allocating at pow2round_up(size) alignment was actually sensible

kind root
#

It's not guaranteed to be page aligned if you use malloc

ionic jetty
tawdry mirage
#

you can use mmap to emulate the pmm

surreal path
#

okay

kind root
#

There's memalign

tawdry mirage
#

mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, -1) boom a page :^)

ionic jetty
#

or just malloc more than you need and then cut off a bit at the front

wicked loom
#

ok printing out the slab addresses that i get from the slab header on free, they seem to check out

#

sadly

ionic jetty
#

dumb question but where do both of you put the slab header? at the front of the slab itself?

elder shoal
#

I put mine at the top of the page because Im special

wicked loom
#

beginning of page

wicked loom
#

basically the first chunk of the slab is allocated to a pointer to the thing

ionic jetty
#

I decided to steal get inspired by linux idea of a struct page array

#

works surprisingly great

#

I can put whatever metadata I want in the page struct

#

and depending on what it is used at put something else there

#

thus not needing seperate headers or whatever

elder shoal
tawdry mirage
#

0xffffffffffffffff is MAP_FAILED

#

(because NULL is technically a valid return value)

surreal path
#

it all worked

#

no errors at ALL

#

wtf

#

my slab allocator works perfectly

kind root
#

U didn't run any aml

surreal path
#

how to do that

kind root
#

This is basic resource tests

kind root
#

acpidump -b

surreal path
#

kk

#

doesnt work in wsl

kind root
#

It does

surreal path
#

no

#

nothing

kind root
#

ls

surreal path
#

ohhhhh

#

ok ok

#

e

#

oh yeah

#

forgot to init slabs

#

memory leak?

#

is that bad?

kind root
#

Yeah thats not a leak

surreal path
kind root
#

Maybe your asan counts global pointers as leaks

#

Anyway your malloc didn't crash

surreal path
#

SO ITS NOT MY SLAB ALLOCATOR HMM?

kind root
#

It is

surreal path
#

it didnt crash

kind root
#

Idk what you did in particular, also wsl aml is tiny

surreal path
kind root
#

Or actually maybe you leaked your own data somehow idk

#

Because those are not uACPI leaks

kind root
#

from windows run the same command

surreal path
#

okay

kind root
#

Just download it first

surreal path
#

kk

kind root
#

Are you actually freeing stuff

tawdry mirage
#

could dump the qemu aml

kind root
#

Or did you comment that out

tawdry mirage
#

since that's what nyaos is running on

kind root
#

Maybe oberrow still has that dump

surreal path
#

feed the dst?

kind root
#

Yup

surreal path
#

im freeing stuff

kind root
#

Im amazed it didn't crash then

#

But idk what u did so

#

Try your pc now

kind root
surreal path
kind root
#

Oh ok

ionic jetty
#

Does uacpi maybe have alignment requirements for that?

kind root
#

Nope

surreal path
kind root
#

Looks like it works

surreal path
#

SEEEE

kind root
#

But im not sure how u get leaks

#

Its very strange

#

You sure you're not doing anything strange?

surreal path
#

all leaks are coming from asan

#

no

#

i can give u the code if u want to try it urself

kind root
#

Run this blob against the vanilla test runner

surreal path
#

oka

kind root
#

Any leaks?

surreal path
#

no leaks

kind root
#

Yup

#

Idk how you get them

surreal path
kind root
#

So u dont free?

surreal path
#

i put it back into the slab freelist so its "free"

#

but i never deallocate a slab or anything

kind root
#

Hmm

#

Well then the bug is in your handling of bigger than 1024 bytes

#

Try making huge slabs

surreal path
#

how big

kind root
#

How do u handle them in your kernel

surreal path
kind root
#

That logic is probably bugged

surreal path
#

my vmm?

kind root
#

Probably somewhere in that neighborhood

surreal path
#

ill try making slabs that are bigger then 1024

#

see if that changes anything

kind root
#

Try it

surreal path
kind root
#

yeah so if that still works then the bug is in your vmm

surreal path
#

same amount of leaks

surreal path
kind root
#

if it survives this then probably

surreal path
#

what the actual fuck

#

so i have been debugging the wrong shit for 2 DAYS

#

2 FUCKING DAYS

#

☠️

kind root
#

port vmm to userspace

surreal path
#

how is that even gonna work

kind root
#

oberrow did that

tawdry mirage
#

port the entire kernel to userspace

#

arch/user/

surreal path
surreal path
kind root
#

who knows

surreal path
#

how tf does that work

ionic jetty
#

what exactly does your vmm do

surreal path
#

allocates a region of virtual memory space, maps x pages to it. returns the base of this region

kind root
#

how does it allocate

surreal path
#

if it finds a gap between 2 memory regions that is large enough to fit the region

#

it sets that up

kind root
#

sounds error prone

ionic jetty
surreal path
#
struct vmm_region
{
    uint64_t base;
    uint64_t length;
    uint8_t flags;
    struct vmm_region *next;
};
#
void vmm_region_setup(uint64_t hhdm_pages)
{
    size_t kernel_size_in_bytes = (size_t)THE_REAL;
    kernel_size_in_bytes = align_up(kernel_size_in_bytes, 4096);
    struct vmm_region *node = kmalloc(sizeof(struct vmm_region));
    node->base = hhdm_request.response->offset;
    node->length = hhdm_pages;
    node->flags = NYA_OS_VMM_PRESENT | NYA_OS_VMM_RW;
    vmm_head = node;
    
    struct vmm_region *kernel_region = kmalloc(sizeof(struct vmm_region));
    kernel_region->base = addr_request.response->virtual_base;
    kernel_region->length = THE_REAL;

    node->next = kernel_region;

    // Regions:
    // -------                          -------
    // - HHDM -                        - KERNEL -
    // -------                          -------
    //       - - - - - - - - - - - - - - ^
    //       next
    serial_print_color("VMM Regions Init!\n", 1);
    vmm_region_walk();
}

region gets setup like this

#
void *vmm_region_alloc(uint64_t size, uint8_t flags)
{
    char shit[64] = "";
    struct vmm_region *cur_node = vmm_head;
    struct vmm_region *prev_node = NULL;
    while (cur_node != NULL)
    {
        // ASSUME REGIONS IN ORDER CAUSE WE COOL :sunglasses:
        if (prev_node == NULL)
        {
            prev_node = cur_node;
            cur_node = cur_node->next;
            continue;
        }
        if ((cur_node->base - (prev_node->base + prev_node->length)) >= align_up(size, 4096) + 0x1000)
        {
            struct vmm_region *new_guy = kmalloc(sizeof(struct vmm_region));
            new_guy->base = (prev_node->base + prev_node->length);
            new_guy->length = size;
            prev_node->next = new_guy;
            new_guy->next = cur_node;
            cur_node = cur_node->next;
            int num_of_pages = align_up(size, 4096) / 4096; // num of pages to alloc :sunglasses:
            for (int i = 0; i < num_of_pages; i++)
            {
                map((uint64_t)pml4 + hhdm_request.response->offset, new_guy->base + (i * 0x1000), pmm_alloc_singlep(), flags);
            }
            return new_guy->base;

        }
        else
        {
            // not enough space for our new region sadly, continue
            prev_node = cur_node;
            cur_node = cur_node->next;
            continue;
        }
    }
    // STILL HERE?
    // PANIC CAUSE NO REGIONS CAN FIT VMM REGION WOWIE!
    write_color(ctx, "No Free Virtual Address Regions!\n", 4);
    asm ("cli");
    for (;;)
    {
        asm ("hlt");
    }
}

allocation works like this

ionic jetty
surreal path
#
SECTIONS
{
    /* We wanna be placed in the topmost 2GiB of the address space, for optimisations */
    /* and because that is what the Limine spec mandates. */
    /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
    /* that is the beginning of the region. */
    . = 0xffffffff80000000;
    AMONG_US = .;
    .text : {
        *(.text .text.*)
    } :text

    /* Move to the next memory page for .rodata */
    . += CONSTANT(MAXPAGESIZE);

    .rodata : {
        *(.rodata .rodata.*)
    } :rodata

    /* Move to the next memory page for .data */
    . += CONSTANT(MAXPAGESIZE);

    .data : {
        *(.data .data.*)
    } :data

    /* Dynamic section for relocations, both in its own PHDR and inside data PHDR */
    .dynamic : {
        *(.dynamic)
    } :data :dynamic

    /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
    /* unnecessary zeros will be written to the binary. */
    /* If you need, for example, .init_array and .fini_array, those should be placed */
    /* above this. */
    .bss : {
        *(.bss .bss.*)
        *(COMMON)
    } :data

    /* Discard .note.* and .eh_frame since they may cause issues on some hosts. */
    /DISCARD/ : {
        *(.eh_frame)
        *(.note .note.*)
    }
    THE_REAL = . - AMONG_US;
}

ionic jetty
#

These naming conventions should be prosecuted

#

Calling anything in your codebase AMONG_US is just criminal

surreal path
#

#ihavenoselfrespect

elder shoal
#

Thats kinda sussy

kind root
ionic jetty
surreal path
#

either way the alloc function looks fine

#

could it be deallocation?

kind root
#

Comment out and find out

surreal path
kind root
#

Unlucky

surreal path
#

wait no

#

njow its faulting here?

#

gpr'd here???

#

but theres no invalid address here

#

now thats getting fucked

#

@kind root wtf

kind root
#

Idk

surreal path
#

bro wtf

#

is going on

#

does anyone have the slightest idea whats going on

kind root
#

A bug

surreal path
#

yes but

#

why is memory getting so corrupted

#

the slab allocator was proven to work in userspace

kind root
#

Who knows

#

Some other bugged part

rigid fable
surreal path
rigid fable
#

and what is itoah? Is not it just an integer to ascii? What is that h

surreal path
#

hex ascii

#

integer to hex ascii

rigid fable
#

you should just add a base argument

#

literally the same code

surreal path
#

its still not the issue

#

someone is fucking my memory

#

rbx has the weird ass address

#

i dont know what to do anymore

#

i tested the slab allocator in userspace it worked, i dont know whats ruining my memory

rigid fable
#

if you do not zero everything, then instead of getting value zero and failing the if nulls it uses garbage values

#

that's my guess

surreal path
#

so should i memzero my memory before i "free it"

rigid fable
#

I am specifically talking about the memory where the allocator variables are stored

tawdry mirage
#

what you should do is bring in managarm/frigg, and have one c++ file to use frg::slab_pool and expose it to the rest of the kernel :^)

surreal path
#

if theres something wrong with the code then its my fault and i should keep trying til i fix it

#

im really at a deadend here

tawdry mirage
#

yeah i'm joking

surreal path
#

yea i know

kind root
#

Add more printfs

surreal path
#

i did

kind root
#

Not enough

surreal path
#

even if i did

#

we tested it in userspace remember?

#

and it worked completely fine

kind root
#

Then you would see where it goes wrong

kind root
#

Other components as well

surreal path
#

sure

tawdry mirage
#

actually, i just remembered

#

an even better method for emulating mapping memory

#

memfd for allocating physical pages, mmap to map them into the address space

#

(replace memfd with tmpfs files if you really want to)

surreal path
#

every single region vmm makes

#

all look valid

#

i dont know what to do anymore this is pain no

finite summit
#

advancement made! oberrow hell

surreal path
#

at least when u tested ur allocator in userspace

#

it didnt work

#

mine fkn worked

finite summit
#

that means it's not the allocator

finite summit
#

It's probably the VMM

#

Does your VMM have an interdependecy on the allocator

#

if it does that might be your problem

finite summit
#

In the vmm

#

?

surreal path
#

ye

finite summit
#

That could be a problem soon

#

it could be the current problem

surreal path
#

why would that be a problem

finite summit
#

Because

#

infinite recursion if no space could be found for all regions

#

rather caches

#

in the allocator

surreal path
#

and i just halt

#

and error out

#

oh you mean the caches

finite summit
#

yes

surreal path
#

i expand them

#

allocate a new page

#

and all

finite summit
#

allocate a page with...

#

vmm_allocate?

surreal path
#

the hhdm offset

#

nope

finite summit
#

Then that shouldn't be your problem then

surreal path
#

yea

finite summit
#

Your kernel is cursed then.

#

Read the code

surreal path
#

I have.

finite summit
#

Zero memory

#

make sure you do

#

run a static analyzer

surreal path
#

i only zero memory on calloc

#

as uacpi says to do

finite summit
#

-fanalyzer to gcc

#

and see what it outputs

surreal path
#

okay

finite summit
#

See if it says anything sus

#

Also your license:

#

says that

surreal path
surreal path
finite summit
#

don't paste the output

surreal path
finite summit
#

read it

#

interpret it

surreal path
#

oka

#

okay i read

#

nothing obvious

#

gcc only complains when

finite summit
#

what about all the null dereferences

surreal path
#

if a cache isnt inited

#

some undefined things will happen

#

thats what these are saying basically

#

all these null dereferences are if a cache ISNT inited

#

but i always init them

#

so this isnt the problem

finite summit
#

what if a cache has some garbage memory address because you never zeroed it

#

or some slab in the cache

surreal path
finite summit
#

I mean in the cache structure itself

#

always zero your slabs

surreal path
#

so zero my slabs before i use them?

finite summit
#

yes

surreal path
#

alr

#

WAIT THAT COULD ACTUALLY BE THE ISSUE!!!

#

WAIT

#

WAIT WAIT WAIT

#

IM GONNA TEST THIS

#

NO MORE GARBAGE MEMORY ADDRESSES?

#

LETS GO!

#

but now

#

it page faults here

finite summit
#

definitely allocator issue

#

If an allocator works in userspace but not in kernel mode

#

probably an issue with zeroed memory

surreal path
finite summit
#

I meant unzeroed

#

memory

surreal path
#

but i zeroed all my memory

#

in my slabs

finite summit
#

Yeah I know

#

I'm just saying

#

That could be the issue

surreal path
#

wait i dont memzero when i allocate with the vmm

kind root
surreal path
#

could that be also an issue?

kind root
#

Yup

surreal path
#

CHAT ARE WE CLOSE?

#

TO GETTING UACPI ON NYAOS

kind root
#

Yes

finite summit
#

Well partially unimplemented uACPI

kind root
#

Also you dont call namespace initialize last time I checked

surreal path
#

i am

kind root
#

Ok

surreal path
#

@kind root @kind root @kind root @kind root @kind root @kind root @kind root @kind root

jaunty hingeBOT
#
Anti-spam Message

(ping spam) Possible spam detected for user: linuxmaster2.0. Please contact a moderator to be unmuted.

cinder plinth
#

um why is he timed out

finite summit
#

spam

cinder plinth
#

ah nvm im an idiot

surreal path
#

😭

#

sorry i got too excited

#

UACPI WORKS ON NYAOS

#

!!!!

finite summit
#

You're welcome

surreal path
#

thank you oberrow

#

so much

finite summit
#

Lets see who's the next to be put into oberrow hell

surreal path
#

😭 😭

#

bro gonna torture the next osdev

#

also our vmm_free function seems to be broken

#

lemme fix it

finite summit
#

ah yes our

surreal path
#

our

finite summit
#

communism in NyaOS confirmed

surreal path
#

real

#

!

#

i think i need to memzero the memory before i deallocate

finite summit
surreal path
#

the page

finite summit
#

where

#

in the vmm_free

#

no probably not

#

What's the bug anyway?

surreal path
#

page fault

#

cause of vmm region dealloc

#

probs memory fucking the memory

finite summit
#

could have something to do with the analyzer

#

warnings

#

Check if it says anything in the vmm_free function'

surreal path
#

use after free?

#

no wait no

#

vmm_free is causing some weird stuff

finite summit
#

do you intend to set freelist to him->next

surreal path
#

void vmm_region_dealloc(uint64_t base)
{
    char shit[64];
    struct vmm_region *cur_node = vmm_head; // find prev node and node after it
    struct vmm_region *prev_prev_node;
    while(cur_node != NULL)
    {
        if (cur_node->base == base)
        {
            if (cur_node->next)
            {
                prev_prev_node->next = cur_node->next;
            }
            int num_of_pages = align_up(cur_node->length, 4096) / 4096;
            for (int i = 0; i < num_of_pages; i++)
            {
                uint64_t phys = unmap((uint64_t)pml4 + hhdm_request.response->offset, cur_node->base + (i * 0x1000));
                pmm_free_singlep((uint64_t)phys + hhdm_request.response->offset);;
            }
            free(cur_node);
            return;
        }
        else
        {
            prev_prev_node = cur_node;
            cur_node = cur_node->next;
            continue;
        }
    }
    // REGION DOESNT EXIST WOWIE!
    write_color(ctx, "Region Provided doesn't exist!\n", 4);
    asm ("cli");
    for (;;)
    {
        asm ("hlt");
    }
}
surreal path
#

page fault happened there cause of same noncanoical address issue due to

#

vmm_region_dealloc

finite summit
#

non canonical is gpf

#

not pf

surreal path
#

wait

#

ur right

kind root
#

But congrats

surreal path
#

hey wait

#

😠

#

thats a physical address

finite summit
#

So are allocator bugs just called oberrow hell now

kind root
#

Yup

#

Technically this guy fixed it faster than you

surreal path
#

😎

finite summit
#

His was a simple bug though

surreal path
#

took me 3 days

kind root
#

Yes

surreal path
#

just goota fix this vmm bug

finite summit
#

I got a one by off error in the most unexpected place ever

#

I don't even remember how I found it

#

well I remember how

#

Just I don't even remember how I got to the allocation that made everything πŸ’©