I have coded in VS2019 using VC++ and compiled using the Intel C++ compiler, a 64 bit command line music file player to play WAV files using WASAPI. The OS is Win 7-SP1.
This is the part of code on which I have questions and need help on. Declaration of variables are left out for conciseness.
// activate an IAudioClient
IAudioClient* pAudioClient;
...
...
// create an event
HANDLE hNeedDataEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// set the event handle
hr = pAudioClient->SetEventHandle(hNeedDataEvent);
...
...
//works fine
do
{
WaitForSingleObject(hNeedDataEvent, INFINITE);
hr = pAudioRenderClient->ReleaseBuffer(nFramesInBuffer, 0);
hr = pAudioRenderClient->GetBuffer(nFramesInBuffer, &pData);
memcpy(pData, sound_buffer + nBytesToSkip, nBytesThisPass);
nBytesToSkip += nBytesThisPass;
} while (--nBuffersPlayed);
I want to replace the line of code: WaitForSingleObject(hNeedDataEvent, INFINITE); with inline Assembly code using a syscall. Portability is unimportant since this is just for experimentation/learning because have no knowledge of Assembler.
I found a syscall table for Win7-SP1 on Github and here's what it says for NtWaitForSingleObject:
; ULONG64 __stdcall NtWaitForSingleObject( ULONG64 arg_01 , ULONG64 arg_02 , ULONG64 arg_03 );
NtWaitForSingleObject PROC STDCALL
mov r10 , rcx
mov eax , 1
;syscall
db 0Fh , 05h
ret
NtWaitForSingleObject ENDP
I think the inline Assembly code to replace the call to WaitForSingleObject should be:
__asm
{
mov r10, ?????? ; pHandle
xor edx, edx ; FALSE: The alert cannot be delivered
xor r8d, r8d ; Time-out interval, in microseconds. NULL means infinite
mov eax, 1 ; code number for WaitForSingleObject
syscall
}
My questions are:
- What exactly do I need to move to r10 so that it will contain the "handle" of the event?
- Is the rest of the inline Assembly code correct?
As an aside, when I disassembled my compiled code I see this:
mov rcx, [rbp+220h+hHandle] ; hHandle
mov edx, 0FFFFFFFFh ; dwMilliseconds
call cs:WaitForSingleObject