1 //===-- GPU Implementation of realloc -------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/stdlib/realloc.h"
11 #include "src/__support/GPU/allocator.h"
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/string/memory_utils/inline_memcpy.h"
16 namespace LIBC_NAMESPACE_DECL
{
18 LLVM_LIBC_FUNCTION(void *, realloc
, (void *ptr
, size_t size
)) {
20 return gpu::allocate(size
);
22 void *newmem
= gpu::allocate(size
);
23 if (newmem
== nullptr)
26 // This will copy garbage if it goes beyond the old allocation size.
27 inline_memcpy(newmem
, ptr
, size
);
32 } // namespace LIBC_NAMESPACE_DECL