Skip to content

Commit

Permalink
Update clang-format
Browse files Browse the repository at this point in the history
* Prefer to never use tabs
* Update all source files with new formatting option
  • Loading branch information
0152la authored and probablytom committed Nov 14, 2023
1 parent 48d18ed commit b5bbc06
Show file tree
Hide file tree
Showing 70 changed files with 3,193 additions and 3,193 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Always
UseTab: Never
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
AllowAllArgumentsOnNextLine: true
Expand Down
18 changes: 9 additions & 9 deletions allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

int main()
{
size_t size = 31;
size_t size = 31;

printf("Size: ");
if (0 == scanf("%lu", &size))
{
error("Extraneous input");
return -1;
}
printf("Size: ");
if (0 == scanf("%lu", &size))
{
error("Extraneous input");
return -1;
}

void *memory = malloc(size);
pp_cap(memory);
void *memory = malloc(size);
pp_cap(memory);
}
12 changes: 6 additions & 6 deletions bounds-cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

int main()
{
std::vector<int> list = {1, 2, 3, 4};
for (unsigned int i = 0; i <= 16; i++)
{
pp_cap(&list[i]);
std::cout << "Value: " << list[i] << std::endl;
}
std::vector<int> list = {1, 2, 3, 4};
for (unsigned int i = 0; i <= 16; i++)
{
pp_cap(&list[i]);
std::cout << "Value: " << list[i] << std::endl;
}
}
18 changes: 9 additions & 9 deletions bounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

int main()
{
int32_t array[16] = {0};
int32_t *typed_array = &array;
int32_t array[16] = {0};
int32_t *typed_array = &array;

uint64_t length = cheri_length_get(typed_array);
for (uint32_t counter = 0; counter <= (length / sizeof(int32_t)) + 15; counter++)
{
pp_cap(typed_array + counter);
// Read value to crash
printf("Count: %d, Value: %d\n", counter, *(typed_array + counter));
}
uint64_t length = cheri_length_get(typed_array);
for (uint32_t counter = 0; counter <= (length / sizeof(int32_t)) + 15; counter++)
{
pp_cap(typed_array + counter);
// Read value to crash
printf("Count: %d, Value: %d\n", counter, *(typed_array + counter));
}
}
130 changes: 65 additions & 65 deletions capability_sharing/cap-to-file/cap_to_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,77 @@

int write_cap(FILE *f, uintptr_t *cap)
{
size_t res = fwrite(cap, sizeof(uintptr_t), 1, f);
if (res != 1)
{
fprintf(stderr, "write failed: %zu\n", res);
return 1;
}

return 0;
size_t res = fwrite(cap, sizeof(uintptr_t), 1, f);
if (res != 1)
{
fprintf(stderr, "write failed: %zu\n", res);
return 1;
}

return 0;
}

int read_cap(FILE *f, uintptr_t *cap)
{
size_t res = fread(cap, sizeof(uintptr_t), 1, f);
if (res != 1)
{
fprintf(stderr, "read failed: %zu\n", res);
return 1;
}

return 0;
size_t res = fread(cap, sizeof(uintptr_t), 1, f);
if (res != 1)
{
fprintf(stderr, "read failed: %zu\n", res);
return 1;
}

return 0;
}

