[英]Inline Assembly code in VC++ :: help needed on syscall to WaitForSingleObject
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.我已经使用 VC++ 在 VS2019 中编码并使用 Intel C++ 编译器编译,这是一个 64 位命令行音乐文件播放器,可以使用 WASAPI 播放 WAV 文件。 The OS is Win 7-SP1.操作系统是 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);我想替换这行代码: 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:我在 Github 上找到了 Win7-SP1 的系统调用表,下面是它对 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:我认为替换对 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
}
My questions are:我的问题是:
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
__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
}
I just assigned the value of hNeedDataEvent to r10 and it worked.我只是将 hNeedDataEvent 的值分配给 r10 并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.