Skip to content

Commit

Permalink
[NDK] Add Affinity helper inline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tkreuzer committed Dec 3, 2023
1 parent 9ea2222 commit 9615891
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
1 change: 0 additions & 1 deletion ntoskrnl/include/internal/ke.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ extern VOID __cdecl KiInterruptTemplate(VOID);

/* MACROS *************************************************************************/

#define AFFINITY_MASK(ProcessorIndex) ((KAFFINITY)1 << (ProcessorIndex))
#define PRIORITY_MASK(Priority) (1UL << (Priority))

/* Tells us if the Timer or Event is a Syncronization or Notification Object */
Expand Down
48 changes: 48 additions & 0 deletions sdk/include/ndk/kefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,54 @@ extern "C"

#ifndef NTOS_MODE_USER

//
// Affinity helper
//
FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index)
{
ASSERT(Index < sizeof(KAFFINITY) * 8);
return (KAFFINITY)1 << Index;
}
#ifdef _WIN64
FORCEINLINE BOOLEAN BitScanForwardAffinity(PULONG Index, KAFFINITY Mask)
{
return BitScanForward64(Index, Mask);
}
FORCEINLINE BOOLEAN BitScanReverseAffinity(PULONG Index, KAFFINITY Mask)
{
return BitScanReverse64(Index, Mask);
}
FORCEINLINE BOOLEAN InterlockedBitTestAndSetAffinity(volatile KAFFINITY *Affinity, ULONG Index)
{
ASSERT(Index < sizeof(KAFFINITY) * 8);
return InterlockedBitTestAndSet64((PLONG64)Affinity, Index);
}
FORCEINLINE BOOLEAN InterlockedBitTestAndResetAffinity(volatile KAFFINITY *Affinity, ULONG Index)
{
ASSERT(Index < sizeof(KAFFINITY) * 8);
return InterlockedBitTestAndReset64((PLONG64)Affinity, Index);
}
#else
FORCEINLINE BOOLEAN BitScanForwardAffinity(PULONG Index, KAFFINITY Mask)
{
return BitScanForward(Index, Mask);
}
FORCEINLINE BOOLEAN BitScanReverseAffinity(PULONG Index, KAFFINITY Mask)
{
return BitScanReverse(Index, Mask);
}
FORCEINLINE BOOLEAN InterlockedBitTestAndSetAffinity(volatile KAFFINITY *Affinity, ULONG Index)
{
ASSERT(Index < sizeof(KAFFINITY) * 8);
return InterlockedBitTestAndSet((PLONG)Affinity, Index);
}
FORCEINLINE BOOLEAN InterlockedBitTestAndResetAffinity(volatile KAFFINITY *Affinity, ULONG Index)
{
ASSERT(Index < sizeof(KAFFINITY) * 8);
return InterlockedBitTestAndReset((PLONG)Affinity, Index);
}
#endif // _WIN64

//
// APC Functions
//
Expand Down

0 comments on commit 9615891

Please sign in to comment.