1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libexec/include/exec/segment.h Tue May 10 22:39:15 2022 +0200
1.3 @@ -0,0 +1,81 @@
1.4 +/*
1.5 + * Program memory segment support.
1.6 + *
1.7 + * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/re/c/dataspace.h>
1.28 +#include <l4/re/c/rm.h>
1.29 +
1.30 +#include <fsclient/client.h>
1.31 +
1.32 +#include <exec/mapped_region.h>
1.33 +
1.34 +
1.35 +
1.36 +/* Program segment abstraction. */
1.37 +
1.38 +class Segment
1.39 +{
1.40 +protected:
1.41 + MappedRegion _region;
1.42 +
1.43 +public:
1.44 + /* Allocated memory. */
1.45 +
1.46 + char *buf;
1.47 + l4re_ds_t ds;
1.48 +
1.49 + /* Segment base and corresponding region base. */
1.50 +
1.51 + l4_addr_t base, region_base;
1.52 +
1.53 + /* Segment size and corresponding region size. */
1.54 +
1.55 + offset_t size, region_size;
1.56 +
1.57 + /* Offset of segment content within the region. */
1.58 +
1.59 + offset_t region_offset;
1.60 +
1.61 + /* Access flags. */
1.62 +
1.63 + l4re_rm_flags_t flags;
1.64 +
1.65 + /* File access details. */
1.66 +
1.67 + offset_t file_offset, file_contents;
1.68 +
1.69 + explicit Segment(offset_t base, offset_t size, l4re_rm_flags_t flags,
1.70 + offset_t file_offset = 0, offset_t file_contents = 0);
1.71 +
1.72 + long allocate();
1.73 +
1.74 + long fill(file_t *file);
1.75 +
1.76 + MappedRegion ®ion();
1.77 +
1.78 + l4_addr_t region_address(char *address);
1.79 +
1.80 + l4_addr_t region_address(l4_addr_t address);
1.81 +};
1.82 +
1.83 +/* vim: tabstop=2 expandtab shiftwidth=2
1.84 +*/