#Nyaux

1 messages ยท Page 27 of 1

hollow goblet
#

for example rust for linux uses a fork of alloc that has stuff like fallible allocations and generally avoids panicking

hollow goblet
#

WHAAA

#

i thought nyaux was still rust

spice yarrow
#

I need to know the first exception that was part of the triple fault, not the last one

#

Also you cropped off all the useful info like the error code

surreal path
#

im using C

surreal path
hollow goblet
#

it's easier to cause UB in C lol

#

rust basically says "uphold normal safe rust guarantees in ur unsafe code (keep it "sound")"

surreal path
#

the llvm compiler

#

fucking hated me

hollow goblet
#

what

hollow goblet
surreal path
#

bro i did everything correct

surreal path
#

sis

hollow goblet
#

np

surreal path
#

im not debugging that

#

im sick of that

#

rust skill issue

#

idc

hollow goblet
#

ffi safety is a thing but rustc doesn't compile uacpi :3

#

ffi safety: don't pass invalid values through ffi

molten grotto
#

more likely the issues were just caused by you using rust like it was c and some other random unrelated issues

#

anyway yeah you are probably better doing it in c

surreal path
#

tbh

hollow goblet
surreal path
#

lol

#

what

#

no

#

tf u on about ๐Ÿ˜ญ

#

okay so

#

whatever is going on

#

its happening here

#

no that takes too much ram

surreal path
#

wait no

#

im not

#

tf is going on

#

๐Ÿ˜ญ ?

#

how did bro 0xd with this

#

i saw that

#

๐Ÿ˜ก

#

oki i will slow down qemu

#

and see

#

now it suddenly works

#

huh?

#

TF???

#

it only works when i print it

#

bro tf is the compiler doing

#

bro

#

now C UB

#

fucking hell

#

am i a bad programmer

#
result pmm_init() {
  spinlock_lock(&pmmlock);
  volatile pnode *cur = &head;
  result ok = {.type = ERR, .err_msg = "pmm_init() failed"};
  kprintf("pmm_init(): entry count %d\n", memmap_request.response->entry_count);
  kprintf("%s(): The HHDM is 0x%lx\n", __FUNCTION__,
          hhdm_request.response->offset);
  for (uint64_t i = 0; i < memmap_request.response->entry_count; i++) {
    struct limine_memmap_entry *entry = memmap_request.response->entries[i];
    switch (entry->type) {
    case LIMINE_MEMMAP_USABLE:
      for (uint64_t i = 0; i < entry->length; i += 4096) {
        volatile pnode *hi =
            (pnode *)(entry->base + i + hhdm_request.response->offset);

        cur->next = (struct pnode *)hi;

        cur = hi;
      }
      break;
    }
  }
  kprintf("FreeList Created\n");
  kprintf("Free Pages %ju\n", get_free_pages());
  spinlock_unlock(&pmmlock);
  ok.type = OKAY;
  ok.okay = true;
  return ok;
}
uint64_t get_free_pages() {
  pnode *cur = &head;
  uint64_t page = 0;
  while (cur != NULL) {
    page += 1;
    cur = (pnode *)cur->next;
  };
  return page;
}
#

i dont understand

#

whats wrong with my code

#

this SHOULD work

#

all the addresses looked fine when i PRINTED them

#

but when i dont print them

#

fucking 0xd with some weird ah cr2

#

what is the compiler doing

#

bro

kind root
#

the compiler is doing what u told it

surreal path
#
uint64_t get_free_pages() {
  pnode *cur = &head;
  uint64_t page = 0;
  while (cur != NULL) {
    page += 1;
    cur = (pnode *)cur->next;
  };
  return page;
}
#

it 0xd'd here

#

CR2=8948fffffb58858b

#

that shouldnt happen how tf am i making a weird ah address

#

like wtf?

kind root
#

what is head

surreal path
#

0x0 initally

#

which is what i set it to

#

NULL

#

oh wait

#

wait

#

wait

#

wait

#

wait

safe spireBOT
#
Anti-spam Message

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

finite summit
#

.!unmute @surreal path

safe spireBOT
#
Command executed by oberrow
Command Error
Type

Permission Error

Details

You must have MODERATE_MEMBERS to execute this command.

kind root
#

.!unmute @surreal path

safe spireBOT
#

@surreal path is not muted.

finite summit
#

@surreal path you are unmuted now

surreal path
#

okay

#

same general protection fault

#

i changed the code aroudn a bit

kind root
#

same skill issue

surreal path
#

bro how

kind root
#

do u have warnings enabled

surreal path
#

yes

#

-Werror

kind root
#

thats not warnigns enabled

surreal path
#

oh

#

how to enable them

kind root
#

-Wall -Wextra -Wpedantic

surreal path
#

okay

#

i only got this

#

and this

#

so um

#

yea

#

tf going on

#

these how i compile

kind root
#

still

#

probably treating some uninitialized memory as a pointer

surreal path
#

look

#

sec

surreal path
#

u mean

#

memzero right @kind root

kind root
#

i dont mean anything particular

surreal path
#

look

#

!!!!

#

i forgot to memset by stuff

#

so happy :)

#

i love C

surreal path
#

C :)

surreal path
#

pmm done

upbeat turret
surreal path
#

bro got 0xb

#

๐Ÿ˜ญ

thorn bramble
#

0xb?

surreal path
#

yea ๐Ÿ˜ญ

thorn bramble
#

where???

surreal path
thorn bramble
#

oh

#

i was looking at

#

v=08

surreal path
flat nymph
flat nymph
#

Why did you need ACPI at that stage in first place?

surreal path
#

heap stress test

