#uACPI - a portable and easy-to-integrate ACPI implementation

1 messages Ā· Page 17 of 1

frank canopy
#

but it should work

mortal yoke
#

maybe there could be an environment variable that would allow overriding the flags (that the kernel would then set in eg. .cargo/config.toml if it wants to override them)

#

then if you want to use msvc for some reason you would set that to whatever flags you use for your kernel

rustic compass
frank canopy
#

so there is a /kernel flag for msvc

#

but thats for windows kernel modules so like idk

#

my recommendation is to just install mingw clang or llvm in general

#

and use that

rustic compass
#

depending on how fast i can find the flags msvc wants compared to the installation of clang for win11, it will decide if uacpi-rs will support msvc as a compiler

frank canopy
#

/link /NODEFAULTLIB outta be equiv-ish for nostdlib

fiery turtle
#

khitiara solo saving uacpi-rs on MSVC LULW

#

the MVP

frank canopy
#

general regs only is included in /kernel

rustic compass
#

3 flags to go

frank canopy
#

and i dont think the stack protector exists on the ms callconvs but im not 100% sure so still looking

#

also the /link stuff has to be at the end

#

/link means everything afterwards gets appended to the linker command line

#

ok yeah afaict the stack protector/red zone/whatever you call it isnt a thing on the windows calling convention so that flag isnt relevant

fiery turtle
#

yea

frank canopy
#

so i think /kernel /link /NODEFAULTLIB oughtta work?

#

try it and let us know ig

#

as long as the link nodefaultlib part is at the end of the command line

#

there can be nothing after it

fiery turtle
#

some things people recommend

frank canopy
#

unless you have a separate linker command line thing, in which case put /NODEFAULTLIB on the linker command line

fiery turtle
#

GS- disables stack probing i think

frank canopy
#

Zi is debugging info

#

Oi generates intrinsics equiv to the __builtin stuff

#

the s after EH enables c++ throw/catch and the c after EH puts nothrow on extern "C" by default

#

yep /GS- is your -fno-stack-protector ig

#

and `/c compiles without linking

#

base is your base virt addr, entry is your entry point, and debug full is obvious on the linker command line there

fiery turtle
#

so i geuss we need /GS- and /EHsh

frank canopy
#

and subsystem:native is "Kernel mode drivers for Windows NT" so yeah that one is right

#

idk about the EHsh tbh depends on if youve got c++ exceptions and stuff

#

also

#

the docs say that any EH option other than /EH- is incompatible with /kernel

fiery turtle
#

ah ok

#

then yeah we can drop it

frank canopy
#

(for reference the other SUBSYSTEM options are windows boot environment, four different efi variants, posix subsystem for windows nt, console where windows gives it a console when you run it, and windows where you dont get a console because you are supposed to be opening win32 windows)

#

also for reference, /kernel disables c++ exceptions, RTTI, and requires the new() and delete() operators to be defined explicitly, does #define _KERNEL_MODE 1, and prevents use of sse avx etc, and passes /KERNEL to the linker which prevents incremental compilation and issues a warning if you link it with an object that wasnt compiled with /kernel

#

interestingly on x86_64 youre allowed to use SSE and SSE2 but still not allowed to use AVX etc, but on 32-bit x86 you cant use any vectorized things

fiery turtle
#

iirc nt has kernel api to use SSE

frank canopy
#

on 64-bit anyway

#

whether you use vectorization in the kernel really comes down to what registers youre willing to deal with saving on interrupts lmao

fiery turtle
#

no what they do is like

xsave()
sse_stuff()
xrstor()
frank canopy
#

ah ok

rustic compass
#

comand line error: name of source file not found

frank canopy
#

now that i got no idea

rustic compass
#

I will try it with clang, if it works then msvc is not supported for now

hasty plinth
#

no chad

#

I'm not strongly tied to my vote there btw, and tbh I dont see myself having any use for the io port versions of thse functions. They're handy hooks to have for access to any resource though (I found the lack of them for pci accesses to be annoying, but possibly thats a design issue on my end) so I'm hesitant to vote for removing just because I dont see a use for them right now.

#

sorry for the late reply btw, crazy time of year nooo

fiery turtle
#

No rush lol

#

Thanks for sharing

rustic compass
#

im getting a shit ton of warnings from uacpi when compiling with clang and it aborts with errors even tho there are none in the log:



#

flags:
.no_default_flags(true)
.remove_flag("-Wall")
.remove_flag("-Wextra")
.flag("-fno-stack-protector")
.flag("-mgeneral-regs-only")
.flag("-nostdlib")
.flag("-ffreestanding");
cc.flag("-mno-red-zone");

north holly
#

to me those look like errors

rustic compass
#

missed thosenooo

north holly
#
125:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
149:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
173:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
197:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
221:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
245:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5: error: expected '}' 
263:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5: error: expected '}' 
281:warning: [email protected]: 7 errors generated.```
#

that's the log with numbers

#

line numbers

#

of where in the log it happened

#

I need to relearn english

rustic compass
#

now the question is are these errors caused by cc or did i use a broken commit?

left orbit
#

did the CI pass on this commit?

#

also show the actual file it errors out on

#

maybe it's partially written or corrupted

rustic compass
north holly
#

compiled for me

rustic compass
#

I will reclone the repository and try again once I'm back home

north holly
#

using clang-19, uacpi compiled

rustic compass
#

Well what clang do I get when installing it via vs22?

north holly
#

idk check

#

use the vs command prompt

#

and do clang --version

#

clang-19 is latest afaik

rustic compass
#

Are you aware of a clang version that will definitely not work with uacpi?

north holly
#

clang-20 hasn't been released afaict

left orbit
#

i don't think clang-cl does llvm 19 yet

#

but i might be wrong

north holly
left orbit
#

llvm 20 isn't released yet

rustic compass
#

I used clang not clang-cl as clang-cl showed the same behavior to the c flags as msvc

north holly
#

it hasn't been released

#

yeah

fiery turtle
left orbit
#

how do you know šŸ’€

#

ah

#

i see

#

i blind ā˜ ļø

fiery turtle
#

basically clicking on green checkmark

winter orbit
#

lol I should add windows 10 to the uACPI leader board

#

Would that mean

fiery turtle
#

Lmao sure that would be hilarious

winter orbit
#

goal for the day established

fiery turtle
#

Do you somehow route all gpes and stuff to windows 10 code as well or how do these bindings even work

#

Since its acpi driver probably has very specific APIs

#

Or e.g. _CRS

winter orbit
#

There’s a massive private dispatch table between HAL,
The PPM part of Hal

And pci essentially

