blob: 2d64f4eb40b70a5cdca6868c4e7f41395fdef941 [file] [log] [blame]
Austin Schuh745610d2015-09-06 18:19:50 -07001// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2// Copyright (c) 2007, Google Inc.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15// * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// ---
32// Author: Craig Silverstein <opensource@google.com>
33//
34// Some obscure memory-allocation routines may not be declared on all
35// systems. In those cases, we'll just declare them ourselves.
36// This file is meant to be used only internally, for unittests.
37
38#include <config.h>
39
40#ifndef _XOPEN_SOURCE
41# define _XOPEN_SOURCE 600 // for posix_memalign
42#endif
43#include <stdlib.h> // for posix_memalign
44// FreeBSD has malloc.h, but complains if you use it
45#if defined(HAVE_MALLOC_H) && !defined(__FreeBSD__)
46#include <malloc.h> // for memalign, valloc, pvalloc
47#endif
48
49// __THROW is defined in glibc systems. It means, counter-intuitively,
50// "This function will never throw an exception." It's an optional
51// optimization tool, but we may need to use it to match glibc prototypes.
52#ifndef __THROW // I guess we're not on a glibc system
53# define __THROW // __THROW is just an optimization, so ok to make it ""
54#endif
55
56#if !HAVE_CFREE_SYMBOL
57extern "C" void cfree(void* ptr) __THROW;
58#endif
59#if !HAVE_POSIX_MEMALIGN_SYMBOL
60extern "C" int posix_memalign(void** ptr, size_t align, size_t size) __THROW;
61#endif
62#if !HAVE_MEMALIGN_SYMBOL
63extern "C" void* memalign(size_t __alignment, size_t __size) __THROW;
64#endif
65#if !HAVE_VALLOC_SYMBOL
66extern "C" void* valloc(size_t __size) __THROW;
67#endif
68#if !HAVE_PVALLOC_SYMBOL
69extern "C" void* pvalloc(size_t __size) __THROW;
70#endif