#

:)

kind root
flat nymph
#

I mean the interface is basically POSIX

kind root
#

close

flat nymph
#

It was easy to plug in

crystal scarab
kind root
#

its either ultra or micro

#

but everyone has their own meaning for the u

cinder plinth
#

in my head canon it's ฮผ

kind root
#

to do what

unkempt relic
#

like how LAI was the LUX ACPI implementation

kind root
unkempt relic
kind root
#

i was there probably before lux was a thing

#

hmm, good question, i dont remember

#

i think i was curious about acpi and how complex it seemed

unkempt relic
kind root
#

hmm

elder shoal
#

there is no special meaning

kind root
#

who knows maybe thats true

finite summit
cinder plinth
#

u = you

#

uACPI is human

glossy walrus
#

that's just called depression

surreal path
#

working on slab allocator

#

should be easy

finite summit
#

C ub is only a problem when the compiler leverages it unexpectedly for optimizations

#

imo

#

ahem ahem

#

strict aliasing

#

ahem ahem

finite summit
#

waow

#

๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘

surreal path
#

thank

#

:)

finite summit
#

joys of using C

surreal path
#

indeed

surreal path
#

@thorn bramble i just realized i found a bug within old nyauxkt when reading the code about the page tables

#

i solved them in my C version now

#

im doing a similar implementation cause i think it was good

#

i might use a linked list for the vmm regions this time

#

but um

#

yea

#

bug found

#

bug squashed

#

yippie

#

also btw

#

you shouldnt do this check when mapping a 2mb page

#

right?

#

cause like

#

that would NEVER happen

#

am i correct

#

cause its only on like page level 2 (0, 1, 2, 3)

#

that happens

surreal path
#

thanks for catching that

hollow goblet
#

it may have happened to me

surreal path
hollow goblet
#

:3

#

thx

surreal path
#

i nap some more then we work on nyaux, i have page table shit mostly done i just need to write a function to setup a kernel pagemap and switch to such pagemap

#

then its vmm regions

#

then uacpi to test the heap

#

then scheduling straight away

surreal path
#

bro what nooo

#

tf are u on about

#

does anyone know how to fix this???

#

this shouldnt be happening?

finite summit
#

or rather

surreal path
#

๐Ÿ˜ญ

finite summit
#

a function to invlpg in a separate asm file

finite summit
#

I have out* and in* for port manip

#

getCR*

#

getEFER

#