do you know how we describe windows as a hybrid kernel usually

#

This isn’t FULLY true

#

there’s a thing called NTOS CORE,

ACPI, PCI,
HAL, ntoskrnl are a ā€œkernelā€

#

It being separate files is only spelt of the story since a bunch of ACPI logic is shared between all 4 components, and vice Versa etc etc

fiery turtle
#

So how does it interface with acpi.sys?

winter orbit
#

You have 3 parts to it I’ll see if I can get all of
Them into some links

#

Hang on..

fiery turtle
#

Im curious how u can even convert uacpi specific structs to stuff it expects to get

winter orbit
#

it’s not a super easy plug in

fiery turtle
#

I suspected as much lol

winter orbit
#

Search ACPI on this site

fiery turtle
#

These are like structs and exports it expects?

winter orbit
#

And a lot more

#

The two above are windows 2003

#

NOT what we’re doing

fiery turtle
#

Interesting

#

So you implemented literally all of those to make uacpi work with windows 10?

winter orbit
#

A lot more than this

#

I’m just at fire stone

#

So I can’t show you my versions of the dispatch tables

#

But it’s 10
Times bigger

fiery turtle
#

Can it run with some of them unimplemeted?

winter orbit
#

yup it can

fiery turtle
#

How does that work?

fiery turtle
winter orbit
#

it’s a tire store im getting an alignment done on my car

fiery turtle
#

Ah

winter orbit
fiery turtle
#

Does it need a way to evaluate arbitrary aml?

winter orbit
#

ACPI.sys is supposed to handled it all internally

fiery turtle
#

Ohh I see

#

So all u get is abstracted away helpers?

#

Im curious about how it abstracts all resources that devices consume

winter orbit
#

yeah that’s how modern windows is architected atm

now this hasn’t ALWAYS been the case

#

Windows ACPI/Pci/hal has gone through a lot of changes

#

I basically am just choosing 2 versions for now and conforming to that

#

Vista and 10 1607

fiery turtle
#

What are the differences between them?

#

And which will reactos ship with

#

And which one does it work with now

winter orbit
#

my plan currently is to make it act like vista OOTB and add some preprocessor options to enable the 1607 capabilitiy

#

there’s a few reasons for this

#

But mostly it comes down to us trying to move our kernel to act like vista, and I want to be able to inject our pci and ACPI into vista when needed

#

And then windows 10 is just better for.. many reasons

#

Just to be clear ACPI.sys and Hal have been rewritten like 16 times I think

#

May be more.. I counted at least 16

#

If I had to guess ACPI is written when engineers from bios vendors get contracted out to MS

#

Which happens every few years

#

anyway the other reason is vista ACPI is primitive as hell

fiery turtle
#

Interesting

#

I wonder how it implements the ec driver for example

#

And device notifications

winter orbit
#

Po is what handles device notifications.

fiery turtle
#

Given it has to be this abstraction

winter orbit
#

I can show you this actually

fiery turtle
winter orbit
#
GitHub

Purpose
This PR is an attempt to resuscitate the Composite Battery driver which is broken, barely usable and it even asserts the kernel because it improperly uses a function with incorrect paramete...

GitHub

ReactOS lacks on any fundamental power management mechanisms in the kernel. We do not have power policies support, no power action functions, battery support is inexistent, we do not implement hibe...

#

Depends on the device but most of the time yeah

fiery turtle
#

12k lines lol

winter orbit
#

You register a notification with Po and then you register a handler with either the device driver or generic

#

and yup that’s just the start

fiery turtle
#

Thanks ill take a look

winter orbit
#

Our Po is being designed off modern windows so you can guarantee it’s close to what’s happening now in win11 :)

fiery turtle
#

Would be cool to have a full win10 compatible implementation for regression testing etc

loud ice
#

what is Po?

#

power?

winter orbit
#

Power management subsystem

loud ice
#

shouldnt it be like Pwr

winter orbit
fiery turtle
winter orbit
#

Power Object

fiery turtle
#

Then I guess id have to load it as a driver somehow

winter orbit
#

ObO

loud ice
#

ObO?

winter orbit
#

object management Object

#

this is shitty inconsistent naming schemes we shouldn’t be mimicking

#

but all of the functions are PoDoSomeShit

fiery turtle
winter orbit
#

stdcall PoRegisterDeviceForIdleDetection(ptr long long long)
@ stdcall PoRegisterDeviceNotify(ptr long long long ptr ptr)
@ stdcall PoRegisterSystemState(ptr long)
@ stdcall PoRequestPowerIrp(ptr long long ptr ptr ptr)
@ stdcall PoRequestShutdownEvent(ptr)

loud ice
#

is any of this stable?

#

ah wonderful

#

yes

winter orbit
#

not yet this is what I’ve been doing

north holly
winter orbit
#

I’m rewriting a bunch of PCI HAL and all of ACPI

Po is getting stable

winter orbit
#

Spec files

#

It’s a wine thing

loud ice
#

ah

#

huh

fiery turtle
winter orbit
#

by the way

#

All of this is the root cause of our driver instability

loud ice
winter orbit
#

no

loud ice
#

it sounds like it should be POwer

winter orbit
#

I believe it

loud ice
#

which is why pwr would make more sense

#

but otoh

#

they also have Zw

#

which doesnt stand for anything clearly

#

right?

winter orbit
#

no clue I’m not actually a big fan of Mimicking MS as much as the other devs

#

If Zw stands for something I’ll eat my shoe

loud ice
#

yeah no meaning

#

its to avoid conflict with other symbols or something

north holly
winter orbit
#

oh snap

loud ice
#

ZavoidingconflictWithothercode

#

:^)

north holly
winter orbit
#

ZwINeedANap

winter orbit
north holly
loud ice
#

so its a fake api clearly

#

you lied

winter orbit
#

Exposed

loud ice
#

yeah

#

busted

north holly
#

ZwIAmInMyBedRn

#

ZwItIsOnly3PM

winter orbit
#

Wait till the ROS prefix comes into play

#

I have tons of those in my modern video driver work

north holly
#

ZwIShouldNotBeThisTired

#

@fiery turtle is there a way to integrate uacpi in my brain so I can call _WAK and wake up

fiery turtle
#

yes

#

implement kernel api.h

north holly
#

Ok

fiery turtle
#

how good is your brains aml

north holly
#

Like server hardware

#

Aml

#

Well tested

winter orbit
#

lmao

north holly
#

Except uacpi just pfed

#

In my brain

#

Damn it memory corruption

winter orbit
#

I should see if uACPI blows up in my dell server

#

and get a dump from it and PR it to that repo

north holly
#

And see if that fixes the buf

