|
From: Andriy R. <ar...@bc...> - 2003-11-15 01:42:48
|
Can anybody confirm this? It seems like valgrind does not handle
posix_memalign, I saw __posix_memalign in the code but apparently it
does not help.
valgrind (up to 2.0.0) on program:
#include <stdlib.h>
int main()
{
int *ptr;
posix_memalign(&ptr, 16, 4096);
ptr[16] = 5;
printf("%d\n", ptr[16]);
free(ptr);
}
gives this:
...
==12016== Invalid free() / delete / delete[]
==12016== at 0x40026961: free (vg_replace_malloc.c:231)
==12016== by 0x8048404: main (posix_mem.c:9)
==12016== by 0x420158F6: __libc_start_main (in /lib/i686/libc-2.3.2.so)
==12016== by 0x8048320: (within /root/work/tmp/posix_mem)
==12016== Address 0x905B020 is not stack'd, malloc'd or free'd
...
Thanks,
Andriy
P.S. in man pages memalign and valloc marked as deprecated in favor of
posix_memalign so it's a pity if valgrind does not support it
|
|
From: Nicholas N. <nj...@ca...> - 2003-11-15 10:49:34
|
On Fri, 14 Nov 2003, Andriy Rysin wrote:
> Can anybody confirm this? It seems like valgrind does not handle
> posix_memalign, I saw __posix_memalign in the code but apparently it
> does not help.
Can you add these lines:
# define weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
weak_alias(__posix_memalign, posix_memalign);
just after __posix_memalign() (line 375) in coregrind/vg_replace_malloc.c?
If it works, I'll commit it.
Thanks.
N
|
|
From: Andriy R. <ar...@bc...> - 2003-11-15 17:31:12
|
Works fine with the pach, thanks. Andriy Nicholas Nethercote wrote: >On Fri, 14 Nov 2003, Andriy Rysin wrote: > > > >>Can anybody confirm this? It seems like valgrind does not handle >>posix_memalign, I saw __posix_memalign in the code but apparently it >>does not help. >> >> > >Can you add these lines: > > # define weak_alias(name, aliasname) \ > extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); > weak_alias(__posix_memalign, posix_memalign); > >just after __posix_memalign() (line 375) in coregrind/vg_replace_malloc.c? > >If it works, I'll commit it. > >Thanks. > >N > > |
|
From: Andriy R. <ar...@bc...> - 2003-11-25 08:06:46
|
sorry, just found out that this patch breaks posix_memalign. It was ok for that small example but when I tried valgrind on my bigger project it seems like posix_memalign sets pointer to 0 and returns 22 (EINVAL), while valgrind w/out this patch or just w/valgrind altogether code works fine. I did not have much time to investigate it more, I allocate about 800*600*3/2 with align 16. If more info needed I'll try to take a look when it breaks. Andriy Nicholas Nethercote wrote: >On Fri, 14 Nov 2003, Andriy Rysin wrote: > > > >>Can anybody confirm this? It seems like valgrind does not handle >>posix_memalign, I saw __posix_memalign in the code but apparently it >>does not help. >> >> > >Can you add these lines: > > # define weak_alias(name, aliasname) \ > extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); > weak_alias(__posix_memalign, posix_memalign); > >just after __posix_memalign() (line 375) in coregrind/vg_replace_malloc.c? > >If it works, I'll commit it. > >Thanks. > >N > > |
|
From: Jeremy F. <je...@go...> - 2003-11-28 06:07:02
|
On Thu, 2003-11-27 at 15:55, Tom Hughes wrote: > /* Test whether the SIZE argument is valid. It must be a power of > two multiple of sizeof (void *). */ > if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0) > return VKI_EINVAL /*22*/ /*EINVAL*/; > Specifically by the second half of the or condition, which doesn't > seem to make any sense to me. N & (N-1) == 0 iff N is a power of 2 - it's the quick idiom to see if a number is a power of 2 or not. J |
|
From: Tom H. <th...@cy...> - 2003-11-28 07:21:03
|
In message <106...@ix...>
Jeremy Fitzhardinge <je...@go...> wrote:
> On Thu, 2003-11-27 at 15:55, Tom Hughes wrote:
> > /* Test whether the SIZE argument is valid. It must be a power of
> > two multiple of sizeof (void *). */
> > if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0)
> > return VKI_EINVAL /*22*/ /*EINVAL*/;
> > Specifically by the second half of the or condition, which doesn't
> > seem to make any sense to me.
>
> N & (N-1) == 0 iff N is a power of 2 - it's the quick idiom to see if a
> number is a power of 2 or not.
I realised that I just couldn't understand why it wanted to insist
on the size begin a power of two ;-) After reading the manual page
it became obvious where the mistake was.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Nicholas N. <nj...@ca...> - 2003-11-25 09:02:54
|
On Tue, 25 Nov 2003, Andriy Rysin wrote: > sorry, just found out that this patch breaks posix_memalign. It was ok > for that small example but when I tried valgrind on my bigger project it > seems like posix_memalign sets pointer to 0 and returns 22 (EINVAL), > while valgrind w/out this patch or just w/valgrind altogether code works > fine. > I did not have much time to investigate it more, I allocate about > 800*600*3/2 with align 16. > If more info needed I'll try to take a look when it breaks. That would help, thanks. N |
|
From: Andriy R. <ar...@bc...> - 2003-11-27 22:35:13
|
test.c:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* p = 0;
int ret = posix_memalign(&p, 16, 800*600*3/2);
printf("ret %d, p %p\n", ret, p);
return 0;
}
# ./test
ret 0, p 0xbf4f8020
# valgrind ./test
==28692== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==28692== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==28692== Using valgrind-2.0.0, a program supervision framework for
x86-linux.
==28692== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==28692== Estimated CPU clock rate is 2025 MHz
==28692== For more details, rerun with: -v
==28692==
ret 22, p (nil)
==28692==
==28692== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==28692== malloc/free: in use at exit: 0 bytes in 0 blocks.
==28692== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==28692== For a detailed leak analysis, rerun with: --leak-check=yes
==28692== For counts of detected errors, rerun with: -v
this is valgrind 2.0.0 with posix_memalign patch:
# define weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
weak_alias(__posix_memalign, posix_memalign);
Andriy
Nicholas Nethercote wrote:
>On Tue, 25 Nov 2003, Andriy Rysin wrote:
>
>
>
>>sorry, just found out that this patch breaks posix_memalign. It was ok
>>for that small example but when I tried valgrind on my bigger project it
>>seems like posix_memalign sets pointer to 0 and returns 22 (EINVAL),
>>while valgrind w/out this patch or just w/valgrind altogether code works
>>fine.
>>I did not have much time to investigate it more, I allocate about
>>800*600*3/2 with align 16.
>>If more info needed I'll try to take a look when it breaks.
>>
>>
>
>That would help, thanks.
>
>N
>
>
|
|
From: Dirk M. <dm...@gm...> - 2003-11-28 00:18:01
|
On Thursday 27 November 2003 22:31, Andriy Rysin wrote: > int ret = posix_memalign(&p, 16, 800*600*3/2); fixed, thanks. |
|
From: Tom H. <th...@cy...> - 2003-11-27 23:55:27
|
In message <3FC...@bc...>
Andriy Rysin <ar...@bc...> wrote:
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> char* p = 0;
> int ret = posix_memalign(&p, 16, 800*600*3/2);
> printf("ret %d, p %p\n", ret, p);
>
> return 0;
> }
>
> # ./test
> ret 0, p 0xbf4f8020
>
> # valgrind ./test
> ==28692== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
> ==28692== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
> ==28692== Using valgrind-2.0.0, a program supervision framework for
> x86-linux.
> ==28692== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
> ==28692== Estimated CPU clock rate is 2025 MHz
> ==28692== For more details, rerun with: -v
> ==28692==
> ret 22, p (nil)
It looks like this is caused by this condition in valgrind's
version of posix_memalign:
/* Test whether the SIZE argument is valid. It must be a power of
two multiple of sizeof (void *). */
if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0)
return VKI_EINVAL /*22*/ /*EINVAL*/;
Specifically by the second half of the or condition, which doesn't
seem to make any sense to me.
In fact, according to the manual page, it is the alignment parameter
that is supposed to be subject to the constraints on being a multiple
of the size of void * and being a power of two.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|