getDR6 (idk what happened with the other debug regs

#

cpuid

#

*msr

#

pause

#

invlpg

#

wbinvd

#

xsave

#

cli

#

sti

#

hlt

surreal path
#

ugh fine

surreal path
#
check_exception old: 0xffffffff new 0xe
   133: v=0e e=0010 i=0 cpl=0 IP=0028:ffffffff8000e1c7 pc=ffffffff8000e1c7 SP=0030:ffff800006683f98 CR2=ffffffff8000e1c7
RIP=ffffffff8000e1c7 RFL=00000082 [--S----] CPL=0 II=0 A20=1 SMM=0 HLT=0
CR0=80010011 CR2=ffffffff8000e1c7 CR3=0000000000008000 CR4=00000020
check_exception old: 0xe new 0xe
   134: v=08 e=0000 i=0 cpl=0 IP=0028:ffffffff8000e1c7 pc=ffffffff8000e1c7 SP=0030:ffff800006683f98 env->regs[R_EAX]=000000000000000d
RIP=ffffffff8000e1c7 RFL=00000082 [--S----] CPL=0 II=0 A20=1 SMM=0 HLT=0
CR0=80010011 CR2=ffffffff800e9ba0 CR3=0000000000008000 CR4=00000020
check_exception old: 0x8 new 0xe

fun

#

when switching to the new pagemap

#

this happens

#

!!!!!

#
void map(uint64_t *pt, uint64_t phys, uint64_t virt, uint64_t flags) {
  uint64_t *f = find_pte_and_allocate(pt, virt);
  *f = phys | flags;
}
uint64_t *find_pte_and_allocate(uint64_t *pt, uint64_t virt) {
  uint64_t shift = 48;
  for (int i = 0; i < 4; i++) {
    shift -= 9;
    uint64_t idx = (virt >> shift) & 0x1ff;
    uint64_t *page_table =
        (uint64_t *)((uint64_t)pt + hhdm_request.response->offset);
    if (i == 3) {
      return (uint64_t *)((uint64_t)page_table + idx);
    }
    if (page_table[idx] & ~PRESENT) {
      uint64_t *guy =
          (uint64_t *)((uint64_t)pmm_alloc() - hhdm_request.response->offset);
      page_table[idx] = (uint64_t)guy | PRESENT | RWALLOWED;
      pt = guy;
    } else if (page_table[idx] & PAGE2MB) {
      uint64_t *guy =
          (uint64_t *)((uint64_t)pmm_alloc() - hhdm_request.response->offset);
      uint64_t old_phys = page_table[idx] & 0x000ffffffffff000;
      uint64_t old_flags = page_table[idx] & ~0x000ffffffffff000;
      for (int j = 0; j < 512; j++) {
        guy[j] = (old_phys + j * 4096) | (old_flags & ~PAGE2MB);
      }
    } else {
      pt = (uint64_t *)(page_table[idx] & 0x000ffffffffff000);
    }
  }
  return 0;
}
#

i dont see an issue

#

or the issue*

finite summit
#

fun

surreal path
#
uint64_t *find_pte_and_allocate2mb(uint64_t *pt, uint64_t virt) {
  uint64_t shift = 48;
  for (int i = 0; i < 4; i++) {
    shift -= 9;
    uint64_t idx = (virt >> shift) & 0x1ff;
    uint64_t *page_table =
        (uint64_t *)((uint64_t)pt + hhdm_request.response->offset);
    if (i == 2) {
      return (uint64_t *)((uint64_t)page_table + idx);
    }
    if (page_table[idx] & ~PRESENT) {
      uint64_t *guy =
          (uint64_t *)((uint64_t)pmm_alloc() - hhdm_request.response->offset);
      page_table[idx] = (uint64_t)guy | PRESENT | RWALLOWED;
      pt = guy;
    } else {
      pt = (uint64_t *)(page_table[idx] & 0x000ffffffffff000);
    }
  }
  return 0;
}
finite summit
#

gl

surreal path
cinder plinth
surreal path
#

()?

cinder plinth
#

you're dereferencing an address

#

yes

surreal path
#

( )?

cinder plinth
#

yes

#

around %0

spice yarrow
#

att syntax is weird

surreal path
#

ik

surreal path
#

oberrow does it

surreal path
#

i dont know whats wrong with this ๐Ÿ˜”

cinder plinth
surreal path
#

@finite summit

#

bug for u

finite summit
#

hai

spice yarrow
finite summit
#

no skill issue for you

surreal path
cinder plinth
#

its fine if oberrow does something like

surreal path
#

compiled in nasm

cinder plinth
#

&addr

finite summit
#

huh

surreal path
#

huh

cinder plinth
#

invplg [rdi] dereferences what is at rdi

spice yarrow
surreal path
finite summit
cinder plinth
#

no

surreal path
finite summit
#
invlpg rdi```
cinder plinth
#

invplg [rdi] is invlpg *rdi in C terms

finite summit
#

is invalid

#

error: invalid combination of opcode and operands

#

and I directly pass the address of the page to invlpg

cinder plinth
finite summit
#

containing m

finite summit
surreal path
#

this can be a work around for u oberrow

cinder plinth
finite summit
#

bro wtf do you mean workaround

#

it's not broken

finite summit
#

or rather

#

not what you intended

surreal path
#

ok i see

cinder plinth
#

[rdi] means "invlpg *rdi"

surreal path
#

i know

finite summit
#

yes invlpg the address pointed to by rdi

cinder plinth
#

so passing an address as rdi would read whatever is at that address

finite summit
#

no

#

think of it like a mov [rdi], 0

#

it accesses the memory at rdi

#

kinda

#

but instead of moving anything in or out of it

#

it invalidates the relavant tlb entry

cinder plinth
#

Invalidates any translation lookaside buffer (TLB) entries specified with the source operand. The source operand is a memory address. The processor determines the page that contains that address and flushes all TLB entries for that page.

#

the source operand is a memory address

spice yarrow
#

It's a memory address, not an integer

cinder plinth
#

same thing

finite summit
#

let me open up the sdm quickly

cinder plinth
#

this is the sdm

finite summit
#

yes I know

#

I am looking for a different section

spice yarrow
#

It's the same as lea

surreal path
#

im too depressed to debug this rn i am feeling sucidal thoughts rn so im just ognna try to distract myself or smthin for a bit

cinder plinth
#

but the at&t code does seem fine tho ๐Ÿค” I really wonder if that's just a syntax quirk of assemblers

finite summit
#

they would assemble to the same thing

cinder plinth
#

yeah I'm just saying maybe assemblers have some kind of check for invlpg

finite summit
#

no at&t syntax

#

nvm

#

that was for immediates

#

I was gonna say it auto derefs

cinder plinth
#

if (%0) is correct then presumably [rdi] is too

#

so that's weird

spice yarrow
#

Wait so what does your invlpg do?

finite summit
#
invlpg:
    invlpg [rdi]
    ret```
#

@cinder plinth it seems like it takes an effective address

#

which is why you wouldn't just give it rdi

cinder plinth
#

yeah so I chalk it up as weird syntax

#

[rdi] typically means take whatever is there

finite summit
#

well I guess it's kinda like lea

#

whatever

#

I think we can all agree that we have better stuff to be doing than arguing about invlpg

#

at least I do

spice yarrow
#

Just reset cr3

finite summit
#

genius

spice yarrow
#

Best invlpg

finite summit
#

nah actually

#

just go into _S3

#

each time

surreal path
#

i asked for help on the osdev fourms cause i do not wanna debug this rn, im gonna go play some val then nap again ig

spice yarrow
surreal path
surreal path
spice yarrow
#

Okay I'll take a look

surreal path
#

thank you

cinder plinth
#

didnt you already have working code for this

cinder plinth
#

cant you just copy it

#

if it doesnt work then it's likely the pmm's fault

surreal path
#

its rust

#

and i copied most of the implementation

cinder plinth
#

you had old nyaux before tho

spice yarrow
#

You can call rust from c

cinder plinth
#

don't

surreal path
#

please

#

for the love of god

spice yarrow
#

But actually... what do you see when you use gdb pt dump?

surreal path
#

i told u i really dont wanna debug this rn

#

im not feeling good at all

#

im just trying to distract myself with val

#

just take a look at it if u want to, if u dont ill try tmrw if im in the mood

spice yarrow
#

Alright

#

I really hope you feel better

surreal path
#

i woke up

#

thats the address

#

thats valid memory

#

so thats not the issue

edgy pilot
#

what is this

page_table[idx] & ~PRESENT
#
!(page_table[idx] & PRESENT)
#

@surreal path

surreal path
#

wdym

edgy pilot
#

wdym wdim

surreal path
#

i invert present

edgy pilot
edgy pilot
surreal path
#

to check if it doesnt have present

#

whats wrong with that

edgy pilot
#

that's not how it works

surreal path
#

wdym

edgy pilot
#

~0b00110010 = 0b11001101

surreal path
#

oh

edgy pilot
#

inb4 nyaux is fixed

surreal path
#

nope

#

lol

#

error code is 0x18

#

0xe exception

#

@edgy pilot

edgy pilot
#

push the code

surreal path
#

kk

#

pushed

#

@edgy pilot

#

take a look

edgy pilot
#

2097152

#

why

#

use hex

surreal path
#

ehhh it dont matter

edgy pilot
#

why do you have so many find_pte functions

surreal path
#

idk man

#

ill fix that later just

#

idk

edgy pilot
#

make it into a single one

surreal path
#

later

edgy pilot
#

duplicated code introduces multiple failure points

#

later often means "never"

surreal path
#

no i will

#

pin that

surreal path
edgy pilot
#

I can't

surreal path
#

any mods here

#

lurking

#

or smthin

#

guessss not

edgy pilot
# surreal path ill fix that later just
auto pagemap::getlvl(entry &entry, bool allocate) -> table *
{
    table *ret = nullptr;
    if (!entry.getflags(valid_table_flags))
    {
        if (allocate == false)
            return nullptr;

        entry.clear();
        entry.setaddr(reinterpret_cast<std::uintptr_t>(ret = new_table()));
        entry.setflags(new_table_flags, true);
    }
    else ret = reinterpret_cast<table *>(entry.getaddr());

    return lib::tohh(ret);
}
// ...
auto pagemap::getpte(std::uintptr_t vaddr, page_size psize, bool allocate) -> std::expected<std::reference_wrapper<entry>, error>
{
    static constexpr std::uintptr_t bits = 0b111111111;
    static constexpr std::size_t levels = 4; // We don't need more than 256 tib of addresses
    static constexpr std::size_t shift_start = 12 + (levels - 1) * 9;

    auto pml = lib::tohh(_table);

    auto retidx = levels - static_cast<std::size_t>(psize) - 1;
    auto shift = shift_start;

    for (std::size_t i = 0; i < levels; i++)
    {
        auto &entry = pml->entries[(vaddr >> shift) & bits];

        if (i == retidx)
            return std::ref(entry);

        pml = getlvl(entry, allocate);
        if (pml == nullptr)
            return std::unexpected { error::invalid_entry };

        shift -= 9;
    }
    std::unreachable();
}

psize is 0=4kib 1=2mib or 2=1gib

surreal path
#

this is c++ code

edgy pilot
#

yes
use it as a reference

surreal path
#

also arent u supposed to be finding this weird ah bug ๐Ÿ˜ญ

edgy pilot
#

I'm supposed to be writing an essay

#

not finding a weird bug

surreal path
#

oh

#

sorry

#

im sorry man

#

im sorry

#

im rlly sorry

#

im sorry

#

im sorry

edgy pilot
#

one sorry was enough :p

surreal path
#

still im sorry

median goblet
#

~page_table[idx] & PRESENT

edgy pilot
#

lol

#

yeah that works too

#

I have never seen that used though

molten grotto
#

its also pretty unreadable when compared to the alternative

surreal path
#

idk why but i still feel actually rlly fucking awful

#

maybe its the bad sleep idfk

#

maybe ill feel better if i sleep some more

tender gorge
tender gorge
glossy walrus
tender gorge
#

sleeping is not really a good coping mechanism

median goblet
median goblet
#

i feel like !(a & b) is more cumbersome than ~a & b

edgy pilot
#

it looks a bit like -

median goblet
#

maybe

molten grotto
#

at least to me ~a & b takes more time because I have to actually think about what it does

edgy pilot
#

^

median goblet
#

btw i see a lot less mods, and those former mods having the secret private club access

#

just an observation

#

has there been a reform of mods lately?

edgy pilot
#

no minors

median goblet
#

like, reform of the mod system

median goblet
molten grotto
#

well not that much

#

couple afaik

median goblet
#

i didn't know czapek/iretq was a minor

frigid cliff
tender gorge
#

sleeping as a coping mechanism can spiral you into a even deeper depression

#

source: me

frigid cliff
#

I mean thatโ€™s kinda what makes it bad

tender gorge
#

i mean yeah

#

must admit i dont really have any other suggestions for coping mechanisms that are good on account of not having had any when i was depressed

frigid cliff
#

Yeah I donโ€™t have any either ๐Ÿ˜“

tender gorge
#

as much as im past it now, hindsight says i probably should have seen a psychiatrist lol

#

but yeah, the only real advice i can give is that it will be alright, and that recovery is not linear

frigid cliff
#

That is generally the advice but speaking to someone can be really hard

tender gorge
#

yeah, but its also what one should do, as hard as it is

#

i mean im saying that while having never actually done that to anyone irl, but yea

frigid cliff
#

Because we know what the correct thing is, but the correct thing is sometimes very hard to first come to the realization thatโ€™s itโ€™s the correct thing and then to actually do that

#

Idk Iโ€™m just saying shit I have been up for over 24 hours

tender gorge
#

lol

tender gorge
#

(i think youre trying to say that we know what the correct thing to do is, but that its sometimes very hard to come to the realization that that is the correct thing to do)

frigid cliff
#

Yesss

thorn bramble
surreal path
#

oh yeah it came to me in a dream what i was doing wrong with the page tables

#

i was doing return (uint64_t *)((uint64_t)page_table + idx)

#

i should be doing

#

return page_table + idx

finite summit
#

it's a sign!

surreal path
#

indeed !!!

#

it fixed the issue

finite summit
#

and it's damn right

surreal path
#

so :)

