Skip to content

Commit

Permalink
Updated atomic functions to avoid fpu instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo720 committed Aug 8, 2024
1 parent 01e6eff commit 8886602
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 1 addition & 3 deletions nboxkrnl/io/hdd/fatx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,8 @@ static NTSTATUS XBOXAPI FatxIrpQueryInformation(PDEVICE_OBJECT DeviceObject, PIR
case FileNetworkOpenInformation: {
PFILE_NETWORK_OPEN_INFORMATION NetworkOpenInformation = (PFILE_NETWORK_OPEN_INFORMATION)Irp->UserBuffer;
// NOTE: FileInfo->LastAccessTime must be read atomically because FatxIrpRead acquires a shared lock, which means it can update it while we are trying to write it here
LARGE_INTEGER LastAccessTime;
atomic_load64(&LastAccessTime.QuadPart, &FileInfo->LastAccessTime.QuadPart);
NetworkOpenInformation->CreationTime = FileInfo->CreationTime;
NetworkOpenInformation->LastAccessTime = LastAccessTime;
NetworkOpenInformation->LastAccessTime.QuadPart = atomic_load64(&FileInfo->LastAccessTime.QuadPart);
NetworkOpenInformation->LastWriteTime = FileInfo->LastWriteTime;
NetworkOpenInformation->ChangeTime = FileInfo->LastWriteTime;
if (FileInfo->Flags & FILE_DIRECTORY_FILE) {
Expand Down
23 changes: 15 additions & 8 deletions nboxkrnl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,25 @@ static inline VOID CDECL disable()
static inline VOID CDECL atomic_store64(LONGLONG *dst, LONGLONG val)
{
__asm {
mov eax, dword ptr [dst]
fild val
fistp qword ptr [eax]
pushfd
cli
}

*dst = val;

__asm popfd
}

static inline VOID CDECL atomic_load64(LONGLONG *dst, LONGLONG *src)
static inline LONGLONG CDECL atomic_load64(LONGLONG *src)
{
__asm {
mov eax, dword ptr [dst]
mov ecx, dword ptr [src]
fild qword ptr [ecx]
fistp qword ptr [eax]
pushfd
cli
}

LONGLONG val = *src;

__asm popfd

return val;
}

0 comments on commit 8886602

Please sign in to comment.