switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.26k stars 167 forks source link

mutex: fix svcArbitrateLock call arguments #620

Closed xerpi closed 1 year ago

xerpi commented 1 year ago

1st (thread handle) and 3rd (tag) arguments were swapped.

fincs commented 1 year ago

https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/source/svc/kern_svc_lock.cpp#L28

The first argument is the handle of the thread that is currently holding the lock, not our own thread handle. The third argument is our own tag. This tag is the value that is supposed to be our own thread handle, which is retrieved a bit earlier: https://github.com/switchbrew/libnx/blob/master/nx/source/kernel/mutex.c#L34C5-L34C38

xerpi commented 1 year ago

https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/source/svc/kern_svc_lock.cpp#L28

The first argument is the handle of the thread that is currently holding the lock, not our own thread handle. The third argument is our own tag. This tag is the value that is supposed to be our own thread handle, which is retrieved a bit earlier: https://github.com/switchbrew/libnx/blob/master/nx/source/kernel/mutex.c#L34C5-L34C38

That makes more sense, thanks for the explanation!