surreal path
#

anyways page tables done now

#

i need to do vmm regions but i feel shit rn so idfk what to do

tender gorge
tender gorge
#

I'd recommend talking with your psychiatrist about your sleeping problems

#

If you haven't already

surreal path
#

i did

rigid fable
#

do no use screens

surreal path
#

he gave me sleep tablets

#

they dont work

#

anymore

#

used to

#

not anymore

rigid fable
#

how much time do you spend on screens?

tender gorge
surreal path
#

caus eim under 18

tender gorge
#

It's normal that meds sometimes stop working and need changing/dose adjustments

surreal path
#

ill try to ask him again

tender gorge
# rigid fable do no use screens

I mean yeah, but I'm gonna assume nyaux is currently in a psych ward based on what happened a few days ago, and if my knowledge of them is correct that's not really much of a option

rigid fable
#

oh he like broke a leg or?

#

iirc

tender gorge
surreal path
#

but if i do anything

#

i will go to one

#

and they'll take away my stuff

#

which means

#

no more nyaux

#

ever

#

so i cannot try to hurt myself

#

again

#

or

#

yk

tender gorge
tender gorge
#

Since they might be able to organise you working on your job/hobbies from within hospital

#

Source: a person I knew who was in a UK psych ward

surreal path
#

i will ask

