summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukáš Ondráček <lukas.ondracek@nic.cz>2024-10-31 17:39:31 +0100
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-11-04 14:39:48 +0100
commit53db552b054fa2bf804e56d3544ab4a56dbfe918 (patch)
tree3859984c42c806f9bf02f06774a362da427bf64e
parentdaemon/ratelimiting: add log-period and dry-run (diff)
downloadknot-resolver-53db552b054fa2bf804e56d3544ab4a56dbfe918.tar.xz
knot-resolver-53db552b054fa2bf804e56d3544ab4a56dbfe918.zip
daemon/mmapped: use static_assert on undefined padding
-rw-r--r--daemon/defer.c11
-rw-r--r--daemon/ratelimiting.c17
2 files changed, 15 insertions, 13 deletions
diff --git a/daemon/defer.c b/daemon/defer.c
index ef24727d..59af3e68 100644
--- a/daemon/defer.c
+++ b/daemon/defer.c
@@ -458,11 +458,12 @@ int defer_init(const char *mmap_file, int cpus)
size_t size = offsetof(struct defer, kru) + KRU.get_size(capacity_log);
size_t header_size = offsetof(struct defer, using_avx2) + sizeof(header.using_avx2);
- kr_assert(header_size ==
- sizeof(header.capacity) +
- sizeof(header.max_decay) +
- sizeof(header.cpus) +
- sizeof(header.using_avx2)); // no undefined padding inside
+ static_assert( // no padding up to .using_avx2
+ offsetof(struct defer, using_avx2) ==
+ sizeof(header.capacity) +
+ sizeof(header.max_decay) +
+ sizeof(header.cpus),
+ "detected padding with undefined data inside mmapped header");
ret = mmapped_init(&defer_mmapped, mmap_file, size, &header, header_size);
if (ret == MMAPPED_WAS_FIRST) {
diff --git a/daemon/ratelimiting.c b/daemon/ratelimiting.c
index 179ce043..528608cf 100644
--- a/daemon/ratelimiting.c
+++ b/daemon/ratelimiting.c
@@ -63,14 +63,15 @@ int ratelimiting_init(const char *mmap_file, size_t capacity, uint32_t instant_l
};
size_t header_size = offsetof(struct ratelimiting, using_avx2) + sizeof(header.using_avx2);
- kr_assert(header_size ==
- sizeof(header.capacity) +
- sizeof(header.instant_limit) +
- sizeof(header.rate_limit) +
- sizeof(header.log_period) +
- sizeof(header.slip) +
- sizeof(header.dry_run) +
- sizeof(header.using_avx2)); // no undefined padding inside
+ static_assert( // no padding up to .using_avx2
+ offsetof(struct ratelimiting, using_avx2) ==
+ sizeof(header.capacity) +
+ sizeof(header.instant_limit) +
+ sizeof(header.rate_limit) +
+ sizeof(header.log_period) +
+ sizeof(header.slip) +
+ sizeof(header.dry_run),
+ "detected padding with undefined data inside mmapped header");
int ret = mmapped_init(&ratelimiting_mmapped, mmap_file, size, &header, header_size);
if (ret == MMAPPED_WAS_FIRST) {