#OBOS (not vibecoded)

1 messages ยท Page 28 of 1

real pecan
#

iasl

flint idol
#

thx

flint idol
#

like if I did acpidump > acpi.txt

#

how do I decompile acpi.txt

real pecan
#

acpidump > dump.txt && acpixtract -a dump.txt && iasl *.dat && code dsdt.dsl

flint idol
#

thanks

#

wait my laptop actually has "sane" aml for wake from suspend

#

well as sane as it gets

#

actually let me make sure

#

nvm

#

it delulu

real pecan
#

lmao

#

whats wrong

flint idol
#

it tells me to put devices into D2 for suspend if I want them to wake me
D2 doesn't exist

real pecan
#

lmao

flint idol
#

same thing on my dev pc

real pecan
#

perhaps ur misunderstanding what it does

#

have u looked at how linux handles these values

flint idol
#

set _S3D to 2 to tell the kernel that this device can only be at a deepest state of 2 to wake the kernel up
no D2 state

flint idol
#

iirc

real pecan
#

how does it react in this case

flint idol
#

well it just hangs after a bit

#

idk why

real pecan
#

i mean linux

flint idol
#

while setting the wake devices

flint idol
real pecan
#

u can add printfs there like mishakov did to figure out where the power button press comes from

flint idol
#

suspends

#

also wakes up

real pecan
#

to see which state it puts the devices in and why

flint idol
#

(reading linux code has traumatized me)

real pecan
#

its not that hard to compile linux lol

#

also code is very easy to read

flint idol
#

anyway, what obos does in this case is not put it in any D state

real pecan
#

what if u force put it in d3

#

does it have that

flint idol
#

let me check

#

nope

real pecan
#

Which does it have

flint idol
#

none

#

no D state objects

#

no wake power resources either

real pecan
#

So then it doesnt matter what it says in _S right

flint idol
#

yeah

real pecan
#

So what happens on suspend

flint idol
#

I think because _S3D is 0x2, which means the deepest state the device can be to wake us is D2, it's fine if I keep it in D0

flint idol
#

before suspend

real pecan
#

Did u figure out where

flint idol
flint idol
flint idol
#

just an acpi spec skill issue

flint idol
#

my obos clone on my laptop

#

is 170 commits behind

#

and one commit ahead

#

on commitf989a176ebaaf320ab3e81929508df331922ca83

#

on the repo

flint idol
#

also why is cmake+make so slow compared to cmake+ninja

thick jolt
#

ninja

haughty abyss
#

but also make is just slower

torpid wigeon
flint idol
#

time for more debugging

#

wake up
shit
get out of bed
do osdev
sleep
repeat

weak kestrel
flint idol
#

typo

#

I meant to put shit after get out of bed

#

wake up
get out of bed
shit
do osdev
sleep
repeat

flint idol
#
/home/oberrow/Code/obos/src/oboskrnl/power/device.c:244:12: warning: 'useDSW' may be used uninitialized [-Wmaybe-uninitialized]
  244 |         if (useDSW)
      |            ^
/home/oberrow/Code/obos/src/oboskrnl/power/device.c:198:10: note: 'useDSW' was declared here
  198 |     bool useDSW = false;```
we just love this warning
thick jolt
flint idol
#

(that warning is not only a false-positive, a stupid one)

#

((the line it shows me shows the variable being initialized))

thick jolt
#

truly a

#

gcc skill issue

#

richard stallman

#

๐Ÿ˜ก

flint idol
#

soon I port obos to clang

thick jolt
#

llvm glazer alert

#

๐Ÿ˜ก ๐Ÿ˜ก

#

all should write their own compiler

flint idol
#

u confoosing

thick jolt
#

listen

#

just write ur own tooling

#

gcc? clang? msvc?

#

no

flint idol
#

you do it first

thick jolt
#

nyauxcompiler

#

one day maybe

flint idol
#

no thanks

thick jolt
#

i might give it a go

flint idol
#

I don't want my compiler to page fault when I throw at it a hello world program

thick jolt
thick jolt
#

itll do better and somehow kill ur entire kernel

#

and brick ur system

flint idol
#
#include <cstdio>
#include <cstring>
#include <type_traits>

int main() {
}

struct A {
    static void (*&_)(int);
    A(float b) { int i; _(*(int*)memcpy(&i, &b, 4)); }
};
std::remove_cvref_t<decltype(A::_)> **O, *P, Q;
decltype(A::_) A::_ = (O = &P, P = &Q, **O);

template<float B, int = 0>
struct _ {
    static const inline A a = (Q = [](int _) { putchar(_); }, A(B));
};

template struct _<0X1.2p-143f>;
template struct _<0X1.94p-143f>;
template struct _<0X1.bp-143f>;
template struct _<0X1.bp-143f,1>;
template struct _<0X1.bcp-143f>;
template struct _<0X1.6p-144f>;
template struct _<0X1p-144f>;
template struct _<0X1.5cp-143f>;
template struct _<0X1.bcp-143f,1>;
template struct _<0X1.c8p-143f>;
template struct _<0X1.bp-143f,2>;
template struct _<0X1.9p-143f>;
template struct _<0X1.08p-144f>;```
#

look at this hello world

#

I found

#

;compile ```c++
#include <cstdio>
#include <cstring>
#include <type_traits>

int main() {
}

struct A {
static void (&_)(int);
A(float b) { int i; _(
(int*)memcpy(&i, &b, 4)); }
};
std::remove_cvref_t<decltype(A::)> **O, *P, Q;
decltype(A::
) A::_ = (O = &P, P = &Q, **O);

template<float B, int = 0>
struct _ {
static const inline A a = (Q = [](int ) { putchar(); }, A(B));
};

template struct _<0X1.2p-143f>;
template struct _<0X1.94p-143f>;
template struct _<0X1.bp-143f>;
template struct _<0X1.bp-143f,1>;
template struct _<0X1.bcp-143f>;
template struct _<0X1.6p-144f>;
template struct _<0X1p-144f>;
template struct _<0X1.5cp-143f>;
template struct _<0X1.bcp-143f,1>;
template struct _<0X1.c8p-143f>;
template struct _<0X1.bp-143f,2>;
template struct _<0X1.9p-143f>;
template struct _<0X1.08p-144f>;```

