- (續 08-11-15@GMT-6)尋找合理懷疑對象:
root@intrepid:~/jfbterm-0.4.7# grep "KD_GRAPHICS" *
vterm.c: ioctl(0, KDSETMODE, KD_GRAPHICS);
root@intrepid:~/jfbterm-0.4.7# grep "KD_TEXT" *
main.c: if (mode == KD_TEXT) {
vterm.c: ioctl(0, KDSETMODE, KD_TEXT);
root@intrepid:~/jfbterm-0.4.7# grep "cannot mmap" *
fbcommon.c: die("cannot mmap(smem)");
fbcommon.c: die("cannot mmap(mmio)");
fbcommon.c: print_message("cannot mmap(mmio) : %s\n", strerror(errno));
- 啟用 DEBUG 旗標,編譯 jfbterm,使用 gdb 追蹤
root@intrepid:~/jfbterm-0.4.7# ./configure --enable-debug
root@intrepid:~/jfbterm-0.4.7# make
root@intrepid:~/jfbterm-0.4.7# gdb ./jfbterm
gdb> run
- 縱使用 gdb 還是無法正常跳回文字模式,因此直接追原始碼。
- 根據錯誤訊息,應該是錯在 fbcommon.c 的第 572 行,往前追造成錯誤的原因是 566 行的 mmap()
566 p->mmio = (u_char*)mmap(NULL, p->mlen, PROT_READ|PROT_WRITE,
567 MAP_SHARED, p->fh, p->slen);
568 if ((long)p->mmio == -1) {
569 #ifdef JFB_MMIO_CHECK
570 die("cannot mmap(mmio)");
571 #else
572 print_message("cannot mmap(mmio) : %s\n", strerror(errno));
573 #endif
- 安裝 manpages-dev 套件,查 mmap manpages
root@intrepid:~/jfbterm-0.4.7# apt-get install manpages-dev
root@intrepid:~/jfbterm-0.4.7# man errno
EINVAL Invalid argument (POSIX.1)
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
ERRORS
EINVAL We don't like addr, length, or offset (e.g., they are too large, or not aligned on a page boundary).
EINVAL (since Linux 2.6.12) length was 0.
EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both of these values.