- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
:) 我正在尝试将一些遗留代码(大型程序)移植到 CentOS 7,但遇到了障碍。代码的核心是一个相当笨拙的结构,围绕使用 mmap 分配硬编码地址并将文件映射到它而构建。该文件就像一个数据库(由一个数据库构建),包括指向映射内存不同部分的硬编码指针。非常丑陋,但它就是这样。整个程序都是围绕这个结构构建的,没有人会资助重写。
问题出在 mmap 行上。这以前有效,但不再适用于 CentOS 7:
mmapAddr = mmap ((void *) SMAddr, SMA_WINDOW_SIZE, PROT_READ | (readOnly ? 0 : PROT_WRITE),MAP_FILE | MAP_FIXED | MAP_SHARED, SMFileDesc, 0);
... 其中 SMAddr
是0x8000000
, SMA_WINDOW_SIZE
是127926272
, 和 readOnly
是假的。所以基本上它试图将文件映射到地址 0x8000000
大小为 122MB。
版本之间可能发生了什么变化,我不知道。但我确实注意到它映射的文件只有 1.5MB。我不确定为什么它需要映射的文件大小远远超过文件大小,但我知道这是必需的,而且我知道出于某种原因在选择“122MB”大小时有很多细微差别。
实际文件大小和分配的大小之间的不匹配在过去可能没有问题但现在不会了吗?我知道SIGBUS
表示尝试访问无效的内存区域。鉴于 mmap 不采用任何类型的分配指针,这一定是它在内部做的事情。
我尝试捕捉和阻止 SIGBUS
(认为它可能会被忽略?),但程序仍然崩溃并显示 SIGBUS
在同一个地方。也许我做错了。
想法?
最佳答案
从这里1 :
The mmap() function can be used to map a region of memory that is larger than the current size of the object. Memory access within the mapping but beyond the current end of the underlying objects may result in SIGBUS signals being sent to the process. The reason for this is that the size of the object can be manipulated by other processes and can change at any moment. The implementation should tell the application that a memory reference is outside the object where this can be detected; otherwise, written data may be lost and read data may not reflect actual data in the object.
Note that references beyond the end of the object do not extend the object as the new end cannot be determined precisely by most virtual memory hardware. Instead, the size can be directly manipulated by ftruncate().
所以最有可能的错误是你的程序试图访问位于文件之外的映射内存区域。然而,mmap 调用应该会成功。你得到的返回值是多少?
关于c - 带有 MAP_FIXED 的 mmap 上的 SIGBUS | map 文件 | MAP_SHARED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960139/
我必须在 android 项目中使用 opencv。一切正常,直到我最近不得不使用 c++ exception_ptr。此后,使用std::rethrow_exception导致SIGBUS(信号SI
我的进程在同一台机器上的 2 个账户中运行良好,但是当我将进程复制到其他账户并运行进程时,我得到了核心转储。当我最后用 strace 运行这个过程时,我得到: --- SIGBUS (Bus erro
这个问题纯粹出于好奇;就我个人而言,我曾看到此信号被发出,但很少见。 我在 the C chatroom 上问过是否有可靠的方法来重现它。在这个房间里,user @Antti Haapala找到一个。
这是我写的示例代码。 #include #include #include #include #include int main() { int fd; long pages
我尝试使用 iText 5.5.0 和文档示例进行签名: private static void pdfSign(String srcFile, String dstFile) throws Exce
我的应用在 iPhone 4 iOS 7.1.3 上崩溃。在 iOS 9 和 iP6 上一切正常。 这是由使用两种泛型类型实例化相当复杂的泛型类引起的。 我可以提供有关实现的详细信息,但该类有数百行。
我的程序最近因以下堆栈而崩溃; Program terminated with signal 7, Bus error. #0 0x00007f0f323beb55 in raise () from
我的调用堆栈显示如下: --- called from signal handler with signal 10 (SIGBUS) --- 001301b8 allocate__t24__def
我的 Android 应用程序在以下代码段的第 4 行报告 SIGBUS 错误(这是一个函数序言): MOV R12, SP STMFD SP!, {R4-R12,LR,PC} SUB R11, R1
在 objective-c 中将自定义对象添加到 mutableArray 时出现内存 SIGBUS 错误。 @interface stak : NSObject { NSString *id
编辑 1:示例程序的平台是 x86_64。 编辑 2: 我正在编辑它以便更好地理解。下面是两个不同的问题。第一个问题是无效的读/写会导致 SIGBUS 吗?第二个问题是 Valgrind 对 SIGB
我目前正在开展一个项目,该项目运行在经过大量修改的 Linux 版本上,该版本已打补丁以能够访问 VMEbus。大部分总线处理已完成,我有一个 VMEAccess 类,它使用 mmap 写入/dev/
我试图在只读内存上捕获错误但无法捕获?如果我处理了错误,那么它的程序可以继续,或者只有选项是退出/中止? #include #include #include #include #include
我想为内存映射文件 io 编写一个包装器,它要么无法映射文件,要么返回一个在取消映射之前有效的映射。使用普通 mmap 时,如果底层文件在映射时被截断或删除,就会出现问题。根据 mmap 的 linu
那是在堆栈跟踪中,我不明白这个错误: 0 CoreFoundation 0x30f57648 ___CFBasicHashFindBucket_Linear_NoCollision + 92
我正在尝试通过映射一个 1 MiB 文件(与 RAM 大小相对应)来为基本 CPU 建模。我想读/写这个文件。目前,我收到 ram[2] = 1 的 SIGBUS 错误,我收集到这是由于尝试在文件范围
我的子进程正在尝试访问 PCI 地址空间。它在大多数时候都运行良好。 但是,有时子进程会进入僵尸状态。 dmesg 日志显示以下总线错误。 [ 501.134156] Caused by (from
我的一个应用程序因 SIGBUS 信号而崩溃。以下是来自 gdb 的堆栈跟踪。基本上,dlopen 调用失败了。我正在运行 CentOS 6.3 64 位。 Program received sign
以下从教程网站获取的基本 SDL2 代码引起了一些奇怪的问题: #include #include #include #include #define SCREENH 768 #define
我无法用以下汇编代码产生“总线错误”。这里我使用的内存地址不是合法的“规范地址”。那么,我该如何触发该错误? 我在带有 NASM 2.14.02 的 Ubuntu 20.04 LTS 下运行这段代码,
我是一名优秀的程序员,十分优秀!