Skip to content

Revert "[libc] make integration test malloc work properly when threaded" #152096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libc/test/IntegrationTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ add_object_library(
DEPENDS
libc.hdr.stdint_proxy
libc.src.__support.OSUtil.osutil
libc.src.__support.CPP.atomic
${arch_specific_deps}
)
15 changes: 5 additions & 10 deletions libc/test/IntegrationTest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "hdr/stdint_proxy.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include <stddef.h>
Expand Down Expand Up @@ -65,19 +65,14 @@ int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }

static constexpr uint64_t MEMORY_SIZE = 16384;
static uint8_t memory[MEMORY_SIZE];
static LIBC_NAMESPACE::cpp::Atomic<size_t> used = 0;
static uint8_t *ptr = memory;

extern "C" {

// For simple test purposes.
void *malloc(size_t s) {
// Emulate the alignment of std::max_align_t.
constexpr size_t DEFAULT_ALIGNMENT = alignof(long double);
s += (-s) & (DEFAULT_ALIGNMENT - 1); // Align to default alignment.
auto res = used.fetch_add(s, LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED);
if (res + s > MEMORY_SIZE)
return nullptr; // Out of memory.
return &memory[res];
void *mem = ptr;
ptr += s;
return static_cast<uint64_t>(ptr - memory) >= MEMORY_SIZE ? nullptr : mem;
}

void free(void *) {}
Expand Down
Loading