Skip to content

Commit

Permalink
Increment numCompartments on its own line
Browse files Browse the repository at this point in the history
Andrei noted that incrementing `numCompartments` is more readable if
done on its own line, rather than when indexing an array, in [PR
review](capablevms#88 (comment)). Thanks for the feedback!
  • Loading branch information
probablytom committed Nov 7, 2023
1 parent c362c4a commit b84412b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions example_allocators/compartment_alloc/compartment_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,36 @@ int numCompartments = 0;
void
*__capability init_compartment(size_t size_in_bytes, void *__capability dc)
{
void *buf;
void *__capability compartment_id;

// We impose a limit on our # of compartments
if (numCompartments + 1 == maxCompartments) {
perror("Too many compartments requested.");
exit(1);
}

// Allocate memory for this compartment
void *buf = mmap(NULL, size_in_bytes, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
buf = mmap(NULL, size_in_bytes, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (buf == MAP_FAILED)
{
perror("error in initial mem allocation");
exit(-1);
}

// Create the new compartment
compartment_id = sealed_reference(buf);
compartments[numCompartments] = (heap_compartment){
buf, // Space on the heap
0, // bytes allocated (currently none!)
size_in_bytes, // Our maximum size, to check when allocating
dc, // The data capability to allocate against (like a DDC)
sealed_reference(buf) // An identifier which allows a holder to allocate in this component
buf, // Space on the heap
0, // bytes allocated (currently none!)
size_in_bytes, // Our maximum size, to check when allocating
dc, // The data capability to allocate against (like a DDC)
compartment_id // An identifier which allows a holder to allocate in this component
};
numCompartments++;

// Return the sealed capability which acts as a token of authentication for a component.
return compartments[numCompartments++].identifier;
return compartment_id;
}

/*
Expand Down

0 comments on commit b84412b

Please sign in to comment.