1.1 --- a/libexec/lib/src/segment.cc Sun Jun 12 17:50:58 2022 +0200
1.2 +++ b/libexec/lib/src/segment.cc Sun Jun 12 18:04:17 2022 +0200
1.3 @@ -49,6 +49,13 @@
1.4 _region_allocated_size = round(region_size() + _region_content_offset, L4_PAGESIZE);
1.5 }
1.6
1.7 +/* Return the capability of the dataspace providing the memory. */
1.8 +
1.9 +l4_cap_idx_t Segment::cap()
1.10 +{
1.11 + return _ds;
1.12 +}
1.13 +
1.14 /* Return the address of allocated memory. */
1.15
1.16 char *Segment::address()
1.17 @@ -65,29 +72,49 @@
1.18
1.19 /* Allocate a writable region for the segment. */
1.20
1.21 -long Segment::allocate()
1.22 +long Segment::allocate(bool attach)
1.23 {
1.24 - return ipc_allocate_align(_region_allocated_size, L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW,
1.25 - L4_PAGESHIFT, (void **) &_buf, &_ds);
1.26 + if (attach)
1.27 + return ipc_allocate_align(_region_allocated_size,
1.28 + L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW,
1.29 + L4_PAGESHIFT, (void **) &_buf, &_ds);
1.30 + else
1.31 + return ipc_new_dataspace(_region_allocated_size,
1.32 + L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW,
1.33 + L4_PAGESHIFT, &_ds);
1.34 }
1.35
1.36 /* Fill a segment region with file content. */
1.37
1.38 -long Segment::fill(file_t *file)
1.39 +long Segment::fill(file_t *file, bool attach)
1.40 {
1.41 - /* Provide the exposed file contents in a masked memory mapped region. */
1.42 + /* Provide the exposed file contents in a masked memory mapped region, or if
1.43 + not attaching the region, merely request access via a dataspace. */
1.44
1.45 - _buf = (char *) client_mmap(file,
1.46 + if (attach)
1.47 + {
1.48 + _buf = (char *) client_mmap(file,
1.49 + file_offset() - _region_content_offset,
1.50 + _region_allocated_size,
1.51 + file_offset(),
1.52 + file_offset() + file_contents(),
1.53 + region_flags());
1.54 + if (_buf == NULL)
1.55 + return -L4_EIO;
1.56 + }
1.57 + else
1.58 + {
1.59 + long err = file_mmap_only(file,
1.60 file_offset() - _region_content_offset,
1.61 _region_allocated_size,
1.62 file_offset(),
1.63 - file_offset() + file_contents(),
1.64 - region_flags());
1.65 + file_offset() + file_contents());
1.66 + if (err)
1.67 + return err;
1.68 + }
1.69
1.70 - if (_buf == NULL)
1.71 - return -L4_EIO;
1.72 - else
1.73 - return L4_EOK;
1.74 + _ds = file->ref;
1.75 + return L4_EOK;
1.76 }
1.77
1.78 /* Define and return the mapped region for the segment. */
1.79 @@ -98,6 +125,14 @@
1.80 return _region;
1.81 }
1.82
1.83 +/* Define and return the region dataspace details. */
1.84 +
1.85 +struct exec_region &Segment::exec_region()
1.86 +{
1.87 + _exec_region = (struct exec_region) {_region_base, _region_allocated_size, region_flags(), _ds};
1.88 + return _exec_region;
1.89 +}
1.90 +
1.91 /* Return the mapped address corresponding to the given address. */
1.92
1.93 l4_addr_t Segment::region_address(char *address)