1.1 --- a/tests/dstest_exec.cc Tue Apr 26 22:52:40 2022 +0200
1.2 +++ b/tests/dstest_exec.cc Tue Apr 26 23:15:30 2022 +0200
1.3 @@ -24,12 +24,12 @@
1.4 #include <l4/sys/factory.h>
1.5 #include <l4/sys/task.h>
1.6 #include <l4/sys/thread.h>
1.7 -#include <l4/util/bitops.h> /* l4util_log2 */
1.8
1.9 #include <fsclient/client.h>
1.10 #include <ipc/cap_alloc.h>
1.11 #include <ipc/mem_ipc.h>
1.12 #include <ipc/server.h>
1.13 +#include <mem/memory_utils.h>
1.14 #include <systypes/fcntl.h>
1.15
1.16 #include <stdio.h>
1.17 @@ -128,21 +128,40 @@
1.18
1.19
1.20
1.21 -static int find_region_exp(offset_t size)
1.22 +static offset_t find_region_size(offset_t size)
1.23 {
1.24 - int exp = l4util_log2(size);
1.25 -
1.26 - if ((1UL << exp) < size)
1.27 - return exp + 1;
1.28 - else
1.29 - return exp;
1.30 + return 1 << page_order(size);
1.31 }
1.32
1.33 -static offset_t find_region_size(offset_t size)
1.34 +
1.35 +
1.36 +/* Capability mapping definitions for the new task. */
1.37 +
1.38 +struct mapped_cap
1.39 +{
1.40 + l4_cap_idx_t cap;
1.41 + unsigned char rights;
1.42 + l4_umword_t spot;
1.43 +};
1.44 +
1.45 +static long map_capabilities(l4_cap_idx_t task, struct mapped_cap mapped_caps[])
1.46 {
1.47 - return 1 << find_region_exp(size);
1.48 + long err = L4_EOK;
1.49 + int i = 0;
1.50 +
1.51 + while (l4_is_valid_cap(mapped_caps[i].cap) && !err)
1.52 + {
1.53 + err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.54 + l4_obj_fpage(mapped_caps[i].cap, 0, mapped_caps[i].rights),
1.55 + l4_map_obj_control(mapped_caps[i].spot, L4_MAP_ITEM_MAP)));
1.56 + i++;
1.57 + }
1.58 +
1.59 + return err;
1.60 }
1.61
1.62 +
1.63 +
1.64 int main(int argc, char *argv[])
1.65 {
1.66 long err;
1.67 @@ -155,23 +174,18 @@
1.68
1.69 /* Allocate capabilities for the task and thread. */
1.70
1.71 - l4_cap_idx_t task, thread;
1.72 + l4_cap_idx_t caps[2];
1.73
1.74 - task = ipc_cap_alloc();
1.75 + err = ipc_cap_alloc_many(caps, 2);
1.76
1.77 - if (l4_is_invalid_cap(task))
1.78 + if (err)
1.79 {
1.80 - printf("Could not allocate task.\n");
1.81 + printf("Could not allocate capabilities.\n");
1.82 return 1;
1.83 }
1.84
1.85 - thread = ipc_cap_alloc();
1.86 -
1.87 - if (l4_is_invalid_cap(thread))
1.88 - {
1.89 - printf("Could not allocate thread.\n");
1.90 - return 1;
1.91 - }
1.92 + l4_cap_idx_t &task = caps[0];
1.93 + l4_cap_idx_t &thread = caps[1];
1.94
1.95 /* Obtain the payload as a dataspace. */
1.96
1.97 @@ -191,7 +205,7 @@
1.98 l4re_ds_t region_ds;
1.99
1.100 err = ipc_allocate_align(region_size, L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RWX,
1.101 - find_region_exp(4000000), (void **) &buf, ®ion_ds);
1.102 + page_order(4000000), (void **) &buf, ®ion_ds);
1.103
1.104 if (err)
1.105 {
1.106 @@ -214,7 +228,7 @@
1.107 /* UTCB location and size. */
1.108
1.109 l4_addr_t utcb_start = Utcb_area_start;
1.110 - int utcb_log2size = find_region_exp(Default_max_threads * L4_UTCB_OFFSET);
1.111 + int utcb_log2size = page_order(Default_max_threads * L4_UTCB_OFFSET);
1.112
1.113 /* Round up to at least one page. */
1.114
1.115 @@ -256,7 +270,7 @@
1.116 pthread_attr_init(&attr);
1.117 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1.118
1.119 - init_pager(&config, (l4_addr_t) buf, find_region_exp(file->size), 0x1000000);
1.120 + init_pager(&config, (l4_addr_t) buf, page_order(file->size), 0x1000000);
1.121
1.122 err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config);
1.123
1.124 @@ -298,53 +312,22 @@
1.125 return 1;
1.126 }
1.127
1.128 - err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.129 - l4_obj_fpage(task, 0, L4_CAP_FPAGE_RWS),
1.130 - l4_map_obj_control(L4_BASE_TASK_CAP, L4_MAP_ITEM_MAP)));
1.131 + /* Define capability mappings for the new task. */
1.132
1.133 - if (err)
1.134 - {
1.135 - printf("Could not map task capability into task.\n");
1.136 - return 1;
1.137 - }
1.138 + struct mapped_cap mapped_caps[] = {
1.139 + {task, L4_CAP_FPAGE_RWS, L4_BASE_TASK_CAP},
1.140 + {thread, L4_CAP_FPAGE_RWS, L4_BASE_THREAD_CAP},
1.141 + {l4re_env()->factory, L4_CAP_FPAGE_RWS, L4_BASE_FACTORY_CAP},
1.142 + {l4re_env()->log, L4_CAP_FPAGE_RWS, L4_BASE_LOG_CAP},
1.143 + {l4re_env()->scheduler, L4_CAP_FPAGE_RWS, L4_BASE_SCHEDULER_CAP},
1.144 + {L4_INVALID_CAP, 0, 0},
1.145 + };
1.146
1.147 - err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.148 - l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS),
1.149 - l4_map_obj_control(L4_BASE_THREAD_CAP, L4_MAP_ITEM_MAP)));
1.150 + err = map_capabilities(task, mapped_caps);
1.151
1.152 if (err)
1.153 {
1.154 - printf("Could not map thread capability into task.\n");
1.155 - return 1;
1.156 - }
1.157 -
1.158 - err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.159 - l4_obj_fpage(l4re_env()->factory, 0, L4_CAP_FPAGE_RWS),
1.160 - l4_map_obj_control(L4_BASE_FACTORY_CAP, L4_MAP_ITEM_MAP)));
1.161 -
1.162 - if (err)
1.163 - {
1.164 - printf("Could not map factory capability into task.\n");
1.165 - return 1;
1.166 - }
1.167 -
1.168 - err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.169 - l4_obj_fpage(l4re_env()->log, 0, L4_CAP_FPAGE_RWS),
1.170 - l4_map_obj_control(L4_BASE_LOG_CAP, L4_MAP_ITEM_MAP)));
1.171 -
1.172 - if (err)
1.173 - {
1.174 - printf("Could not map log capability into task.\n");
1.175 - return 1;
1.176 - }
1.177 -
1.178 - err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
1.179 - l4_obj_fpage(l4re_env()->scheduler, 0, L4_CAP_FPAGE_RWS),
1.180 - l4_map_obj_control(L4_BASE_SCHEDULER_CAP, L4_MAP_ITEM_MAP)));
1.181 -
1.182 - if (err)
1.183 - {
1.184 - printf("Could not map scheduler capability into task.\n");
1.185 + printf("Could not capabilities into task.\n");
1.186 return 1;
1.187 }
1.188
1.189 @@ -368,9 +351,9 @@
1.190
1.191 /* Map the payload into the new task. */
1.192
1.193 - printf("Map %p with size %ld (2 ** %d).\n", buf, file->size, find_region_exp(file->size));
1.194 + printf("Map %p with size %ld (2 ** %d).\n", buf, file->size, page_order(file->size));
1.195
1.196 - l4_fpage_t payload_fpage = l4_fpage((l4_addr_t) buf, find_region_exp(file->size), L4_FPAGE_RX);
1.197 + l4_fpage_t payload_fpage = l4_fpage((l4_addr_t) buf, page_order(file->size), L4_FPAGE_RX);
1.198
1.199 err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP, payload_fpage, 0x1000000));
1.200