jekyll -> zola
This commit is contained in:
22
code/cheri/Makefile
Normal file
22
code/cheri/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
CFLAGS += -Wall -g -fno-stack-protector -O0
|
||||
CC := clang
|
||||
PURECAP_CC ?= ~/cheri/output/sdk/utils/cheribsd-riscv64-purecap-clang
|
||||
|
||||
SOURCES := $(wildcard *.c)
|
||||
OBJECTS := $(patsubst %.c, %, $(SOURCES))
|
||||
OBJECTS_CHERIBSD := $(patsubst %.c, %-cheribsd, $(SOURCES))
|
||||
|
||||
all: all-host all-cheribsd
|
||||
|
||||
all-host: $(OBJECTS)
|
||||
|
||||
all-cheribsd: $(OBJECTS_CHERIBSD)
|
||||
|
||||
%: %.c
|
||||
$(CC) $< $(CFLAGS) -o $@
|
||||
|
||||
%-cheribsd: %.c
|
||||
$(PURECAP_CC) $< $(CFLAGS) -o $@
|
||||
|
||||
clean:
|
||||
rm $(OBJECTS) $(OBJECTS_CHERIBSD)
|
BIN
code/cheri/membug
Executable file
BIN
code/cheri/membug
Executable file
Binary file not shown.
5305
code/cheri/membug-cheri.S
Normal file
5305
code/cheri/membug-cheri.S
Normal file
File diff suppressed because it is too large
Load Diff
BIN
code/cheri/membug-cheribsd
Executable file
BIN
code/cheri/membug-cheribsd
Executable file
Binary file not shown.
13
code/cheri/membug.c
Normal file
13
code/cheri/membug.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char my_perfect_string[] = "what a beautiful string"; // so beautiful, I sure hope no-one touches it
|
||||
char user_name[32];
|
||||
|
||||
printf("enter your name: ");
|
||||
fgets(user_name, 1000, stdin); // get user's name from stdin
|
||||
printf("hello %s", user_name);
|
||||
printf("my_perfect_string: %s\n", my_perfect_string);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
code/cheri/ptrs_as_numbers
Executable file
BIN
code/cheri/ptrs_as_numbers
Executable file
Binary file not shown.
BIN
code/cheri/ptrs_as_numbers-cheribsd
Executable file
BIN
code/cheri/ptrs_as_numbers-cheribsd
Executable file
Binary file not shown.
22
code/cheri/ptrs_as_numbers.c
Normal file
22
code/cheri/ptrs_as_numbers.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int magic = 9999;
|
||||
(void)magic; // suppress unused warning
|
||||
|
||||
int arr[] = { 1234, 5678 };
|
||||
|
||||
int *x = &(arr[0]); // x is a pointer to first element of arr
|
||||
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("*(%lx)=%d\n", (size_t) x, *x);
|
||||
|
||||
x_addr += 4;
|
||||
x = (int *) x_addr;
|
||||
printf("*(%lx)=%d\n", (size_t) x, *x);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
code/cheri/ptrtypes
Executable file
BIN
code/cheri/ptrtypes
Executable file
Binary file not shown.
BIN
code/cheri/ptrtypes-cheribsd
Executable file
BIN
code/cheri/ptrtypes-cheribsd
Executable file
Binary file not shown.
37
code/cheri/ptrtypes.c
Normal file
37
code/cheri/ptrtypes.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main() {
|
||||
printf("type size (hex) size (dec)\n");
|
||||
printf("=====================================\n");
|
||||
#ifdef __PTRADDR_TYPE__
|
||||
printf("ptraddr_t 0x%.2lx %.2lu\n", sizeof(ptraddr_t), sizeof(ptraddr_t));
|
||||
#endif
|
||||
printf("uintptr_t 0x%.2lx %.2lu\n", sizeof(uintptr_t), sizeof(uintptr_t));
|
||||
printf("size_t 0x%.2lx %.2lu\n", sizeof(size_t), sizeof(size_t));
|
||||
printf("void* 0x%.2lx %.2lu\n", sizeof(void*), sizeof(void*));
|
||||
printf("=====================================\n");
|
||||
|
||||
#ifdef __CHERI__
|
||||
int x = 111;
|
||||
int y[] = { 888, 999 };
|
||||
|
||||
int *a = &x;
|
||||
int *b = &(y[0]);
|
||||
|
||||
// transplant address from capability a to capability b
|
||||
printf("*b: %d\n", *b);
|
||||
ptraddr_t a_addr = __builtin_cheri_address_get(a);
|
||||
b = __builtin_cheri_address_set(a, a_addr);
|
||||
printf("*b: %d\n", *b);
|
||||
|
||||
b = &(y[0]);
|
||||
// uintptr_t is an unsigned integer type that preserves capabilities
|
||||
uintptr_t b_uintptr = (uintptr_t) b;
|
||||
b_uintptr += sizeof(int);
|
||||
b = (int*) b_uintptr;
|
||||
printf("*b: %d\n", *b);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
BIN
code/cheri/sizes
Executable file
BIN
code/cheri/sizes
Executable file
Binary file not shown.
BIN
code/cheri/sizes-cheribsd
Executable file
BIN
code/cheri/sizes-cheribsd
Executable file
Binary file not shown.
7
code/cheri/sizes.c
Normal file
7
code/cheri/sizes.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main () {
|
||||
printf("void *: %lu, size_t: %lu\n", sizeof(void *), sizeof(size_t));
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user