使用syscall调用函数报错,如下代码,是不是我的写法有问题
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>
int main(){
int size = 10;
int fd = open ("test.txt", O_RDONLY);
// // 这样调用是正常的
char *f1 = (char *) mmap( 0, size, PROT_READ, MAP_PRIVATE, fd, 0);
printf("[1] mmap result : %s", f1);
// // 这么写有问题吗 会报错
char *f2 = (char *) syscall(SYS_mmap, 0, size, PROT_READ, MAP_PRIVATE, fd, 0);
printf("[2] mmap result : %s", f2);
// int fd_ = syscall(SYS_open, "test.txt", 0);
// printf("%d ----", fd_);
return 0;
}
或者能否提供个syscall调用mmap的helloworld参考一下,谢谢各位大佬了### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
mmap调用的系统调用时mmap2 不是 mmap 所以你也要使用mmap2