align1.c
up: index
prev: ip2.c
next: align2.c
#include <stdlib.h>
#include <stdio.h>
#include <stdalign.h>
#include "capprint.h"
struct my_header { size_t x; };
static void *my_malloc_wrapper(size_t size)
{
void *p = malloc(sizeof(struct my_header) + size);
((struct my_header *)p)->x = size;
return (char *)p + sizeof(struct my_header);
}
int main()
{
fprintf(stderr, "alignof(int*): %zu\n", alignof(int*));
fprintf(stderr, "sizeof(struct my_header): %zu\n", sizeof(struct my_header));
int x = 42;
int **p = my_malloc_wrapper(sizeof(int*));
fprintf(stderr,"Ptr %" PTR_FMT "\n", sptr((void*)p));
*p = &x;
fprintf(stderr,"Value %d\n", **p);
}
Experimental data (what does this mean?)
cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi exit codes: compile 0 / execute 1
Undefined {ub: "UB043_indirection_invalid_value", loc: "<23:5--23:7>"}
alignof(int*): 16
sizeof(struct my_header): 8
Ptr (@disabled, 0xffffe568 [rwRW,0xffffe560-0xffffe578])
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia exit codes: compile 0 / execute 1
Undefined {ub: "UB043_indirection_invalid_value", loc: "<23:5--23:7>"}
alignof(int*): 16
sizeof(struct my_header): 8
Ptr (@116, 0xffffe568 [rwRW,0xffffe560-0xffffe578])
clang-riscv-O3-bounds-subobject-safe exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
0x00000000001020c8 in main () at tests/cheri/align1.c:23
23 *p = &x;
#0 0x00000000001020c8 in main () at tests/cheri/align1.c:23
x = <optimized out>
p = <optimized out>
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
0x00000000001020e2 in main () at tests/cheri/align1.c:23
23 *p = &x;
#0 0x00000000001020e2 in main () at tests/cheri/align1.c:23
x = 42
p = 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
clang-riscv-O3-bounds-conservative exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
main () at tests/cheri/align1.c:23
23 *p = &x;
#0 main () at tests/cheri/align1.c:23
x = 42
p = <optimized out>
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
0x00000000001020aa in main () at tests/cheri/align1.c:23
23 *p = &x;
#0 0x00000000001020aa in main () at tests/cheri/align1.c:23
x = 42
p = 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40a1d008 [rwRW,0x40a1d000-0x40a1d018]
clang-morello-O3-bounds-subobject-safe exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
main () at tests/cheri/align1.c:23
23 *p = &x;
#0 main () at tests/cheri/align1.c:23
x = 42
p = <optimized out>
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
0x0000000000110f68 in main () at tests/cheri/align1.c:23
23 *p = &x;
#0 0x0000000000110f68 in main () at tests/cheri/align1.c:23
x = 42
p = 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
clang-morello-O3-bounds-conservative exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
main () at tests/cheri/align1.c:23
23 *p = &x;
#0 main () at tests/cheri/align1.c:23
x = 42
p = 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only exit codes: compile 0 / execute 1
Program received signal SIGBUS, Bus error.
Invalid address alignment.
0x0000000000110f30 in main () at tests/cheri/align1.c:23
23 *p = &x;
#0 0x0000000000110f30 in main () at tests/cheri/align1.c:23
x = 42
p = 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40c1d008 [rwRW,0x40c1d000-0x40c1d018]
gcc-morello-O3 alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40000018 [rwRW,0x40000010-0x40000028]
Value 42
gcc-morello-O0 exit codes: compile 0 / execute 137
alignof(int*): 16
sizeof(struct my_header): 8
Ptr 0x40000018 [rwRW,0x40000010-0x40000028]