warm shuttleBOT
#
Compiler Output
<source>:12:6: error: 'remove_cvref_t' in namespace 'std' does not name a template type
   12 | std::remove_cvref_t<decltype(A::_)> **O, *P, Q;
      |      ^~~~~~~~~~~~~~
<source>:12:1: note: 'std::remove_cvref_t' is only available from C++20 onwards
   12 | std::remove_cvref_t<decltype(A::_)> **O, *P, Q;
      | ^~~
<source>:13:24: error: 'O' was not declared in this scope
   13 | decltype(A::_) A::_ = (O = &P, P = &Q, **O);
      |                        ^
<source>:13:29: error: 'P' was not declared in this scope
   13 | decltype(A::_) A::_ = (O = &P, P = &Q, **O);
      |                             ^
<source>:13:32: error: 'P' was not declared in this scope
   13 | decltype(A::_) A::_ = (O = &P, P = &Q, **O);
      |                                ^
<source>:13:37: error: 'Q' was not declared in this scope
   13 | decltype(A::_) A::_ = (O = &P, P = &Q, **O);
      |                                     ^
<source>:13:42: error: 'O' was not declared in this scope
   13 | decltype(
flint idol
#

wait momentarily

#

;compile -std=c++20 ```c++
#include <cstdio>
#include <cstring>
#include <type_traits>

int main() {
}

struct A {
static void (&_)(int);
A(float b) { int i; _(
(int*)memcpy(&i, &b, 4)); }
};
std::remove_cvref_t<decltype(A::)> **O, *P, Q;
decltype(A::
) A::_ = (O = &P, P = &Q, **O);

template<float B, int = 0>
struct _ {
static const inline A a = (Q = [](int ) { putchar(); }, A(B));
};

template struct _<0X1.2p-143f>;
template struct _<0X1.94p-143f>;
template struct _<0X1.bp-143f>;
template struct _<0X1.bp-143f,1>;
template struct _<0X1.bcp-143f>;
template struct _<0X1.6p-144f>;
template struct _<0X1p-144f>;
template struct _<0X1.5cp-143f>;
template struct _<0X1.bcp-143f,1>;
template struct _<0X1.c8p-143f>;
template struct _<0X1.bp-143f,2>;
template struct _<0X1.9p-143f>;
template struct _<0X1.08p-144f>;```

warm shuttleBOT
#
Program Output
Hello, World!
flint idol
#

@thick jolt

thick jolt
#

wtf

#

modern c++

white mulch
#

its not even idiomatic c++ and contains reserved identifiers + shadowing lol

thick jolt
#

more unreadable then complex rust

flint idol
#

I added a command line option to obos to set the log level

#

at runtime

#

and to do so, I also made a way for the kernel command line to be parsed long before having an allocator

torpid wigeon
#

omega cringe

flint idol
#

I mean theorerically it's not too much work

torpid wigeon
#

what's not working

flint idol
#

but I've never tried

flint idol
white mulch
#

you shouldn't use that target anyway, its garbage

flint idol
#

x86_64-linux??

white mulch
#

yes

flint idol
#

k

torpid wigeon
#

huh

#

i've been using the x86_64-none-elf all this time

flint idol
#

in fact

#

I'm going to port obos to clang rn

#

and also I should improve how I get options in cmake

white mulch
#

you might also want to make it use out-of-line instrumentation for asan on clang if you don't support inline instrumentation

#

as in making it always generate calls to the asan functions instead of consulting the shadow map itself like it does by default for functions that have less than some amount of accesses (idk what the default amount is but its not zero like in gcc)

flint idol
#

cmake doesn't support string options using the option command

#

so I need to do it manually

weary hound
flint idol
#

it was because I used a goto to skip it's initializiation

#

without knowing

weary hound
#

stupid warning

white mulch
flint idol
#

yeah

#

I ended up doing that

#

and I am also adding a new option, OBOS_USE_CLANG

vale nymph
thick jolt
#

ur shitting our bed

#

i shit in my sleep

#

๐Ÿ˜Ž

#

we are not the same

short mortar
#

Do you not sleep in bed?

thick jolt
#

no i shit in my bed

#

and sleep in the toilet

flint idol
#

or do I remove the -elf

#

or is it x86_64-unknown-linux-elf

white mulch
#

I don't really know, I use x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu

#

but very likely those work too

flint idol
#

maybe -gnu instead of -elf is better

#

all goes well until linking oboskrnl

#
/usr/bin/ld: src/oboskrnl/CMakeFiles/oboskrnl.dir/arch/x86_64/entry.asm.obj: relocation R_X86_64_32S against symbol `__stack_chk_guard' can not be used when making a PIE object; recompile with -fPIE```
weary hound
#

the stack check is probably also using fs:[0x40] for the cookie with -gnu

flint idol
white mulch
#

the fix for that should be easy tho, just make the asm position independent

flint idol
#
src/oboskrnl/CMakeFiles/oboskrnl.dir/arch/x86_64/smp.c.obj: in function `Arch_SMPStartup':
/home/oberrow/Code/obos/src/oboskrnl/arch/x86_64/smp.c:(.text+0x42f): failed to convert GOTPCREL relocation against 'Arch_SMPTrampolineStart'; relink with --no-relax
/home/oberrow/Code/obos/src/oboskrnl/arch/x86_64/smp.c:(.text+0x435): failed to convert GOTPCREL relocation against 'Arch_SMPTrampolineRSP'; relink with --no-relax
/home/oberrow/Code/obos/src/oboskrnl/arch/x86_64/smp.c:(.text+0x44b): failed to convert GOTPCREL relocation against 'Arch_SMPTrampolineCPULocalPtr'; relink with --no-relax```
#

now I get those

#

so I guess I link with --no-relax?

#

I got it to link

#

but it triple faults

weary hound
#

also i've never seen that error before lol

flint idol
#

I switched to lld

#

instead of binutils

#

and I now get ld.lld: error: unknown argument '-pic'

#

for linking drivers

#

but I do think the kernel linked

#

it wants to use gs:0x28 to get the stack guard

#

which doesn't work, obviously

#

causing a triple fault

flint idol
#

wtf

#

why is the obos binary 2.4M

#

with llvm

white mulch
#

debug info?

white mulch
flint idol
#

thanks

white mulch
#

it also works on gcc so you don't have to guard it

flint idol
#

because the compiler emits many of those

#

even with that

white mulch
#

weird

#

for the stack guard still?

flint idol
#

no, for something else

white mulch
#

for what specifically

flint idol
#

waiiiit

#

it does something dumb

thick jolt
#

tf

#

cringe

#

why i never use clang

flint idol
#

it gets the address of __stack_chk_guard

#

then makes a gs-relative access

#

with it's address

thick jolt
#

gcc would never

white mulch
#

oh right ๐Ÿ’€ I missed the address space part of the llvm code

#

I guess this is one of the "bad" things about the linux target, you'd have to use either fs or gs relative stack protector cookie

flint idol
#

bruh

#

dat stoobid

white mulch
#

as a poor workaround ig you could setup the gs to point to some dumb static struct with the cookie in the entry asm until you setup a proper per cpu/thread struct

flint idol
#

or I could not support stack protector on clang

white mulch
#

or that

flint idol
#

if that makes sense

#

unless the value is in the symbol itself

white mulch
#

you can use that symbol thing somehow or just specify the offset manually with -mstack-protector-guard-offset=<some number>

flint idol
#

ok

white mulch
#

and the reg with -mstack-protector-guard-reg=gs though if you use kernel code model its the default from the looks of it

flint idol
#

thx

flint idol
#

bruh

#

why is the compiler ignoring my requests

white mulch
#

what is it doing now

flint idol
#

aka __attribute__((no_stack_protector))

#

actually

#

maybe it's something else

flint idol
#

it gets to loading the initrd driver

#

for it to crash

#

in the loader

real pecan
#

wait whats happening why is obos broken

flint idol
real pecan
#

ah

flint idol
thick jolt
real pecan
#

clang is great

flint idol
thick jolt
flint idol
#

if I were wrong I would know I was

#

instead, you are wrong

thick jolt
#

๐Ÿ˜ญ

#

๐Ÿ’€

#

hey i mean

#

clang is like

#

cringe

#

so uhh

#

ur cringe

#

#roasted

flint idol
#

opinion rejected

#

L+bozo+get better+ratio

flint idol
#

hold on I need to say something quickly

thick jolt
#

kk

flint idol
#

FUCK BASHAR AL ASSAD

thick jolt
#

what

#

๐Ÿ˜ญ

#

oh yeah

#

the guy who ruled over syria

#

yea hes mega cringe

#

i am partially syrian so

#

yk

flint idol
#

I am syrian

thick jolt
#

woah

flint idol
#

millions dead for no reason as a result of him

thick jolt
#

exactly

flint idol
#

@ infy you're in moscow, find him and torture him for me
kthx

torpid wigeon
#

cringe ass gnu toolchain ๐Ÿคข

thick jolt
#

๐Ÿ˜ก

flint idol
#

gnu tastes bad

torpid wigeon
#

i have already won

#

gcc gets an automatic L for using autoconf

#

anything that's not autotools >> autotools

weak kestrel
#

found the portal player

thick jolt
#

how u know

short mortar
weak kestrel
thick jolt
#

and to this day im still waiting for oberrow to play portal 2 coop with me

#

๐Ÿ˜ก

short mortar
thick jolt
#

not anymore

weak kestrel
thick jolt
short mortar
#

I switched from GCC to clang and my stuff worked without changing anything

thick jolt
#

i didnt try nyaux on clang

short mortar
#

Like 3 months ago

thick jolt
#

mostly because im lazy

weak kestrel
#

you'll have a hard time finding something that's not UB meme

thick jolt
#

but also

weak kestrel
thick jolt
#

@short mortar prove me wrong

#

run nyaux on every piece of hardware u have

weak kestrel
#

high chance that it'll just work with your kernel

thick jolt
#

til u find ub

thick jolt
short mortar
weak kestrel
#

based

thick jolt
#

ok run nyaux on 12 pcs

#

i dont have 12 pcs

weak kestrel
#

llvm > gnu

thick jolt
#

lucky bastard

#

bro is hoarding electonics

#

๐Ÿ˜ก

short mortar
thick jolt
#

HERE WE GO

short mortar
thick jolt
#

it doesnt triple fault anymore

#

it runs perfectly

#

now i fixed those 2 bugs

weak kestrel
thick jolt
short mortar
#

I have 7 PCs, and people from this server were also trying it and it was working

thick jolt
#

nyaux runs perfectly now

weak kestrel
short mortar
#

Can you turn it off with a power button?

thick jolt
#

๐Ÿ˜ญ

#

i mean i could implment that soon

#

i js am sick todayh

short mortar
#

The only user input I have atm ultrameme

weak kestrel
#

you just need uacpi

#

ezpz

thick jolt
thick jolt
#

so ezpc

short mortar
thick jolt
weak kestrel
thick jolt
#

i dont have pci yet

#

ive NEVER done pci before

short mortar
#

Also I'm the only hobby os which implements AMD GPIO driver

thick jolt
#

ive always just went straight to userspace and mlibc

#

with my rewrites

#

im interestined in it tho

weak kestrel
thick jolt
#

not atm

#

but that comes tmrw

#

when im not sick

#

okay

weak kestrel
weak kestrel
thick jolt
#

yeaaaaa

#

that didnt work

short mortar
weak kestrel
thick jolt
#

nice

weak kestrel
#

lmfao

thick jolt
weak kestrel
#

yes lmao

thick jolt
#

oh thanks mint

torpid wigeon
thick jolt
#

she does it for me

#

i love u mint !!!

short mortar
thick jolt
#

its compiling

weak kestrel
#

yeah properly implement ubsan or disable it

thick jolt
#

i did

weak kestrel
#

also use lld instead of ld

thick jolt
#

i swear i did

weak kestrel
thick jolt
#

how

weak kestrel
#

no you didn't

thick jolt
weak kestrel
#

there are ton of ubsan functions

thick jolt
#

its because i have this check

#

why do i have this check

weak kestrel
#

just disable ubsan

thick jolt
#

why did rayan put that there

thick jolt
#

dont believe me?

#

read the soruce

short mortar
weak kestrel
thick jolt
#

i added that myself

#

actually

weak kestrel
#

why would you?

thick jolt
#

i dont remember why tho

weak kestrel
#

doesn't make sense

thick jolt
#

ubsan works on clang right???

flint idol
#

yes

thick jolt
#

okay

flint idol
#

it came from clang

weak kestrel
#

no only Richard stallman knows the magic of UB

thick jolt
flint idol
#

skill issue

weak kestrel
thick jolt
#

fine

weak kestrel
#

you and your "fine" smh

flint idol
#

omg

#

nyaux try not to half ass something challenge: level impossible

thick jolt
#

lol

thick jolt
#

fine

#

yk?

#

fine :)

