pmm_malloc.h revision 302408
1294113Sbapt/* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
2241675Suqs
3241675Suqs   This file is part of GCC.
4279527Sbapt
5274880Sbapt   GCC is free software; you can redistribute it and/or modify
6241675Suqs   it under the terms of the GNU General Public License as published by
7241675Suqs   the Free Software Foundation; either version 2, or (at your option)
8241675Suqs   any later version.
9241675Suqs
10241675Suqs   GCC is distributed in the hope that it will be useful,
11294113Sbapt   but WITHOUT ANY WARRANTY; without even the implied warranty of
12241675Suqs   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13294113Sbapt   GNU General Public License for more details.
14241675Suqs
15241675Suqs   You should have received a copy of the GNU General Public License
16241675Suqs   along with GCC; see the file COPYING.  If not, write to
17241675Suqs   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
18241675Suqs   Boston, MA 02110-1301, USA.  */
19241675Suqs
20241675Suqs/* As a special exception, if you include this header file into source
21241675Suqs   files compiled by GCC, this header file does not by itself cause
22241675Suqs   the resulting executable to be covered by the GNU General Public
23241675Suqs   License.  This exception does not however invalidate any other
24274880Sbapt   reasons why the executable file might be covered by the GNU General
25241675Suqs   Public License.  */
26241675Suqs
27241675Suqs#ifndef _MM_MALLOC_H_INCLUDED
28241675Suqs#define _MM_MALLOC_H_INCLUDED
29241675Suqs
30294113Sbapt#include <stdlib.h>
31294113Sbapt
32294113Sbapt/* We can't depend on <stdlib.h> since the prototype of posix_memalign
33241675Suqs   may not be visible.  */
34294113Sbapt#ifndef __cplusplus
35294113Sbaptextern int posix_memalign (void **, size_t, size_t);
36241675Suqs#else
37241675Suqsextern "C" int posix_memalign (void **, size_t, size_t);
38274880Sbapt#endif
39241675Suqs
40274880Sbaptstatic __inline void *
41241675Suqs_mm_malloc (size_t size, size_t alignment)
42241675Suqs{
43241675Suqs  void *ptr;
44279527Sbapt  if (alignment == 1)
45241675Suqs    return malloc (size);
46241675Suqs  if (alignment == 2 || (sizeof (void *) == 8 && alignment == 4))
47261344Suqs    alignment = sizeof (void *);
48274880Sbapt  if (posix_memalign (&ptr, alignment, size) == 0)
49241675Suqs    return ptr;
50241675Suqs  else
51241675Suqs    return NULL;
52241675Suqs}
53294113Sbapt
54294113Sbaptstatic __inline void
55294113Sbapt_mm_free (void * ptr)
56241675Suqs{
57241675Suqs  free (ptr);
58241675Suqs}
59294113Sbapt
60241675Suqs#endif /* _MM_MALLOC_H_INCLUDED */
61241675Suqs