tender gorge
#

Alright, sounds good

#

It'll be alright ๐Ÿซ‚

surreal path
#

got vmm regions working

#

this test works

#

page faults at memset

#

because it is

#

unmapped!!!

surreal path
#

this doesnt cause a page fault

#

is this bad

#

im sure its fine

#

time to integrate uacpi

#

ummmm

#

idk what this means ???

#

wha

#

nvm

#

i got that working

#

time to impl kernel_api.h

surreal path
#

thats fun

#

and it fails using my memset so

#

probs memory corruption

#

yippie !

#

nyaux hell 2015i0925890125901285th time

rigid fable
#

more colors on logs is what we need

#

obos and astral will be no more

surreal path
finite summit
#

Jokes on you

edgy pilot
#

every line should have a different random rgb value

#

and panic when you're out of colours

rigid fable
edgy pilot
#

but every letter is of a random one

edgy pilot
rigid fable
#

the random function?

edgy pilot
#

yes

#

but every time it's different

#

for 255*255*255 calls

rigid fable
#

I recall you can use the timer with a specific algorithm. idk if that actually works but there are probably better methods

edgy pilot
#

any algorithm that guarantees that?

elder shoal
#

Define a bitmap 255255255 big troll

edgy pilot
#

based

rigid fable
#

but what is likely is to get similar colors

#

iirc ToaruOS had a screen with some random colored chars, maybe I am wrong but whatever

rigid fable
edgy pilot
#

I believe that was on playstation 2

rigid fable
#

ECDSA

edgy pilot
#

ah

rigid fable
#

reason why you can't cfw a super slim

rigid fable
edgy pilot
#

there's xkcd about that

rigid fable
#

Literally from the like 10 photos I have on my phone

edgy pilot
#

so it wasn't 4

edgy pilot
#

but most of that storage is taken up by videos

rigid fable
#

depending on what you'd consider meme

edgy pilot
#

everything from memes channels or Reddit

#

and is funny

cinder plinth
#

I assign a random color based on pid for every task

edgy pilot
#

randomise pids on every context switch

cinder plinth
#

Openbsd is scared of this man

surreal path
#

hi chat need more sleep

#

eta 1am my time i wake up

#

(irish time)

edgy pilot
#

to be fair I don't think it's a bad idea if you use a good hash map implementation

#

has better lookup times than a rb tree

cinder plinth
#

a good hashmap implementation is implemented using a rbtree or avl

#

I'd just use an array

#

which is instant

#

the problem is sparse memory areas

edgy pilot
#

then you need to resize that array

cinder plinth
#

yeah so

edgy pilot
#

how would you map addresses to index

#

that's still a mini hash map lol

cinder plinth
#

no

#

you just do

#

page / page size

#

or rather

#

offset / page size

edgy pilot
#

that becomes very inefficient if address isn't small

#

please correct me if i'm wrong

cinder plinth
#

I'm not sure what you mean

#

you keep an array of pages per anonymous mapping

#

the indices are based on the offset into that mapping

#

and for sparse areas, you can mitigate that using chunking

edgy pilot
#

wasn't the previous conversation about mapping when page faulting

#

and you would need to look up the data structure with the faulting address

cinder plinth
#

so

#

you keep an rbtree or something of mappings

#

then in that mapping you can find a single page using the array

#

that's like

#

O(log n) + O(1) amortized

edgy pilot
#

lookup would be faster with a proper hashmap

#

wouldn't it?

cinder plinth
#

well

#

trees have better worst-case performance

#

and resizing a hashtable is very inefficient

#

and self-balanced trees are sorted too

edgy pilot
#

you said good hashmaps are implemented using a rbtree or an avl

#

so resizing it wouldn't be so bad

cinder plinth
#

pretty sure you still need to rehash everything

edgy pilot
#

not always

#

only when a new hash conflicts with some other

#

iirc

cinder plinth
#

you can also lookup ranges better

#

in a tree

#

since it's ordered

#

and less overhead probs

edgy pilot
#

when would you need to lookup ranges though

#

in this case

cinder plinth
#

unmap

#

let's say you have a mapping from [0, 0x1000) and another one [0x1000, 0x2000)

#

now you unmap 0 with size 0x2000

#

also I think trees are preferred because worst case hashtables kinda suck while performance can be more easily predicted in a tree