#

how does that sound

flint idol
#

I copy+pasted my ubsan implementation

thick jolt
#

im not gonna half ass this

weak kestrel
thick jolt
#

way*

#

im future i will say that nicely :)

flint idol
#

fine is usually used when someone tells you to do something that you don't want to do, but do anyway
room mate x to y: do the dishes
y: fine

thick jolt
#

ig but

#

i mean it positively

#

is the like a firefox extention that automatically spell checks ur words and replaces them with the spell check

weak kestrel
#

could you tell someone "shit yourself" positively?

#

depends on the thing being said

thick jolt
#

i did not say that

weak kestrel
thick jolt
#

that is not positively

thick jolt
#

listen me and you @weak kestrel are besties okeyyyy :)

weak kestrel
#

depends on the default meaning of the word

thick jolt
flint idol
#

it's around -10 degrees outside, should I keep my window open

#

(what could possibly go wrong?)

thick jolt
#

open it meme

weak kestrel
flint idol
#

it is open, I'm asking should I keep it open

weak kestrel
flint idol
#

no

#

I'm canadian, that's impossible

short mortar
#

ilobilo force bebestfriended

weak kestrel
flint idol
thick jolt
flint idol
#

would be fun though

weak kestrel
weak kestrel
flint idol
#

holy shit

