update cheri article

This commit is contained in:
2022-11-22 00:13:56 +00:00
parent f88766280a
commit 25594e233e
3 changed files with 45 additions and 34 deletions

View File

@ -1,4 +1,4 @@
CFLAGS += -Wall -g -fno-stack-protector
CFLAGS += -Wall -g -fno-stack-protector -O0
CC ?= clang
PURECAP_CC ?= ~/cheri/output/sdk/utils/cheribsd-riscv64-purecap-clang

View File

@ -2,20 +2,21 @@
int main() {
int magic = 9999;
(void)magic;
(void)magic; // suppress unused warning
int arr[] = { 1234, 5678 };
int *x = &(arr[0]); // x is a pointer to first element of arr
printf("*x=%d\n", *x);
printf("*(%lx)=%d\n", (size_t) x, *x);
unsigned long x_addr = (size_t) x; // we're going to assume size_t = unsigned long here
x_addr += 4; // sizeof(int) == 4
x = (int *) x_addr;
printf("*x=%d\n", *x);
printf("*(%lx)=%d\n", (size_t) x, *x);
x_addr += 4;
x = (int *) x_addr;
printf("*x=%d\n", *x);
printf("*(%lx)=%d\n", (size_t) x, *x);
return 0;
}