diff --git a/conts/posix/mm0/mm/capability.c b/conts/posix/mm0/mm/capability.c index b8171b9..a3010fb 100644 --- a/conts/posix/mm0/mm/capability.c +++ b/conts/posix/mm0/mm/capability.c @@ -517,7 +517,7 @@ int cap_find_replicate_reduce_grant(struct capability *cap) if ((err = l4_capability_control(CAP_CONTROL_DESTROY, 0, 0, 0, &new_cap)) < 0) { - printf("l4_capability_control() replication of " + printf("l4_capability_control() destruction of " "capability failed.\n Could not " "complete CAP_CONTROL_DESTROY request " " on cap (%d), err = %d.\n", diff --git a/conts/posix/mm0/mm/utcb.c b/conts/posix/mm0/mm/utcb.c index c9223bb..028d855 100644 --- a/conts/posix/mm0/mm/utcb.c +++ b/conts/posix/mm0/mm/utcb.c @@ -108,7 +108,7 @@ int task_delete_utcb_desc(struct tcb *task, struct utcb_desc *d) } /* - * Upon fork, the utcb descriptor list is origaced by a new one, since it is a new + * Upon fork, the utcb descriptor list is replaced by a new one, since it is a new * address space. A new utcb is allocated and mmap'ed for the child task * running in the newly created address space. * diff --git a/src/generic/container.c b/src/generic/container.c index 8f248ad..4beca9b 100644 --- a/src/generic/container.c +++ b/src/generic/container.c @@ -94,7 +94,6 @@ int init_pager(struct pager *pager, struct ktcb *task; struct address_space *space; int first = !!current_pgd; - struct capability *cap; /* * Set up dummy current cap_list so that cap accounting @@ -140,6 +139,7 @@ int init_pager(struct pager *pager, /* Add the address space to container space list */ address_space_add(task->space); +#if 0 /* Initialize uninitialized capability fields while on dummy */ list_foreach_struct(cap, ¤t->cap_list.caps, list) { /* Initialize owner */ @@ -158,8 +158,9 @@ int init_pager(struct pager *pager, else cap->resid = CAP_RESID_NONE; } +#endif - printk("%s: Mapping 0x%lx bytes (0x%lx pages) from 0x%lx to 0x%lx for %s\n", + printk("%s: Mapping 0x%lx bytes (%lu pages) from 0x%lx to 0x%lx for %s\n", __KERNELNAME__, pager->memsize, __pfn(page_align_up(pager->memsize)), pager->start_lma, pager->start_vma, cont->name); @@ -184,6 +185,93 @@ int init_pager(struct pager *pager, return 0; } +/* + * All first-level dynamically allocated resources + * are initialized, which includes the pager thread ids + * and pager space ids. + * + * Update all capability target ids that target such + * run-time allocated resources. + */ +int update_dynamic_capids(struct kernel_resources *kres) +{ + struct ktcb *pager, *tpager; + struct container *cont, *tcont; + struct capability *cap; + + /* Containers */ + list_foreach_struct(cont, &kres->containers.list, list) { + /* Pagers */ + list_foreach_struct(pager, &cont->ktcb_list.list, task_list) { + /* Capabilities */ + list_foreach_struct(cap, + &pager->space->cap_list.caps, + list) { + + /* They all shall be owned by their pager */ + cap->owner = pager->tid; + + /* + * Pager Space/Thread targets need updating + * from the given static container id to their + * run-time allocated ids. + */ + + /* Quantity caps don't have target ids */ + if (cap_type(cap) == CAP_TYPE_QUANTITY) + cap->resid = CAP_RESID_NONE; + + /* + * Space _always_ denotes current pager's + * space. Other containers are not addressable + * by space ids. + */ + if (cap_rtype(cap) == CAP_RTYPE_SPACE) + cap->resid = pager->space->spid; + + /* + * Thread _always_denotes another container's + * pager. There is simply no other reasonable + * thread target in the system. + */ + if (cap_rtype(cap) == CAP_RTYPE_THREAD) { + + /* Find target container */ + if (!(tcont = + container_find(kres, + cap->resid))) { + printk("FATAL: Capability " + "configured to target " + "non-existent " + "container.\n"); + BUG(); + + } + + /* Find its pager */ + if (list_empty(&tcont->ktcb_list.list)) { + printk("FATAL: Pager" + "does not exist in " + "container %d.\n", + tcont->cid); + BUG(); + } + + tpager = + link_to_struct( + tcont->ktcb_list.list.next, + struct ktcb, task_list); + + /* Assign pager's thread id to cap */ + cap->resid = tpager->tid; + } + } + } + } + + return 0; +} + /* * Initialize all containers with their initial set of tasks, * spaces, scheduler parameters such that they can be started. @@ -209,6 +297,12 @@ int container_init_pagers(struct kernel_resources *kres, } } + /* Update any capability fields that were dynamically allocated */ + update_dynamic_capids(kres); + return 0; } + + + diff --git a/src/generic/resource.c b/src/generic/resource.c index 705cf78..a56da55 100644 --- a/src/generic/resource.c +++ b/src/generic/resource.c @@ -430,6 +430,7 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo) cap_info = &pinfo->caps[i]; + cap->resid = cap_info->target; cap->type = cap_info->type; cap->access = cap_info->access; cap->start = cap_info->start; @@ -527,8 +528,8 @@ void setup_kernel_resources(struct boot_resources *bootres, * See how many containers we have. Assign next * unused container id for kernel resources */ - //kres->cid = id_get(&kres->container_ids, bootres->nconts + 1); - kres->cid = id_get(&kres->container_ids, 0); + kres->cid = id_get(&kres->container_ids, bootres->nconts + 1); + // kres->cid = id_get(&kres->container_ids, 0); // Gets id 0 /* First initialize the list of non-memory capabilities */ cap = boot_capability_create();