#

yeah they're O(n) worst case

#

rbtree is always O(log n)

#

anyway I'm not a data structure expert but that's probably the biggest reason

surreal path
#

hi i woke up (early this time !!!)

#

anyways

#

im gonna play one val comp game

#

then uhhh figure out whats going on lol

edgy pilot
#

(in the future)

cinder plinth
#

but yeah I think tldr hashmaps are less predictable than trees

edgy pilot
#

abseil::btree_map looks interesting

cinder plinth
#

std::map is tree-based

edgy pilot
#

stl has pretty inefficient implementations though

#

as it needs to work with everything

cinder plinth
#

yeah

#

but you dont have access to abseil do you

#

is it even freestanding

edgy pilot
#

it has abseil btee structures ported

#

basically the same thing

surreal path
#

chat what are we talking abt :3

edgy pilot
#

I was already using flat hash map in my "old" kernel

edgy pilot
surreal path
#

also im losing so bad in this val game

surreal path
#

tbh

#

hashmap >= anything else

#

fight me

#

๐Ÿ˜ค

#

guys multidimensional hashmap

#

NEED

cinder plinth
#

might scale better

edgy pilot
cinder plinth
#

then again, how many mappings are there in a process

surreal path
#

guys

#

what do yall think of multidimensional hashmaps

cinder plinth
#

Hashmap<Hashmap<>, Hashmap<>>

edgy pilot
cinder plinth
surreal path
edgy pilot
#

why?

#

just std::pair<val1, val2> as a key

cinder plinth
#

then that's overhead too

#

because this not intrusive like rbtree

edgy pilot
#

but I don't think it'll be that large

cinder plinth
#

I don't think you can reasonably uniquely hash a structure like that

edgy pilot
#

just have a good hashing function meme

surreal path
#

AND ALSO

#

YEA

cinder plinth
#

wait no

#

you can

#

nvm

#

I'm stupid

#

you hash using the address

#

not the data

edgy pilot
#

aren't we all

#

yeah

cinder plinth
#

then yeah maybe it'd work but

#

the main two issues are overhead and predictability/scalability

surreal path
#

btw i just said in a val game

#

WE ARE VALORANT

#

i made the entire team cringe

edgy pilot
#

with btree_map or a hashmap

#

which one are you talking about

cinder plinth
#

hashmap

edgy pilot
#

yes

cinder plinth
#

best-case I think a hashmap would be pretty good tho

surreal path
edgy pilot
#

might use that

cinder plinth
#

yes

#

then again, how common is that

#

idk

edgy pilot
#

one issue is that btree moves items a lot so the structure needs to not be very large

#

what else would you store in it:

  • paddr
  • vaddr
  • offset
  • length
  • prot/flags
#

not that much

#

there are probably way more knowledgeable people here

cinder plinth
#

why offset

edgy pilot
#

wait what was I thinking about

#

I forgor why

#

nvm that

cinder plinth
#

"and hash tables (which are not kept sorted to be easily traversed in order, and must be tuned for a specific size and hash function where rbtrees scale gracefully storing arbitrary keys)."

#

according to linux

edgy pilot
#

and I froggot length

#

40 bytes max

edgy pilot
#

saving 7 bytes

surreal path
#

maybe its my slab allocator?

#

wait nvm

#

tried watching it

#

got nothing rlly

#

cause

#

the address changes everytime

#

what it faults with in cr2

#

after memsetting with my slabs the cr2 is now consistent

#

okay interesting

#

theres no base that exists with this address

#

so um

#

wtf

edgy pilot
#

what's at rip

surreal path
#

memset

#

my memset function which came with the limine c template

edgy pilot
#

what is it memsetting

surreal path
#

i dont know

#

im trying to figure that out rn

edgy pilot
#

printf

surreal path
#

dude

#

its uacpi doing itr

#

not me

edgy pilot
#

you are doing it

surreal path
#

no im not?

edgy pilot
#

and uacpi is failing because of that

surreal path
#

uacpi is using MY memset

#

i printf'd all the addresses

#

being allocated and deallocated

#

nothing found

edgy pilot
#

then you are allocating or mapping incorrectly

#

what's the error code

#

in binary

thorn bramble
#

maybe it is uacpi failing, but it's your fault it's doing that

surreal path
#

0x2

thorn bramble
#

you are clearly not upholding something

edgy pilot
thorn bramble
#

so yeah, print!

edgy pilot
thorn bramble
#

make sure your malloc is up to spec

edgy pilot
#

see what it means

surreal path
#

i know what that means

#

it means non present write

edgy pilot
#

check your mapper

surreal path
edgy pilot
#

and combine those functions

surreal path
#

im not combining them

#

that isnt gonna solve the issue

edgy pilot
#

combine them

surreal path
#

no

edgy pilot
#

please

surreal path
#

bru

edgy pilot
#

or I'll be sad

surreal path
#

maybe later

#

promise

#

not rn tho

#

i wanna get rid of this bug

edgy pilot
surreal path
#

this should be correct

#

bru

edgy pilot
#

what is that

surreal path
#

part of my vmm region allocation

#

wait one sec i have an idea

edgy pilot
#

good night

surreal path
#

taking away both free functions

#

causes a different

#

result

#

fucking hell

