#Nyaux

1 messages ยท Page 13 of 1

elder shoal
#

thats one of the ld.so load addresses

#

your mapping is bad

tawdry mirage
#

this is the address mlibc just mmaped

surreal path
elder shoal
kind root
#

Because you fucked it up

surreal path
#

its mapped?

#

info tlb result

#

and its pointing to a physical page?

#

????

elder shoal
#

do info mem

surreal path
tawdry mirage
elder shoal
tawdry mirage
#

no

#

yeah mlibc passes PROT_READ | PROT_EXEC | PROT_WRITE for the mapping

surreal path
#

oh im stupid

kind root
#

Bro mapped it read-only

surreal path
#

not it cant find

#

libintl

#

bruh

kind root
#

Mlibc pronouns is he him confirmed

cinder plinth
#

I'd try running hello world before

#

tho

surreal path
#

i have syscalls

cinder plinth
#

yeah

surreal path
#

lol

cinder plinth
#

but

#

you dont have

#

int main() { printf("hello world\n"); return 0; }

elder shoal
#

oh yeah

#

uh

#

@surreal path do you have stdin/stdout/stderr

kind root
#

Lol

elder shoal
#

you'll need that

surreal path
#

but why cant it find libintl

#

wtf

kind root
#

I removed it

cinder plinth
#

just do if fd < 3

kind root
#

If fd โค๏ธ

surreal path
#

like

#

wait

#

i have more fuckin vfs bugs

#

to fix

kind root
#

Speedrun dead

cinder plinth
#

write(-1, "hello")

#

lol

kind root
#

Thats an unsigned number tho

cinder plinth
#

oh right

#

fds are unsigned

#

forgot

surreal path
#

it found usr

#

it found lib

#

but it couldnt find

cinder plinth
#

.so.8 is a symlink

surreal path
#

libintl.so.8?

#

oh

#

fuckin hell

#

symlinks

#

guess who doesnt have symlinks

#

!!!

kind root
#

Bro is fucked

surreal path
#

me!!

#

i am unironically screwed

kind root
#

Just read linked file and follow it

surreal path
#

how do symlinks work

#

lemem check

kind root
#

Its just a path

tawdry mirage
#

the symlink just contains the path to the actual file

surreal path
#

in ascii?

kind root
#

No, in utf-256

tawdry mirage
#

holy

cinder plinth
#

nah

kind root
#

Lmao

cinder plinth
#

they changed it

#

last spec

#

it's utf-2048

#

with variable endianness

kind root
#

Octal encoded endiannes

surreal path
#

how do i know if its a symlink

#

if a vnode is a symlink

elder shoal
#

at least make it page aligned smh they should make it utf-${pagesize_of_the_system} because portability is for cowards

tawdry mirage
kind root
surreal path
#

oh

#

easy

#

๐Ÿ˜Ž

#

no its not a symlink

#

it seems

#

i think it may be a hard link

tawdry mirage
#

it is a symlink

#

a hard link is indistinguishable from a regular file (because every regular file is already a hard link)

kind root
#

This is just ls showing you the resolved path I think

tawdry mirage
#

yeah

wicked loom
#

it's a symlink

#

also get the fuck in vc i wanna listen to something

surreal path
#

okay this check is failing

#

oh wait

#

tried reading the data out of a symlink

#

clearly thats not

#

proper

#

do symlinks have file size

#

in tar

wicked loom
#

it's a symlink

surreal path
#

no?

#

oh

#

makes sense

#

is the symlink not null terminated?

wicked loom
#

it may not be i think

surreal path
#

cause this aint workin

#

fuckin hell

#

how am i supposed to get the length

wicked loom
#

you have a size

#

it's the size of the file

#

except it's a symlink

surreal path
#

the size of the file is zero

wicked loom
#

uhhh

#

ok let me check one sec

surreal path
#

who fucking designed this standard

#

๐Ÿ˜‚

wicked loom
#

the US government or somethin

surreal path
#

ustar my butt

wicked loom
#

that's why it's called UStar

surreal path
#

star into the butt

wicked loom
#

no i think it's 0 terminated lol

tawdry mirage
surreal path
wicked loom
#

that's 2 rubles deposited to my bank account

tawdry mirage
#

ah i see

surreal path
#

right forgot null terminator

#

strlen + 1

#

hZ

#

bRO

#

can u be normal for once and write normally to my file

#

THERE WE GO

#

THERE WE FUCKIN GO

#

will symlinks be absolute paths?

#

like all the time?

#

i suppose they would be?

tawdry mirage
#

symlinks can be relative

#

in which case they're relative to where the symlink is

