Skip to content

Commit fb49721

Browse files
committed
Merge patch-axel-12
2 parents 9059b21 + 070911a commit fb49721

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

libsel4allocman/src/bootstrap.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,19 @@ int bootstrap_add_untypeds_from_bootinfo(bootstrap_info_t *bs, seL4_BootInfo *bi
227227

228228
static int bootstrap_add_untypeds_from_simple(bootstrap_info_t *bs, simple_t *simple) {
229229
int error;
230-
int i;
231230
/* if we do not have a boot cspace, or we have added some uts that aren't in the
232231
* current space then just bail */
233232
if (!bs->have_boot_cspace || (bs->uts && !bs->uts_in_current_cspace)) {
234233
return 1;
235234
}
236-
for (i = 0; i < simple_get_untyped_count(simple); i++) {
235+
236+
int cnt = simple_get_untyped_count(simple);
237+
if (cnt < 0) {
238+
ZF_LOGW("Could not get untyped count (%d)", cnt);
239+
return 1;
240+
}
241+
242+
for (int i = 0; i < cnt; i++) {
237243
size_t size_bits;
238244
uintptr_t paddr;
239245
bool device;
@@ -1005,10 +1011,7 @@ static int handle_device_untyped_cap(add_untypeds_state_t *state, uintptr_t padd
10051011
bool cap_tainted = false;
10061012
int error;
10071013
uintptr_t ut_end = paddr + BIT(size_bits);
1008-
int num_regions = 0;
1009-
if (state != NULL) {
1010-
num_regions = state->num_regions;
1011-
}
1014+
int num_regions = state ? state->num_regions : 0;
10121015
for (int i = 0; i < num_regions; i++) {
10131016
pmem_region_t *region = &state->regions[i];
10141017
uint64_t region_end = region->base_addr + region->length;
@@ -1111,23 +1114,25 @@ int allocman_add_simple_untypeds_with_regions(allocman_t *alloc, simple_t *simpl
11111114
int error = prepare_handle_device_untyped_cap(alloc, simple, &state, num_regions, region_list);
11121115
ZF_LOGF_IF(error, "bootstrap_prepare_handle_device_untyped_cap Failed");
11131116

1114-
size_t i;
1115-
size_t total_untyped = simple_get_untyped_count(simple);
1117+
int total_untyped = simple_get_untyped_count(simple);
1118+
if (total_untyped < 0) {
1119+
ZF_LOGW("Could not get untyped count (%d)", total_untyped);
1120+
return 0; /* don't report an error, just do nothing */
1121+
}
11161122

1117-
for(i = 0; i < total_untyped; i++) {
1123+
for(int i = 0; i < total_untyped; i++) {
11181124
size_t size_bits;
11191125
uintptr_t paddr;
11201126
bool device;
11211127
cspacepath_t path = allocman_cspace_make_path(alloc, simple_get_nth_untyped(simple, i, &size_bits, &paddr, &device));
1122-
int dev_type = device ? ALLOCMAN_UT_DEV : ALLOCMAN_UT_KERNEL;
1123-
// If it is regular UT memory, then we add cap and move on.
1124-
if (dev_type == ALLOCMAN_UT_KERNEL) {
1125-
error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, dev_type);
1126-
ZF_LOGF_IF(error, "Could not add kernel untyped.");
1127-
} else {
1128-
// Otherwise we are Device untyped.
1128+
if (device) {
1129+
// Separates device RAM memory into separate untyped caps
11291130
error = handle_device_untyped_cap(state, paddr, size_bits, &path, alloc);
1130-
ZF_LOGF_IF(error, "bootstrap_arch_handle_device_untyped_cap failed.");
1131+
ZF_LOGF_IF(error, "handle_device_untyped_cap failed (%d).", error);
1132+
} else {
1133+
// for regular UT memory we add cap
1134+
error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, ALLOCMAN_UT_KERNEL);
1135+
ZF_LOGF_IF(error, "Could not add kernel untyped (%d).", error);
11311136
}
11321137
}
11331138
if (state) {

libsel4simple/src/simple.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
bool simple_is_untyped_cap(simple_t *simple, seL4_CPtr pos)
1010
{
11-
int i;
11+
int cnt = simple_get_untyped_count(simple);
12+
if (cnt < 0) {
13+
ZF_LOGW("Could not get untyped count (%d)", cnt);
14+
return false;
15+
}
1216

13-
for (i = 0; i < simple_get_untyped_count(simple); i++) {
17+
for (int i = 0; i < cnt; i++) {
1418
seL4_CPtr ut_pos = simple_get_nth_untyped(simple, i, NULL, NULL, NULL);
1519
if (ut_pos == pos) {
1620
return true;

0 commit comments

Comments
 (0)