Обсуждение: mremap and bus error

Поиск
Список
Период
Сортировка

mremap and bus error

От
Pavel Stehule
Дата:
Hi,

I playing with mmap. I have  a problem with mremap function. It
doesn't allocate correct memory.  All others work well.

static void *
mmap_realloc(void *ptr, Size size)
{       Size oldsize;       void *result;       int     i;       char *x;
       ptr = (char *) ptr - MAXALIGN(sizeof(Size));
       oldsize = *((Size *) ptr);       size = MAXALIGN(size) + MAXALIGN(sizeof(Size));
       ptr = mremap(ptr, oldsize,                                   size,
MREMAP_MAYMOVE);
       if (ptr == MAP_FAILED)               ereport(ERROR,                       (errcode(ERRCODE_OUT_OF_MEMORY),
                errmsg("out of memory"),                        errdetail("Failed on request of size %lu.",
                            (unsigned long) size)));
 
       *((Size*) ptr) = size;       result = (char *) ptr + MAXALIGN(sizeof(Size));
       /* check allocated memory */       x = ptr;
       fprintf(stderr, "allocated memory %ld\n", size);       for (i = 0; i < size; i++)       {               if (i >
oldsize)              {                       *x = 0;               }               x++;       }       fprintf(stderr,
"memorychecked\n");
 
       return result;
}

log:
>>>> 1 <<<>>> 1048584
>>>> 3 <<<>>> 2097216
>>>> 3 <<<>>> 9024
allocated memory 10304
memory checked
allocated memory 11584
memory checked
allocated memory 12864

gdb

Program terminated with signal 7, Bus error.
#0  mmap_realloc (size=12864, ptr=<value optimized out>) at mmap_alloc.c:357
357                *x = 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.10.2-1.x86_64

(gdb) print x
$1 = 0x7f92055df000 ""
(gdb) print i
$2 = 12289

Can somebody help me?

Regards
Pavel Stehule


Re: mremap and bus error

От
Robert Haas
Дата:
On Wed, Mar 31, 2010 at 11:05 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> Can somebody help me?

I think it's pretty hopeless to try to debug this without the complete
source code...

...Robert


Re: mremap and bus error

От
Pavel Stehule
Дата:
2010/4/1 Robert Haas <robertmhaas@gmail.com>:
> On Wed, Mar 31, 2010 at 11:05 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> Can somebody help me?
>
> I think it's pretty hopeless to try to debug this without the complete
> source code...

I am sorry. I am able to write test case, but I leaved it. Simply, I
don't use a function mremap. I searched about it on net, and I think
it is known issue on Linux :(.

Regards
Pavel Stehule

>
> ...Robert
>