#

it might be a bit problematic with how you created the tar archive but ig you could just prepend a / to the symlink path

wicked loom
#

all symlinks are relative

#

to the location of the symlink

surreal path
#

oka

tawdry mirage
# wicked loom all symlinks are relative

oh huh my bad

   Symbolic links are interpreted at run time as if the contents of the link had
   been substituted into the path being followed to find a file or directory.

from man 2 symlink

#

istr symlinks with an abs path but i can't find any examples on my system :^)

unkempt relic
tawdry mirage
#

hm no i do have absolute symlinks on my system

surreal path
#

bro

#

why couldnt u satify

#

that

#

bro

wicked loom
tawdry mirage
#

yeah but the wording implies that it just takes the contents and plops them straight into the path being resolved

wicked loom
#

yeah, the wording is wrong

#

or at best misleading

surreal path
#

bro

#

how tf do i debug this

#

its clearly resolving the path

#

and its giving the vnode

#

so like

#

why tf

unkempt relic
#

there is a logging option that will tell you a bit more

surreal path
#

how to enable

unkempt relic
#

where mlibc is checking and such

#

logLdPath maybe

surreal path
#

no i mean

#

how to enable this option

#

what do i do

#

oh wait

#

its a bool

#

yea trying to find

#

then it had tried to read

#

why is it failing on the read

wicked loom
#

does it even succeed to open the file?

tawdry mirage
#

it must've, it looks like its reading the elf ehdr

surreal path
#

it has a check

tawdry mirage
#

judging by the buf print

surreal path
#

mhm

#

offset 0

wicked loom
#

i guess you may try to open that file yourself in the kernel to see what happens, without relying on mlibc

tawdry mirage
#

inb4 it returns the symlink path

#

instead of the target file contents

surreal path
#

ill try printing some of the file data

#

ptr->type == NYAVNODE_SYMLINK is failing so

#

wtf

#

oh

#

its giving me back a directory

#

what am i supposed to do in this case

#

if it resolves to a directory

#

???

#

if the symlink resolves to a directory like

#

what am i supposed to do exactly

#

cause its resolving to /usr/lib/bash

wicked loom
#

you can symlink to a directory

#

you just open the directory

surreal path
surreal path
#

???

#

like wha

wicked loom
surreal path
#

how

wicked loom
#

libstdc++ resolving to /usr/lib/terminfo makes no fucking sense

#

neither does anything else there

surreal path
#

wtf

#

why is the data like

#

completely wrong

#

wtf

wicked loom
#

you tell me

surreal path
#

seems like an isuse with the tar itself

#

for some reason

wicked loom
#

nah, the tarball is fine

surreal path
#

how do u know

#

if its giving me

#

/usr/lib/terminfo

#

like wtf

wicked loom
#

i trust GNU tar and i use the same script to generate tarballs and they generate fine

#

that's how i know

surreal path
#

lemme extract the stuff and see

wicked loom
#

but you can unpack and check for yourself

#

yeah

#

it's initramfs.tar, go to a different dir and run tar -xf <path to>/initramfs.tar

surreal path
#

bro im dying

#

why is that happening

#

why tf

#

what da helll

#

missing null terminator

#

OK I FIXED IT

wicked loom
#

nice cool

surreal path
#

sys_tcb_set

#

bro

wicked loom
#

it's really simple

#

it's used to set FS basically

#

which is used for thread local stuff

#

but the sysdep is essentially just wanting you to do FS = arg

finite summit
#

if you want, you can use wrfsbase to write the fs base

#

instead of adding a syscall

wicked loom
#

yes but this is yet another microoptimisation and requires CPU support since that's not baseline

#

i would say just do a normal syscall and set it normally

finite summit
#

idk what ended up with him and deciding to ensure wrfsbase is supported

#

and failing otherwise

surreal path
#

so just write to the fs base msr

#

the arg

#

thats it?

wicked loom
#

yes

#

well of course your scheduler needs to save and restore FS properly

#

if it doesn't already

surreal path
#

it does

#

๐Ÿ˜Ž

wicked loom
#

cool

surreal path
#

sig action

#

bro

wicked loom
#

you can stub it out

#

return enosys

surreal path
#

what did mlibc

#

just try to do

wicked loom
#

make sure you're not for some reason leaking kernel pointers to userland and expect it to be able to access them fine

#

if that is a page fault with that cr2, it suggests that's what's going on

#

you don't have KASLR on do you?

#

yeah you have it off

#

else the address would be different each time

surreal path
#

bro wtf

#

now its not resolving symlinsk

#

what

#

the

#

fuck

#

it just decided

#

