1.1 --- a/libexec/lib/src/stack.cc Sun Jun 12 17:50:58 2022 +0200
1.2 +++ b/libexec/lib/src/stack.cc Sun Jun 12 18:04:17 2022 +0200
1.3 @@ -26,7 +26,6 @@
1.4
1.5 #include <mem/memory_utils.h>
1.6
1.7 -#include <stdio.h>
1.8 #include <string.h>
1.9
1.10 #include "stack.h"
1.11 @@ -39,23 +38,58 @@
1.12 : _segment(segment)
1.13 {
1.14 _element = (l4_umword_t *) (segment.address() + segment.size());
1.15 +}
1.16
1.17 - /* Add a terminator for any additional initial capabilities. */
1.18 +/* Set any additional initial capabilities. */
1.19 +
1.20 +void Stack::set_init_caps(l4re_env_cap_entry_t *entries)
1.21 +{
1.22 + _cap_entries = entries;
1.23 +}
1.24 +
1.25 +/* Set any indicated memory regions. */
1.26 +
1.27 +void Stack::set_regions(struct exec_region *regions)
1.28 +{
1.29 + _region_entries = regions;
1.30 +}
1.31
1.32 - l4re_env_cap_entry_t *entry = (l4re_env_cap_entry_t *) _element;
1.33 +/* Push any indicated memory regions. */
1.34 +
1.35 +void Stack::push_regions()
1.36 +{
1.37 + struct exec_region *region = (struct exec_region *) _element;
1.38 + struct exec_region *regions = _region_entries;
1.39 +
1.40 + /* Terminate the regions with a null entry. */
1.41
1.42 - *(--entry) = l4re_env_cap_entry_t();
1.43 - _element = (l4_umword_t *) entry;
1.44 + *(--region) = (struct exec_region) {0, 0, 0, L4_INVALID_CAP};
1.45 +
1.46 + for (; (regions != NULL) && (regions->ds != L4_INVALID_CAP); regions++)
1.47 + {
1.48 + *(--region) = *regions;
1.49 + }
1.50 +
1.51 + _regions = (l4_addr_t) region;
1.52 + _element = (l4_umword_t *) region;
1.53 }
1.54
1.55 /* Push any additional initial capabilities. */
1.56
1.57 -void Stack::push_cap_entries(l4re_env_cap_entry_t *entries)
1.58 +void Stack::push_init_caps()
1.59 {
1.60 l4re_env_cap_entry_t *entry = (l4re_env_cap_entry_t *) _element;
1.61 + l4re_env_cap_entry_t *entries = _cap_entries;
1.62
1.63 - while ((entries != NULL) && (entries->cap != L4_INVALID_CAP))
1.64 + /* Terminate the capabilities with a null entry. */
1.65 +
1.66 + *(--entry) = l4re_env_cap_entry_t();
1.67 +
1.68 + for (; (entries != NULL) && (entries->flags != ~0UL); entries++)
1.69 + {
1.70 *(--entry) = *entries;
1.71 + _num_caps++;
1.72 + }
1.73
1.74 _caps = (l4_addr_t) entry;
1.75 _element = (l4_umword_t *) entry;
1.76 @@ -102,6 +136,15 @@
1.77
1.78 void Stack::push_l4re_aux()
1.79 {
1.80 + /* Regions for the region mapper. */
1.81 +
1.82 + if (_regions)
1.83 + *(--_element) = _segment.region_address((char *) _regions);
1.84 + else
1.85 + *(--_element) = 0;
1.86 +
1.87 + /* Reserve space for the actual L4Re auxiliary structure. */
1.88 +
1.89 _aux = (l4re_aux_t *) _element;
1.90 _aux--;
1.91 _element = (l4_umword_t *) _aux;
1.92 @@ -239,6 +282,11 @@
1.93
1.94 void Stack::populate(int argc, char *argv[], char *envp[])
1.95 {
1.96 + /* Populate stack with any regions and capabilities. */
1.97 +
1.98 + push_regions();
1.99 + push_init_caps();
1.100 +
1.101 /* Populate stack with environment and argument values. */
1.102
1.103 push_env(envp);