#Nyaux

1 messages ยท Page 11 of 1

wicked loom
#

yeah

#

np

surreal path
thorn bramble
#

oh wow he did it

surreal path
#

I WILL MAKE NYAUX RUN FUCKING USERSPACE IF ITS THE LAST THING I DO

#

Why you think my dad angry at me cause Iโ€™ve been skipping school to do osdev

marble surge
#

okay wtf this thread has 9993 messages already and it was posted only 21 days ago??

finite summit
#

9995th message

#

So this thread is pretty cool

#

Like cool

#

Pretty cool ngl

#

Idk what to say

#

10000th message

thorn bramble
#

bruh

worldly condor
#

bruh x2

#

30 second slowmode has been enabled to encourage members to produce longer messages

marble surge
#

NOOOOOOOOOOOOO WHO PURGED OLDER MESSAGES

worldly condor
#

no older messages got furged?

thorn bramble
#

it says 9975

worldly condor
#

probably a discord moment

marble surge
#

sms my head someone probably did it on purpose

leaden hinge
surreal path
#

it shows how much grind i put into this os ๐Ÿ˜Ž

worldly condor
#

fine

#

5 seconds

surreal path
#

fine thats more bearable

#

but this better be temporary ๐Ÿ˜ 

surreal path
#

everyday i dream of kernel code. when i wake up i open vscode and start writing code

surreal path
#

first osdev thread with 10,000 messages?

worldly condor
#

If you are working so much on your OS, why do you talk so much on Discord? halfmemeright

surreal path
#

HEY LISTEN, its been a month working on my os and im already close to userspace ๐Ÿ˜ 

#

just gotta implement syscalls and whatever and we epic gamer

worldly condor
#

I mean

#

last time I started writing an OS from scratch, I got to userspace in 2 weeks

#

well

#

it wasn't quite userspace

#

since real mode

worldly condor
leaden hinge
#

well real mode is much easier because the true power of your cpu hasnt been unleashed yet

surreal path
leaden hinge
#

just delete some of your old messages until its 9999 then send one more

#

(dont do that)

surreal path
#

which i did ๐Ÿ˜Ž

surreal path
#

ok everyone no more procrastination, time to setup syscalls!!!!

surreal path
#

starting to feel really discouraged i guess. i feel like maybe i was being spoonfed all this time and maybe i dont understand anything and maybe i should stop doing osdev cause im stupid and dumb and i never understood anything

idk what this feeling is called ig

ionic jetty
#

Dunning kruger effect

#

Bro why tf are you skipping school for this

#

Give me some of that 3am motivation

unkempt relic
#

you have made excellent progress

wicked loom
#

impostor syndrome is really stupid

worldly condor
wicked loom
#

the concept i guess

#

"oh no despite the fact that i have no reason to feel like this i will choose to feel like i'm not actually who i am and feel bad about it"

#

like ??? lol

wicked loom
#

i know

frigid cliff
#

Yeah, imposter syndrome kinda just happens unfortunately

alpine mulch
#

The sus imposter

#

My brain is rotten

frigid cliff
worldly condor
wicked loom
#

i am talking about the concept of impostor syndrome: it's like cancer, it's bad and no one should suffer from it

worldly condor
#

well, by "finding the concept really stupid", I understood implying that impostor syndrom is not real

frigid cliff
#

I kinda took it as mint saying imposter syndrome like as a concept sounds dumb on paper

surreal path
# surreal path idk

like i feel like im just inherently too stupid to continue with osdev but maybe thats just wrong or

frigid cliff
#

I dont think thatโ€™s true

surreal path
#

ill just keep trying ig. to not make the time i spent on nyaux a waste of time and a waste of time on others for helping me reach to this point

frigid cliff
#

It wouldnโ€™t be a waste for anyone, Iโ€™m sure the people who have helped enjoyed helping, and weโ€™re all here to learn together anyways. I donโ€™t think you should stop OS dev because you think youโ€™re not good enough for it

finite summit
#

don't give up

leaden hinge
#

im definitely not good enough for osdev

finite summit
#

we all learn

leaden hinge
#

and yet here i am

surreal path
#

im not going to stop i just feel a bit overwhelmed with everything thats all

finite summit
#

take a break

#

and sleep

leaden hinge
frigid cliff
finite summit
leaden hinge
#

instead of like 6-7 hours a day or whatever you're doing, just work on it for an hour or two

frigid cliff
#

Yeah

leaden hinge
#

or yeah take a break for a couple days

surreal path
#

im gonna take a break for an hour

#

i think thats what i need

frigid cliff
#

Good idea

