-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtagged_ptr_test.c
37 lines (27 loc) · 918 Bytes
/
tagged_ptr_test.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
/* iso_alloc tagged_ptr_test.c
* Copyright 2023 - [email protected] */
#include <stdio.h>
#include <string.h>
#include "iso_alloc.h"
#include "iso_alloc_internal.h"
#if !MEMORY_TAGGING
#error "This test intended to be run with -DMEMORY_TAGGING=1"
#endif
#define SIZE 256
int main(int argc, char *argv[]) {
iso_alloc_zone_handle *_zone_handle = iso_alloc_new_zone(SIZE);
if(_zone_handle == NULL) {
abort();
}
void *p = iso_alloc_from_zone_tagged(_zone_handle);
void *up = iso_alloc_untag_ptr(p, _zone_handle);
uint8_t tag = ((uintptr_t) p >> 56);
uint8_t itag = iso_alloc_get_mem_tag(up, _zone_handle);
if(tag != itag) {
LOG_AND_ABORT("Tags %d and %d do not match", tag, itag);
}
/* We can pass a tagged or untagged pointer to iso_free_from_zone */
iso_free_from_zone(p, _zone_handle);
iso_alloc_destroy_zone(_zone_handle);
return 0;
}