L4Re/departure

Changeset

511:2bab05fdeee5
2023-03-10 Paul Boddie raw files shortlog changelog graph Provide the filesystem capability to the new process.
libexec/lib/src/process_creating.cc (file)
     1.1 --- a/libexec/lib/src/process_creating.cc	Fri Mar 10 01:20:57 2023 +0100
     1.2 +++ b/libexec/lib/src/process_creating.cc	Fri Mar 10 01:21:50 2023 +0100
     1.3 @@ -26,6 +26,7 @@
     1.4  #include <fsserver/resource_server.h>
     1.5  #include <ipc/cap_alloc.h>
     1.6  #include <ipc/map.h>
     1.7 +#include <systypes/env.h>
     1.8  #include <systypes/fcntl.h>
     1.9  
    1.10  #include <stdio.h>
    1.11 @@ -189,7 +190,7 @@
    1.12    struct exec_region rm_regions[_program_payload->segments() + 2];
    1.13  
    1.14    /* Define capabilities for mapping, including region dataspace capabilities,
    1.15 -     the stack dataspace capability, and the server capability. */
    1.16 +     the stack dataspace capability, plus the pager capability. */
    1.17  
    1.18    struct ipc_mapped_cap rm_mapped_caps[_program_payload->segments() + 3];
    1.19  
    1.20 @@ -223,7 +224,10 @@
    1.21  
    1.22    /* Map these additional capabilities. */
    1.23  
    1.24 -  _process.map_capabilities(rm_mapped_caps, false);
    1.25 +  long err = _process.map_capabilities(rm_mapped_caps, false);
    1.26 +
    1.27 +  if (err)
    1.28 +    return err;
    1.29  
    1.30    /* Define the IPC gate as an initial capability to be acquired by the region
    1.31       mapper via the l4re_env API. The capability index is assigned above when
    1.32 @@ -242,7 +246,7 @@
    1.33       exception handler plus region mapper). */
    1.34  
    1.35    l4_cap_idx_t mapped_pager = L4_INVALID_CAP;
    1.36 -  long err = _process.configure_thread(pager, &mapped_pager);
    1.37 +  err = _process.configure_thread(pager, &mapped_pager);
    1.38  
    1.39    if (err)
    1.40      return err;
    1.41 @@ -289,12 +293,41 @@
    1.42    if (err)
    1.43      return err;
    1.44  
    1.45 +  /* Obtain the filesystem capability for exporting to the task. */
    1.46 +
    1.47 +  l4_cap_idx_t fsserver_cap = _process.allocate_cap();
    1.48 +  l4_cap_idx_t fsserver = l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME);
    1.49 +
    1.50 +  /* Define the capabilities to be mapped for the filesystem. */
    1.51 +
    1.52 +  struct ipc_mapped_cap program_mapped_caps[] = {
    1.53 +    {fsserver_cap, fsserver, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS},
    1.54 +    {0, L4_INVALID_CAP, 0, 0},
    1.55 +    };
    1.56 +
    1.57 +  /* Map these additional capabilities. */
    1.58 +
    1.59 +  err = _process.map_capabilities(program_mapped_caps, false);
    1.60 +
    1.61 +  if (err)
    1.62 +    return err;
    1.63 +
    1.64 +  /* Define initial capabilities to be acquired by the region mapper via the
    1.65 +     l4re_env API. Each capability index is assigned above when mapping the
    1.66 +     capability and encoded in the entry below. */
    1.67 +
    1.68 +  l4re_env_cap_entry_t program_init_caps[] = {
    1.69 +    l4re_env_cap_entry_t(ENV_FILESYSTEM_SERVER_NAME, fsserver_cap, L4_CAP_FPAGE_RWS),
    1.70 +    l4re_env_cap_entry_t()
    1.71 +    };
    1.72 +
    1.73    /* Populate a thread stack with argument and environment details for the
    1.74       actual program. The server capability should be assigned to the region
    1.75       mapper capability slot already. */
    1.76  
    1.77    Stack program_st(*_program_stack);
    1.78  
    1.79 +  program_st.set_init_caps(program_init_caps);
    1.80    program_st.populate(argc, argv, envp);
    1.81  
    1.82    /* Start the program thread in the appropriate stack. */