to end its life

#

and stop resolving the symlinks

#

man i hate this

#

uh huh

#

bro

#

someone is modifying

#

my shit

#

and making my vnode

#

type

#

file

#

wtf

#

my kernel is cursed my kernel is cursed my kernel is cursed my kernel is cursed

#

does the fucking compiler not see this line

#

notneeded->type = NYAVNODE_SYMLINK

#

im done

#

im done

#

its not evening trying to resolve a symlink

#

its the heckin

#

sys_read

#

uh huh

#

okay i found that issue

#

it was the prepending

#

CLEARLY VALID FILE DATA

#

LIKE BRO

#

THE MEMCPY GOES FINE

#

like wtf

#

WHAT IS MLIBC DOING

#

HM?

#

seriously where is this address coming from

surreal path
#

after further debugging it seems to be happening in the actual bash executable itself

#

tho i cannot addr2line it

#

or no

#

its not happening in bash

#

i dont know actually

#

cpl was 3 when this page fault happens

#

heres what we do know, the address is not something canoical at all. kernel never uses this memory so it cannot be a leak

#

i cannot addr2line this rip anywhere

#

cannot find in gdb

#

im very confused honestlyl

wicked loom
#

we'll sort it out later

#

like every bug you've hit before, they all seem silly in retrospect

surreal path
#

ill print every syscall mlibc makes

#

okay very last thing mlibc does

#

syscall_fs

#

mmap is giving valid addresses

#

looks valid

#

yea fs base is fine too

#

so wtf is going on

#

bro

#

i dont see any type of memory leak

#

in all the addresses syscall_mmap

#

all userspace addresses

thorn bramble
#

why is the cr2 0xffffffff...

#

lol

surreal path
#

i have no fucking idea

thorn bramble
#

what is the instruction at rip

surreal path
#

i cant addr2line it

thorn bramble
#

yes you can

surreal path
#

it doesnt makes sense at all

#

i tried

#

removing the base

thorn bramble
#

try harder

surreal path
#

bru

thorn bramble
#

enable all logging in ld.so

surreal path
#

before the fault

#

it likes does something for a few seconds no logging

#

then it faults

thorn bramble
#

lol fun

surreal path
#

yep

#

amazing

thorn bramble
#

im sure its something silly

#

everything up to this point was :^)

#

you'll get this

surreal path
#

sure i will

#

๐Ÿ˜ƒ

thorn bramble
#

you will !!!!

surreal path
#

DT_init function?

thorn bramble
#

log all the functions it's trying to run

#

you can modify the mlibc source code

#

add some prints

surreal path
#

seems to be hanging

#

here

#

wait wrong image

thorn bramble
#

log the function pointers

#

figure out which one makes it die

#

use gdb

#

figure out what exactly makes it die

#

you can put a breakpoint on it before jumping to userspace

surreal path
#

how to print a ptr with mlibc's logger

#

im not good at c++

thorn bramble
#

idk just << the pointer

#

or cast it to void* beforehand

surreal path
#

its not letting me do this

#

oh right

thorn bramble
#

then (void*)...

surreal path
#

uh huh

thorn bramble
#

looks alright? i think

#

go check the so

surreal path
#

ok

thorn bramble
#

use objdump

#

and look for the last 4-5 nibbles

#

also look where libc.so is loaded lol

#

its not gonna be loaded at 0x40000000

#

that's the ld.so is loaded

surreal path
#

and corrupting memory

thorn bramble
#

no, is it?

#

what does mlibc say

#

it should tell you what the base for each dso is

surreal path
thorn bramble
#

enable more logging

#

im pretty sure mlibc has more logging

surreal path
#

most of it is enabled

thorn bramble
#

logBaseAddresses should be good

surreal path
#

its not logging base addresses

#

0x-1a0

thorn bramble
#

that is fineโ„ข๏ธ iirc

surreal path
#

okay so

#

wtf is going on

#

this is fucking pain to debug

#

ill try breakpointing 0x4121abb0

thorn bramble
#

no idea i dont have your os built

#

i cant test it myself

#

hard to do remote debugging

surreal path
#

just build it trl

thorn bramble
#

if i wanted to debug userspace i would just bring back my old zigux code

#

im gonna have to at some point

surreal path
#

ok lets see

#

its not hitting my breakpoint

thorn bramble
#

break *0x4121abb0

#

you are asking it to break on a function named 00000....abb0

surreal path
thorn bramble
#

zeroes!

surreal path
#

add %al, (%rax)

thorn bramble
#

0000

surreal path
thorn bramble
#

:)

#

its invalid code

#

you are executing zeroes