#

you're right

thick jolt
#

how do ichange the linker

flint idol
thick jolt
#

okayokay

#

sorry for littering ur thread

flint idol
#

np

weak kestrel
#

obos has been hijacked

flint idol
#

this talk about ubsan is making me want to go improve my ubsan implementation
it was directly plagarised from sortix, so it only has the features sortix has

thick jolt
flint idol
#

it's np

thick jolt
#

okay

weak kestrel
#

they print their names and halt the kernel

flint idol
#

I just copy pasted the entire file

weak kestrel
#

obsan when

flint idol
#

OBOSsan

#

oberrow os sanitizer

weak kestrel
flint idol
#

true

#

but I want to make it also print type info because I have that

lean glen
#

tinyubsan exists

#

its fine

weak kestrel
lean glen
#

like what

weak kestrel
#

I don't remember exactly

#

maybe C++ just generates more checks than C does

flint idol
#

I installed pwndbg

#

and it is a really nice gdb plugin

short mortar
#

Better solution: just don't have UB KEKW

flint idol
#

I found my bug

#

lld doesn't emit a symbol hash table

#

like GNU binutils does

#

but I use it assuming there is one

#

causing me to get a bogus pointer

#

page faulting

#

rather that OR I find the relocations before the hash table

#

it has a DT_GNU_HASH

#

so guess I'm implementing GNU_HASH support now

#

openbsd is the most freedom bsd right?

flint idol
weary hound
#

isn't there some flag to make it emit the sysv hash table?

flint idol
#

yes

#

there is

#

but I've heard gnu hash is better anyway

thick jolt
#

im taking this too @flint idol

flint idol
#

I was able to get it past the driver loading stage

#

but it mysteriously page faults in the vfs

#

it page faults in the initrd driver

#
size_t dirnamelen = uacpi_strnlen(dir_filename, 100);```
#
const char* dir_filename = (const char*)&dir->filename;```
#

causing Page fault at 0x3b36 in kernel-mode while to execute page at 0x3b36, which is unpresent. Error code: 16

#

wait wtf

#

ok found the bug

#

lld is putting DT_JMPREL before specifying it's size

#

fixed the bug

#

except now wake from suspend triple faults

#

fixed that

#

now it gets to:

Kernel Panic on CPU 0 in thread 10, owned by process 2. Reason: OBOS_PANIC_STACK_CORRUPTION. Information on the crash is below:
Stack corruption detected at IP=0xffffffff80029a18 (overwrite of stack canary).```
#

frick

#

thread 10 is a user thread

#

a user thread has wreaked havoc in the kernel

flint idol
flint idol
#

somehow causing this all to break

#

whoops

#

fixed

#

yeah there are some bugs with wake from suspend, even on GCC

#

but other than that, obos now supports clang

#

I really should add CI tests for obos

#

rn I feel like I'm getting many config options

#

and I might accidentally break something

#

and not notice it until someone tries to do that

#
option (OBOS_UP "Make a Uniprocessor-Build of obos.")
option (OBOS_ENABLE_UBSAN "Enables UBSan.")
option (OBOS_ENABLE_KASAN "Enables KAsan.")
option (OBOS_ENABLE_FANALYZER "(Developers only) Enables the compiler's static analyzer")
option (OBOS_ENABLE_WERROR "(Developers only) Enables the -Werror option")
option (OBOS_USE_CLANG "Use clang instead of GCC to build.")```
#