#

*bug

fiery turtle
#

but would be nice if u tried

winter orbit
#

very cool

winter orbit
#

I have 400 devices

#

I wonder how many I can add

#

Want to see my hardware testing cart

fiery turtle
#

wait what

#

how

north holly
#

Test obos on them

#

Inb4 crashes on 399/400

fiery turtle
#

403/400

winter orbit
fiery turtle
#

daamn

#

is this just hobby or why do u have so many

dusky glade
#

please

north holly
#

It crashes on all

fiery turtle
#

inb4 it kills them all

north holly
#

We already know the answer

winter orbit
#

I’m trying to fix reactos

north holly
#

Obos crashing in the EC driver on his hardware

winter orbit
#

And I work as a bios dev

north holly
#

Infy has said some stuff about firmware devs

winter orbit
#

He’s right

fiery turtle
#

does it boot on all?

#

i mean reactos

winter orbit
#

yeah as of a couple months ago

dusky glade
#

NUH UH

fiery turtle
north holly
#

#1217009725711847465 message

fiery turtle
#

do u write aml at work meme

winter orbit
#

I have like 6 of these carts

winter orbit
north holly
#

#schedulers message

winter orbit
#

My position is a UEFI Innovation Engineer

fiery turtle
#

lmao

winter orbit
#

I do a lot of things

fiery turtle
north holly
fiery turtle
#

so mostly uefi-related work?

winter orbit
winter orbit
#

I have never seen anything conform to UEFI and ACPI spec perfectly

fiery turtle
#

very true

winter orbit
#

driver#### is the most broken thing ever

fiery turtle
#

what is that?

north holly
#

#1141057599584878645 message

winter orbit
#

do you know what boot#### is

fiery turtle
#

nope

north holly
#

retarbios

winter orbit
#

Uh think of it like a list of allowed, and ordered boot options

#

Driver#### is that for driver options

fiery turtle
#

is this like a spec, an app, or what?

winter orbit
#

hang on

#

This one

fiery turtle
#

ah that one

winter orbit
#

Each load option entry resides in a Boot####, Driver####, SysPrep####, OsRecovery#### or PlatformRecovery#### variable where #### is replaced by a unique option number in printable hexadecimal representation using the digits 0-9, and the upper case versions of the characters A-F (0000-FFFF).

fiery turtle
#

why is it broken?

winter orbit
#

Well on Intel AMI bioses you can replace one of them with zeros and brick your system forever

loud ice
#

im guessing people dont implement it correctly

winter orbit
#

most systems have it so it kills itself after the first boot of it existing

loud ice
#

lmfao

winter orbit
#

I got a lot of horror stories

fiery turtle
#

why does that happen

loud ice
#

does a cmos reset not fix it?

winter orbit
#

nah

loud ice
#

holy shit

winter orbit
#

AMI thinks cmos is old people

#

let’s store my uefi boot### into permissible storage

#

or wait here’s a good one

north holly
#

you mean this stuff?

loud ice
#

yeah but you can still reset efivars i thought?

fiery turtle
#

why does removing it brick the system?

winter orbit
#

dunno I work at phoenix not AMI I won’t investigate it for them for free

winter orbit
fiery turtle
#

lol

winter orbit
#

Firmware vendors wipe ass with spec

north holly
#

wow even firmware devs hate firmware devs

winter orbit
#

I do hate firmware devs

#

They’re evil

#

Anyway insyde is the best bios

#

Phoenix is okay most of the time but the latest thinkpads suck

north holly
winter orbit
#

no I work at phoenix

#

we admit our flaws

#

Insyde rocks

north holly
#

you guys admit your flaws inside of rocks /j

winter orbit
#

Only then will a true bios be made

north holly
#

once infy qwinci and I found a bug with seabios where they would restore ECAM with ECAM after resume from S3

winter orbit
#

lol

torpid ferry
winter orbit
#

You should dump the HII database from any AMD laptop

#

It’s a hilarious

winter orbit
#

Is it a book 3?

winter orbit
#

Or any of that stupid line

winter orbit
north holly
#

not that I have an amd laptop

north holly
torpid ferry
winter orbit
winter orbit
north holly
winter orbit
#

You should put it to rest

#

My contract super loose about what I’m allowed to talk about. That’s why I can say these funny things.

#

But there are a few things I can’t say

torpid ferry
winter orbit
#

That’s insanely long for a bomb

torpid ferry
#

had a tiny ass battery, like 46wh, for a 17.6 inch monster

winter orbit
#

I have a Samsung book 3

north holly
#

phoneix

#

or wait

#

brain fart

winter orbit
#

Only for a couple lines

#

I mean, pick up a ThinkPad and look at who made the bios

north holly
#

I've an ideapad

winter orbit
#

That’s not us

#

That has a secret menu by the way

#

With funny options

#

You should unlock it

torpid ferry
#

acer has one too

north holly
torpid ferry
#

quite hilarious as you have to press a konami code ass sequence to unlock it

#

and you need it to even enable svm on cpus that support it

winter orbit
north holly
#

my laptop's bios is InsydeH20

winter orbit
#

yes insyde let’s goooo

kindred beacon
north holly
#

but I can't for the life of me find the secret bios menu

winter orbit
#

Managarm crashes less

loud ice
#

you sure

winter orbit
#

yeah

loud ice
#

doubtful

#

assertos crashes a lot too afaik

winter orbit
#

I mean oh no we’re getting so much better dw we don’t crash as much

north holly
#

damn it

#

there is something I can run

#

but it's windows only

#

not that I trust it anyway

winter orbit
#

damn

loud ice
#

the binaries are gone

#

so

#

🤷

left orbit
#

it's just setting an efi variable {6ACCE65D-DA35-4B39-B64B-5ED927A7DC7E}

winter orbit
#

we love that

north holly
#

hmm setting random EFI variables

#

how safe

winter orbit
#

lol

north holly
#