surreal path
#

so wtf

#

rip is

#

why tf are we executing this code

thorn bramble
#

idk maybe ur not reading in the library file into memory correctly

#

idk lol

#

also on that note, where tf are open+read calls?

#

i didnt see any in the syscall log you showed earlier

surreal path
#

heres the full log

thorn bramble
#

show seek implementation

surreal path
#

kk

#
void syscall_seek(struct syscall_frame *frame, struct per_thread_cpu_info_t *ptr)
{
    kprintf("syscall_seek()\n");
    int fd = frame->rsi;
    int offset = frame->rdx;
    int flag = frame->r10;
    struct process_info *pro = get_cur_process_info();
    struct FileDescriptor *d = &pro->Descriptors[fd];
    switch (flag)
    {
        case 0:
            if (d)
            {
                d->offset = offset;
                frame->rdx = 0;
                frame->rax = d->offset;
                return;
            }
            else 
            {
                frame->rdx = -1;
                return;
            }
            break;
        case 1:
            if (d)
            {
                d->offset = d->offset + offset;
                frame->rdx = 0;
                frame->rax = d->offset;
                return;
            }
            else 
            {
                frame->rdx = -1;
                return;
            }
            break;
        case 2:
            if (d)
            {
                d->offset = d->ptr->ops->v_filesz(d->ptr) + offset;
                frame->rdx = 0;
                frame->rax = d->offset;
                return;
            }
            else 
            {
                frame->rdx = -1;
                return;
            }
            break;
        default:
            kprintf("%d\n", flag);
            kprintf("Flags are wrong?\n");
            frame->rdx = -1;
            return;
            break;
    }
}
thorn bramble
#

oh god ok

#

do you have the code on github btw

surreal path
#

ye

thorn bramble
#

one "problem" i see is that v_filesz returns a size_t and idk how adding a negative int would work with that?

surreal path
#

okay then ill cast the size_t into an int

thorn bramble
#

it seems to work, nvm

green elbow
# surreal path

you can double check that the initArray pointer actually points to the correct place by logging it and checking the elf file with readelf -d

surreal path
#

okay lets readelf

#

yea its correct

#

0xbf000

#

bro

#

this is clearly not a silly bug

finite summit
#

inb4 it's vmm shenanigans

green elbow
#

hmmm

#

that is weird

finite summit
#

Well if it's memory being zeroed without anything telling it to be zeroed

#

Try setting hardware watchpoints on the affected address

#

Using the debug registers

#

Or fill in newly allocated addresses with some constant like 0xCC

finite summit
#

Then if you jump to some bogus address that happens to be allocated nut untouched, instead of getting a bunch of add instructions, you'll get int3

finite summit
#

And see if anything changes

surreal path
finite summit
#

In the vmm of course

surreal path
#

okay 0xCC

finite summit
#

If it is you jumping to uninitialized memory, you'll break using int3 instead of going to some random rip

surreal path
#

int3?

thorn bramble
#

breakpoint

finite summit
#

You know the int instruction

thorn bramble
finite summit
surreal path
#

okay so somewhere, do int3

thorn bramble
#

no

#

memset to 0xCC

surreal path
#

yes

thorn bramble
#

so instead of executing 00000000

#

you execute CCCCCCC

#

which is int3

#

and not some random add [rax], al

surreal path
#

doing this causes mlibc to panic

#

is this oberrow hell round 2

finite summit
#

Probably mlibc not zeroing memory on its own

thorn bramble
#

that is very possible

surreal path
#

bru

finite summit
#

Well just undo that

#

And get some XD prot flag working in your VMM

surreal path
#

why

finite summit
#

And continue to execute it

surreal path
#

so itll just cause a page fault when it tries to execute the page

finite summit
#

If it tries to jump to a bogus address

#

You'll need prot flags in some way for this to work

surreal path
#

okay fine

finite summit
#

You can't just set any page that should be executable to XD

surreal path
#

isnt the xd bit the last bit in the entry

finite summit
#

Bit 63

surreal path
#

okay bit 63

finite summit
#

But it's technically not guaranteed to be supported or enabled

finite summit
#

But it's only unsupported on old cpus

thorn bramble
#

i prefer NX because XD makes me laugh (im mentally 12)

molten grotto
thorn bramble
#

yep that too

surreal path
#

how

finite summit
#

Check some bit of EFER to see if XD is enabled

thorn bramble
#

1 is of type int

surreal path
#

okay then cast to uint64

thorn bramble
#

yep

#

or just 1UL

#

or ULL

#

1UL << 63 is probably fine

surreal path
#

okay and now i check prot if its executable

