1169689Skan/* Copyright (C) 2004, 2006 Free Software Foundation, Inc. 2169689Skan 3169689Skan This file is part of GCC. 4169689Skan 5169689Skan GCC is free software; you can redistribute it and/or modify 6169689Skan it under the terms of the GNU General Public License as published by 7169689Skan the Free Software Foundation; either version 2, or (at your option) 8169689Skan any later version. 9169689Skan 10169689Skan GCC is distributed in the hope that it will be useful, 11169689Skan but WITHOUT ANY WARRANTY; without even the implied warranty of 12169689Skan MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13169689Skan GNU General Public License for more details. 14169689Skan 15169689Skan You should have received a copy of the GNU General Public License 16169689Skan along with GCC; see the file COPYING. If not, write to 17169689Skan the Free Software Foundation, 51 Franklin Street, Fifth Floor, 18169689Skan Boston, MA 02110-1301, USA. */ 19169689Skan 20169689Skan/* As a special exception, if you include this header file into source 21169689Skan files compiled by GCC, this header file does not by itself cause 22169689Skan the resulting executable to be covered by the GNU General Public 23169689Skan License. This exception does not however invalidate any other 24169689Skan reasons why the executable file might be covered by the GNU General 25169689Skan Public License. */ 26169689Skan 27169689Skan#ifndef _MM_MALLOC_H_INCLUDED 28169689Skan#define _MM_MALLOC_H_INCLUDED 29169689Skan 30169689Skan#include <stdlib.h> 31169689Skan 32169689Skan/* We can't depend on <stdlib.h> since the prototype of posix_memalign 33169689Skan may not be visible. */ 34169689Skan#ifndef __cplusplus 35169689Skanextern int posix_memalign (void **, size_t, size_t); 36169689Skan#else 37226430Sstefanfextern "C" int posix_memalign (void **, size_t, size_t); 38169689Skan#endif 39169689Skan 40169689Skanstatic __inline void * 41169689Skan_mm_malloc (size_t size, size_t alignment) 42169689Skan{ 43169689Skan void *ptr; 44169689Skan if (alignment == 1) 45169689Skan return malloc (size); 46169689Skan if (alignment == 2 || (sizeof (void *) == 8 && alignment == 4)) 47169689Skan alignment = sizeof (void *); 48169689Skan if (posix_memalign (&ptr, alignment, size) == 0) 49169689Skan return ptr; 50169689Skan else 51169689Skan return NULL; 52169689Skan} 53169689Skan 54169689Skanstatic __inline void 55169689Skan_mm_free (void * ptr) 56169689Skan{ 57169689Skan free (ptr); 58169689Skan} 59169689Skan 60169689Skan#endif /* _MM_MALLOC_H_INCLUDED */ 61