1.1 --- a/libexec/include/exec/segment.h Wed May 11 01:23:28 2022 +0200
1.2 +++ b/libexec/include/exec/segment.h Wed May 11 16:37:05 2022 +0200
1.3 @@ -37,39 +37,47 @@
1.4 protected:
1.5 MappedRegion _region;
1.6
1.7 -public:
1.8 /* Allocated memory. */
1.9
1.10 - char *buf;
1.11 - l4re_ds_t ds;
1.12 + char *_buf;
1.13 + l4re_ds_t _ds;
1.14
1.15 /* Segment base and corresponding region base. */
1.16
1.17 - l4_addr_t base, region_base;
1.18 + l4_addr_t _base, _region_base;
1.19
1.20 /* Segment size and corresponding region size. */
1.21
1.22 - offset_t size, region_size;
1.23 + offset_t _size, _region_size;
1.24
1.25 /* Offset of segment content within the region. */
1.26
1.27 - offset_t region_offset;
1.28 + offset_t _region_offset;
1.29
1.30 /* Access flags. */
1.31
1.32 - l4re_rm_flags_t flags;
1.33 + l4re_rm_flags_t _flags;
1.34
1.35 /* File access details. */
1.36
1.37 - offset_t file_offset, file_contents;
1.38 + offset_t _file_offset, _file_contents;
1.39
1.40 +public:
1.41 explicit Segment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags,
1.42 offset_t file_offset = 0, offset_t file_contents = 0);
1.43
1.44 + char *address();
1.45 +
1.46 + offset_t size();
1.47 +
1.48 + /* Segment population methods. */
1.49 +
1.50 long allocate();
1.51
1.52 long fill(file_t *file);
1.53
1.54 + /* Mapped region methods. */
1.55 +
1.56 MappedRegion ®ion();
1.57
1.58 l4_addr_t region_address(char *address);
2.1 --- a/libexec/lib/src/segment.cc Wed May 11 01:23:28 2022 +0200
2.2 +++ b/libexec/lib/src/segment.cc Wed May 11 16:37:05 2022 +0200
2.3 @@ -35,12 +35,27 @@
2.4
2.5 Segment::Segment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags,
2.6 offset_t file_offset, offset_t file_contents)
2.7 -: base(base), size(size), flags(flags), file_offset(file_offset),
2.8 - file_contents(file_contents)
2.9 +
2.10 +: _base(base), _size(size), _flags(flags), _file_offset(file_offset),
2.11 + _file_contents(file_contents)
2.12 {
2.13 - region_base = trunc(base, L4_PAGESIZE);
2.14 - region_offset = base - region_base;
2.15 - region_size = round(size, L4_PAGESIZE);
2.16 + _region_base = trunc(_base, L4_PAGESIZE);
2.17 + _region_offset = _base - _region_base;
2.18 + _region_size = round(_size, L4_PAGESIZE);
2.19 +}
2.20 +
2.21 +/* Return the address of allocated memory. */
2.22 +
2.23 +char *Segment::address()
2.24 +{
2.25 + return _buf;
2.26 +}
2.27 +
2.28 +/* Return the size of the allocated memory. */
2.29 +
2.30 +offset_t Segment::size()
2.31 +{
2.32 + return _size;
2.33 }
2.34
2.35 /* Allocate a region for the segment. */
2.36 @@ -49,27 +64,27 @@
2.37 {
2.38 /* Make regions writable if they need to be filled. */
2.39
2.40 - l4re_rm_flags_t allocation_flags = flags;
2.41 + l4re_rm_flags_t allocation_flags = _flags;
2.42
2.43 - if (file_contents)
2.44 + if (_file_contents)
2.45 allocation_flags |= L4RE_RM_F_W;
2.46
2.47 - return ipc_allocate_align(size, L4RE_RM_F_SEARCH_ADDR | allocation_flags,
2.48 - L4_PAGESHIFT, (void **) &buf, &ds);
2.49 + return ipc_allocate_align(_size, L4RE_RM_F_SEARCH_ADDR | allocation_flags,
2.50 + L4_PAGESHIFT, (void **) &_buf, &_ds);
2.51 }
2.52
2.53 /* Fill a segment region with file content. */
2.54
2.55 long Segment::fill(file_t *file)
2.56 {
2.57 - if (!file_contents)
2.58 + if (!_file_contents)
2.59 return L4_EOK;
2.60
2.61 - memset(buf, 0, region_size);
2.62 - client_seek(file, file_offset, SEEK_SET);
2.63 - offset_t nread = client_read(file, buf + region_offset, file_contents);
2.64 + memset(_buf, 0, _region_size);
2.65 + client_seek(file, _file_offset, SEEK_SET);
2.66 + offset_t nread = client_read(file, _buf + _region_offset, _file_contents);
2.67
2.68 - if (nread < file_contents)
2.69 + if (nread < _file_contents)
2.70 return -L4_EIO;
2.71 else
2.72 return L4_EOK;
2.73 @@ -79,7 +94,7 @@
2.74
2.75 MappedRegion &Segment::region()
2.76 {
2.77 - _region = MappedRegion((l4_addr_t) buf, page_order(region_size), flags, region_base);
2.78 + _region = MappedRegion((l4_addr_t) _buf, page_order(_region_size), _flags, _region_base);
2.79 return _region;
2.80 }
2.81
2.82 @@ -87,12 +102,12 @@
2.83
2.84 l4_addr_t Segment::region_address(char *address)
2.85 {
2.86 - return (l4_addr_t) ((address - buf) + (char *) region_base);
2.87 + return (l4_addr_t) ((address - _buf) + (char *) _region_base);
2.88 }
2.89
2.90 l4_addr_t Segment::region_address(l4_addr_t address)
2.91 {
2.92 - return (address - (l4_addr_t) buf) + region_base;
2.93 + return (address - (l4_addr_t) _buf) + _region_base;
2.94 }
2.95
2.96 /* vim: tabstop=2 expandtab shiftwidth=2
3.1 --- a/libexec/lib/src/stack.cc Wed May 11 01:23:28 2022 +0200
3.2 +++ b/libexec/lib/src/stack.cc Wed May 11 16:37:05 2022 +0200
3.3 @@ -38,7 +38,7 @@
3.4 Stack::Stack(Segment &segment)
3.5 : _segment(segment)
3.6 {
3.7 - _element = (l4_umword_t *) (segment.buf + segment.size);
3.8 + _element = (l4_umword_t *) (segment.address() + segment.size());
3.9
3.10 /* Add a terminator for any additional initial capabilities. */
3.11