Allow gcc to know result is aligned

Someone on the internet found out gcc only understand posix_memalign.

The alloc_align attribute may be applied to a function that returns
a pointer and takes at least one argument of an integer or enumerated
type. It indicates that the returned pointer is aligned on a boundary
given by the function argument at position.

Change-Id: I4b0af6ef3020da1fb460652117286193d5d72f1e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4514
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Fredrik Holmqvist 2021-09-30 23:18:12 +02:00 committed by waddlesplash
parent 4a850ca730
commit 48eb7d981d
4 changed files with 9 additions and 7 deletions

View File

@ -84,9 +84,11 @@
__attribute__((format(__printf__, _format_, _args_)))
#if __GNUC__ >= 4
# define _ALIGNED_BY_ARG(_no_) __attribute__((alloc_align(_no_)))
# define _EXPORT __attribute__((visibility("default")))
# define B_ALWAYS_INLINE __attribute__((always_inline)) inline
#else
# define _ALIGNED_BY_ARG(_no_)
# define _EXPORT
#endif
#define _IMPORT

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
* Copyright 2002-2021 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MALLOC_H
@ -17,7 +17,7 @@ extern void *malloc(size_t numBytes);
extern void *realloc(void *oldPointer, size_t newSize);
extern void *calloc(size_t numElements, size_t size);
extern void free(void *pointer);
extern void *memalign(size_t alignment, size_t numBytes);
extern void *memalign(size_t alignment, size_t numBytes) _ALIGNED_BY_ARG(1);
extern void *valloc(size_t numBytes);
#ifdef _GNU_SOURCE

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
* Copyright 2002-2021 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _STDLIB_H_
@ -50,7 +50,7 @@ extern void free(void *pointer);
extern void *malloc(size_t size);
extern int posix_memalign(void **_pointer, size_t alignment, size_t size);
#ifdef _ISOC11_SOURCE
extern void *aligned_alloc(size_t alignment, size_t size);
extern void *aligned_alloc(size_t alignment, size_t size) _ALIGNED_BY_ARG(1);
#endif
extern void *realloc(void *oldPointer, size_t newSize);

View File

@ -59,10 +59,10 @@ extern "C" {
#endif
void* memalign_etc(size_t alignment, size_t size, uint32 flags);
void* memalign_etc(size_t alignment, size_t size, uint32 flags) _ALIGNED_BY_ARG(1);
void free_etc(void* address, uint32 flags);
void* memalign(size_t alignment, size_t size);
void* memalign(size_t alignment, size_t size) _ALIGNED_BY_ARG(1);
void deferred_free(void* block);
@ -74,7 +74,7 @@ void heap_add_area(heap_allocator* heap, area_id areaID, addr_t base,
size_t size);
heap_allocator* heap_create_allocator(const char* name, addr_t base,
size_t size, const heap_class* heapClass, bool allocateOnHeap);
void* heap_memalign(heap_allocator* heap, size_t alignment, size_t size);
void* heap_memalign(heap_allocator* heap, size_t alignment, size_t size) _ALIGNED_BY_ARG(2);
status_t heap_free(heap_allocator* heap, void* address);
#if KERNEL_HEAP_LEAK_CHECK