Skip to content

Commit e4b87b5

Browse files
mudlerclaude
andcommitted
fix(vt): alloc overflow guard, registry bounds check, whole-archive on library interface
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent d7b3f77 commit e4b87b5

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ add_library(vllm STATIC
4949
src/vt/backend.cpp
5050
src/vt/cpu/cpu_backend.cpp)
5151
add_library(vllm::vllm ALIAS vllm)
52+
# Static-init registrars (e.g. the CPU backend) live in archive members no
53+
# consumer references directly; force-link the whole vllm archive so every
54+
# consumer (tests, C API shared lib, benchmarks) gets backend registration.
55+
if(UNIX AND NOT APPLE)
56+
target_link_options(vllm INTERFACE "LINKER:--whole-archive,$<TARGET_FILE:vllm>,--no-whole-archive")
57+
endif()
5258
target_include_directories(vllm
5359
PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/include)
5460
target_include_directories(vllm SYSTEM PUBLIC third_party)

include/vt/backend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class Backend {
3030
};
3131

3232
Backend& GetBackend(DeviceType type);
33+
// Threading contract: all registration must complete before main() runs
34+
// (backends register via static initializers). After that, GetBackend is
35+
// lock-free reads only; no synchronization is performed.
3336
void RegisterBackend(DeviceType type, Backend* backend);
3437

3538
} // namespace vt

src/vt/backend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ std::array<Backend*, kNumDeviceTypes>& Registry() {
1717
} // namespace
1818

1919
Backend& GetBackend(DeviceType type) {
20+
VT_CHECK(static_cast<size_t>(type) < kNumDeviceTypes, "invalid device type");
2021
Backend* b = Registry()[static_cast<size_t>(type)];
2122
VT_CHECK(b != nullptr, std::string("no backend registered for device type ") +
2223
std::to_string(static_cast<int>(type)));

src/vt/cpu/cpu_backend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// vllm.cpp original (vt runtime, inventory deviation §9.1); no upstream mirror.
2+
#include <cstdint>
23
#include <cstdlib>
34
#include <cstring>
45

@@ -10,6 +11,7 @@ namespace {
1011
class CpuBackend final : public Backend {
1112
public:
1213
void* Alloc(size_t bytes) override {
14+
VT_CHECK(bytes <= SIZE_MAX - 63, "cpu alloc size overflow");
1315
void* p = std::aligned_alloc(64, ((bytes + 63) / 64) * 64); // 64B-aligned, padded size
1416
VT_CHECK(p != nullptr, "cpu alloc failed");
1517
return p;

tests/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ target_include_directories(vllm_test_main SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/thir
44
function(vllm_cpp_add_test name)
55
add_executable(${name} ${ARGN})
66
target_link_libraries(${name} PRIVATE vllm::vllm vllm_test_main)
7-
# Static-init registrars (e.g. the CPU backend) live in archive members no
8-
# test references directly; force-link the whole vllm archive so they run.
9-
if(UNIX AND NOT APPLE)
10-
target_link_options(${name} PRIVATE "LINKER:--whole-archive,$<TARGET_FILE:vllm>,--no-whole-archive")
11-
endif()
127
vllm_cpp_set_warnings(${name})
138
add_test(NAME ${name} COMMAND ${name})
149
endfunction()

0 commit comments

Comments
 (0)