with fanalyzer and werror being mutually exclusive

#

that's like 32 different possible combinations of options that I might want to test

#

in both release and debug mode

#

over two architectures

limber wave
flint idol
#

@ infy

#

it hangs evaluating _PTS

real pecan
#

well see which kernel api

flint idol
#

@real pecan it hangs talking a mutex

#

*taking

short mortar
#

mutex doesn't want to talk

real pecan
flint idol
#

no

#

because I added logs around that specific mutex

#

you never release it

#

it's from uacpi

real pecan
#

which mutex even

flint idol
#

I only have a pointer to it atm

#

I will do a stack trace

#

to find out where you create it

real pecan
#

make sure your get_thread_id() is not bogus

flint idol
#

it's not a recursive lock

#

it's waiting for TID 1 to release that lock in TID 10

real pecan
#

how do u know

#

its impossible to tell from kernel api

flint idol
#

but it's possible for my kernel to tell me

real pecan
#

uacpi has its own recursive locks that operate on normal acquire_mutex

flint idol
#

well my get thread id is not bogus

real pecan
#

return Core_GetCurrentThread()->tid;

flint idol
#

yes

real pecan
#

what if task gets switched after this call but before we read tid

flint idol
#

that's a bug I am planning to fix later in obos

real pecan
#

anyway it only reproduces in obos so i doubt its a uacpi bug

#

but dump stacks and lets see

haughty abyss
flint idol
#

me?

haughty abyss
#

yeah

flint idol
#

to get the current TID?

haughty abyss
#

just do (uintptr_t) Core_GetCurrentThread()

#

lol

flint idol
#

I mean

#

sure, why not

real pecan
#

yeah

haughty abyss
#

saves a pointer deref

white mulch
#

or the tid for that matter

real pecan
#

The task could get moved to a different core which would return the tid of some other thread that now runs on that core no?

flint idol
#

depends on where it gets switched

#

if it gets switched in get current thread's implementation

#

then yes

#

before dereferencing the cpu local pointer

white mulch
real pecan
#

yes

#
cpu *cpu = get_percpu_ptr();
return cpu->thread;

if its something like this ig

flint idol
#

yeah it's like that

white mulch
#

yeah you should prevent that by either preventing the switch inside there or just doing an atomic gs-relative load (or storing the thread in gs instead of cpu)

flint idol
#

I got the stack trace

#

I now need to decode it to function names

short mortar
#

#1236769772805554206 message

flint idol
#
Frame 0: /home/oberrow/Code/obos/dependencies/uACPI/source/types.c:189 (inlined)
Frame 1: /home/oberrow/Code/obos/dependencies/uACPI/source/types.c:199
Frame 2: /home/oberrow/Code/obos/dependencies/uACPI/source/types.c:339
Frame 3: /home/oberrow/Code/obos/dependencies/uACPI/source/namespace.c:102 (inlined)
Frame 4: /home/oberrow/Code/obos/dependencies/uACPI/source/namespace.c:172
Frame 5: /home/oberrow/Code/obos/dependencies/uACPI/source/uacpi.c:318
Frame 6: /home/oberrow/Code/obos/src/oboskrnl/power/init.c:58
Frame 7: /home/oberrow/Code/obos/src/oboskrnl/arch/x86_64/entry.c:573
END
#

@real pecan I think it's a problem with my specific blob

real pecan
#

this is the global lock

flint idol
#

I thought that was a spinlock though?

real pecan
#

its a mutex, a spinlock, an event, and a field in FACS

flint idol
#

and uacpi only modifies it when firmware asks it right?

real pecan
#

yeah

#

can u enable tracing?

#

it traces global lock acquires

flint idol
#

sure

real pecan
#

its acquired in basically one place

#

access_field_unit

#

its definitely released there as well

#

or wait

#

i think i might be brain damaged

