-
Notifications
You must be signed in to change notification settings - Fork 0
/
align.c
69 lines (53 loc) · 1.98 KB
/
align.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/****************************************************************
* Pointer alignment
*
* Experiments in manipulating aligned objects.
*
* Copyright Alastair Reid 2020
* SPDX-Licence-Identifier: BSD-3-Clause
****************************************************************/
#include "stddef.h"
#include "stdint.h"
#include "wrap.h"
/****************************************************************
* Alignment annotations
****************************************************************/
// VeriFast does not support alignas or alignof so
// we just define them to do nothing and are forced to treat
// them as documentation.
//
// To compensate for this, we have the 'aligned' predicate
#define alignas(n) /* nothing */
#define alignof(t) /* nothing */
#define is_aligned(p, alignment) (((intptr_t)p) % alignment == 0)
// Alas, it is not possible to use the is_aligned macro to define this predicate.
//@ predicate aligned(void* p, size_t alignment;) = ((intptr_t)p) % alignment == 0;
/****************************************************************
* Alignment-sensitive functions
****************************************************************/
#define PAGE_SIZE 4096
// A dummy function that requires an aligned pointer
void foo(void* p);
//@ requires aligned(p, PAGE_SIZE);
//@ ensures aligned(p, PAGE_SIZE);
/****************************************************************
* Sequential tests
****************************************************************/
// not usable by VeriFast
// static const int TABLE_SIZE = 65536;
// not usable by VeriFast
// #define TABLE_SIZE (PAGE_SIZE * 16)
// Alas, this is the only working variant that I have found.
#define TABLE_SIZE 65536
alignas(PAGE_SIZE) char table[TABLE_SIZE];
void test_align()
//@ requires true;
//@ ensures true;
{
//@ assume(is_aligned(&table, PAGE_SIZE));
foo(table);
foo(table);
}
/****************************************************************
* End
****************************************************************/