Skip to content
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
21 changes: 17 additions & 4 deletions include/shared/cache_shm/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,26 @@ constexpr std::size_t CONTROL_HEADER_SIZE = offsetof(CacheShmControl, stripes);
static_assert(CONTROL_HEADER_SIZE == 48, "the control segment header is a frozen layout; see the comment above");
static_assert(std::is_standard_layout_v<CacheShmControl>, "the control segment is shared across processes and builds");

// Whether a control segment of `actual` bytes was written by *this* build; the kernel rounds an shm object up to a page.
// Anything larger has a stripes[] of unknown stride and must never be walked with our layout. Shared by the attach gate,
// the purge primitive and `traffic_ctl cache shm status` so the three cannot drift apart.
/// Whether @a actual is the object size this platform reports after truncating
/// a POSIX shared-memory object to @a requested bytes.
inline bool
is_expected_shm_size(std::size_t actual, std::size_t requested)
{
#if defined(__APPLE__)
// macOS rounds the reported object size up to the VM page size.
return actual >= requested && actual <= INK_ALIGN(requested, ats_pagesize());
#else
return actual == requested;
#endif
}

// Whether a control segment of `actual` bytes was written by *this* build. Anything else has a stripes[] of unknown
// stride and must never be walked with our layout. Shared by the attach gate, the purge primitive and
// `traffic_ctl cache shm status` so the three cannot drift apart.
inline bool
is_own_control_size(std::size_t actual)
{
return actual >= CONTROL_SIZE && actual <= INK_ALIGN(CONTROL_SIZE, ats_pagesize());
return is_expected_shm_size(actual, CONTROL_SIZE);
}

// Frame the operator's middle word (e.g. "ats") as "/<word>-". The framing is supplied here so it cannot be mis-typed:
Expand Down
7 changes: 3 additions & 4 deletions include/shared/cache_shm/Purge.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ purge_segments(const std::string &prefix)
return report;
}

// Larger than this build's page-rounded CONTROL_SIZE means a build with a different
// sizeof(CacheShmControl) wrote it. The frozen header prefix is still readable (so
// the owner guard above applies), but stripes[] may have a different stride entirely,
// so its names must not drive shm_unlink.
// A control size this build does not accept means a build with a different sizeof(CacheShmControl) wrote it. The frozen
// header prefix is still readable (so the owner guard above applies), but stripes[] may have a different stride
// entirely, so its names must not drive shm_unlink.
if (magic_ok && is_own_control_size(static_cast<std::size_t>(sb.st_size))) {
unlink_table_stripes(prefix, ctrl, report.unlinked);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/fastlz/fastlz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void flz_smallcopy(uint8_t* dest, const uint8_t* src, uint32_t count) {
}

/* special case of memcpy: exactly MAX_COPY bytes */
static void flz_maxcopy(void* dest, const void* src) {
static void flz_maxcopy(uint8_t* dest, const uint8_t* src) {
#if defined(FLZ_ARCH64)
const uint32_t* p = (const uint32_t*)src;
uint32_t* q = (uint32_t*)dest;
Expand Down
2 changes: 1 addition & 1 deletion lib/swoc/unit_tests/test_bw_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ TEST_CASE("bwstring std formats", "[libswoc][bwprint]") {

w.print("{}", swoc::bwf::Errno(13));
REQUIRE(w.view() == "EACCES: Permission denied [13]"sv);
w.clear().print("{}", swoc::bwf::Errno(134));
w.clear().print("{}", swoc::bwf::Errno(192));
REQUIRE(w.view().substr(0, 22) == "Unknown: Unknown error"sv);
w.clear().print("{:s}", swoc::bwf::Errno(13));
REQUIRE(w.view() == "EACCES: Permission denied"sv);
Expand Down
Loading