VC ++中的内联汇编代码::在对WaitForSingleObject的系统调用中需要帮助

问题描述 投票:0回答:1

我已经使用VC ++在VS2019中进行了编码,并使用了Intel C ++编译器进行了编译,这是一个64位命令行音乐文件播放器,可以使用WASAPI播放WAV文件。操作系统是Win 7-SP1。

这是我有疑问并需要帮助的代码部分。为简洁起见,省略了变量的声明。

// 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);

我想替换代码行:WaitForSingleObject(hNeedDataEvent,INFINITE);使用系统调用的内联汇编代码。可移植性并不重要,因为它只用于实验/学习,因为不了解汇编器。

我找到了Win7-SP1 on Github的系统调用表,这就是它对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

我认为用于替换对WaitForSingleObject的调用的内联汇编代码应为:

__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
}

我的问题是:

  1. 我到底需要什么才能移至r10,以便包含事件的“句柄”?
  2. 内联汇编代码的其余部分是否正确?

顺便说一句,当我反汇编我的编译代码时,我看到了:

    mov     rcx, [rbp+220h+hHandle] ; hHandle
    mov     edx, 0FFFFFFFFh ; dwMilliseconds
    call    cs:WaitForSingleObject
winapi visual-c++ x86-64 system-calls inline-assembly
1个回答
0
投票
__asm
{
   mov r10, hNeedDataEvent ; 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
}
© www.soinside.com 2019 - 2024. All rights reserved.