Upgrade all C_ASSERT to static_assert (#3702)

Signed-off-by: Alan Jowett (from Dev Box) <alanjo@microsoft.com>
This commit is contained in:
Alan Jowett 2024-07-16 10:46:04 -07:00 коммит произвёл GitHub
Родитель b9d6cb6b7e
Коммит a055146760
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 19 добавлений и 7 удалений

Просмотреть файл

@ -2,6 +2,8 @@
// SPDX-License-Identifier: MIT
#pragma once
#pragma pack(push)
#pragma pack(1)
struct tcphdr
{
uint16_t source;
@ -27,9 +29,18 @@ struct tcphdr
uint16_t check; // Checksum
uint16_t urg_ptr; // Urgent Pointer
};
#pragma pack(pop)
// Verify the bit fields give the correct header size.
#ifndef C_ASSERT
#define C_ASSERT(e) typedef char __C_ASSERT__[(e) ? 1 : -1]
#ifndef FIELD_OFFSET
#define FIELD_OFFSET(type, field) ((long)&(((type*)0)->field))
#endif
C_ASSERT(sizeof(struct tcphdr) == 20);
// check the offset of each field
static_assert(FIELD_OFFSET(struct tcphdr, source) == 0, "source offset mismatch");
static_assert(FIELD_OFFSET(struct tcphdr, dest) == 2, "dest offset mismatch");
static_assert(FIELD_OFFSET(struct tcphdr, seq) == 4, "seq offset mismatch");
static_assert(FIELD_OFFSET(struct tcphdr, ack_seq) == 8, "ack_seq offset mismatch");
// Skip bit fields
static_assert(FIELD_OFFSET(struct tcphdr, window) == 14, "window offset mismatch");
static_assert(FIELD_OFFSET(struct tcphdr, check) == 16, "check offset mismatch");
static_assert(FIELD_OFFSET(struct tcphdr, urg_ptr) == 18, "urg_ptr offset mismatch");

Просмотреть файл

@ -128,9 +128,10 @@ static const ebpf_extension_program_dispatch_table_t _ebpf_link_dispatch_table_w
};
// Assert that the invoke function is aligned with ebpf_extension_dispatch_table_t->function.
C_ASSERT(
static_assert(
EBPF_OFFSET_OF(ebpf_extension_dispatch_table_t, function) ==
EBPF_OFFSET_OF(ebpf_extension_program_dispatch_table_t, ebpf_program_invoke_function));
EBPF_OFFSET_OF(ebpf_extension_program_dispatch_table_t, ebpf_program_invoke_function),
"Invoke function offset mismatch.");
NTSTATUS
_ebpf_link_client_attach_provider(

Просмотреть файл

@ -33,7 +33,7 @@ typedef struct _ebpf_bitmap_cursor_internal
uint64_t current_block_copy; // Copy of the current block being searched.
} ebpf_bitmap_cursor_internal_t;
C_ASSERT(sizeof(ebpf_bitmap_cursor_internal_t) == sizeof(ebpf_bitmap_cursor_t));
static_assert(sizeof(ebpf_bitmap_cursor_internal_t) == sizeof(ebpf_bitmap_cursor_t), "Size mismatch of cursor types.");
// The number of bits within a block.
#define BITS_IN_BLOCK (sizeof(uint64_t) * 8)