Use static assertion to verify that union epoll_ref is the right size
union epoll_ref is used to subdivide the 64-bit data field in struct epoll_event. Thus it *must* fit within that field or we're likely to get very subtle and nasty bugs. C11 introduces the notion of static assertions which we can use to verify this is the case at compile time. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
8218d99013
commit
b15ce5b6ce
1 changed files with 4 additions and 0 deletions
4
passt.h
4
passt.h
|
@ -32,6 +32,8 @@ struct tap_l4_msg {
|
|||
union epoll_ref;
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#include "packet.h"
|
||||
#include "icmp.h"
|
||||
|
@ -64,6 +66,8 @@ union epoll_ref {
|
|||
};
|
||||
uint64_t u64;
|
||||
};
|
||||
static_assert(sizeof(union epoll_ref) <= sizeof(union epoll_data),
|
||||
"epoll_ref must have same size as epoll_data");
|
||||
|
||||
#define TAP_BUF_BYTES \
|
||||
ROUND_DOWN(((ETH_MAX_MTU + sizeof(uint32_t)) * 128), PAGE_SIZE)
|
||||
|
|
Loading…
Reference in a new issue