real pecan
# flint idol sure
--- a/source/io.c
+++ b/source/io.c
@@ -209,18 +209,22 @@ static uacpi_status access_field_unit(

         switch (op) {
         case UACPI_REGION_OP_READ:
-            return uacpi_read_field_unit(
+            ret = uacpi_read_field_unit(
                 field->data, in_out, field->access_width_bytes
             );
+            break;
         case UACPI_REGION_OP_WRITE:
-            return uacpi_write_field_unit(
+            ret = uacpi_write_field_unit(
                 field->data, in_out, field->access_width_bytes
             );
+            break;
         default:
             ret = UACPI_STATUS_INVALID_ARGUMENT;
-            goto out;
+            break;
         }

+        goto out;
+
#

like this is definitely a bug but

#

how did it not trigger before

#

on that same hw

flint idol
#

idk

#

maybe it did but I thought it was an obos bug

real pecan
#

but u said it hangs on shutdown

#

and it definitely shutdown before

flint idol
#

oh yeah

#

it was literally the first device I ever tested uacpi shutdown with

real pecan
#

anyway try this

flint idol
#

like the patch?

#

sure

real pecan
#

yup

flint idol
#

how to apply

real pecan
#

manually

flint idol
#

k

real pecan
#

IndexField isnt used that much so makes sense it went undetected but im not sure why it didnt break before on your stuff

#

when was the last time u tested shtudown on this pc

flint idol
#

months ago

real pecan
#

ah

#
โฏ grep IndexField *.dsl
dsdt.dsl:            IndexField (BRAI, BRAD, ByteAcc, NoLock, Preserve)
โฏ grep IndexField *.dsl
dsdt.dsl:                    IndexField (INDX, DATA, ByteAcc, NoLock, Preserve)

From 2 dumps that i have from you there isn't a locked indexfield

flint idol
#

you're missing my laptop's dump

#

you must complete your collection of my windows license keys your collection of aml blobs

real pecan
#

ah

flint idol
#

yay

#

it shuts down now

real pecan
#

worked?

#

damn cool

flint idol
#

yes

#

maybe this bug also fixed suspend

real pecan
#

how were u able to track down the place where the mutex gets created?

flint idol
#

I first printed each mutex acquire/release along with the address

#

until it deadlocked

#

then I narrowed logging to just that address

real pecan
#

is it guaranteed that the address is the same each time lol?

flint idol
#

since I have no kaslr or the like, the address of the mutex was the same

real pecan
#

races and stuff?

flint idol
#

on the same machine yes

flint idol
real pecan
#

or is uacpi init before smp

flint idol
#

uacpi init is after smp, but nothing else allocates memory

#

but uacpi

#

at the time

real pecan
#

ah ok

#

test suspend btw

flint idol
#

let me rephrase that

#

uacpi init is after smp, but there is only one thread, which is the one it runs on

#

the idle threads don't allocate memory

#

there's my laptop's dump

real pecan
#

obos dies because of uacpi bug what a day

flint idol
#

something that hasn't happened for 8+ months

#

with the table parsing

#

or whatever

real pecan
# flint idol

dsdt.dsl: IndexField (BKDX, BKDA, ByteAcc, Lock, Preserve) indeed

flint idol
real pecan
#

lmao

flint idol
#

almost one full year since I blamed it on uacpi and was right KEKW

real pecan
#

uacpi didnt even have a table subsystem back then

#

it was adhoc crappy code

flint idol
#

yeah iirc it was just there

#

it was untested at the time of writing that report, according to you

#

#560042023638269955 message

real pecan
#

i think i know why it didnt reproduce

#

this lock is recursive obviosuly since its an aml mutex

#

if u keep running it from the same thread it will always succeed in acquiring

#

if u shutdown from the same thread as well it will succeed

flint idol
#

yeah but I do remember in my third rewrite having a shutdown command in my dumb shell that worked

#

and the shell was in a user thread

real pecan
#

i dont think i even supported the global lock back then

flint idol
#

oh

#

anyway testing suspend now

real pecan
#

this firmware is kinda fucked as well

#

they didnt need Lock there

flint idol
#

well good news

#

it suspended

#

bad news

real pecan
#
    Field (CBK1, ByteAcc, Lock, Preserve)
    {
        BKDX,   8, 
        BKDA,   8
    }

The fields it references are already locked anyway

flint idol
#

it triple faulted

real pecan
#

lmao

#

on resume?

flint idol
#

yes

real pecan
#

F

flint idol
#

but good news

#

it woke from a keyboard press

real pecan
#

nice

#

that means u set wake gpes correctly

flint idol
#

now to find out where it triples

#

without printf

#

while(1) debugging

#

here I go

real pecan
#

nice

flint idol
#

ok it doesn't hang in the smp trampoline

real pecan
#

so later?

flint idol
#

yup

real pecan
#

or u mean doesnt triple fault there

flint idol
#

triple fault yeah

#

it triple faults somewhere during void on_wake(cpu_local* info)

#

or after

real pecan
#

or could be e.g. igpu resetting the cpu because the gpu page table is zeroed-out and you're writing via it by using the BAR

flint idol
real pecan
#

but u should trace it down

real pecan
# flint idol <:thonk:575445129863888896>

basically BAR2 (I think) on igpus is the aperture aka a view into gpu virtual memory, so offset 0 is gpu virtual address 0, and usually the framebuffer u get is just that BAR address, with the actual physical memory used for scanout mapped to GPU virtual 0

#

and writes have to go through it and not to that physical memory directly because it caches stuff internally, so u would only see partial updates otherwise

flint idol
real pecan
#

but its just a guess

flint idol
#

well now I know it hangs somewhere here:

    irql oldIrql = Core_RaiseIrqlNoThread(0xf);
    OBOS_UNUSED(oldIrql);
    Arch_InitializeMiscFeatures();
    // UC UC- WT WB UC WC WT WB
    Arch_RestoreMTRRs();
    wrmsr(0x277, 0x0001040600070406);
    asm volatile("mov %0, %%cr3" : :"r"(getCR3()));
    wbinvd();
    Arch_LAPICInitialize(info->isBSP);
    wrmsr(0xC0000080 /* IA32_EFER */, rdmsr(0xC0000080)|BIT(0));
    Arch_InitializeIDT(false);
    OBOSS_InitializeSyscallInterface();
real pecan
#

is that before _WAK or after

flint idol
#

before

real pecan
#

ah

flint idol
#

_WAK is called right after the arch revives vital state

#

like the scheduler timer

#

idt

#

gdt

#

caching stuffs

real pecan
#

makes sense

flint idol
#

triple faults damn it

#

I'm so used to stuff hanging

#

I default to saying "hangs"

real pecan
#

lmao

flint idol
#

and I need to relearn english grammar

#

or start typing slower than I can think

#

I now know it triple faults somewhere here:

    asm volatile("mov %0, %%cr3" : :"r"(getCR3()));
    wbinvd();
    Arch_LAPICInitialize(info->isBSP);```
#

it's probably initializing the LAPIC

#

it is in LAPIC init

#

it now triple faults somewhere else

#

somewhere here:

    OBOS_Debug("Reinitialized timer for CPU %d.\n", CoreS_GetCPULocalPtr()->id);
    if (info->isBSP)
    {
        OBOS_WokeFromSuspend = true;
        Core_SuspendScheduler(false);
    }```
#

it's after the scheduler was unsuspended

devout niche
#

that's what they do in south africa

real pecan
#

Lol

flint idol
#

lol

#

Le brai est une substance noirรขtre pรขteuse et collante obtenue par pyrolyse de matiรจres organiques en conditions anoxiques ou en atmosphรจre trรจs pauvre en oxygรจne

devout niche
real pecan
#

I pushed the fix to the pr btw, rebase just in case @flint idol

flint idol
#

ok

flint idol
#

not yet

#

well it most definitely crashes in here:

CoreS_SwitchToThreadContext(&CoreS_GetCPULocalPtr()->currentThread->context);
#
    if (info->isBSP)
    {
        OBOS_WokeFromSuspend = true;
        Core_SuspendScheduler(false);
    }
    CoreS_SwitchToThreadContext(&CoreS_GetCPULocalPtr()->currentThread->context);```
#

the current thread is not nullptr

#

so the thread context truly was corrupted

real pecan
#

Your ARCH_FLUSH_CACHE is correct right

flint idol
#
#define UACPI_ARCH_FLUSH_CPU_CACHE() asm volatile ("wbinvd")```
#

yes

real pecan
#

Hm

flint idol
#

cr3 is legit

#

in the context frame

#

although I have a idt, so idk why it's triple faulting

real pecan
#

I wonder if you're relying on some cpu or hw state that gets reset

flint idol
#

maybe

#

maybe it triple faults in the thread

#

and not while switching to it

short mortar
#

Is S3 difficult to implement? meme

flint idol
#

S3, no.
Wake from suspend, yes.

#

Getting wake GPEs to work, yes.

real pecan
#

But wake is difficult yes

short mortar
#

Like do I need a GPU driver?

flint idol
#

if you want a framebuffer after wake

#

yes

#

I have a bochs vbe driver for the sole purpose of restoring the framebuffer on wake

real pecan
#

You wake up in real mode and all hw state is reset

flint idol
#

(including most, if not all, PCI state)

#

all devices need to be brought back from the dead

vale nymph
#

scary zombies

short mortar
#

My laptop and desktop both have Navi GPUs

#

Will uDRM manage framebuffers?

flint idol
#

I think

short mortar
#

I have 3 generations/architecturs of AMD GPUs

#

Navi (RX 5700 XT, 780M), GCN (HD 7850) and whatever there was before that (in 3 PCs)

real pecan
short mortar
#

Do you accept contributions to uDRM?
I have no idea how this stuff works, but...

torpid wigeon
devout niche
#

we are all eager to see what will happen with uDRM

torpid wigeon
#

i'm waiting on headers meme

devout niche
#

Your Digital Rights Management Solution

#

maybe i should do uStorPort

real pecan
haughty abyss
#

why do uStorPort when you can have uDisk meme

flint idol
#

uBtrFs

#

uExt4

thick jolt
#

ustar is like the easier thing to get working

flint idol
thick jolt
#

ustor?

#

what is a ustor

flint idol
#

That's a hard disk driver

thick jolt
#

huh

#

my brain is confused

#

how does the word ustor have anything to do with disk drives

flint idol
#

Search StorPort

thick jolt
#

for things like nvme

#

oh okay

lean glen
#

for disks

#

it's fairly simple to use them in a hobby os

thick jolt
#

yea i see

#

wait wha

#

u can use them in hobby oses?

#

????????????

#

microsoft pulling a W??

lean glen
#

if you implement a shim yea

#

it's not intended by microsoft

#

it wasnt made for hobby OSes

thick jolt
lean glen
#

but their nature makes it easy to just add a shim layer

thick jolt
#

?

lean glen
#

glue code

thick jolt
#

oh yea

lean glen
#

that sits between your kernel

#

and the driver

thick jolt
#

since its a sys driver

lean glen
#

so like you need PE loading and some nt functions

thick jolt
#

u probs need a pe loader

#

yea

#

thats be cool

#

tahtd

#

thatd

real pecan
#

in a way microsoft made a ustorport already

vale nymph
#

uvm when

timid elk
#

port it to linux while you're on it as well

#

especially if it's stable

#

imagine btrfs but stable

#

i have been using btrfs for almost 2 years but daily for the last year

#

it fucking loves corruption and it's repair tools are shit

#

fun fact a random weird windows disk recovery utility happens to be able to read btrfs lol and i can almost guarantee their implementation is probably better than actual btrfs

empty kernel
#

btrfs randomly corrupted itself because stupid nvidia made it so my PC couldn't wake from suspend properly

flint idol
#

I just got rid of the uacpi table logs in obos

#

were cluttering the logs

#

thank god the triple fault isn't in the context switching function

#

and I am glad to say that it is somewhere here:

uacpi_prepare_for_wake_from_sleep_state(UACPI_SLEEP_STATE_S3);
UACPI_ARCH_ENABLE_INTERRUPTS();
uacpi_wake_from_sleep_state(UACPI_SLEEP_STATE_S3);```
#

it's when I enable interrupts

#

so I guess my idt is just fucked then

#

wait

#

I wonder if it has anything to do with the PIC

#

theory: on wake-from-suspend I get a bunch of bogus PIC IRQs because the IMR register of the PICs was reset on suspend

real pecan
#

why would that triple fault tho

flint idol
#

idk

thick jolt
#

because I SAID so

flint idol
#

but masking the PIC fixes the triple fault

real pecan
#

ah its probably because u expect an error code to be pushed

flint idol
#

oh yeah right

#

I was able to get it to not triple fault anymore

#

instead it hangs

#

so I need to now use triple fault debugging to find the bug

#

it hangs in uacpi_wake_from_sleep_state(UACPI_SLEEP_STATE_S3);

#

cc @real pecan

real pecan
#

could mean a lot of things

flint idol
#

indeed

#

to make sure you don't forget to release a lock before suspend

#

I will be dumping every single uacpi lock's status

#

then debug from there

#

in theory, all of them are released

#

and it's a bug somewhere else

#

but I don't want to speculate right now, I need to find this bug

real pecan
#

yeah

flint idol
#

first I will make a linked list of mutexes created via uacpi_kernel_create_mutex

flint idol
#

all mutexes were released..

real pecan
#

interesting

#

@flint idol maybe check spinlocks while at it, who knows

flint idol
#

Yeah

real pecan
#

yeah no highly doubt it

#

looked through all possible places

#

probably unrelated to locking

#

is your scheduler online at that point?

flint idol
thick jolt
#

am i a scheduler

#

are YOUJ

#

a scheduler?

real pecan
#

like is it eval_wak?

flint idol
#

Sure

#

I'll test that

real pecan
#

then we'll have to do kernel api triple fault dehanging

flint idol
#

was afk when you asked me to do that

real pecan
#

Im going to bed but lemme know

flint idol
#

sure

#

gn

real pecan
#

Gngn

flint idol
#

uh oh

#

it doesn't get there

#

wait nvm

real pecan
#

Lol

flint idol
#

I forgor to remove one of the triple faults

#

@real pecan it hangs in eval_wak

real pecan
#

Oh well

#

One funny thing we could do is store your real hw tables in obos and override dsdt with your laptops one and just uacpi_table_install ssdts

#

Then it will run this wak when it wakes up

flint idol
#

cursed, but less cursed than whatever the hell I'm doing

#

triple fault debugging

real pecan
#

Its not guaranteed to repro or even work because obviously it would be trying to access non existent hw

flint idol
#

yeah first I'd need to be able to suspend

#

I can't do that in qemu with my laptop's blob

real pecan
#

Suspend should still work

#

It doesnt need real aml

#

Or well

#

We can hack _S3

#

To contain what qemu has

flint idol
#

first I'm going to check what _WAK even does

#

(inb4 nothing and obos is just cursed)

real pecan
#

It does so much shit so gl

#

But you might see something who knows

flint idol
#

ooo

#

it seems to do framebuffer stuffs

real pecan
#

Wdym

flint idol
#

I think it restores the framebuffer

real pecan
#

Oh that's possible yeah

flint idol
#
            Local0 = \_SB.PCI0.LPCB.EC0.IBT1
            If ((\_SB.PCI0.GFX0.TCHE & 0x0100))
            {
                If ((\_SB.IAOE.ITMR == One))
                {
                    If (((Local0 & One) && ((\_SB.IAOE.WKRS & 0x02) || (
                        \_SB.IAOE.WKRS & 0x10))))
                    {
                        \_SB.PCI0.GFX0.STAT = ((\_SB.PCI0.GFX0.STAT & 0xFFFFFFFC) | One)
                    }
                    Else
                    {
                        \_SB.PCI0.GFX0.STAT = (\_SB.PCI0.GFX0.STAT & 0xFFFFFFFC)
                    }
                }
                ElseIf (CondRefOf (\_SB.PCI0.LPCB.EC0.IBT1))
                {
                    Local0 = \_SB.PCI0.LPCB.EC0.IBT1
                    If (((Local0 & One) && ((\_SB.IAOE.WKRS & 0x02) || (
                        \_SB.IAOE.WKRS & 0x10))))
                    {
                        \_SB.PCI0.GFX0.STAT = ((\_SB.PCI0.GFX0.STAT & 0xFFFFFFFC) | One)
                    }
                    Else
                    {
                        \_SB.PCI0.GFX0.STAT = (\_SB.PCI0.GFX0.STAT & 0xFFFFFFFC)
                    }
                }
            }```
#

judging by GFX0

real pecan
#

Yeah maybe

#

Is your pci restored at this point?

flint idol
#

basic reads/writes would work

#

but no BARs are restored

#

or anything of the like

real pecan
#

Ah yeah thats probably fine

flint idol
real pecan
#

Id hope so

flint idol
#

and not seabios level of stupidity
restoring ECAM using ECAM

real pecan
#

Lmao

flint idol
#

it reads ICNF from a fieldop:

Field (GNVS, AnyAcc, Lock, Preserve)```
#

anding it with 0x10 to do some stuff

real pecan
#

Should work

flint idol
#

and it is set to 0x8

#

so I can skip an entire block

real pecan
#

Ohhhh

#

I might know why

flint idol
#

enlighten me, oh infy

real pecan
#

NVS is non volatile storage

#

Technically firmware expects you to preserve it and then restore

#

That might be why its hanging

#

If you have any ACPI_NVS stuff

flint idol
#

is that what Preserve means here

real pecan
#

Nah that's just field access rule

#

But its called nvs

flint idol
#

mhm

real pecan
#

And u dont preserve nvs

#

Btw I have an idea

flint idol
#

ya

real pecan
#

uacpi_context_set_while_loop_timeout(3)

#

Maybe its spinning waiting for something that will never happen

flint idol
#

wait what does TRAP() do

#

TrapOp

#

saw that in WAK and was curious

real pecan
#

Thats just some method

#

TrapOp is not a thing

flint idol
#

ah

#

it sounded like something to trap into the kernel or smth

real pecan
#

Probably trap into SMM

#

But u can see implementation

#

But anyway I think its related to that if its not a bug because of something else

flint idol
#

it's uacpi_context_set_loop_timeout(3)

real pecan
#

Nvs is supposed to be preserved in s3, Linux suspend to ram impl might give u clues

#

I can take a look tomorrow as well

flint idol
#

but I'll do that

real pecan
#

Try that who knows

#

Or maybe your hpet stops counting

#

So it hangs

flint idol
#

that wasn't it

flint idol
#

that could be it

real pecan
#

Lmao

flint idol
#

I completely forgor to restore hpet state

real pecan
#

๐Ÿ’€

flint idol
#

if it isn't that, it's still a bug you just found for me

real pecan
#

I highly doubt it keeps state after reset

thick jolt
#

๐Ÿ˜ก

flint idol
#

-# ignore

#

hmm should I save the entire HPET state