blob: 4892b1dd9a524b45ed70b8a95d3e9bfb87374183 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
Daniel Micay4200e262015-11-03 05:14:08 -05002 * Copyright (C) 2015 The Android Open Source Project
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 * 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
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Daniel Micay4200e262015-11-03 05:14:08 -050028
29#include <sys/mman.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030#include <stdarg.h>
31
Daniel Micay4200e262015-11-03 05:14:08 -050032extern "C" void* ___mremap(void*, size_t, size_t, int, void*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033
Daniel Micay4200e262015-11-03 05:14:08 -050034void* mremap(void* old_address, size_t old_size, size_t new_size, int flags, ...) {
35 void* new_address = nullptr;
36 // The optional argument is only valid if the MREMAP_FIXED flag is set,
37 // so we assume it's not present otherwise.
38 if ((flags & MREMAP_FIXED) != 0) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039 va_list ap;
Daniel Micay4200e262015-11-03 05:14:08 -050040 va_start(ap, flags);
41 new_address = va_arg(ap, void*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042 va_end(ap);
Daniel Micay4200e262015-11-03 05:14:08 -050043 }
44 return ___mremap(old_address, old_size, new_size, flags, new_address);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045}