(I'll pass)

winter orbit
#

It’ll be fineeee

left orbit
#
pBuffer = 1;
strcpy(Guid, "{6ACCE65D-DA35-4B39-B64B-5ED927A7DC7E}");
strcpy(Name, "cE!");
if ( GetFirmwareEnvironmentVariableA(Name, Guid, &pBuffer, 1u) )
{
  sub_140001020("Locking\n");
  v4 = 0;
}
else
{
  pBuffer = 1;
  sub_140001020("Unlocking\n");
  v4 = 1;
}
if ( SetFirmwareEnvironmentVariableA(Name, Guid, &pBuffer, v4) )
{
  sub_140001020("Success\n");
}```
#

decompiled

#

not sure how that works

winter orbit
#

If you can do it from windows it’s probs pretty safe

#

but then again

#

Fw vendors are dumb

left orbit
#

poking random efi variables is probably never safe

#

lmao

#

knowing vendors yeah

winter orbit
#

Don’t trust firmware devs

#

We’re all evil

left orbit
#

rm -rf /sys/firmware/efi/efivars

winter orbit
#

We take an ancient oath to never conform to the spec properly

left orbit
#

go see if ur hw vendor is retarded

winter orbit
#

no better

#

Replace all data portions with zero

left orbit
#

(dont, or do, but i am not responsible for ur hardware meme)

north holly
winter orbit
#

it is

mortal yoke
#

just modify the bios

left orbit
#

oh yeah it absolutely is

winter orbit
#

uACPI become ā€œfw-retardā€ channel

left orbit
#

what's even more retarded is that there is a 50% chance that this will brick ur motherboard

winter orbit
#

I bet you it’s more than 50%

mortal yoke
#

and garbo laptops likely have no good way of emergency flashing a bios lol

winter orbit
#

Nothing made in the last 10 years will survive that

north holly
#

this was made 11 years ago

winter orbit
#

listen buddy

left orbit
#

or whatever interface modern laptops use anyway

north holly
#

EC

winter orbit
mortal yoke
#

thankfully on desktop mobos its pretty common for them to have a dedicated flasher chip on-board that can flash the bios from an usb

#

(on decent ones at least)

left orbit
#

yeah but the firmware chip

#

is probably not the ec

#

or part of it

loud ice
#

imagine not having CCD meme

#

(cros_ec lets you reflash the bios via special usb afaik)

north holly
#

I wonder what "reboot to setup mode" does

#

in my bios

#

it says it clears pk

#

disables secure boot

left orbit
#

enters tpm setup mode?

north holly
#

and enters setup boot

north holly
winter orbit
#

Probably bricks it too

north holly
#

only one way to find out /j

#

it's tempting

winter orbit
#

randomly resetting shit has never gone wrong

mortal yoke
#

also one thing I don't like is that fw vendors are always hiding the fun options

loud ice
#

yeah

winter orbit
#

they never hide it very well

#

More people need to read the HII spec

mortal yoke
winter orbit
#

Steam deck definitely isn’t hiding funny things beneath surface

#

It is definitely not hiding the funniest thing ever

#

Zero funny things in steam deck

winter orbit
#

those who know

north holly
#

mango mango?

mortal yoke
#

just throw your bios to uefi editor and look what menus they hide and make them accessible

winter orbit
#

Uefi easy patcher . Exe

mortal yoke
#

thankfully its not exe lol

slim panther
#

.EFI

mortal yoke
#

(instead its a website)

#

anyway this isn't related to uacpi anymore

north holly
winter orbit
#

no

#

wait maybe in the past

north holly
#

2013

winter orbit
#

I doubt it

mortal yoke
#

my acer has insyde and its garbage

winter orbit
#

nooo insyde my poster child

#

:(

torpid ferry
#

somehow the most uefi compliant machine i have is a lumia

hollow elm
torpid ferry
#

i use it to ssh into it since i only bring my tablet to uni

flat badge
#

I'm surprised that you can set a laptop's wifi to ap mode

#

Iirc i tried it on the raspi4 and it didn't work

#

Although it works on some intel chipset that i have

torpid ferry
#

works on all of my machines

flat badge
#

Ah nvm the issue was not ap mode but attaching the wifi to a bridge

#

Some wifi firmware / hardware refuses to send packets with mac address != the wifi adapter's mac address

pine leaf
#

everything I've seen from the past 10 years is either AMI or Insyde

calm latch
#

My laptop has Phoenix bios

#

Made in 2023

vast kestrel
#

AMI master race

#

All my hardware has AMI

calm latch
#

I think my parents' old laptop also has Phoenix

rustic compass
# left orbit also show the actual file it errors out on
opcodes.c
14| static const struct uacpi_op_spec opcode_table[0x100] = {
15|    UACPI_ENUMERATE_OPCODES  //<<Erros on first char
16| };

18|static const struct uacpi_op_spec ext_opcode_table[] = {
19|    UACPI_ENUMERATE_EXT_OPCODES  //<<Erros on first char
20|};
#

lines 14-20

#

clang version is 18.1.8

#

@fiery turtle clang complains about this code with these error messages:

125:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
149:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
173:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
197:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
221:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:5: error: expected '}' 
245:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5: error: expected '}' 
263:warning: [email protected]: C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5: error: expected '}' 
281:warning: [email protected]: 7 errors generated.
hollow elm
#

can you post the preprocessed source code?

#

copy the clang command, add -E and change the -o ... to point to a different file

rustic compass
#

where do i have to add the -E?

hollow elm
#

to the clang command used to compile the opcodes.o file

rustic compass
#
Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\Llvm\\bin\\clang.exe" "-I" "C:\\Users\\juven\\SynologyDrive\\uacpi-rs\\uacpi-sys\\uacpi-src/include" "-Wall" "-Wextra" "-fno-stack-protector" "-mgeneral-regs-only" "-nostdlib" "-ffreestanding" "-mno-red-zone" "-DUACPI_SIZED_FREES=1" "-o" "C:\\Users\\juven\\Desktop\\9b5d1a837e7b6553-opcodes.o" "-c" "C:\\Users\\juven\\SynologyDrive\\uacpi-rs\\uacpi-sys\\uacpi-src/source/opcodes.c

where exactly do i need to add -E, or can i just append it?

hollow elm
#

it can go wherever, just change the path after -o to something else as well

rustic compass
#

i hate windows so much

#

cc can execute the compiler invocation command just fine but when i do it in powershell it breaks and complains about too many arguments

fiery turtle
#

If it works on MSVC no way it breaks on clang

rustic compass
#

i now got it

#
.\clang.exe -I "C:\\Users\\juven\\SynologyDrive\\uacpi-rs\\uacpi-sys\\uacpi-src/include" -Wall -Wextra -fno-stack-protector -mgeneral-regs-only -E -nostdlib -ffreestanding -mno-red-zone -DUACPI_SIZED_FREES=1 -o "C:\\Users\\juven\\Desktop\\9b5d1a837e7b6553-opcodes.o" -c "C:\\Users\\juven\\SynologyDrive\\uacpi-rs\\uacpi-sys\\uacpi-src/source/opcodes.c"
rustic compass
#

which didnt help much

fiery turtle
#

Iirc it compiles on apple clang for Mac os ci

#

So that works at least

hollow elm
#

well managarm's kernel is compiled with clang so

rustic compass
north holly
rustic compass
#

i hope you guys find the error, i will go to bed now and install clang standalone tomorrow if the error cant be found

#

and if that doesnt work i will compile uacpi by hand because apparently clang doesnt have a problem then

hollow elm
#

hmm i can reproduce this locally meme ```
qookie@selenium /tmp Ī» clang 9b5d1a837e7b6553-opcodes.c -c -o foo.o -m32 -std=c23 -target x86_64-win32
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:28656: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:28543: note: to match this '{'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:29052: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:28939: note: to match this '{'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:29448: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:29335: note: to match this '{'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:29843: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:29730: note: to match this '{'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:30490: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:15:30377: note: to match this '{'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5193: error: expected '}'
C:\Users\juven\SynologyDrive\uacpi-rs\uacpi-sys\uacpi-src/source/opcodes.c:19:5111: note: to match this '{'
7 errors generated.

hollow elm
#

the file is preprocessed

fiery turtle
#

Ah

#

Any ideas what it doesn't like and why it works everywhere else?

slim panther
hollow elm
#

just rename .o to .c

slim panther
#

same line nums?

hollow elm
#

yeah i didn't edit the file

hollow elm
slim panther
#

these line nubers make 0 sense

hollow elm
#

static const struct uacpi_op_spec ext_opcode_table[] = {
    { "ReservedExtOp", .decode_ops = { UACPI_PARSE_OP_BAD_OPCODE, }
fiery turtle
#

Thats one long line

hollow elm
#

UACPI_PARSE_OP_BAD_OPCODE should've been replaced by the define's value

slim panther
#

is that not an enum

fiery turtle
hollow elm
#

oh is it?

slim panther
#

uacpi_parse_op

hollow elm
#

so it is

#

why is it all uppercase then meme

slim panther
#

^

#

coding style L

fiery turtle
#

Like literally every uacpi enum

#

Id make it lower if it was scoped like c++

hollow elm
#

fair enough

vast kestrel
#

It's pretty common to use uppercase for enums as well

hollow elm
slim panther
#

šŸ’€

#

hell naw

hollow elm
#

opcodes.c line 15 is at line 1366 in the preprocessed file

fiery turtle
hollow elm
slim panther
#

forgor

hollow elm
#

there's a comma missing here

#

!!!

slim panther
#

!!!!!!!!!!!!!!!

hollow elm
#

!!!

fiery turtle
#

Wait but how does it still compile

#

I think it got preprocessed incorrectly

#

Any chance its a FieldOp?

hollow elm
#

CreateDWordFieldOp

fiery turtle
#

Yup

#
#define UACPI_DO_BUILD_BUFFER_FIELD_OP(type, code, node_idx, ...)     \
UACPI_OP(                                                             \
    type##FieldOp, code,                                              \
    {                                                                 \
        UACPI_PARSE_OP_TERM_ARG_UNWRAP_INTERNAL,                      \
        UACPI_PARSE_OP_TYPECHECK, UACPI_OBJECT_BUFFER,                \
        UACPI_PARSE_OP_OPERAND,                                       \
        __VA_ARGS__                                                   \
        UACPI_PARSE_OP_CREATE_NAMESTRING_OR_NULL_IF_LOAD,             \
        UACPI_PARSE_OP_SKIP_WITH_WARN_IF_NULL, node_idx,              \
        UACPI_PARSE_OP_OBJECT_ALLOC_TYPED, UACPI_OBJECT_BUFFER_FIELD, \
        UACPI_PARSE_OP_INVOKE_HANDLER,                                \
        UACPI_PARSE_OP_INSTALL_NAMESPACE_NODE, node_idx,              \
    }                                                                 \
)
#

va args removes the comma

hollow elm
#

trolled

slim panther
#

##__VA_ARGS__ meme

hollow elm
#

__VA_OPT__(,) :^)

fiery turtle
#

but its not optional in this case right

hollow elm
#

ah true

fiery turtle
#
UACPI_DO_BUILD_BUFFER_FIELD_OP(                             \
    Create, UACPI_EXT_OP(0x13), 3,                          \
    UACPI_PARSE_OP_OPERAND,                                 \
)                                                           \
#

one example

#

i guess that last comma gets stripped

#

is it possible c23 has something to do with that

hollow elm
#

add a comma after __VA_ARGS__?

fiery turtle
#

that will break every other compiler no?

hollow elm
#

and i only have the preprocessed one so

fiery turtle
#

like that would fix your version of clang

#

but break other versions i guess

#

because it would be UACPI_PARSE_OP_OPERAND,,

slim panther
#

how would you even use this?

fiery turtle
#

is there something like negated __VA_OPT__? meme

fiery turtle
slim panther
#

the macro

#

why is it a vararg?

fiery turtle
#

most field ops dont need anything in there

slim panther
#

ah

fiery turtle
#

but this one has an extra opcode inserted in the middle

slim panther
fiery turtle
#

what does this do?

slim panther
#

removes the comma if no vaarg is given

#

you can add a , at the end

fiery turtle
#
--- a/include/uacpi/internal/opcodes.h
+++ b/include/uacpi/internal/opcodes.h
@@ -396,7 +396,7 @@ UACPI_OP(                                                             \
         UACPI_PARSE_OP_TERM_ARG_UNWRAP_INTERNAL,                      \
         UACPI_PARSE_OP_TYPECHECK, UACPI_OBJECT_BUFFER,                \
         UACPI_PARSE_OP_OPERAND,                                       \
-        __VA_ARGS__                                                   \
+        ##__VA_ARGS__,                                                \
         UACPI_PARSE_OP_CREATE_NAMESTRING_OR_NULL_IF_LOAD,             \
         UACPI_PARSE_OP_SKIP_WITH_WARN_IF_NULL, node_idx,              \
         UACPI_PARSE_OP_OBJECT_ALLOC_TYPED, UACPI_OBJECT_BUFFER_FIELD, \
@@ -1146,7 +1146,7 @@ UACPI_OP(                                                   \
 )                                                           \
 UACPI_DO_BUILD_BUFFER_FIELD_OP(                             \
     Create, UACPI_EXT_OP(0x13), 3,                          \
-    UACPI_PARSE_OP_OPERAND,                                 \
+    UACPI_PARSE_OP_OPERAND                                  \
 )                                                           \
 UACPI_OUT_OF_LINE_OP(                                       \
     LoadTableOp, UACPI_EXT_OP(0x1F),                        \
#

this seems to work on MSVC at least

hollow elm
#

god bless the c preprocessor

fiery turtle
#

does it work for u as well qookie?

hollow elm
#

i mean i didn't have any issues either way

#

as i said, i'm only testing the preprocessed file Shinribo posted

fiery turtle
#

ah

fiery turtle
fiery turtle
#

since it works in clang 19 i guess its a temporary regression they had?

hollow elm
#

seems so

fiery turtle
#

it repros for u on clang 18 right

hollow elm
#

could probably dig through github issues to find out

#

managarm has clang 18.1.2 and that works

fiery turtle
#

hmm

hollow elm
#

the failure was on 18.1.8

fiery turtle
#

i guess it was very temporary then

hollow elm
#

so still chance that it's a regression

#

but yeah it was likely fixed

fiery turtle
hollow elm
#

lol

#

i can test locally with clang 19.1.4

fiery turtle
#

yeah u can try compiling the test runner with clang

hollow elm
#

doing that rn

fiery turtle
#

thx

hollow elm
#

that compiles

fiery turtle
#

i guess it was then

hollow elm
#

btw in other news, gcc 15 adds a new warning that triggers for uacpi: ```
/tmp/uACPI/source/namespace.c:24:56: error: initializer-string for array of ā€˜char’ is too long [-Werror=unterminated-string-initialization]
24 | [UACPI_PREDEFINED_NAMESPACE_GPE] = MAKE_PREDEFINED("_GPE"),
| ^~~~~~
/tmp/uACPI/source/namespace.c:17:22: note: in definition of macro ā€˜MAKE_PREDEFINED’
17 | .name.text = name_str,
| ^~~~~~~~

fiery turtle
#

PLS

hollow elm
#

it's crying because there is no space for the null terminator

slim panther
#

šŸ¤“

fiery turtle
#

leave me alone compilers crywojak

hollow elm
#

i mean it's a good warning in general, uncovered some bugs in leenocks iirc

fiery turtle
#

yes

#

ig

slim panther
#

is this because an int cast of a string?

fiery turtle
#

its a char[4]

slim panther
#

šŸ—æ

fiery turtle
#

assigned a char[5]

hollow elm
#

no, it's because text is char[4] but "_GPE" is char[5]

slim panther
#

{'_', 'G', 'P', 'E'}

fiery turtle
#

\0

mortal yoke
#

or just make it a char[5]

fiery turtle
#

it's a uacpi_object_name struct so i can quickly type pun to ints

#

aligned on a 32-bit boundary

hollow elm
#

#pragma GCC diagnostic ignored "-Wunterminated-string-initialization" meme

mortal yoke
fiery turtle
#

so u32 vs u32 cmp

#

instead of memcmp etc

slim panther
#
union trolling {
    char fuck[4];
    uint32_t you;
};
mortal yoke
#

pretty sure the compiler would optimize that out anyway

fiery turtle
#

it cant unless there's an alignment guarantee

#

also not unless people define it to __builtin_memcmp

#

also memcmp is like harder to type out lol

mortal yoke
#

bruh

fiery turtle
#

if (uacpi_memcmp(node0.name, node1.name, sizeof(node0.name)) == 0)

#

repeat this every time

#

id rather do node0.name.id == node1.name.id

#

and i can quickly check agaisnt constants etc

#

anyway not that important tbh

hollow elm
#

that's not that bad imo

mortal yoke
fiery turtle
#

With built-in or without

kindred beacon
mortal yoke
#

well on arches like x86_64 that unconditionally support it it doesn't depend on march

#

and if the arch doesn't support it and you do it manually its going to be screwed that way too

mortal yoke
#

ah yeah

kindred beacon
#

You sure? Last time I checked march has a bunch of cost factors for different operations, I'd imagine unaligned access being one

mortal yoke
#

well at least when you don't pass any march it optimizes it to just a normal u32 load

#

or with march sandybridge/alderlake

fiery turtle
#

And if u use a custom memcmp

mortal yoke
#

well yeah if you'd not define uacpi memcmp to the builtin one and compile with ffreestanding then it would be slower

#

but there aren't really a lot of reasons to not define them to the builtin ones to let the compiler optimize calls to them

#

anyway I just wanted to see if the compiler would optimize it, you can ofc keep it how it is KEKW

fiery turtle
#

Not a lot of people are well versed in compiler internals

#

And know to use builtins unfortunately

#

Nyaux probably doesn't

mortal yoke
#

lol

kindred beacon
#

The shade

fiery turtle
#

Lmao

#

Nothing personnel kid

left orbit
#

when you call the builtin it emits a call to mem* anyway 90% of the time

#

so it's not even like a "magic" fix, you still need to implement the function

fiery turtle
#

Yeah but its IR so it can optimize cases like we've just discussed

#

And not actually emit a call

left orbit
#

yea i didn't really read it

#

but yeah that's probably the 10% i was talking about

fiery turtle
#

Yeah

#

I mean probably most small compares can be optimized to integer loads

#

So its about the size of the objects you're comparing

calm latch
#

Don't compilers replace calls to those functions with builtins automatically?

slim panther
#

not guaranteed

calm latch
#

I had some fun where my libc would break because GCC would replace calloc with call to itself

#

Which would stack overflow

slim panther
#

fun

fiery turtle
#

Thats a different optimization

#

Recognizing a memcmp and just replacing it with that call

#

Builtins are the other way around, they try to avoid memcmp work entirely and do an ad hoc version

calm latch
#

I think what GCC does is replace memcpy with builtin

#

And functions like that

left orbit
#

if they match the right signature, it probably does

mortal yoke
calm latch
#

I don't

left orbit
#

i would still expect that to happen even in freestanding given the signature is correct

mortal yoke
#

it doesn't happen

#

ffreestanding implies fno-builtin

calm latch
#

And in freestanding you can tell compilers that the functions should be treated as builtins

left orbit
#

ah

calm latch
#

Like the printf attribute

fiery turtle
calm latch
#

I pass -fno-builtins to select c files in my libc

mortal yoke
#

it doesn't make it an actual builtin the compiler can optimize calls to

calm latch
#

Or you can also do macros shit

mortal yoke
#

yeah that works

fiery turtle
calm latch
#

uACPI doesn't call memcpy

#

?

fiery turtle
#

It calls uacpi_memcpy

#

Which is whatever u tell it

calm latch
#

Then there's also loop unrolling I would imagine

#

But idk how well that works

#

"I don't know what I'm doing"

frank canopy
fiery turtle
#

Yeah

frank canopy
#

plus i can make the cast an inline function and then itll evaluate at comptime to let me define actual enum constants

fiery turtle
#

Nice

frank canopy
#

still dont know why ACPI only lets names be four characters long but it sure is convenient for exactly this reason lol

sterile egret
winter orbit
#

Thank you

sterile egret
#

Also...

#

;compile ```c
#include <stdio.h>

int main(int argc, char **argv) {
int value = '\x01\x02\x03\x04';
printf("%x\n", value);
}```

autumn cairnBOT
#
Program Output
1020304
Compiler Output
<source>: In function 'main':
<source>:4:15: warning: multi-character character constant [-Wmultichar]
    4 |   int value = '\x01\x02\x03\x04';
      |               ^~~~~~~~~~~~~~~~~~
sterile egret
#

Multi-character literals are a thing meme

rustic compass
#

Will send the new error log in an hour

torpid root
#

I pulled the latest uacpi and now it deadlocks after

[info] uacpi: enabled 2 GPEs in block _GPE@[0->64]
#

single thread

#

I don't believe it's an issue with my spinlock

#

previous clone was before the leaderboard

rustic compass
#

i rechecked the patch and its exactly what you send me

#

so i dont think i messed up

#

hopefully

fiery turtle
torpid root
#

it's a stub

#

but that shouldn't matter for single thread?

fiery turtle
#

You always run uacpi on one thread?

torpid root
#

well I don't have a scheduler yet lol

fiery turtle
#

Ah

#

Can you check where it deadlocks?

torpid root
#

hmm can't currently

#

maybe in 8 ish hours

fiery turtle
#

Sure

#

But I think it is an issue with your spinlocks or mutexes, currently I think managarm, pmos and obos all use the latest uacpi

torpid root
#

my locks are basically frigg ticket lock

#

I even tried just doing bool is_locked

fiery turtle
#

What are your mutexes

torpid root
fiery turtle
#

Lol

#

Btw that message is like the last thing it ever prints in log during init

torpid root
#

oh lol

fiery turtle
#

How did u deduce that it deadlocks?

torpid root
#

if I don't actually lock in my locks, it continues

fiery turtle
#

It?

torpid root
#

I mean the uacpi function returns and kernel continues fine

fiery turtle
#

Ah so it never returns from that init?

torpid root
#

I don't think so, I haven't checked which function it was, didn't have much time

fiery turtle
#

Its namespace_initialize

#

Anyway lemme know once u do a bit more digging

fiery turtle
#

This version has some sort of regression in macros expansion

#

Or downgrade it works as well

rustic compass
#

apparently vs22 forces clang 18.1.8

left orbit
#

update

#

ur build tools

rustic compass
#

how? i cant select the clang version in vs22

left orbit
#

oh actually the latesat is 18.1.8, you are right

#

also, you can open the visual studio installer and click "update"

#

if there is a newer version it would be downloaded

fiery turtle
#

Bruh did they put a shitty version of clang on purpose so people keep using MSVC

left orbit
#

no

#

llvm has builds for windows

#

and they ship clang-cl

#
C:\Users\hacker>clang-cl --version
clang version 19.1.5
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin```
#

if you need this shit for whatever reason lol

fiery turtle
left orbit
#

i mean realistically the only reason visual studio ships clang-cl is because that's the only way to use an llvm toolchain within visual studio (without cmake), but if you're using rust why are you using visual studio??? and even disregarding that you aren't tied to msbuild, so you can use a proper llvm installation

rustic compass
#

In not using vs22 I'm just using clang from it

left orbit
#

then don't lol

#

the only reason it's there so you can use it with msbuild projects

rustic compass
#

Is there a installer for clang on windows or do I have to compile it from source?

left orbit
#

yeah of course

#

there should be an installer

#

llvm-19.1.6.exe

#

then just add <llvm install path>\bin to your path

gentle peak
fiery turtle
#

Big

frank canopy
#

and imaginarium though my mutexes are still stubbed

rustic compass
left orbit
#

fair, that works too

rustic compass
#

you gonna be shitting me, same errors

#

clang version 19.1.6

#

its using clang.exe from the llvm install and it still breaks

#

is it by any means possible that a certain compile order has to maintained?

fiery turtle
#

Very interesting

#

I'll try to work around once I get to my pc

frank canopy
#

I think I'm technically compiling uacpi via clang on windows but I'm doing it by way of zig cc not directly and I'm not sure if zig includes its own llvm here

fiery turtle
#

Yeah no idea

#

Maybe shinribos pc is just cursed

rustic compass
frank canopy
#

well llvm isnt bundled with zig

#

so yeah im technically compiling uacpi with clang on windows

calm latch
#

wls2?

frank canopy
#

oh wait nvm again it might actually be linked into zig

frank canopy
#

ok yeah i was sorta wrong

#

zig does bundle its own clang/llvm

#

i didnt realise because there arent any big bundles of llvm files in zig's install dir

#

because it seems its statically linked

#

i think anyway, this is deeper into the zig source than ive gone before lol

#

anyway it is clang 19.1.0

#

idk if anyone sees anything i dont that might matter here but yeah

fiery turtle
#

give this a try

calm latch
slow drift
#

what font is that

north holly
#

the one with english letters

slow drift
#

huh

#

is it from uacpi itself

torpid root
fiery turtle
#

the uacpi font

rustic compass
#

now i get a billion rust errors caused by the new uacpi bindingsKEKW

#

but it fucking works now

#

o boy time to write wrappers around 7kloc of bindgen

#

but we have progressletsgo

slim panther
#

@fiery turtle told you meme

#

i know my C preprocessor hacks

rustic compass
#

this was your fault?

slim panther
#

no, i suggested the fix

rustic compass
#

may you have a long and healthy live

fiery turtle
slim panther
#

#1217009725711847465 message

rustic compass
#

@fiery turtle can you commit these fixes to github?

torpid root
#

@fiery turtle this gets stuck, not namespace load

uacpi_install_fixed_event_handler(
    UACPI_FIXED_EVENT_TIMER_STATUS,
    [](uacpi_handle) -> uacpi_interrupt_ret
    {
        timers::acpipm::overflows++;
        return UACPI_INTERRUPT_HANDLED;
    }, nullptr
);
fiery turtle
#

Any chance u get an irq at the same time that tries to acquire the same lock

torpid root
fiery turtle
#

where exactly

fiery turtle
#

it acquries a mutex, does two field writes, then releases it

torpid root
#

yes in the spinlock while loop :(

fiery turtle
#

which

torpid root
#

which?

fiery turtle
#

which function, which spinlock etc

#

give me at least something LULW

torpid root
#

I guess this one: ret = uacpi_recursive_lock_acquire(&g_event_lock);

#

line 2227

fiery turtle
#

thats a mutex

torpid root
#

event.c

torpid root
fiery turtle
#

can u use gdb at least

torpid root
fiery turtle
#

do your uacpi spinlocks disable interrupts?

torpid root
#

yes

fiery turtle
#

apparently not

#

or well

#

that shouldnt matter

#

that spinlock is released right away in that same function

torpid root
fiery turtle
#

is your unlock_spinlock correct THINKAUTISTIC

fiery turtle
#

unrelated to event.c

#
uacpi_status uacpi_write_register_field(
    enum uacpi_register_field field_enum, uacpi_u64 in_value
)
{
    uacpi_status ret;
    uacpi_u8 field_idx = field_enum;
    const struct register_field *field;
    const struct register_spec *reg;
    uacpi_u64 data;
    uacpi_cpu_flags flags;

    if (uacpi_unlikely(field_idx > UACPI_REGISTER_FIELD_MAX))
        return UACPI_STATUS_INVALID_ARGUMENT;

    field = &fields[field_idx];
    reg = &registers[field->reg];

    in_value = (in_value << field->offset) & field->mask;

    flags = uacpi_kernel_lock_spinlock(g_reg_lock);

    if (reg->kind == REGISTER_ACCESS_KIND_WRITE_TO_CLEAR) {
        if (in_value == 0) {
            ret = UACPI_STATUS_OK;
            goto out;
        }

        ret = do_write_register(reg, in_value);
        goto out;
    }

    ret = do_read_register(reg, &data);
    if (uacpi_unlikely_error(ret))
        goto out;

    data &= ~field->mask;
    data |= in_value;

    ret = do_write_register(reg, data);

out:
    uacpi_kernel_unlock_spinlock(g_reg_lock, flags);
    return ret;
}
#

this is where u hang, and this is the only place this spinlock is referenced

torpid root
#

I don't understand this

#

beacause spinlock definitely disables interrupts

fiery turtle
#

i think it doesnt matter whether it does or not

#

auto ticket = _next_ticket.fetch_add(1, std::memory_order_relaxed); wait why is this relaxed

#

relaxed won't produce lock add

#

relaxed just means it guarantees no tearing

#

but two acquires can produce the same ticket in your case

#

i doubt thats the problem here but i think its still a bug

fiery turtle
torpid root
#

no need

#

I found the issue

#

as always, it's my skill problems

fiery turtle
#

what was it?

torpid root
#
auto current = _serving_ticket.load(std::memory_order_relaxed);
_serving_ticket.store(current + 1, std::memory_order_release);
if constexpr (ints)
    arch_unlock();

vs

if constexpr (ints)
    arch_unlock();
auto current = _serving_ticket.load(std::memory_order_relaxed);
_serving_ticket.store(current + 1, std::memory_order_release);
#

I'm sorry

fiery turtle
#

lol

#

npnp

fiery turtle
#

or well its fine as long as you dont have smp

torpid root
#

doesn't matter if it's acquite or not

fiery turtle
#

in your case two threads will end up with the same ticket

#

if i understand relaxed semantics correctly

torpid root
#

hmmm are you sure

fiery turtle
#

relaxed just means a thread wont end up with garbage ticket as a result of other thread doing a partial write

#

which isnt possible on x86

#

so its a no-op

fiery turtle
torpid root
#

because it's still atomic, thread one returns and increments while thread two waits for it to finish doing so

fiery turtle
#

if it isnt a lock; inc then im right

torpid root
#

sure

fiery turtle
hollow elm
#

cc @flat badge because this is the frigg ticket spinlock impl :^)

fiery turtle
#

only this operation

flat badge
#

relaxed still generates lock xadd

fiery turtle
#

hmm u sure?

torpid root
#

yes

fiery turtle
#

i wonder why

flat badge
#

relaxed doesn't mean that it's not atomic

#

just that it's not ordered with other non-atomic accesses

slow drift
torpid root
#

np

fiery turtle
#

hmm well docs dont make it sound like that

flat badge
#

only this operation's atomicity is guaranteed

fiery turtle
#

yes, so u read 1 and write back 2, 2 is stored

flat badge
#

no, that wouldn't be atomic

fiery turtle
#

u dont read or write partial values

#

atomic means it's done as one singular op

hollow elm
#

the whole fetch, modify, write is one atomic op

flat badge
#

a relaxed atomic op is not the same as a non-atomic op

fiery turtle
#

yes

#

non-atomic doesn't guarantee no tearing if an interrupt comes in the middle for example

#

a relaxed atomic does

flat badge
#

fetch_add guarantees in any case:

#

Atomically replaces the current value with the result of arithmetic addition of the value and arg. That is, it performs atomic post-increment. The operation is a read-modify-write operation.

fiery turtle
#

but apparently it also enforces lock in this case

flat badge
#

the memory order is a guarantee on top of that

fiery turtle
#

yeah i guess its just how fetch_add is to prevent foot shooting

flat badge
#

if you want the op that you're describing, you need to do

fiery turtle
#

just relaxed load and relaxed store

flat badge
#
temp = x.load(std::memory_order_relaxed);
x.store(temp + 1, std::memory_order_relaxed);
fiery turtle
#

yeah

flat badge
#

which we actually do use sometimes in managarm

#

but in the context of a mutex, it's true that relaxed ordering would not be enough

#

the reason why it is enough here is that it's followed by a store-release

fiery turtle
#

yea

flat badge
#

Usually you want to restore to the previous state instead of re-enabling them unconditionally in unlock()

fiery turtle
#

wait u dont do that?

flat badge
#

the naive implementation will break if you take two spinlocks at the same time

torpid root
#

yes arch_unlock does that

flat badge
#

ah i see, then that should work

fiery turtle
torpid root
#

circular dependencies

fiery turtle
#

like if (should_reenable) arch_really_unlock()

#

but u store previous state somewhere right

torpid root
fiery turtle
#

hmm

torpid root
#

because arch.cppm -> lib.cppm -> lock.cppm
and arch specific functions are in arch.cppm
so lock.cpp imports it and calls those

fiery turtle
#

I see

#

anyway I just realized uacpi has completely broken event initialization order

#

strange this never caused issues

#

or actually i guess its less bad than i thought but still

#

if there is a global firmware lock contention at namespace load time it will hang forever

#

because the SCI handler is not yet installed at that point

torpid root
#

so this skill issue searching actually resulted in something good?

fiery turtle
#

always spot random stuff when people report issues

torpid root
#

I shall do it more often then

fiery turtle
#

lmao

torpid root
#

jk

fiery turtle
#

if i discover a uacpi bug for every false uacpi bug report its good enough i guess

calm latch
#

The cosmetic issue

fiery turtle
#

nah

fiery turtle
calm latch
#

That it complains about some uninitialized variable

north holly
#

test obos on it lol