Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#223 closed defect (fixed)

posix_memalign() is broken

Reported by: dmik Owned by: bird
Priority: normal Milestone: libc-0.6.4
Component: libc Version: 0.6
Severity: normal Keywords:
Cc:

Description

posix_memalign() does not work as expected. In particular, it is not always able to allocate a block aligned to 256K: it will return -1 in such cases w/o even setting errno to something. The attached example demonstrates this.

Attachments (1)

posix_memalign_test.c (1.1 KB) - added by dmik 14 years ago.

Download all attachments as: .zip

Change History (8)

Changed 14 years ago by dmik

Attachment: posix_memalign_test.c added

comment:1 Changed 14 years ago by dmik

Note that on my system (eComStation 2.0 Silver Release, libc063) it fails at the very first posix_memalign() call that requests the 256K alignment. Interesting that if you uncomment line #50 in posix_memalign_test() (which asks for some smaller alignments), the first call requesting the 256K alignment will succeed, but the next one will fail.

comment:2 Changed 13 years ago by bird

Milestone: libc-0.6.4

comment:3 Changed 13 years ago by bird

The problem occurs when there is no suitable block on the heap and a new one is allocated. With a large alignment, there is a fear chance that OS/2 won't give us a lump of memory with the same alignment. Since the _um_heap_expand function doesn't take the alignment into account when expanding the heap for a posix_memalign() call, the following _um_lump_alloc_noexpand call will fail due to misalignment.

comment:4 Changed 13 years ago by bird

(In [3719]) posix_memalign: Fixed problem with large alignment values. References #223.

comment:5 Changed 13 years ago by bird

Resolution: fixed
Status: newclosed

(In [3720]) 0.6: Backported r3719: posix_memalign: Fixed problem with large alignment values. Fixes #223.

comment:6 Changed 13 years ago by bird

(In [3721]) posix_memalign.c: Always set errno. References #223.

comment:7 Changed 13 years ago by bird

(In [3722]) 0.6: Backported r3721: posix_memalign.c: Always set errno. References #223.

Note: See TracTickets for help on using tickets.