Method Signature
Description
Invokes a syscall by its identifier with type-safe arguments. The method performs a binary search to locate the syscall stub, then executes it with the provided arguments.Template Parameters
The return type of the syscall.Common types:
NTSTATUS- Windows NT status codes (most common)HANDLE- Handle to kernel objectsULONG- Unsigned long integeruintptr_t- Generic pointer-sized integer (default)void- No return value (though syscalls typically return NTSTATUS)
- Returns
STATUS_UNSUCCESSFULif manager is not initialized - Returns
STATUS_PROCEDURE_NOT_FOUNDif syscall is not found
Variadic template parameters matching the syscall’s argument types. Must match the exact types expected by the target syscall.Example:
Parameters
The identifier of the syscall to invoke. Must be created using the
SYSCALL_ID macro.Type notes:- With
SYSCALLS_NO_HASHdefined:SyscallKey_tisstd::string - Without
SYSCALLS_NO_HASH:SyscallKey_tishashing::Hash_t(compile-time hash)
The arguments to pass to the syscall. Must match the syscall’s expected parameter types and count.Arguments are perfectly forwarded to the syscall stub:
Return Value
Returns a value of type
Ret (specified as template parameter).Special return values when Ret is NTSTATUS:STATUS_UNSUCCESSFUL- Manager failed to initialize automaticallySTATUS_PROCEDURE_NOT_FOUND- Syscall identifier not found in parsed syscalls
- Returned if initialization fails or syscall is not found
- For pointer types:
nullptr - For integer types:
0 - For custom types: default constructor result
- Returns the actual result from the syscall execution
Behavior Details
Automatic Initialization
If the manager is not initialized,invoke() automatically calls initialize():
Syscall Lookup
Uses binary search to locate the syscall stub:Stub Execution
Depending on the stub generation policy:-
Direct Policy (
policies::generator::direct)- Executes syscall stub directly
- No additional setup required
-
Gadget Policy (
policies::generator::gadget)- Selects a random gadget from the pool
- Executes syscall via the gadget
-
Exception Policy (
policies::generator::exception)- Sets up exception context guard
- Selects a random gadget (Windows x64) or uses KiFastSystemCall (Windows x86)
- Executes syscall via exception handler
Inlining
The method is markedSYSCALL_FORCE_INLINE to minimize call overhead. The compiler will attempt to inline the entire invocation path for optimal performance.
Thread Safety
Once initialized,invoke() is thread-safe without additional locking:
- The syscall vector is read-only after initialization
- Random gadget selection uses thread-safe
rdtscp()instruction - Exception context guards use thread-local storage
Examples
Basic Syscall Invocation
Memory Allocation
Query System Information
Error Handling
Template Type Deduction
Performance Considerations
- Binary search: O(log n) lookup time, very fast even with hundreds of syscalls
- Inlining: Compiler will inline the method for minimal overhead
- Randomization: Random gadget selection uses fast
rdtscp()instruction - No locks: Once initialized, no synchronization overhead during invocation
Common Pitfalls
Incorrect Argument Types
Missing Pointer Arguments
Not Checking Return Status
See Also
- Manager Overview - Complete Manager class documentation
- Manager Initialization - Details on the
initialize()method - SYSCALL_ID Macro - How to create syscall identifiers
- NT Status Codes - Windows NT status code reference