免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6965 | 回复: 9
打印 上一主题 下一主题

mmap bus error [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-04 23:05 |只看该作者 |倒序浏览
本来文件长度是0,mmap一定长度后,访问那段长度,出现bus error,
有哪位朋友能详细说说?是没有对齐,还是其他原因、

论坛徽章:
0
2 [报告]
发表于 2010-02-04 23:13 |只看该作者
没有对齐吧,是sun的机器么?

论坛徽章:
0
3 [报告]
发表于 2010-02-04 23:17 |只看该作者
linux, 当我用ftruncate将文件设置为要访问的那么多长度后,一切正常,我想要知道的是,为什么会这样。。。。do something behind me?  感觉很不爽。

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
4 [报告]
发表于 2010-02-04 23:23 |只看该作者
返回值?

论坛徽章:
0
5 [报告]
发表于 2010-02-04 23:32 |只看该作者
回复 4# OwnWaterloo


   void *map;
   map = mmap(NULL,1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
   //ftruncate(fd,1000);
   nodes = (NODES *)((char*)(map + 1));
一到nodes这一举,就出错了,buss error.但是加上注释的一句,没有问题

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
6 [报告]
发表于 2010-02-04 23:40 |只看该作者
我傻了……  都bus error了……  还返回个p……

void *mmap(void *addr, size_t len, int prot, int flags,
       int fildes, off_t off);

The range of bytes starting at off and continuing for len bytes shall be legitimate for the possible (not necessarily current) offsets in the file, shared memory object, or [TYM]   typed memory object   represented by fildes.

论坛徽章:
0
7 [报告]
发表于 2010-02-04 23:44 |只看该作者
,返回bus error,这个错误,还是很惊喜的,
有本c语言书上说过段错误,和bus error,段错误我经常出现,但是好像bus error没出现过(也不知道是为什么),这里出现错误,也就罢了,但是返回bus error,令人浮想联翩。。。

论坛徽章:
0
8 [报告]
发表于 2010-02-05 08:41 |只看该作者
回复  OwnWaterloo


   void *map;
   map = mmap(NULL,1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0) ...
peidright 发表于 2010-02-04 23:32


NODES 是怎么定义的?如果它需要4字节对齐,而这里地址是map+1,可能不是4字节对齐的

论坛徽章:
1
天蝎座
日期:2014-02-28 16:08:53
9 [报告]
发表于 2010-05-04 13:58 |只看该作者
我觉得跟文件大小有关系的。
mmap一个空文件去读就出错了。
但是如果这个文件有内容就ok

论坛徽章:
0
10 [报告]
发表于 2010-05-04 14:37 |只看该作者
SIGBUS Attempted access to a portion of the buffer that does not corre-
      spond to the file (for example, beyond  the  end  of  the  file,
      including  the  case  where  another  process  has truncated the
      file).
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP