gpt4 book ai didi

c - ioperm 无需 root 权限即可工作

转载 作者:行者123 更新时间:2023-11-30 19:00:54 24 4
gpt4 key购买 nike

我读到我们需要 super 用户权限才能从用户空间访问 I/O 端口。但我说的是不同的行为。普通用户下ioperm成功。

#include <stdio.h>
#include <errno.h>
#include <sys/io.h>

int main(int argc, char *argv[])
{
if (!ioperm(0x70, 3, 1)) {
perror("ioperm failed");
}
else {
printf("ioperm on 0x70 success\n");
}

return 0;
}

$ ./prog
ioperm on 0x70 success

这是预期的行为

最佳答案

来自the manual :

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

你把这个搞反了。 -1 表示失败,但您的代码错误地认为它表示成功。

关于c - ioperm 无需 root 权限即可工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58830017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com