# HG changeset patch # User Paul Boddie # Date 1652279825 -7200 # Node ID 224d34e52d8513b1240b45408bb144cb20cea5c5 # Parent 7ea58a920abe99fa8b68b13e83e5eb39d48cfe1f Made various members protected, introducing access methods. diff -r 7ea58a920abe -r 224d34e52d85 libexec/include/exec/segment.h --- a/libexec/include/exec/segment.h Wed May 11 01:23:28 2022 +0200 +++ b/libexec/include/exec/segment.h Wed May 11 16:37:05 2022 +0200 @@ -37,39 +37,47 @@ protected: MappedRegion _region; -public: /* Allocated memory. */ - char *buf; - l4re_ds_t ds; + char *_buf; + l4re_ds_t _ds; /* Segment base and corresponding region base. */ - l4_addr_t base, region_base; + l4_addr_t _base, _region_base; /* Segment size and corresponding region size. */ - offset_t size, region_size; + offset_t _size, _region_size; /* Offset of segment content within the region. */ - offset_t region_offset; + offset_t _region_offset; /* Access flags. */ - l4re_rm_flags_t flags; + l4re_rm_flags_t _flags; /* File access details. */ - offset_t file_offset, file_contents; + offset_t _file_offset, _file_contents; +public: explicit Segment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags, offset_t file_offset = 0, offset_t file_contents = 0); + char *address(); + + offset_t size(); + + /* Segment population methods. */ + long allocate(); long fill(file_t *file); + /* Mapped region methods. */ + MappedRegion ®ion(); l4_addr_t region_address(char *address); diff -r 7ea58a920abe -r 224d34e52d85 libexec/lib/src/segment.cc --- a/libexec/lib/src/segment.cc Wed May 11 01:23:28 2022 +0200 +++ b/libexec/lib/src/segment.cc Wed May 11 16:37:05 2022 +0200 @@ -35,12 +35,27 @@ Segment::Segment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags, offset_t file_offset, offset_t file_contents) -: base(base), size(size), flags(flags), file_offset(file_offset), - file_contents(file_contents) + +: _base(base), _size(size), _flags(flags), _file_offset(file_offset), + _file_contents(file_contents) { - region_base = trunc(base, L4_PAGESIZE); - region_offset = base - region_base; - region_size = round(size, L4_PAGESIZE); + _region_base = trunc(_base, L4_PAGESIZE); + _region_offset = _base - _region_base; + _region_size = round(_size, L4_PAGESIZE); +} + +/* Return the address of allocated memory. */ + +char *Segment::address() +{ + return _buf; +} + +/* Return the size of the allocated memory. */ + +offset_t Segment::size() +{ + return _size; } /* Allocate a region for the segment. */ @@ -49,27 +64,27 @@ { /* Make regions writable if they need to be filled. */ - l4re_rm_flags_t allocation_flags = flags; + l4re_rm_flags_t allocation_flags = _flags; - if (file_contents) + if (_file_contents) allocation_flags |= L4RE_RM_F_W; - return ipc_allocate_align(size, L4RE_RM_F_SEARCH_ADDR | allocation_flags, - L4_PAGESHIFT, (void **) &buf, &ds); + return ipc_allocate_align(_size, L4RE_RM_F_SEARCH_ADDR | allocation_flags, + L4_PAGESHIFT, (void **) &_buf, &_ds); } /* Fill a segment region with file content. */ long Segment::fill(file_t *file) { - if (!file_contents) + if (!_file_contents) return L4_EOK; - memset(buf, 0, region_size); - client_seek(file, file_offset, SEEK_SET); - offset_t nread = client_read(file, buf + region_offset, file_contents); + memset(_buf, 0, _region_size); + client_seek(file, _file_offset, SEEK_SET); + offset_t nread = client_read(file, _buf + _region_offset, _file_contents); - if (nread < file_contents) + if (nread < _file_contents) return -L4_EIO; else return L4_EOK; @@ -79,7 +94,7 @@ MappedRegion &Segment::region() { - _region = MappedRegion((l4_addr_t) buf, page_order(region_size), flags, region_base); + _region = MappedRegion((l4_addr_t) _buf, page_order(_region_size), _flags, _region_base); return _region; } @@ -87,12 +102,12 @@ l4_addr_t Segment::region_address(char *address) { - return (l4_addr_t) ((address - buf) + (char *) region_base); + return (l4_addr_t) ((address - _buf) + (char *) _region_base); } l4_addr_t Segment::region_address(l4_addr_t address) { - return (address - (l4_addr_t) buf) + region_base; + return (address - (l4_addr_t) _buf) + _region_base; } /* vim: tabstop=2 expandtab shiftwidth=2 diff -r 7ea58a920abe -r 224d34e52d85 libexec/lib/src/stack.cc --- a/libexec/lib/src/stack.cc Wed May 11 01:23:28 2022 +0200 +++ b/libexec/lib/src/stack.cc Wed May 11 16:37:05 2022 +0200 @@ -38,7 +38,7 @@ Stack::Stack(Segment &segment) : _segment(segment) { - _element = (l4_umword_t *) (segment.buf + segment.size); + _element = (l4_umword_t *) (segment.address() + segment.size()); /* Add a terminator for any additional initial capabilities. */