leaden hinge
#

one thing you have which i think a lot of people dont(including me) is being able to work consistently for hours on end

surreal path
#

i get kinda obsessed with stuff sometimes

#

so yk

leaden hinge
#

i do as well

#

but like

frigid cliff
#

Very relatable

leaden hinge
#

even if i work on something for a full day, i still would take breaks for at least 30 mins every few hours minimum

surreal path
#

i dont rlly take breaks usually

#

unless im sleeping

#

lol

leaden hinge
#

i cant function without taking a break to go outside or drink tea or something

surreal path
#

okay im ready to come back to this now

#

not exactly an hour but halfmemeright

#

anyways

#

the gs msr can store anything i want right?

#

its unused by the cpu

#

can i use it to store the stack pointer for the kernel stack cause syscall doesnt change that automatically

#

fs is for thread local data

#

i dont have to worry much about it other then making sure i save and load the state of this msr as needed

ionic jetty
ionic jetty
#

For โ€žnormalโ€œ interrupts from tss.rsp0

finite summit
finite summit
#

only interrupts

ionic jetty
#

Not from IA32_SYSENTER_ESP?

surreal path
surreal path
finite summit
#

scheduler info

finite summit
#

not syscall

ionic jetty
#

Oh yeah i remember

#

My bad

surreal path
finite summit
#

I'm talking about GS

surreal path
#

since the syscall doesnt do it for u

#

where do u store the kernel stack

#

???

#

can i store this in the smp info thing

#

or is that not good

finite summit
#

that's what I did

#

also move any global variables in the scheduler there

#

if you're planning ahead for smp, you really need to think

worldly condor
#

yeah

#

just misunderstood

#

plus there's many people who think it isn't real

surreal path
# finite summit also move any global variables in the scheduler there

okay so for my thread struct i need to modify it to

struct thread_t
{
...
struct smp_info *gs_base;
uint64_t fs; // points to thread local data
}

struct smp_info
{
uint64_t kernel_stack_ptr;
}

