重载内存映射文件加载器(C ++) [英] Overloading memory mapped file loader (C++)

查看:50
本文介绍了重载内存映射文件加载器(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可能使内存映射文件加载器过载?如果出现页面错误,Linux内核不会从磁盘加载请求的数据,而是会调用用户定义的函数来代替它,该函数将填充内存页面.

Is it possible to overload memory mapped file loader? In case of page fault, Linux kernel would not load the requested data from disk, but instead of it, user-defined function would be called, which would fill the memory page.

我想将其用于巨大的压缩光栅文件的内存映射.使用的压缩算法允许快速块解压缩.用户定义的加载功能可以动态地逐页解压缩文件.

I would like to use this for memory mapping of huge compressed raster file. Used compression algorithm allows fast block decompression. User-defined loading function would decompress the file page by page on the fly.

压缩文件是只读的.首选用户空间解决方案.

The compressed files are read-only. User-space solution is preferred.

推荐答案

是否可能使内存映射文件加载器过载?如果出现页面错误,Linux内核不会从磁盘加载请求的数据,而是会调用用户定义的函数来代替它,该函数将填充内存页面.

Is it possible to overload memory mapped file loader? In case of page fault, Linux kernel would not load the requested data from disk, but instead of it, user-defined function would be called, which would fill the memory page.

这是可能的,某些库正是这样做的.参见 libsigsegv .

It is possible and some libraries do just that. See libsigsegv.

使用以下签名为您的处理程序安装带有 sigaction SIGSEGV 的信号处理程序:

Install a signal handler for SIGSEGV with sigaction using the following signature for your handler:

void sigsegv_handler(int, siginfo_t* si, void*) {
    si->si_addr; // Memory location which caused the page fault.
    // mmap the missing page and return here

    // On error alternatives:
    //   * restore the previous SIGSEGV handler and return (the default one dumps core), or
    //   * abort() (dumps core), or
    //   * _exit(EXIT_FAILURE).
}

这篇关于重载内存映射文件加载器(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