[libc] Add custom operator new to handle allocation failures gracefully.
authorSiva Chandra Reddy <sivachandra@google.com>
Wed, 7 Dec 2022 21:35:38 +0000 (21:35 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Sun, 11 Dec 2022 00:29:04 +0000 (00:29 +0000)
commitf3400305771d4e0084d2ebc8e3e5d2736ba3bd7c
treeb9899c760aed245f3b89a361c40b1621d5eb7c4c
parent90559ed6e650e1a7b8e8d13c84388b2debcbb4b9
[libc] Add custom operator new to handle allocation failures gracefully.

This patch adds the implementation of the custom operator new functions.
The implementation of the internal strdup has been updated to use
operator new for allocation.

We will make it a policy and document that all allocations have to go
through the libc's own operator new. A future change will also add
operator delete replacements and make it a policy that deallocations in
libc internal code have to go through those replacements.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D139584
libc/src/__support/CPP/new.h [new file with mode: 0644]
libc/src/string/CMakeLists.txt
libc/src/string/allocating_string_utils.h
libc/src/string/strdup.cpp
libc/src/unistd/linux/getcwd.cpp
libc/test/src/string/CMakeLists.txt
libc/test/src/string/strdup_test.cpp