背景
在 RHEL7 中, dovecot 在运行的过程中其中一个 imap 进程挂掉,出来这么一个 coredump.
Program terminated with signal 7, Bus error.
(gdb) f 0
#0 0x00007fbb15868c17 in mail_cache_transaction_open_if_needed (ctx=ctx@entry=0x7fbb173c1430)
at mail-cache-transaction.c:218
218 if (ext->reset_id == cache->hdr->file_seq || i == 2)
(gdb) p cache
$1 = (struct mail_cache *) 0x7fbb173af2d0
(gdb) p cache->hdr
$3 = (const struct mail_cache_header *) 0x7fbb15ce5000
(gdb) p cache->hdr->file_seq
Cannot access memory at address 0x7fbb15ce5008
# cat maps | grep 7fbb15ce5000
7fbb15ce5000-7fbb15ced000 r--s 00000000 00:2c xxxxxxxxx /xxxxxxx/dovecot.index.cache
(gdb) f 0
#0 0x00007fbb15868c17 in mail_cache_transaction_open_if_needed (ctx=ctx@entry=0x7fbb173c1430)
at mail-cache-transaction.c:218
218 if (ext->reset_id == cache->hdr->file_seq || i == 2)
(gdb) p cache
$1 = (struct mail_cache *) 0x7fbb173af2d0
(gdb) p cache->hdr
$3 = (const struct mail_cache_header *) 0x7fbb15ce5000
(gdb) p cache->hdr->file_seq
Cannot access memory at address 0x7fbb15ce5008
# cat maps | grep 7fbb15ce5000
7fbb15ce5000-7fbb15ced000 r--s 00000000 00:2c xxxxxxxxx /xxxxxxx/dovecot.index.cache
挂掉的原因是 "signal 7, bus error" ((bad memory access)). 从 gdb 中可以看到,进程挂的时候在尝试访问 ext->reset_id 和 cache->hdr->file_seq, 而从 maps 可以看出 cache->hdr 指向的是 file-backend 的地址空间。
那么问题来了,怎样可以把一个结构体,映射到一个文件,而不是匿名页?另外一个问题是,在 gdb 中看到 “Cannot access memory at address” 是意味着这段地址存在问题吗?
测试环境
Debian 8 - jessie
继续阅读“用 mmap 将某些 struct 存放到文件中 (map virtual memory to a file)”