thorn bramble
#

i think unsigned long is 64 bits on 64 bits

surreal path
#

if its executble no xd

thorn bramble
#

yeah

#

if !(prot & PROT_EXEC) flags |= NX

molten grotto
kind root
#

llp64 iwannadie

finite summit
#

Doubt anyone is using msvc to compile Nyaux

#

or a windows toolchain

thorn bramble
#

i should try doing osdev with msvc

#

should be fun

molten grotto
#

then also make the kernel garbage just like the compiler is

kind root
#

At least you shouldn't expect any destructive compiler optimizations

thorn bramble
#

pe+ kernel

finite summit
kind root
#

Just use the windows loader

finite summit
thorn bramble
#

yea it should be fun, especially given that link.exe can link efi applications :^)

surreal path
thorn bramble
#

so i can technically write it all and compile using windows tooling

#

i should use msbuild if i want it all to be extra shit

finite summit
surreal path
#

no?

molten grotto
#

you have to conform whatever abi you use in mlibc tho (well you can still make your own abi but if you use one of the existing ones then you have to use the constants from that)

surreal path
#

im using the one copied by vinix

thorn bramble
#

most default sysdeps use linux abi now

surreal path
thorn bramble
#

probably linux abi then

surreal path
#

okay found

haughty kite
#

or just use kernelcaches :^)

surreal path
#

okay um

#

right

thorn bramble
#

good job

surreal path
#

just realized

thorn bramble
#

you need all flags to be unsigned long

#

:)

molten grotto
#

well no

thorn bramble
#

oh wait is he accepting flags as uint8_t

molten grotto
#

yes

thorn bramble
#

yeah i just checked

#

makes sense.

surreal path
#

yea just changed types

#

no page fault?

#

still err=4

#

bru

#

does qemu have xd bit support disabled

molten grotto
#

no

surreal path
#

weird

#

yea um

#

it maps some memory to not be executabl

#

to which

#

i do no problem

#

err still = 4

#

bru

#

bro like what the actual fuck

#

is going on

#

this is pain

#

mlibc just doesnt want me going to bash

green elbow
#

there is a >95% chance it is not mlibc's fault meme

surreal path
#

bru

#

then wtf is going on

surreal path
#

this is hell

kind root
#

If you dont see the bug you dont have enough printfs

#

Remember this rule

surreal path
#

bro

thorn bramble
#

he aint wrong tho

surreal path
#

i've being putting printfs everywhere

#

i cant find this fuckin issue

unkempt relic
surreal path
#

even tho all memory i give to mlibc is 0'd and correct and valid addresses

unkempt relic
#

how bogus are we talking? something truly unforgivable like 0xc2ba349d66? or a slightly bogus address, like 0x430582

surreal path
#

jumping to a bunch of instructions that literarly just

#

dont make sense

#

also all data using sys_read thats read into the buffer seems valid

surreal path
unkempt relic
# surreal path lol

i want you to check whether that address seems to be legitimate with respect to bash (it looks like if bash is loaded at 0x40000 then that could be within it?)

surreal path
#

not bash

#

in which

#

the init array

#

is correct, bf000

#

could it be init_arraysz

#

its valid

#

wtf is going on

#

@unkempt relic do u have any idea whats going on

unkempt relic
#

have you inserted a print after the DT_INIT_ARRAYs are all invoked?

unkempt relic
#

because if we know that the problem is within one of the INIT_ARRAY functions then that is useful information

surreal path
#

it seems to be within one of the init_array functions

#

otherwise rtld would have printed complete

#

this is the instruction

unkempt relic
#

are you single-core?

surreal path
#

yes

unkempt relic
#

good

#

and you did enable SSE i think

surreal path
#

yes

#

as well as proper saving of fpu state

#

and loading

#

using xsave and friends

unkempt relic
#

well don't save it

#

turn it all off

surreal path
#

why???

unkempt relic
#

i want to see what happens if you don't touch FPU state in the kernel at all

surreal path
#

oka

unkempt relic
#

keep SSE on you've only got one process that deals with it

surreal path
#

same issue

#

even when not saving or restoring fpu state

unkempt relic
#

then we can be assured your FPU state management is not to blame for this

surreal path
#

yep

unkempt relic
#