#
uint64_t *find_pte_and_allocate(uint64_t *pt, uint64_t virt) {
  uint64_t shift = 48;
  for (int i = 0; i < 4; i++) {
    shift -= 9;
    uint64_t idx = (virt >> shift) & 0x1ff;
    uint64_t *page_table =
        (uint64_t *)((uint64_t)pt + hhdm_request.response->offset);
    if (i == 3) {
      return page_table + idx;
    }
    if (!(page_table[idx] & PRESENT)) {
      uint64_t *guy =
          (uint64_t *)((uint64_t)pmm_alloc() - hhdm_request.response->offset);
      page_table[idx] = (uint64_t)guy | PRESENT | RWALLOWED;
      pt = guy;
    } else if (page_table[idx] & PAGE2MB) {
      uint64_t *guy = (uint64_t *)((uint64_t)pmm_alloc());
      uint64_t old_phys = page_table[idx] & 0x000ffffffffff000;
      uint64_t old_flags = page_table[idx] & ~0x000ffffffffff000;
      for (int j = 0; j < 512; j++) {
        guy[j] = (old_phys + j * 4096) | (old_flags & ~PAGE2MB);
      }
      pt = (uint64_t *)((uint64_t)guy - hhdm_request.response->offset);
    } else {
      pt = (uint64_t *)(page_table[idx] & 0x000ffffffffff000);
    }
  }
  return 0;
}

my mapping function

#
void map(uint64_t *pt, uint64_t phys, uint64_t virt, uint64_t flags) {
  uint64_t *f = find_pte_and_allocate(pt, virt);
  *f = phys | flags;
}
#
void kvmm_region_dealloc(void *addr) {
  if (addr == NULL) {
    return;
  }
  VMMRegion *cur = (VMMRegion *)ker_map.head;
  while (cur != NULL) {
    if (cur->base == (uint64_t)addr) {
      memset((void *)cur->base, 0, cur->length);
      uint64_t amount_to_allocateinpages = cur->length / 4096;
      for (uint64_t i = 0; i != amount_to_allocateinpages; i++) {
        uint64_t phys = unmap(ker_map.pml4, cur->base + (i * 4096));
        pmm_dealloc((void *)(phys + hhdm_request.response->offset));
      }
      slabfree(cur);
      return;
    } else {
      cur = (VMMRegion *)cur->next;
      continue;
    }
  }
}
#

region deallocator

#
void *kvmm_region_alloc(uint64_t amount, uint64_t flags) {
  assert(ker_map.head != NULL);
  assert(ker_map.pml4 != NULL);
  VMMRegion *cur = (VMMRegion *)ker_map.head;
  VMMRegion *prev = NULL;
  while (cur != NULL) {
    if (prev == NULL) {
      prev = cur;
      cur = (VMMRegion *)cur->next;
      continue;
    }
    if ((cur->base - (prev->base + prev->length)) >=
        align_up(amount, 4096) + 0x1000) {
      VMMRegion *new =
          create_region((prev->base + prev->length), align_up(amount, 4096));
      prev->next = (struct VMMRegion *)new;
      new->next = (struct VMMRegion *)cur;
      uint64_t amount_to_allocateinpages = new->length / 4096;
      for (uint64_t i = 0; i != amount_to_allocateinpages; i++) {
        void *page = pmm_alloc();
        map(ker_map.pml4, (uint64_t)page, new->base + (i * 4096), flags);
      }
      memset((void *)new->base, 0, new->length);
      return (void *)new->base;
    } else {
      prev = cur;
      cur = (VMMRegion *)cur->next;
      continue;
    }
  };
  kprintf("No free Regions, Too Much Memory being used!!!\n");
  panic("Sir madamm this should never occur");
  return NULL;
}

region allcocator

#
void init_cache(cache *mod, uint64_t size) {
  mod->size = size;
  mod->slabs = (struct slab *)init_slab(size);
}
void *slab_alloc(cache *mod) {
  spinlock_lock(&pmmlock);
  if (mod->slabs == NULL || mod->size == 0) {
    return NULL;
  }
  slab *cur = (slab *)mod->slabs;
  while (true) {
    if (cur->freelist == NULL) {
      if (cur->next != NULL) {
        cur = (slab *)cur->next;
        continue;
      }
      break;
    }
    void *guy = cur->freelist;
    cur->freelist = ((pnode *)cur->freelist)->next;
    memset(guy, 0, mod->size);
    spinlock_unlock(&pmmlock);
    return guy;
  };
  cur->next = (struct slab *)init_slab(mod->size);
  cur = (slab *)cur->next;
  void *guy = cur->freelist;
  cur->freelist = ((pnode *)cur->freelist)->next;
  memset(guy, 0, mod->size);
  spinlock_unlock(&pmmlock);
  return guy;
}
void *slaballocate(uint64_t amount) {
  amount = next_pow2(amount);
  for (int i = 0; i != 7; i++) {
    cache *c = &caches[i];
    assert(c->size != 0);
    return slab_alloc(c);
  }
  return NULL;
}
void slabfree(void *addr) {
  spinlock_lock(&pmmlock);
  uint64_t real_addr = (uint64_t)addr;
  if (real_addr == 0) {
    spinlock_unlock(&pmmlock);
    return;
  }
  slab *guy = (slab *)(real_addr & ~0xFFF);
  memset(addr, 0, sizeof(pnode));
  pnode *node = (pnode *)addr;
  pnode *old = (pnode *)guy->freelist;
  node->next = (struct pnode *)old;
  guy->freelist = (struct pnode *)node;
  spinlock_unlock(&pmmlock);
}
slab *init_slab(uint64_t size) {
  void *page = pmm_alloc();
  uint64_t obj_amount = (4096 - sizeof(slab)) / size;
  slab *hdr = (slab *)page;
  pnode *first = (pnode *)((uint64_t)page + sizeof(slab));
  pnode *cur = first;
  hdr->freelist = (struct pnode *)first;
  for (uint64_t i = 1; i < obj_amount; i++) {
    pnode *new = (pnode *)((uint64_t)first + (i * size));
    new->next = (struct pnode *)cur;
    cur = new;
  };
  return hdr;
}
#