void create_thread(...)
{
...
new_thread->gs_base = kmalloc(sizeof(struct smp_info);
new_thread->gs_base->kernel_stack_ptr = kernel_stack_ptr;
}

// in isr stubs
isr_stub_usr:
  swapgs
  // do saving registers
  // do loading registers
  swapgs
  iretq
isr_stub:
  // if not an error stub: rsp:8, else rsp:16
  cmp USR_CODE_SEL, [rsp:8]
  je swapgs

// syscall handler
syscall:
  swapgs // we always come from usermode
  // load kernel stack from gs
  mov rsp, [gs:0]
  // do whatever
  swapgs
  sysret

is this a correct way of doing it

#

or am i misunderstanding again

finite summit
#

sure that's a write way

surreal path
#

okay then doesnt seem too complicated

#

ill change my isr stubs and stuff

surreal path
finite summit
#

*right

#

idk how I made that mistake

surreal path
#

no write ๐Ÿ˜Ž

#

wait osdev wiki says i should disable interrupts in the syscall handler to avoid a race condition with interrupts and stuff

#

correct?

#

guess not?

#

ill try it ig

#

doesnt it trying!

#

!!!

#

shit

#

this is fuckin cursed

#

but ill just assume swapgs is a 1 byte op code!!!!

#

how tf am i gonna skip one instruction in a asm stub where i cant make any fuckin labels cause its a macro and itll fuckin duplicate this label everywhere

#

this would be easier if i was using gas

#

but i use nasm

#

im dying of nasm cancer

median goblet
#

acpi reduced?

#

what's that mean

surreal path
#

oh frick u

#

why cant i do this instruction bro

#

i may be the worst asm programmer in existence

#

why cant i fuckin

#

rsp+16

#

like bro

wicked loom
#

swap the operands

surreal path
#

assembler still fuckin hates me

#

no wait

#

now its saying operation size not specified

#

tf

wicked loom
#

add qword before [rsp...

surreal path
#

yea was just about to try that

#

ok compiles

#

lets see if my interrupt handler doesnt gpf or smthin!

#

and this check for usermode works!!!

#

yep works

#

(i think)

#

okay now i gotta heckin setup gs base and kernel base or whatev

#

okay i think im understanding it

#

also where tf is my auto completeion

#

๐Ÿ˜ 

#

man i hate vscode

#

okay so heres what im gonna do now,

#

if an interrupt was called and i came from the userland i will run swapgs to put whatever was in gs base into kernelbasemsr

#

then i shall read from the kernel base msr and put whatever that points to into the per_thread_cpu_info_t struct for the current thread

#

then after im done with that, i select the next thread. load its per_thread_cpu_info_t into the kernelbasemsr

kind root
surreal path
#

then run swapgs, done ๐Ÿ˜Ž

kind root
#

char name[64] etc

surreal path
surreal path
#

i just dynamically allocate the name ๐Ÿ˜Ž

kind root
#

Because its strange to allocate these separately

#

E.g. Linux allows up to like 8 chars for the thread name I think

#

Or approximately that amount

surreal path
#

so threadname should be
char name[8]

kind root
#

Well whatever limit you decide

surreal path
#

well because my kernel is SO much better then linux (#real) i will allow for a max thread name of 16 chars!!!!

#

OH MY FUCKING GOD 16 CHARS????

#

๐Ÿ˜ฑ

kind root
#

I could be wrong and maybe it is 16 lol

#

No idea

surreal path
#

32 chars!!!!

kind root
#

4 gigabytes

#

Of chars

surreal path
surreal path
surreal path
#

orrrr

#

?

kind root
surreal path
#

now i will uhhh

#

right ik

#

for each thread do i need to allocate a kernel stack????

#

isnt that like

#

waste of memory

#

???

tawdry mirage
#

what about multiple kernel stacks per thread

surreal path
#

why would you want that?????

#

tf?

tawdry mirage
#

in case you get preempted while in the kernel

#

during a syscall or whatever

surreal path
#

how many kernel stacks do u need then?

tawdry mirage
#

1 per thread?

surreal path
#

now ur saying 1

#

๐Ÿ˜ญ

#

???

tawdry mirage
#

yeah i was joking

#

you want 1 kernel stack per thread to run the syscall handler on

surreal path
#

okay

#

wait so

#

my interrupt frame

#

has a field called rsp to store the stack pointer for the interrupt frame

#

if a interrupt happened that was a context switch to kernel mode from usermode and we did swapgs and stuff and we saved the old thread cpu info and loaded the new thread cpu info into kernelgsbase

#

wait

#

yea i dont have to worry

#

its fine

#

nvm

#

ill only have to worry when making a new thread for usermode

#

in which i must give a userspace stack

#

into the interrupt frame.rsp

#

and i may need to take an additonal field for the kernelstack

#

as for threads that are kernel mode

#

uhhh

#

wait

#

im lost now

#

this gets overly complicated now

#

this is my new cpu context function

#

for creating a frame

#

which i use to make a kernel mode thread

#

now issue is

#

i have to worry about kernel stack ptr now

#

fuck

#

this gets really fucking complicated

#

bruh

#

me rn

surreal path
#

should the kernel stack ptr for the syscall handler and the uhhh kernel stack for the thread be the same or different?

#

cause im very VERY confused

tawdry mirage
#

kernel threads don't need a syscall stack?

surreal path
surreal path
#

ig

#

right?

#

something like

#

i will need to also read fs and put that into my thread

#

now i think my scheduler is ready

kind root
surreal path
#

anyways

#

now that i save fs and gs

#

and now i have swapgs in my isr stubs

#

its time for syscalls now????

#

lets gooo????

#

also my os still page faults in bios mode

#

idk if i should care lmao

#

i think it happens when looking for da ps2 keyboard

#

or whatever

#

idk bios stuff

#

okay so

#

syscalls

#

seems like i need to write to a few msrs

#

so i need to write the syscall handler RIP to LSTAR

#

huh???

#

i enabled the syscall extension now

#

now i neeed to configure syscall

#

who tf

#
userland CS will be loaded from STAR 63:48 + 16 and userland SS from STAR 63:48 + 8 on SYSRET
#

designed this

#

Its the same fucking msr

#

bro

#

what do i have to rearrange my gdt

#

userland code
userland data
to
userland data
userland code

#

???

#

wtf

#

who the actual fuck designed this shit

cinder plinth
#

what

#

theyre just different offsets

#

write userland cs to star + 16

#

and ss to star + 8

tawdry mirage
cinder plinth
#

oh

surreal path
#

lmao

#

๐Ÿ˜ญ

cinder plinth
#

mb I forgot it worked like that

surreal path
#

IM THIS FUCKING CLOSE TO GETTING SYSCALLS TO WORK

#

BUT THIS STUPID SWAPGS ISSUE WHERE GOING FROM A USER THREAD BACK TO A KERNEL THREAD nooo

#

CAUSE CS IN INTERRUPT FRAME IS USER WHEN WE COME IN THE SCHED

AND WHEN WE COME OUT OF THE SCHED FUNCTION ITS THE KERNEL CS AND WE DONT SWAPGS AND THIS CAUSES ISSUES !!!!!

#

DO U SEE HOW CLOSE WE ARE

#

THATS A FUCKING SYSCALL

kind root
#

It happens in your os not bios

surreal path
kind root
#

Oh

surreal path
#

FUCKING GG

#

๐Ÿ˜Ž

#

THATS A SYSCALL

#

RIGHT THERE

#

!!!!!

#

@kind root LOOK AT THIS SHIT!!!!! ๐Ÿ˜ฑ SYSCALLS AND FUCKING USERMODE!!!!

#

and i was yapping yesterday about fucking giving up

#

๐Ÿ˜‚

#

thats crazy

kind root
#

Nice

surreal path
#

guys soon bash

#

once i figure out how to parse an elf

#

and load fuckin userspace programs

#

and oh shit.

#

dynamic linking.

#

thats gonna be fucking pain

#

and my vmm doesnt give out userspace virtual addresses

#

shit

molten grotto
tawdry mirage
#

it's pretty simple from the kernel's pov

molten grotto
#

the libc does it, you just basically load the interpreter and the program binary to memory

surreal path
#

oh

surreal path
tawdry mirage
#

just load the interpreter into the address space along with the main executable, use the interpreter's entry point, and pass stuff about the original binary via aux vectors

surreal path
#

i will have to watch videos about elf files

#

and how to parse them

#

and read some shit about elfs

#

first

surreal path
#

i will need to have my vmm manage userspace addresses

#

but as i have my vmm designed it only deals with in between allocated regions

#

meaning that well. im fucking screwed

#

cause regions at the start look like this

kernel allocated hhdm region -> kernel allocated binary region

#

and then my vmm deals with the virtual addresses in between

#

but i need to somehow manage userspace addresses at the same time

#

and what about separate fucking page maps

#

oh shit

molten grotto
#

just make your allocator not depend on any global variables

#

and store an instance of it inside each process

surreal path
#

store an instance of the allocator regions?

molten grotto
#

whatever the allocator needs

surreal path
#
struct pagemap
{
  struct vmm_region *pagemap_regions;
  uint64_t pml4:
}
#

but what about userspace addresses

molten grotto
#

you could probably even make the kernel have its own process and then have one allocator for all kinds of processes (whether kernel or not)

#

I half-did it like that, there is a kernel process that contains the kernel pagemap but I have a separate allocator for userspace processes

molten grotto
#

because then you don't have to write multiple allocators

#

well ig for the kernel it could also live in some global variable but whatever

surreal path
#

wha

#

๐Ÿ’ฅ

#

this is confusing

#

kernel pagemap? is that gonna store every region in the virtual address space thats allocated or smthin?

#

like huh

molten grotto
#

a pagemap that is used for kernel only threads

surreal path
#

why would u want this

molten grotto
#

because they have to use some pagemap, what else would they use

surreal path
#

right

#

but wha about userspace processes

molten grotto
#

they have their own pagemaps

surreal path
#

and i will represent the entire kernel higher half as allocated in this user pagemap

#

?

#

so i dont give out kernel virtual addresses

molten grotto
#

yeah you don't want to allocate stuff from there to userspace

surreal path
#

that makes sense then, and then i will switch to the kernel pagemap whenever i need to allocate memory for the kernel

molten grotto
#

you don't really need to do that either, you can just copy the upper 256 pagemap entries from the kernel pagemap to each user pagemap

#

then you can use the user pagemap to access whatever kernel stuff you want

surreal path
#

wha.

#

im confused

surreal path
#

when doing vmm_region_alloc

#

on the user pagemap

#

i will need to switch to the kernel pagemap before allocating any memory at all for the kernel

#

also btw im not the hyensky of vmms

molten grotto
#

you don't want to switch to the kernel pagemap just to immediately switch back to the user one for no reason

surreal path
#

or smthing

molten grotto
#

why would you have to switch the pagemap to allocate memory?

surreal path
#

cause otherwise im going to be giving userspace addresses?

molten grotto
#

I don't really understand why

surreal path
#

i think i should explain my vmm in further detail

#

sorry my bad

#

my vmm has regions that represent an allocated regions, vmm_region_alloc scans this region list to find a space in between this region to fit a new region and returns the base address and modifies the region list accordingly

#

currently at the moment my region list looks like this at the beginning

kernel hhdm allocated region -> [vmm space inbetween] -> kernel binary region allocated

#

vmm region scans for that space in between

#

right?

molten grotto
#

just have a separate vmm instance which you use to allocate kernel memory

#

and one inside each process that you can use to allocate user memory

surreal path
#

wdym vmm instance???

molten grotto
#

a struct that stores the region list

surreal path
#

you mean separate region list?

#

for each process

molten grotto
#

yes

surreal path
#

what about pagemaps tho

#

should i store the address to pagemaps too?

#
struct vmm_instance
{
struct vmm_region *list;
uint64_t pml4;
}

struct thread_t
{
...
struct vmm_instance *instance;
}

molten grotto
#

yes that would work

surreal path
#

and i can just make a global variable for the kernel vmm instance

#

n use that

#

when allocating kernel memory

molten grotto
surreal path
#

that was easy to do

#

actually

#

all i need to do is

#

make a create_pagemap function

#

and uhhh

#

make a vmm_region_alloc for userpagemaps

#

yea

unkempt relic
wicked loom
surreal path
#

guess who got syscalls

wicked loom
#

hi

surreal path
#

๐Ÿ˜Ž

wicked loom
#

yeah gg

surreal path
#

and guess who got

#

vmm allocator for userspace addresses

#

and fuckin

#

yea

surreal path
molten grotto
surreal path
#

now is time

#

to write an elf

#

parser

#

banish me to the depths of elf headers

ionic jetty
#

You may hold the servers record for userspace right there (or was there someone faster once?)

tawdry mirage
surreal path
#

do I?

#

do i get a prize

ionic jetty
#

I dont know you just were very fast

#

Youre making great progress

surreal path
#

userspace in 22d

#

๐Ÿ˜Ž

molten grotto
ionic jetty
surreal path
#

step 2:

tawdry mirage
#

ig if mlibc's ld.so supported being run as a standalone program then the kernel could just find interp and reexec with the path as a param (but that breaks for memfd etc?)

surreal path
#

ditch school for osdev

#

step 3:

ionic jetty
#

My mum would murder me

surreal path
#

get sent to a mental hospital soon

#

(my dad wants to admit me)

ionic jetty
#

Better doing osdev in the mental facility than not doing osdev type mindset

#

(I agree fully)

surreal path
#

they will probs take away my laptop or smthin

#

idk

ionic jetty
#

Write a phone os then

surreal path
#

bruh

#

๐Ÿ’€

#

make my phone run x86 first

#

๐Ÿ˜ 

molten grotto
#

aarch64 isn't that bad

#

its pretty nice

ionic jetty
#

Just write one for aarch

#

Yeah

surreal path
#

ew

#

go ARM urself

#

so madiens

#

#roasted

#

๐Ÿ˜Ž

ionic jetty
#

โ€ฆ

wicked loom
#

skibidi rizz ohio ong

surreal path
wicked loom
#

(i am a zoomer too)

tawdry mirage
# wicked loom why

because existing oses already do load the executable, so you need to keep the code for that in (also doing it via an ld.so arg technically introduces a toctou vuln with someone swapping the exec for a new one between the kernel launching ld.so, and ld.so reading it)

wicked loom
surreal path
#

??

wicked loom
#

on google

leaden hinge
#

the internet

wicked loom
#

also man elf

#

in linux

surreal path
#

i thought it was hidden between a secret bunker

#

๐Ÿ˜ฑ

leaden hinge
#

the wikipedia page on it isnt terrible for the basic structure

#

but it doesnt go into much detail about other stuff like relocations or symtab

surreal path
#

is this the spec

leaden hinge
#

see the part where it says executable and linkable format specification

surreal path
#

yea i do

#

it looks quite complicated

haughty kite
#

its horrendously insecure

tawdry mirage
#

you mean using ld.so program? yeah there's toctou between the kernel reexecing program as ld.so program and ld.so reading the executable again

haughty kite
#

yeah with setuid

#

unless you have statfd i guess

#

then you can restat in the child to make sure setuid is cleared properly

#

also just load it the normal way smh

surreal path
#

i may be stupid

haughty kite
surreal path
#
  1. i dont know what any of yall are talking about. 2. elf spec looks very complicated and maybe im too stupid idk 3. this is gonna be pain nooo
wicked loom
#

you can read the Vinix code for this

surreal path
#

i dont wanna steal

wicked loom
#

it's rather straight forwards

#

well it's not about stealing, first off it's in V

#

it's more about comparing it with the ELF spec and seeing what you're supposed to do

surreal path
#

ok

tawdry mirage
wicked loom
#

lmao

surreal path
#

bruh

wicked loom
#

autofree bugs included

haughty kite
#

lmaooo

surreal path
#

multiple pmm page allocation iwannadie

#

guess who has a freelist allocator that doesnt allocate contagious pages

#

#me

#

!!!!

#

tf am i supposed to do!!!!

#

๐Ÿ˜ฑ

tawdry mirage
#

also lol contagious

surreal path
#

wait ur right

#

i can just loop over

#

every page

#

and allocate and map to virtual address as needed

#

yea

#

also

#

elf spec doesnt say anything about aux val?

#

what is that

wicked loom
#

that's just how Vinix's pmm works

surreal path
#

elf spec says nothing about this

#

like at all

wicked loom
surreal path
#

fuckin wha

wicked loom
#

dw about it

haughty kite
#

you never need that

#

except for iommu memes sometimes

surreal path
#

do i have to care about aux

#

what is that

haughty kite
#

yes

#

auxvector

#

very important

surreal path
#

i am completely and utterly lost

#

like a cow in a field of no trees or grass

#

why is every step to making an os getting more complicated then the last

wicked loom
surreal path
#

wait is this it

#

i think

wicked loom
#

this explains auxiliary vectors

tawdry mirage
surreal path
#

what auxilary vectors does mlibc need

#

in this case

tawdry mirage
#

huh i didn't know about AT_EXECFD

#

that makes mint's idea more viable ig

thorn bramble
#

i give mlibc AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM

surreal path
#

do i manually hard code this stuff, do i always assume the elf executable in question will be linked will mlibc

thorn bramble
#

hardcode what?

surreal path
#

so i always provide these auxilary vectors

thorn bramble
#

the phdr ids? or the values?

tawdry mirage
#

you should provide them regardless of what the elf file is

thorn bramble
#

or the auxvs themselves

#

oh yeah

thorn bramble
#

you always provide them, of course

surreal path
#

where do i put the auxilary values

#

exactly

thorn bramble
#

on the stack

#

just like argv, envp

surreal path
#

wh

thorn bramble
#

lmaoo its gonne be so much fun

surreal path
#

yea i can tell this is gonna be a long weekend

thorn bramble
#

i have a slight feeling someone's gonna lose their mind

#

:^)

surreal path
#

okay so heres what im gonna do ig

#

im gonna just try and load a statically linked elf file and see if that works

#

something simple

#

no libc no nothing just a simple asm program compiled to a elf file

#

i run it from my tmpfs file system

#

just to get started

thorn bramble
#

i thought you already have done that?

surreal path
#

no i hardcoded the program

thorn bramble
#

ah

surreal path
thorn bramble
#

fun

surreal path
#

lol

thorn bramble
#

im gonna watch

#

its gonna be a long night

surreal path
#

sure

median goblet
#

Like instead of YoinkerSploinker.exe it would say YoinkerSploinke.exe

unkempt relic
#

at least i thought it was

#

looks like from unix research 6 to unix 4.2 bsd, user->u_comm was DIRSIZ long

#

that was 14

#

by 4.4BSD it was moved into struct proc, p_comm was MAXCOMLEN + 1, MAXCOMLEN being 16

#

modern linux

/*
 * Define the task command name length as enum, then it can be visible to
 * BPF programs.
 */
enum {
    TASK_COMM_LEN = 16,
};
``` lmao, bpf really will be linux and linux will be bpf
haughty kite
#

eBPF (which doesn't and indeed never stood for anything) is the best technology ever!

#

and remember, oceania was always at war with eastasia

kind root
haughty kite
#

yeah

unkempt relic
haughty kite
#

or even better, implement your own

#

call it ktrace or something

#

i mean if windows has dtrace you can too

unkempt relic
#

i would like to do dtrace

#

windows has both eBPF and dtrace nowadays

haughty kite
#

true

#

you should implement your own mechanism that is highly portable to other hobby OSes

#

it is highly fashionable nowadays to maintain cross-os tooling in these circles

unkempt relic
#

it would be nice to invent a debugger like MDB as well

#

it pairs well with dtrace

surreal path
#

found the issue

#

vnode_path_lookup

#

i need to rewrite this entire function cause clearly its causing some string fuckery

#

thats my bad for copying astrals implementation of path parsing

#

guess kara

#

karma

#

i fucking hate dealing with strings

#

surprised this bug didnt come up until now

kind root
#

I sense a skill issue

surreal path
surreal path
#

should i just rewrite this entire function at this point

#

fucking memory corruption with the strings

#

and i cannot solve it

#

no matter what i do

#

this bool is never true for no fucking reason and if i try to do strlen + 1 it causes funny memory corruption

#

@elder shoal i dont know what u did with astral but even tho my implmentation of this string parsing is very similar to yours it doesnt seem to be working nooo

#

fuckin hell

#

it is clearly failing to create the directories properly

#

it finds the usr directory but the bin directory doesnt exist

#

of course

#

because my kernel hates me

#

and there will be probs a bug with the elf loader that will make me have to rewrite it too even after i fuckin fix this vfs bug, probs user stack fuckery or smthin idk

#

all of this just for bash

elder shoal
#

What does your vfs create function look lije

surreal path
#

uh huh

surreal path
#
int vfs_create(struct vnode *indir, char *path, int type, struct vnode **res)
{
    if (path[0] == '\0')
    {
        return -1;
    }
    char *component = kmalloc(strlen(path) + 1);
    struct vnode *our_par = vnode_path_lookup(indir, path, true, component);
    if (!our_par)
    {
        
        kfree(component, strlen(path) + 1);
        return -1;
    }
    struct vnode *created = NULL;
    if (type == 0)
    {
        // CREATE DIRECTORY
        our_par->ops->v_mkdir(our_par, component, &created);
        kfree(component, strlen(path) + 1);
        *res = created;
        return 0;
    }
    else if (type == 1)
    {
        kprintf("Created file\n");
        our_par->ops->v_create(our_par, component, &created);
        kfree(component, strlen(path + 1));
        *res = created;
        return 0;
    }
    else
    {
        // not supported
        return -1;
    }

}
#

ive tracked the problem to vnode_path_lookup

#

but i dont know why its not able to create the right directories

surreal path
#

create the vnodes for

#

them

#

my vnode_path_lookup function

#

this is pain

elder shoal
#

Pastebin isnt loading for me
Just add printfs in every error or something to try figuring out whats happening

surreal path
#

i solved the vfs issue i think

#

okay so solved vfs issue

#

but now

#

very fuckin weird issue

#

when trying to open bash

#

wtf

#

why does /usr/bin/bash have an elf header type of 24930

#

like

#

wtf

#

????

#

im writing into the file fine

#

when unpacking and loading the tar

#

into the tmpfs file system

#

so why tf

#

looks fine

#

looks fine here too

#

so why tf

#

thats clearly not valid

#

why

#

pain

#

fucking pain

#

yea size is valid

#

um yea

#

thats the first part of the bash file?

#

so why tf

#

is it not copying it to the file right

#

um yea

#

thats correct

#

yea the memcpy operation went fine?

#

as you'd expect

elder shoal
surreal path
#

into a char type

#

lol

#

what the fuck...

#

thats not the correct

#

file data

#

wtf

#

why is THIS the data

#

this makes

#

zero sense

#

im losing my mind

#

fucking memory corruption

#

my favourite

#

im going to

#

fucking idk

cinder plinth
#

try moving your vfs logic to userspace linux maybe

#

with asan

#

enabled

surreal path
#

is this the fucking issue

#

yea seems like so

#

name is valid

#

but this memcpy is clearly

#

not working right

#

fucking hell

surreal path
#

sorry

#

i dont know how to setup asan

#

idfk whats the issue anymore

#

somethings memory corrupting something

#

and i cant figure it out

#

this is fucking hell

#

yea where tf is it getting these names

#

xfce?

#

thats not in the sysroot folder

#

what in the actual fuck

#

oh it is there

#

so i fixed the name corruption issues but

#

not the memory corruption

#

im stuck

#

im rlly fucking stuck

#

i added kprintfs in every fucking known place

#

and i dont know where this memory corruption is going on

#

this fucking address

#

0xffff8002503e1000

#

shouldnt be allowed

#

what the fuck

#

kmalloc will NEVER return an address like that

#

what in the actual fuck

#
int vnode_create(struct vnode *dirtocreatefilein, const char *name, struct vnode **newfile)
{
    if (dirtocreatefilein->type == NYAVNODE_DIR)
    {
        // create name lol
        struct tmpfs_dir *dir = dirtocreatefilein->data;
        char *thename = kmalloc(strlen(name) + 1);
        memset(thename, 0, strlen(name) + 1);
        strcpy(thename, name);
        // create dir entry
        struct tmpfs_dir_entry *new_dir_entry = kmalloc(sizeof(struct tmpfs_dir_entry));
        memset(new_dir_entry, 0, sizeof(struct tmpfs_dir_entry));
        new_dir_entry->name = thename;
        new_dir_entry->next = dir->head;
        dir->head = new_dir_entry;

        struct vnode *newnode = kmalloc(sizeof(struct vnode));
        memset(newnode, 0, sizeof(struct vnode));
        newnode->type = NYAVNODE_FILE;
        newnode->data = (struct tmpfs_node*)kmalloc(sizeof(struct tmpfs_node));
        memset(newnode->data, 0, sizeof(struct tmpfs_node));
        newnode->ops = &tmpfsops;
        new_dir_entry->ptr_to_vnode = newnode;
        *newfile = newnode;
        return 0;
    }
    else
    {
        return -1;
    }
}

somethings clearly wrong in this function

#

however im doing it

#

what????

#

WHAT THE FUCK

#

BRO

#

WHAT

#

no wait that makes sense

#

okay this looks like a normal address

#

๐Ÿ˜Š

#

okay this makes sense

#

as its using my big ol vmm region alloc for this

#

cause 206 pages

#

for this bash executable

#

so wtf is going on

surreal path
#

someone is corrupting both our ptr to vnode field

#

for the dir entry

#

and the -> data field

#

wtf

#

i need help i dont know what to do

#

i cant figure this out

#

i've looked over the code so many times, i dont know where this memory corruption is happening

#

the urge to give up on all this is very strong

surreal path
#

so after looking into it more

#

its not memory corruption

#

rather

#

how im searching for the vnodes and such

#

seems to not be right cause

#

there could be a directory named

#

fuckin

#

bash

#

and then a file named bash

#

and seems like something with

#

this if statement never true

#

meaning

#

somethings going off

#

its finding it

kind root
#

i like the type

#

whats the difference against normal directory

surreal path
#

its fucking

#

its a fucking directory

#

i cant do this fucking

#

shit

#

anymore

#

five straight fucking hours i have been debugging this

#

i cant figure it out

#

why in the actual fuck

#

why

kind root
#

whats the problem

surreal path
#

i dont fucking know

#

thats the problem

#

i dont fucking know why this is happening

#

something very funky is going on

kind root
#

what is happening

#

log looks fine

surreal path
#

my vfs is shitting itself

#

and not giving me the right vnode

#

the right fucking vnode

#

and it cannot be memory corruption because i tried with asan and nothing violation in a userspace program

#

im fucking

#

lost

kind root
#

show the actual problem

#

i dont see printf everywhere like i taught u

surreal path
#

i am literarly

#

printfing in every location

#

every address

kind root
#

wrong printfs/not enough

surreal path
#

bro

#

yea okay

kind root
#

you're loggin size as a string

surreal path
#

oh wait

#

my bad

kind root
#

you dont listen when i tell u enable warnings

#

so enjoy suffering

surreal path
#

fucking 6912

#

this isnt real

surreal path
#

i cannot find this issue

#

somehow this check succeeds but not in the v_lookup function above

#

which makes

#

zero sense

#

what soever

#

which is like

#

what

#

so like bro

#

PART IS FUCKING BASH

#

BRO

#

bashbug?

#

oh

#

OH

#

OH MY FUCKING GOD

#

IS THAT THE ISSUE

#

U ACTUALLY HAVE TO BE LEGIT KIDDING ME IS THAT THE ISSUE????

#

bro

#

that explains everything

#

i finally fixed that issue

#

but now

#

we have issues with the elf loader itself

#

of course!

#

afterall

#

i cannot escape my fath

#

elf header type 2

#

right

#

why is bash dynamically linked

#

i thought it would use the interrupter

#

huh?

molten grotto
#

it is dynamically linked and it does use the dynamic interpreter (in your case at least)

#

you don't have to care about PT_DYNAMIC in your kernel

surreal path
#

then why is it crashing

#

and page faulting

#

and crying

#

like a baby

#

like what the actual fuck

#

why is the program header

#

that now

#

huh???

#

wtf

#

okay did the memsetting thing for the .bss section

#

andddd

#

that causes a page fault

#

course

#

ok i just memset every page

#

as im lazy

#

and only write into buffer as required

#

okay but still

#

why is the program header that

#

???

#

im using hdr.e_phnum

tawdry mirage
surreal path
#

we can load into the linker

#

but page faults here

#

i think i need a bigger stack

tawdry mirage
#

most likely 4k is not enough

surreal path
#

yea

tawdry mirage
#

others like PT_PHDR and PT_DYNAMIC and PT_INTERP etc are just extra information (that you do still need)

surreal path
#

this should work???

#

ummm

#

why is it page faulting now when i try to make a stack using this function

#

bruh

#

when i try to access it

#

to put the aux vecs

#

ugh

#

right i just realized

#

blud what

#

blud what

#

bro

#

oh right

surreal path
#

fixed stack issue but now sse issue

#

cause userspace wants sse

unkempt relic
#

switch it on

surreal path
#

we did

#

now we are 0xd'ing here

#

interestingly

tawdry mirage
#

your stack is misaligned