c - 修复地址的 mmap 失败
问题描述
我想将存储在 ramdisk 中的文件映射到固定地址,但 mmap 失败。我在做什么错误?有没有其他方法可以做到这一点?
int fd = open("/mnt/tmpfs/hello.txt",
(O_RDONLY),
(S_IRWXU | S_IRWXG | S_IRWXO) );
if ( fd < 0 )
perror("open() error");
struct stat buf;
fstat(fd, &buf);
void * address = aligned_alloc(PGSIZE, buf.st_size)
void *new_address = mmap(address,
buf.st_size,
PROT_READ,
(MAP_SHARED|MAP_FIXED),
fd,
0);
if (new_address != address) {
perror("mmap failed!")
}
解决方案
推荐阅读
- javascript - 试图从周历中获取周输入值
- android - 如何使用深层链接准确打开 Play 商店?
- swift - 如何将 Pagecounter 连接到 ScrollView
- c# - 如何修复“Microsoft.Office.Interop.Outlook 参考”错误?
- sql-server - 左连接上的 CTE 性能缓慢
- excel - VBA cannot create new CXMLHTTPHandler
- reactjs - 是否可以通过 AWS Amplify 的 withAuthenticator() 登录后触发功能?
- windows - 如何在 Windows 上运行 nvidia-smi?
- python - 如何在 abaqus 的 python 中修复这个循环错误?
- reactjs - 地图启动时出现 React-mapbox-gl-draw 错误