(that's the only reason i asked, it got rid of one degree of freedom)

surreal path
#

this line

unkempt relic
#

let's find out where and why control jumps to this address

surreal path
unkempt relic
#

step through in GDB, instruction-by-instruction if necessary, until it jumps to the funny address

surreal path
#

okay

#

then it jumps here

#

to which it jumps here

#

more instructions

#

jumps here

#

now here

#

this is the instruction

#

that makes it jump to a funny address

#

0x491aa6

#

to these very invalid instructions

#

this new_set instruction

#

which is a macro

#

what do u think is happening @unkempt relic ?

unkempt relic
surreal path
#

i am unsure, i will run gdb again and see

#

this instruction

#

which makes it jump here

#

this instruction

#

is before it jumps to 0x49xxxx

#

what tf is going on

#

any ideas?

unkempt relic
surreal path
#

i know

unkempt relic
#

you're sure that if you stepi when on this instruction, it jumps to 0x49xxxx?

surreal path
#

i used si

surreal path
#

this is very weird

#

i have no further ideas on how to debug this further

unkempt relic
#

kindly p /x 0x412bffb0

surreal path
#

alr

#

this is the value

#

dereferencing the data gives

#

is that wrong @unkempt relic ?

unkempt relic
#

you could set a watchpoint in that address if you want

#

btw if you use add-symbol-file -o 0xloadaddress path/to/loaded/file you can see where you are in it in GDB

thorn bramble
#

watch

#

don't remember the exact usage tho

unkempt relic
#

watch (void*)0xaddress (you'd want to do it early on and see where it's getting changed, add-symobl-file helps)

thorn bramble
#

might want to help watch

#

or that, thanks

surreal path
#

clearly

#

nothing is modifying that address

#

so i do not know whats going on

#

hmmm??

unkempt relic
#

it's where it was changed to 0x491a80 that interests me more

surreal path
unkempt relic
#

add-symbol-file -o 0x40000000 path/to/ld.so

surreal path
unkempt relic
#

now bt

surreal path
unkempt relic
#
        case R_X86_64_IRELATIVE: {
            auto ptr = object->baseAddress + addend;
            auto target = reinterpret_cast<uintptr_t (*)(void)>(ptr)();
            *((uintptr_t *)rel_addr) = target;
            break;
        }
surreal path
#

i am quite confused

#

what this is

unkempt relic
#

that's the relevant lines in mlibc (assuming you are using mlbic master or that the line numbers haven't changed much)

#

the question is why libc.so would want to jump to that address

surreal path
#

i do not know

#

maybe the people behind mlibc would know

#

does anyone know?

#

this is truly confusing

#

im stuck

#

does no one have any idea whats going on

#

please anyone

#

๐Ÿ™

finite summit
#

Inb4 rewrite 2 of Nyaux

surreal path
#

no

molten grotto
#

could you regenerate the mlibc patch and push?

surreal path
molten grotto
#

ah yeah, I just had to delete the mlibc dirs to get them to update

molten grotto
#

I can't really figure out anything either, it just goes to some completely different code that is certainly not within the libc from the jump in getenv<plt>

surreal path
#

i know

surreal path
#

if u do find the issue @molten grotto let me know, im going sleep

unkempt relic
#

does bash provide a getenv?

molten grotto
#

actually yes it looks to be overwriting it

#

that would explain why it jumps there but idk why doesn't it show that address in gdb

surreal path
#

just woke up

molten grotto
#

I think this is some sort of memory bug as eg. 0x47fffc has a valid instruction from the bash executable but if you look at what there is when it dies there is just garbage there

surreal path
#

maybe the vmm is giving back that address cause of mmap_range

#

which doesnt create a region to mark that memory range as allocated

molten grotto
#

so yeah you want to create a region when you load an elf that spans the range it uses (the first PT_LOAD phdr's pt_vaddr is always the start and the last PT_LOAD's pt_vaddr + pt_memsz is the end as they are ordered by the vaddr field)

surreal path
#

i will modify that when im not sick

#

right now im too weak to do anything

#

i feel like i might collapse my entire body hurts

surreal path
#

but modify mmap range to create an allocated region correct?

molten grotto
#

I mean yeah you probably want that too, but you don't use mmap_range in the elf code

surreal path
#

why?

molten grotto
#

idk, you just don't

#

you could

#

I don't think you had mmap_range when you wrote the loading code

surreal path
#

i will modify this later

#

i hate being sick

molten grotto
#

also MAP_FIXED actually does funny stuff like if there already is an allocated region that contains the range it tries to map using that flag then it splits the already existing region into different parts (possibly one from the start of the old region before the region range mapped with MAP_FIXED, one for the actual region range and then possibly one for the region from that range to the end of the old region)

surreal path
#

wha

tawdry mirage
#

if you MAP_FIXED over an existing mapping it replaces that part of the existing mapping

surreal path
#

oh

#

isnt it supposed to do that

tawdry mirage
#

that is the intended behavior

surreal path
#

