小编fsd*_*kds的帖子

FreeBSD 系统调用比 Linux 破坏更多的寄存器?内联汇编优化级别之间的不同行为

最近我在玩 freebsd 系统调用,我对 i386 部分没有问题,因为它在这里有很好的记录但是我找不到 x86_64 的相同文档。

我看到人们在 linux 上使用相同的方式,但他们只使用程序集而不是 c。我想在我的例子中,系统调用实际上改变了一些被高优化级别使用的寄存器,所以它给出了不同的行为。

/* for SYS_* constants */
#include <sys/syscall.h>

/* for types like size_t */
#include <unistd.h>

ssize_t sys_write(int fd, const void *data, size_t size){
    register long res __asm__("rax");
    register long arg0 __asm__("rdi") = fd;
    register long arg1 __asm__("rsi") = (long)data;
    register long arg2 __asm__("rdx") = size;
    __asm__ __volatile__(
        "syscall"
        : "=r" (res)
        : "0" (SYS_write), "r" (arg0), "r" (arg1), "r" (arg2)
        : "rcx", "r11", "memory"
    ); …
Run Code Online (Sandbox Code Playgroud)

c freebsd x86-64 system-calls inline-assembly

7
推荐指数
1
解决办法
259
查看次数

WaitForMultipleObjects 不会在 Wine 中发出标准输入信号

当标准输入有东西时我想收到信号。下面的代码在 Windows 11 中按预期工作。

在 Windows 11 中,无论你按什么键,都会发出信号,但在 Wine 中,无论你按什么键,都不会发生任何情况。

#include <stdio.h>
#include <windows.h>
#include <io.h>

#ifndef STDIN_FILENO
    #define STDIN_FILENO 0
#endif

int main(){
    HANDLE handles[1];
    handles[0] = (HANDLE)_get_osfhandle(STDIN_FILENO);
    while(1){
        DWORD r = WaitForMultipleObjects(1, handles, FALSE, INFINITE);
        if(r != WAIT_OBJECT_0){
            printf("error WaitForMultipleObjects %d\n", r);
            return 1;
        }
        printf("stdin is triggered\n");
        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么 Wine 的行为与 Windows 11 不同?代码有问题吗?

c windows winapi wine

5
推荐指数
0
解决办法
204
查看次数

标签 统计

c ×2

freebsd ×1

inline-assembly ×1

system-calls ×1

winapi ×1

windows ×1

wine ×1

x86-64 ×1