my slab allocator

#

all on github

#

and btw

#

i cannot even figure out whats calling what because memset is being used thousands of times from uacpi

#

i tried back tracing i got nothinggggg

#

wtf is that

#

why is that

#

all garbage data

#

wtf

#

but C sees it fine

#

wtf

#

MORE BUGS??

#

of course because a shitty programmer like me cannot even fucking do something as simple as a memory allocator

#

i fuck everything, the stack, the heap

#

what next

#

i cannot even go up because the stack is corrupt???

#

wtf

#

fucking kill me

#

im gonna legit cry

#

doesnt matter what language i write in

#

i always make UB

spice yarrow
spice yarrow
finite summit
steady flume
surreal path
#

hi i think i need a break for today

#

sorry

finite summit
#

it's np

steady flume
#

all good :)

tender gorge
surreal path
#

btw i found something cause i was bored and decided to debug for like 15 minutes

...
ffff8000ffc00000: 00000000ffc00000 --P-----W
ffff8000ffe00000: 00000000ffe00000 --P-----W
ffff800100400000: 0003800000033000 X-------W    <------- Messed up
ffff800100401000: 0003800000036000 X-------W    <------- Messed up
ffffffff80000000: 0000000002125000 ----A---W
ffffffff80001000: 0000000002126000 ----A---W
ffffffff80002000: 0000000002127000 ----A---W
...

something is wrong with my mapping function

#

eh

#

anyways im gonna go back on my break for today

#

tmrw we figure this out

surreal path
#

hi chat todays halloween and i still kinda want to spend this time with my family and go out trick or treating

#

i didnt realize yesterday that tmrw was halloween

#

promise tmrw ill get something done

#

im srry

tender gorge
steady flume
#

are you feeling pressured to work on this project? if so, i don't think that's particularly healthly

spice yarrow
#

It's not like GitHub is gonna fire you cause you didn't do enough work on Nyaux
Just do whatever you want to, if you decide to abandon this project that's totally fine

surreal path
#

im not gonna abandon

#

im okay now

#

ill work on it!!!

#

rn im opening vscode

#

time to debug this shit

surreal path
#

im just letting you guys know whats going on

#

okay so time for epic nyaux debugging

surreal path
#

i found more information

#

it seems my page entries get messed up at levels 1 and 2

#

im unsure what is causing this still but

#

that is useful information to know

#

it seems like the upper 17 bits get all set?

#

tf?

#

lower bits seems fine

#

but

#

wtf

#

is going on

thorn bramble
#
check_exception old: 0xffffffff new 0xe
     0: v=0e e=0008 i=0 cpl=0 IP=0028:ffffffff8000114e pc=ffffffff8000114e SP=0030:ffff800007f38fe0 CR2=ffff800007f38fe0```
#

the nyaux curse ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ

#

lol i love operator precedence! :)

#

apparently pte_flags |= PTE_P * (flags & MMU_PRESENT) != 0; isn't equivalent to pte_flags |= PTE_P * ((flags & MMU_PRESENT) != 0); =w=

#

it actually makes sense tho, now that i think about it

tender gorge
surreal path
#

but now a new issue

#

as usual

#

nyaux curse continues

#
Page Fault! CR2 0xffff800100c001d8
RIP is 0xffffffff80010666
NYAUX Panic! Reason: Page Fault:c
#

happens in uacpi

#

probs cause my allocator shit or smthin idfk

surreal path
#

happens here so def allocator bug

#

more bug as usual

#

the nyaux curse continues

surreal path
#

welp at least we made progress today

surreal path
#

man this is tiring

#

but maybe its find_pte

#

to be honest

#

AND ALSO

#

sorry for the very slow progress, just this bug is persisent

#

and honestly i dont wanna burn myself out at the same time so i kinda work on nyaux in bursts now

#

whenever i feel not horrible

#

i think its more sustainable

#

ima sleep

#

then tmrw ill look into find_pte and see if it is encountering a 2mb entry or smthin

#

maybe that be the issue who knows

surreal path
#

it is not find_pte

#

im afraid

surreal path
steady flume
#

poor nyaux

surreal path
#

its because

#

uhhh

#

idk man

#

๐Ÿคทโ€โ™‚๏ธ

#

i just get tortured by bug after bugi

#

yea i know

#

it is how i talk ๐Ÿ˜Ž

#

how u know ๐Ÿ˜ฑ

#

also @fa#

#

@unkempt relic i see u lurking!!

#

say hiii

#

hiii

#

i am NOT used to this 60% keyboard ๐Ÿ˜ญ

#

i cannot type for shit with this

#

anyways more nyaux debugging after i take a nap!!

#

also i was debugging all night

#

i didnt find much

#

๐Ÿ˜”

#

all i know is that its just another page table bug of some kind i THINK

#

ill keep inspecting every entry and

#

figure it out

surreal path
#

is that the cr2 isnt some null deref

#

is it something with memory corruption cause memset?

#

no?

#

i memset all my pages and every piece of memory that goes in and out

#

maybe its with unmap

#

idk ima nap then try commenting out unmap

#

maybe thats ze issue

surreal path
#

shit

#

i have school tmrw

#

ill debug this rn

#

i dont have much timne

#

cause schol

tender gorge
#

but also not too much

edgy pilot
#

I either sleep 4 hours or 12

surreal path
#

me and oberrow joined forces to debug on it, a lot of bugs going on. we continue debugging after school !

#

obos x nyaux