int main(int argc, char **argv)
{
int x = 1;
uintptr_t cap = (uintptr_t) &x;
FILE *f = NULL;

if (!(f = tmpfile()))
{
perror("failed to create temporary file");
return 1;
}

printf("Writing capability to file: %#lp\n", (void *) cap);
assert(cheri_is_valid((void *) cap));

if (write_cap(f, &cap))
{
return 1;
}

if (fflush(f))
{
perror("failed to flush");
return 1;
}

if (fseek(f, 0, SEEK_SET))
{
perror("failed to seek");
return 1;
}

uintptr_t stored_cap = 0;
// 0 is not a valid capability
assert(!cheri_is_valid((void *) stored_cap));

if (read_cap(f, &stored_cap))
{
return 1;
}

printf("Read capability from file: %#lp\n", (void *) stored_cap);
assert(cap == stored_cap);

// XXX the capability should not be valid but due to a bug in CheriBSD
// this assertion succeeds!
assert(cheri_is_valid((void *) stored_cap));

fclose(f);

return 0;
int x = 1;
uintptr_t cap = (uintptr_t) &x;
FILE *f = NULL;

if (!(f = tmpfile()))
{
perror("failed to create temporary file");
return 1;
}

printf("Writing capability to file: %#lp\n", (void *) cap);
assert(cheri_is_valid((void *) cap));

if (write_cap(f, &cap))
{
return 1;
}

if (fflush(f))
{
perror("failed to flush");
return 1;
}

if (fseek(f, 0, SEEK_SET))
{
perror("failed to seek");
return 1;
}

uintptr_t stored_cap = 0;
// 0 is not a valid capability
assert(!cheri_is_valid((void *) stored_cap));

if (read_cap(f, &stored_cap))
{
return 1;
}

printf("Read capability from file: %#lp\n", (void *) stored_cap);
assert(cap == stored_cap);

// XXX the capability should not be valid but due to a bug in CheriBSD
// this assertion succeeds!
assert(cheri_is_valid((void *) stored_cap));

fclose(f);

return 0;
}
50 changes: 25 additions & 25 deletions capability_sharing/leak-capability/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@
*/
int main(int argc, char **argv)
{
uintptr_t cap = 0;
// 0 is not a valid capability
assert(!cheri_is_valid((void *) cap));
uintptr_t cap = 0;
// 0 is not a valid capability
assert(!cheri_is_valid((void *) cap));

FILE *f = fopen(CAP_FILE, "r");
FILE *f = fopen(CAP_FILE, "r");

if (f == NULL)
{
perror("failed to open file");
return 1;
}
if (f == NULL)
{
perror("failed to open file");
return 1;
}

size_t n = fread(&cap, sizeof(uintptr_t), 1, f);
size_t n = fread(&cap, sizeof(uintptr_t), 1, f);

if (n != 1)
{
fprintf(stderr, "read failed: %zu\n", n);
return 1;
}
if (n != 1)
{
fprintf(stderr, "read failed: %zu\n", n);
return 1;
}

if (fclose(f))
{
perror("failed to close file");
return 1;
}
if (fclose(f))
{
perror("failed to close file");
return 1;
}

printf("Read capability from %s: %#lp\n", CAP_FILE, (void *) cap);
printf("Read capability from %s: %#lp\n", CAP_FILE, (void *) cap);

// XXX the capability should not be valid but due to a bug in CheriBSD
// this assertion succeeds!
assert(cheri_is_valid((void *) cap));
// XXX the capability should not be valid but due to a bug in CheriBSD
// this assertion succeeds!
assert(cheri_is_valid((void *) cap));

return 0;
return 0;
}
42 changes: 21 additions & 21 deletions capability_sharing/leak-capability/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@
*/
int main(int argc, char **argv)
{
FILE *f = fopen(CAP_FILE, "w");
FILE *f = fopen(CAP_FILE, "w");

if (f == NULL)
{
perror("failed to open file");
return 1;
}
if (f == NULL)
{
perror("failed to open file");
return 1;
}

int x = 1;
uintptr_t cap = (uintptr_t) &x;
int x = 1;
uintptr_t cap = (uintptr_t) &x;

size_t n = fwrite(&cap, sizeof(uintptr_t), 1, f);
size_t n = fwrite(&cap, sizeof(uintptr_t), 1, f);

fprintf(stderr, "Wrote capability to %s: %#lp\n", CAP_FILE, (void *) cap);
fprintf(stderr, "Wrote capability to %s: %#lp\n", CAP_FILE, (void *) cap);

if (n != 1)
{
fprintf(stderr, "write failed: %zu\n", n);
return 1;
}
if (n != 1)
{
fprintf(stderr, "write failed: %zu\n", n);
return 1;
}

if (fclose(f))
{
perror("failed to close file");
return 1;
}
if (fclose(f))
{
perror("failed to close file");
return 1;
}

return 0;
return 0;
}
24 changes: 12 additions & 12 deletions capability_sharing/mmap-shared-vs-private/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

#define MMAP_SIZE 4096
#define INIT_TEST_CASE(prot_in, flags_in, fd_in) \
{ \
.prot = prot_in, .flags = flags_in, .fd = fd_in, \
.details = "flags = " #flags_in ", prot = " #prot_in \
}
{ \
.prot = prot_in, .flags = flags_in, .fd = fd_in, \
.details = "flags = " #flags_in ", prot = " #prot_in \
}

typedef struct mmap_test_case
{
/* The memory protection flags */
int prot;
/* The visibility flags */
int flags;
/* The file descriptor, if a file mapping was requested. */
int fd;
/* A string describing the mapping (used for debugging). */
char *details;
/* The memory protection flags */
int prot;
/* The visibility flags */
int flags;
/* The file descriptor, if a file mapping was requested. */
int fd;
/* A string describing the mapping (used for debugging). */
char *details;
} mmap_test_case_t;

int run_mmap_test(mmap_test_case_t);
Expand Down
4 changes: 2 additions & 2 deletions capability_sharing/mmap-shared-vs-private/private_anon_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

int main(int argc, char **argv)
{
mmap_test_case_t test = INIT_TEST_CASE(PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1);
mmap_test_case_t test = INIT_TEST_CASE(PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1);

return run_mmap_test(test);
return run_mmap_test(test);
}
Loading

0 comments on commit b5bbc06

Please sign in to comment.