Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.programmer > #495
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.unix.programmer |
| Subject | Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! |
| Date | 2011-05-11 14:39 +1200 |
| Message-ID | <92ub6nF51qU7@mid.individual.net> (permalink) |
| References | <6e42b7e2-8f29-4c41-98eb-3caa4108f964@m10g2000yqd.googlegroups.com> <92u6qhF51qU6@mid.individual.net> <47f02d32-a19d-4690-b4d9-9f6e0deac555@q32g2000yqn.googlegroups.com> |
On 05/11/11 02:22 PM, loozadroog wrote: > On May 10, 8:24 pm, Ian Collins<ian-n...@hotmail.com> wrote: >> On 05/11/11 10:24 AM, loozadroog wrote: >> >> >> >>> I just posted a version of this program last night in clc, >>> asking for a general look-through. But now I've run into >>> a problem when using mmap that doesn't happen with >>> malloc. >> >>> I'm getting a bus error in memset, attempting to clear >>> the new memory. What could be going wrong? >> >>> Some relevant variables from gdb at the point of crash: >>> (gdb) r >>> Starting program: /home/olpc/xpost3/proto/v >> >>> Program received signal SIGBUS, Bus error. >>> 0xb7ec079f in memset () from /lib/libc.so.6 >>> (gdb) backtrace >>> #0 0xb7ec079f in memset () from /lib/libc.so.6 >>> #1 0x08048799 in mfalloc (mem=0x8049e90, sz=8008) at v.c:79 >>> #2 0x080487b7 in initmtab (mem=0x8049e90) at v.c:99 >>> #3 0x080489c5 in init () at v.c:162 >>> #4 0x080489f1 in main () at v.c:171 >>> (gdb) up >>> #1 0x08048799 in mfalloc (mem=0x8049e90, sz=8008) at v.c:79 >>> 79 memset(mem->base + adr, 0, sz); /* bus error with MMAP ! >>> */ >>> (gdb) p adr >>> $1 = 0 >>> (gdb) p sz >>> $2 = 8008 >>> (gdb) p pgsz >>> $3 = 4096 >>> (gdb) p mem->max >>> $4 = 12288 >>> (gdb) quit >> >> It looks like you map pgsz (4096) bytes here: >> >> mem->base = mmap(NULL, pgsz, PROT_READ|PROT_WRITE, MAP_SHARED >> |MAP_ANONYMOUS,-1,0 ); >> >> and attempt to write sz (8008) bytes here: >> >> memset(mem->base + adr, 0, sz); >> >> You have the same error with malloc, you just don't see it because the >> write does not enter unmapped memory, it just pisses on the heap! > > But gdb tells mem->max is 12288, so mfalloc must have called growmem, > and therefore either mremap or realloc has increased the allocation. I see, well I couldn't test the code, mremap is Linux specific. > Wouldn't it be a segv if I had overrun the region? I would have thought so. Why don't you try something like valgrind to look for memory access problems? > Bus error seems to suggest a problem with the width of the data being > accessed. memset doesn't have any alignment restrictions. >> By the way, why this line? >> >> #define _GNU_SOURCE > > To activate mremap. So I see! -- Ian Collins
Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! loozadroog <mijoryx@yahoo.com> - 2011-05-10 15:24 -0700
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! Ian Collins <ian-news@hotmail.com> - 2011-05-11 13:24 +1200
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! loozadroog <mijoryx@yahoo.com> - 2011-05-10 19:22 -0700
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! Ian Collins <ian-news@hotmail.com> - 2011-05-11 14:39 +1200
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! loozadroog <mijoryx@yahoo.com> - 2011-05-10 23:02 -0700
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! pacman@kosh.dhis.org (Alan Curry) - 2011-05-11 06:40 +0000
Re: bzero(mmap(NULL, 12288, ANON), 8008) raising bus error! loozadroog <mijoryx@yahoo.com> - 2011-05-11 17:38 -0700
csiph-web