i will just not use mmap range

unkempt relic
#

for what it's worth you shouldn't have to worry too much about supporting MAP_FIXED yet, i didn't need it for mlibc loading, but of course you've got to make sure you don't allocate the areas that mlibc wants to map DSOs into

unkempt relic
kind root
#

Oh you mean that aspect of it

unkempt relic
#

btw if it turns out you are giving out memory that was already mapped then that makes good sense

#

with regar dto the problems you experienced earlier

surreal path
#

i do not know how to fix this anymore

#

as i am mega confused on what i need to do

unkempt relic
#

well

#

you saw how it got into code which was all add %al, %(rax)

surreal path
#

yes

unkempt relic
#

that's zero

#

if you zero pages when you give them out then there's a working hypothesis on what's going wrong

surreal path
#

that is what i do

unkempt relic
#

the answer is simple then

#

make sure not to give out memory that was already mapped when mlibc has asked you to map some anonymous memory anywhere

surreal path
#

i think its because i do mmap_range in the elf loader

#

to whihc

#

doesnt mark the region as allocated

unkempt relic
#

and thus it gets intruded on

surreal path
#

yes

unkempt relic
#

then make sure it's marked allocated so it's not given out again

surreal path
#

do i worry about the stack?

#

or no

#

as i just load that into 0x7000000

unkempt relic
#

i am not familiar with your kernel design

#

if the stack is loaded up there and your allocator allocaets from low addresses before high then it shouldn't be intruded on for a while

surreal path
#

this is what i shall do

#

even marking it as allocated

#

still the same issue

#

wait

#

i know

#

great

#

clearly this didnt solve it

#
 struct vmm_region *cur_node = maps->head;
                    struct vmm_region *prev_node = NULL;
                    uint64_t f = align_down(base + phdr.p_vaddr, 4096);
                    while (cur_node != NULL)
                    {
                        if (prev_node == NULL)
                        {
                            prev_node = cur_node;
                            cur_node = cur_node->next;
                            continue;
                        }
                        if ((cur_node->base) > f && (prev_node->base + prev_node->length) < f)
                        {
                            struct vmm_region *new_guy = kmalloc(sizeof(struct vmm_region));
                            new_guy->base = f;
                            new_guy->length = (align_up(phdr.p_memsz + misaligned, 4096));
                            kprintf("done\n");
                            prev_node->next = new_guy;
                            new_guy->next = cur_node;
                            cur_node = cur_node->next;
                            goto done;
                        }
                        else
                        {
                            // not enough space for our new region sadly, continue
                            prev_node = cur_node;
                            cur_node = cur_node->next;
                            continue;
                        }
                    }
                    done:

what i do

finite summit
#

nyaux rewrite /j

unkempt relic
#

see whether it's supposed to be 0'd or not

#

if i were debugging it first i would objdump bash and check the address looks like there should be code at it

molten grotto
#

did you change the code to mark the region where the elf is loaded at as allocated? because I am 99% sure thats the issue

unkempt relic
surreal path
finite summit
#

I feel like it's a scheduler problem

surreal path
#

how

finite summit
#

Idk

#

Try stopping scheduler preemption

surreal path
#

still same issue

molten grotto
surreal path
molten grotto
# surreal path how

well for an example if there is no previous node you set current node to the next node and continue when you should put the new node at the head if you want to keep them ordered and you don't really care if the prev node base + prev node size is less than the base if they are ordered (well you could still do <= if you wanted as the end is exclusive)

finite summit
#

Line 28 and 29

#

Why do you add misaligned while rounding up

surreal path
#

always at least 2

molten grotto
molten grotto
#

the points that I said still apply

surreal path
#

i am confused then

#

like

#

i dont get what is the issue with this

well for an example if there is no previous node you set current node to the next node and continue

molten grotto
#

then they aren't going to be properly ordered

#

for an example if head's base is 0x50000 and the node's that you are trying to insert is 0x40000

surreal path
#

it is assumed that heads base is always 0x0

#

i do not modify head in any way

molten grotto
#

ah, in that case there is only the issue with using < instead of <=

surreal path
#

where am i doing <=?

molten grotto
#

you don't and thats the issue

surreal path
surreal path
#

something like this i suppose

#

OH MY FUCKIN GOD

#

OH MY

#

FUCK

#

IN

#

GOD

#

THANK U QWINCI

molten grotto
surreal path
#

yea i get u

surreal path
#

sys_futex_wake

molten grotto
#

likely it uses pthread mutex and that needs it

surreal path
#

well im happy we are closer to bash now

surreal path
#

i dont have locks in my kernel so

#

do i just do nothing?

thorn bramble
#

so it turned out that it was ur vmm being shit?

surreal path
#

yes

thorn bramble
#

happens

#

return ENOSYS from futex_wait/futex_wake

#

u should be able to get further

#

bash shouldnt need them

green elbow
#

mlibc uses locks internally by default

#

but if you don't have multithreading it's not needed

finite summit
surreal path
#

yes u were omar

surreal path
#

sorry guys im just

#

not having a good time rn

#

kinda hard to work on the project when some things happening irl

wicked loom
#

i mean take your time

#

no one is forcing you, it's not your job

surreal path
#

i do want to work on it tho

#

i rlly do feel a passion for this project

#

just guess that this whole skipping school and everything just to work all day on nyaux is just not sustainable anymore

wicked loom
#

yeah that's probably a good call

#

but you can just work on it without skipping on the rest, just partition your time better

surreal path
#

kinda difficult to work on it all together when i have final exams next week

#

โ˜ ๏ธ

wicked loom
#

well bruh

#

you can still work on it after lol

surreal path
#

fair lmao

wicked loom
#

prioritise your finals for now

surreal path
#

alr

surreal path
#

also yk u could probs get to userspace faster then me, if u knew exactly what u were doing probs under 24 hours

#

thats if u knew EXACTLY of what u were doing

#

but this was a from scratch kernel for me without any previous knowledge so ๐Ÿ˜ƒ

#

random thought

#

why is mlibc trying to write to fd 2

tawdry mirage
#

stderr

surreal path
#

clearly bash is looking for things ig

#

now what is sys_dup

#

i have no fuckin idea

#

!!

tawdry mirage
#

just handle fd 2 the same way you handle fd 1 for now

#

it's stderr

surreal path
#

what do i just print it out

#

or

#

what

tawdry mirage
#

yeah

#

i mean what do you do for fd 1 :^)

surreal path
#

wha about sys_dup

#

that syscall

#

what am i supposed to do

tawdry mirage
#

return a new file descriptor referring to the same open file description

surreal path
#

but why

#

and also

#

ill have to make a new file descriptor that points to the same vnode

#

as i dont have that extra level of indirection

wide nexus
surreal path
#

using jinx build system

wide nexus
#

ah I see

surreal path
#

what the heck is F_DUPFD?

tawdry mirage
#

fcntl command? don't worry about it

#

you can just give it it's own syscall

surreal path
#

ok

#

oh bash didnt care that i errored out for sys_dup

#

it just continued ig

#

but now it wants fuckin

#

sys_tcgetattr

#

why

tawdry mirage
#

probably to set up raw mode on the tty for readline

surreal path
#

wha

#

me when im completely lost

#

like wha?

#

huh??

tawdry mirage
#

it's configuring the terminal to disable line buffering and echo

#

since readline provides line editing on it's own

surreal path
#

do i just return -1

#

as i dont have a tty

#

im just writing everything directly to flanterm

tawdry mirage
#

not sure how well it'll take tcgetattr/tcsetattr failing

surreal path
#

well what else am i supposed to do huh

#

yea it didnt give a shit

#

now it wants sys_ppoll

#

which ill return -1

tawdry mirage
#

are you still ignoring fd 2?

surreal path
#

i tried printing it but it was empty

#

okay yea its clearly not happ

#

y

tawdry mirage
#

well ig since poll fails, there's no way for it to get input

#

since bash does poll(stdin fd) => poll completes => read(stdin)

surreal path
#

okay then what should i do

unkempt relic
#

any bash prompt printed at all? did you implement isatty?

#

if bash thinks stdin is not a tty it will quit

surreal path
unkempt relic
#

because if stdin is not a tty then bash must be being used not as an interactive shell, but rather to run a script

tawdry mirage
unkempt relic
surreal path
#

ig

tawdry mirage
surreal path
#

either way i dont know what to do

#

i just want a basic prompt

unkempt relic
surreal path
#

mr @elder shoal promised me this would be easy nooo

tawdry mirage
#

small amount of syscalls doesn't mean you don't need to implement their functionality properly :^)

surreal path
#

i did tho for the syscalls he listed

#

he didnt include all these other syscalls

#

now bash wants poll

#

what am i supposed to return

unkempt relic
#

this is the tricky part of mlibc

elder shoal
unkempt relic
#

it's so featureful that sometimes it gives you too much

#

but i think you can literally have poll just return ENOSYS and bash should happily deal

elder shoal
#

Yeah

surreal path
#

okay

#

lets see if we get into bash or no

tawdry mirage
#

just don't make your read return 0 immediateely

#

since that's treated as EOF