2022-10-11 00:38:29 +00:00
|
|
|
//===-- Simple malloc and free for use with integration tests -------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
|
|
|
|
// various other parts of the libc. Since SCUDO development does not use
|
|
|
|
// LLVM libc build rules, it is very hard to keep track or pull all that SCUDO
|
|
|
|
// requires. Hence, as a work around for this problem, we use a simple allocator
|
|
|
|
// which just hands out continuous blocks from a statically allocated chunk of
|
|
|
|
// memory.
|
|
|
|
|
|
|
|
static uint8_t memory[16384];
|
|
|
|
static uint8_t *ptr = memory;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
void *malloc(size_t s) {
|
|
|
|
void *mem = ptr;
|
|
|
|
ptr += s;
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void *) {}
|
|
|
|
|
2023-03-05 00:23:48 +00:00
|
|
|
void *realloc(void *ptr, size_t s) {
|
|
|
|
free(ptr);
|
|
|
|
return malloc(s);
|
|
|
|
}
|
|
|
|
|
2022-10-11 00:38:29 +00:00
|
|
|
} // extern "C"
|