# HG changeset patch # User Paul Boddie # Date 1618179171 -7200 # Node ID 3bc33e8c5306e744dd1cc522292fe7d89d411b57 # Parent 00dc578063750732c4adcf3fdac2f94469556f2e Introduced distinct types instead of using the file offset type throughout. This makes a difference on 32-bit architectures where the address type will only be 32 bits wide, whereas the file offset type should be 64 bits wide. diff -r 00dc57806375 -r 3bc33e8c5306 client/client.cc --- a/client/client.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/client/client.cc Mon Apr 12 00:12:51 2021 +0200 @@ -30,7 +30,7 @@ /* Default size of pipe regions. */ -const offset_t DEFAULT_PIPE_SIZE = 4096; +const length_t DEFAULT_PIPE_SIZE = 4096; @@ -159,7 +159,7 @@ /* Map a memory region to a file. */ -void *client_mmap(file_t *file, offset_t position, offset_t length) +void *client_mmap(file_t *file, offset_t position, length_t length) { if ((file == NULL) || (file_mmap(file, position, length))) return NULL; diff -r 00dc57806375 -r 3bc33e8c5306 client/client.h --- a/client/client.h Sun Apr 11 19:34:07 2021 +0200 +++ b/client/client.h Mon Apr 12 00:12:51 2021 +0200 @@ -34,7 +34,7 @@ /* File and region operations. */ long client_flush(file_t *file); -void *client_mmap(file_t *file, offset_t position, offset_t length); +void *client_mmap(file_t *file, offset_t position, length_t length); /* Pipe region operations. */ diff -r 00dc57806375 -r 3bc33e8c5306 client/file.cc --- a/client/file.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/client/file.cc Mon Apr 12 00:12:51 2021 +0200 @@ -124,7 +124,8 @@ return -L4_EINVAL; client_Opener opener(server); - unsigned long size, flags; + length_t size; + flags_t flags; long err; file_init(file); @@ -175,7 +176,7 @@ /* Map a region of the given file to a memory region, obtaining an updated file size and populated data details. Unmap any previously mapped region. */ -long file_mmap(file_t *file, offset_t position, offset_t length) +long file_mmap(file_t *file, offset_t position, length_t length) { char *memory = file->memory; client_MappedFile mapped_file(file->ref); @@ -217,15 +218,15 @@ /* Return the amount of data in the mapped region for the given file. */ -offset_t file_populated_span(file_t *file) +length_t file_populated_span(file_t *file) { - offset_t size = file_span(file); + length_t size = file_span(file); return (file->data_end < size) ? file->data_end : size; } /* Return the size of the mapped region for the given file. */ -offset_t file_span(file_t *file) +length_t file_span(file_t *file) { return file->end_pos - file->start_pos; } @@ -235,9 +236,9 @@ /* Get a pointer to any terminated string at the given offset or NULL if the data from offset is not terminated. */ -char *file_string_get(file_t *file, offset_t offset) +char *file_string_get(file_t *file, length_t offset) { - offset_t limit = file_span(file) - offset; + length_t limit = file_span(file) - offset; if (strnlen(file->memory + offset, limit) < limit) return file->memory + offset; @@ -250,10 +251,10 @@ characters copied, excluding the zero terminator is provided via the written parameter if it is not specified as NULL. */ -int file_string_set(file_t *file, const char *data, offset_t offset, - offset_t *written) +int file_string_set(file_t *file, const char *data, length_t offset, + length_t *written) { - offset_t i, pos, limit = file_span(file); + length_t i, pos, limit = file_span(file); /* Do not attempt to copy data with an invalid offset. */ @@ -292,7 +293,7 @@ /* Return the number of remaining populated bytes in the region. */ -offset_t file_data_available(file_t *file) +length_t file_data_available(file_t *file) { return file_populated_span(file) - file->data_current; } @@ -304,6 +305,15 @@ return file->memory + file->data_current; } +/* Return the amount of remaining space in the region. */ + +length_t file_data_space(file_t *file) +{ + return file_span(file) - file->data_current; +} + + + /* Return the current access position in the file. */ offset_t file_data_current_position(file_t *file) @@ -318,13 +328,6 @@ return file->start_pos + file->data_end; } -/* Return the amount of remaining space in the region. */ - -offset_t file_data_space(file_t *file) -{ - return file_span(file) - file->data_current; -} - /* Copy data to the given buffer from the current data position, updating the @@ -358,7 +361,7 @@ /* Open two pipe endpoints using the given pipe server. */ -long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server) +long pipe_open(length_t size, file_t *reader, file_t *writer, l4_cap_idx_t server) { if (l4_is_invalid_cap(server)) return -L4_EINVAL; @@ -437,7 +440,7 @@ /* Set the size of the written region. */ -long pipe_written(file_t *pipe, offset_t size) +long pipe_written(file_t *pipe, length_t size) { if (size <= pipe->size) { diff -r 00dc57806375 -r 3bc33e8c5306 client/file.h --- a/client/file.h Sun Apr 11 19:34:07 2021 +0200 +++ b/client/file.h Mon Apr 12 00:12:51 2021 +0200 @@ -42,8 +42,8 @@ /* File region parameters. */ offset_t start_pos, end_pos; /* start and end positions of region */ - offset_t data_end; /* amount/extent of data in the region */ - offset_t data_current; /* client access offset */ + length_t data_end; /* amount/extent of data in the region */ + length_t data_current; /* client access offset */ /* Total size of file. */ @@ -71,26 +71,29 @@ /* File and region operations. */ long file_flush(file_t *file); -long file_mmap(file_t *file, offset_t position, offset_t length); +long file_mmap(file_t *file, offset_t position, length_t length); long file_resize(file_t *file, offset_t size); /* File and region properties. */ -offset_t file_populated_span(file_t *file); -offset_t file_span(file_t *file); +length_t file_populated_span(file_t *file); +length_t file_span(file_t *file); /* Convenience functions. */ -char *file_string_get(file_t *file, offset_t offset); -int file_string_set(file_t *file, const char *data, offset_t offset, offset_t *written); +char *file_string_get(file_t *file, length_t offset); +int file_string_set(file_t *file, const char *data, length_t offset, length_t *written); /* Client data functions. */ -offset_t file_data_available(file_t *file); +length_t file_data_available(file_t *file); char *file_data_current(file_t *file); +length_t file_data_space(file_t *file); + +/* Client data position functions. */ + offset_t file_data_current_position(file_t *file); offset_t file_data_end_position(file_t *file); -offset_t file_data_space(file_t *file); /* Client data transfer functions. */ @@ -101,13 +104,13 @@ /* Pipe operations. */ -long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server); +long pipe_open(length_t size, file_t *reader, file_t *writer, l4_cap_idx_t server); /* Pipe region operations. */ long pipe_current(file_t *pipe); long pipe_next(file_t *pipe); -long pipe_written(file_t *pipe, offset_t size); +long pipe_written(file_t *pipe, length_t size); EXTERN_C_END diff -r 00dc57806375 -r 3bc33e8c5306 files/block_file_accessor.cc --- a/files/block_file_accessor.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/files/block_file_accessor.cc Mon Apr 12 00:12:51 2021 +0200 @@ -1,10 +1,9 @@ #include +#include #include #include #include -#include - #include "block_file_accessor.h" @@ -69,8 +68,11 @@ void BlockFileAccessor::fill_populated(Flexpage *flexpage) { offset_t filepos = flexpage->base_offset; - offset_t addr = flexpage->base_addr; - offset_t populated_size = std::min(flexpage->size, _size - filepos); + address_t addr = flexpage->base_addr; + offset_t populated_size = _size - filepos; + + if (populated_size > flexpage->size) + populated_size = flexpage->size; /* Tag the region with file state. */ @@ -91,8 +93,11 @@ void BlockFileAccessor::flush_populated(Flexpage *flexpage) { offset_t filepos = flexpage->base_offset; - offset_t addr = flexpage->base_addr; - offset_t populated_size = std::min(flexpage->size, _size - filepos); + address_t addr = flexpage->base_addr; + offset_t populated_size = _size - filepos; + + if (populated_size > flexpage->size) + populated_size = flexpage->size; /* Remove the file state tag from the region. */ diff -r 00dc57806375 -r 3bc33e8c5306 files/file_pager.h --- a/files/file_pager.h Sun Apr 11 19:34:07 2021 +0200 +++ b/files/file_pager.h Mon Apr 12 00:12:51 2021 +0200 @@ -36,7 +36,7 @@ /* Pager and mapped file methods. */ - virtual long map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, + virtual long map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region); virtual long mmap(offset_t position, offset_t length, offset_t *start_pos, diff -r 00dc57806375 -r 3bc33e8c5306 files/opener_context_resource.h --- a/files/opener_context_resource.h Sun Apr 11 19:34:07 2021 +0200 +++ b/files/opener_context_resource.h Mon Apr 12 00:12:51 2021 +0200 @@ -36,15 +36,15 @@ /* Opener context interface methods. */ - long open(flags_t flags, size_t *size, l4_cap_idx_t *file); + long open(flags_t flags, offset_t *size, l4_cap_idx_t *file); /* Pager/dataspace methods. */ - long map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, + long map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) { return SimplePager::map(offset, hot_spot, flags, region); } - long info(unsigned long *size, unsigned long *flags) + long info(length_t *size, flags_t *flags) { return SimplePager::info(size, flags); } }; diff -r 00dc57806375 -r 3bc33e8c5306 generic/pager.cc --- a/generic/pager.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/generic/pager.cc Mon Apr 12 00:12:51 2021 +0200 @@ -46,13 +46,13 @@ /* Expose a region of the file. */ -long Pager::mmap(offset_t position, offset_t length, offset_t *start_pos, +long Pager::mmap(offset_t position, length_t length, offset_t *start_pos, offset_t *end_pos, offset_t *size) { /* Define region characteristics. */ - _start = trunc(position, PAGE_SIZE); - _size = round(position + length, PAGE_SIZE) - _start; + _start = trunc_offset(position, PAGE_SIZE); + _size = round_offset(position + length, PAGE_SIZE) - _start; /* Return the start and end positions plus populated extent. */ @@ -66,7 +66,7 @@ /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' (flexpage offset). */ -long Pager::map(offset_t offset, l4_addr_t hot_spot, flags_t flags, +long Pager::map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) { offset_t file_offset = _start + offset; diff -r 00dc57806375 -r 3bc33e8c5306 generic/pager.h --- a/generic/pager.h Sun Apr 11 19:34:07 2021 +0200 +++ b/generic/pager.h Mon Apr 12 00:12:51 2021 +0200 @@ -23,7 +23,7 @@ /* Paging methods. */ - virtual long map(offset_t offset, l4_addr_t hot_spot, flags_t flags, + virtual long map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region); /* Limit methods. */ @@ -38,7 +38,7 @@ /* Mapped file methods. */ - virtual long mmap(offset_t position, offset_t length, offset_t *start_pos, + virtual long mmap(offset_t position, length_t length, offset_t *start_pos, offset_t *end_pos, offset_t *size); }; diff -r 00dc57806375 -r 3bc33e8c5306 generic/simple_pager.cc --- a/generic/simple_pager.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/generic/simple_pager.cc Mon Apr 12 00:12:51 2021 +0200 @@ -29,7 +29,7 @@ /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' (flexpage offset). */ -long SimplePager::map(offset_t offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region) +long SimplePager::map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) { Flexpage flexpage(_region); @@ -52,7 +52,7 @@ return IPC_MESSAGE_SENT; } -long SimplePager::info(offset_t *size, flags_t *flags) +long SimplePager::info(length_t *size, flags_t *flags) { *size = _region->size(); *flags = L4_FPAGE_RW; diff -r 00dc57806375 -r 3bc33e8c5306 generic/simple_pager.h --- a/generic/simple_pager.h Sun Apr 11 19:34:07 2021 +0200 +++ b/generic/simple_pager.h Mon Apr 12 00:12:51 2021 +0200 @@ -22,9 +22,9 @@ /* Paging methods. */ - long map(offset_t offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region); + long map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region); - long info(offset_t *size, flags_t *flags); + long info(length_t *size, flags_t *flags); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 00dc57806375 -r 3bc33e8c5306 mapping/flexpage.cc --- a/mapping/flexpage.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/mapping/flexpage.cc Mon Apr 12 00:12:51 2021 +0200 @@ -30,7 +30,7 @@ /* Get the file offset for the base of the flexpage. This will be a multiple of the flexpage size for alignment purposes. */ - base_offset = trunc(offset, size); + base_offset = trunc_offset(offset, size); /* The page being accessed is relative to the base. (This is transient information recording the initialising access @@ -86,23 +86,23 @@ /* Return a "send" flexpage for an access to 'offset' by positioning it relative to 'hot_spot' for the receive flexpage window. */ -SendFlexpage Flexpage::to_send(offset_t offset, offset_t hot_spot, +SendFlexpage Flexpage::to_send(offset_t offset, address_t hot_spot, flags_t flags, offset_t max_offset) { /* The dataspace offset of the flexpage base is a multiple of the flexpage size. */ - offset_t receive_base_offset = trunc(offset, size); + offset_t receive_base_offset = trunc_offset(offset, size); /* The offset of the accessed page within the flexpage is constrained by the current flexpage size. */ - offset_t page_offset = trunc(offset - receive_base_offset, PAGE_SIZE); + length_t page_offset = trunc(offset - receive_base_offset, PAGE_SIZE); /* The receive flexpage offset (hot spot) must be constrained to the flexpage, both the size and the start. */ - offset_t receive_size; + length_t receive_size; if (max_offset) { @@ -115,7 +115,7 @@ if (!receive_size) return SendFlexpage(base_addr, page_order(0), flags); - offset_t receive_page_offset = hot_spot % receive_size; + length_t receive_page_offset = hot_spot % receive_size; while ((receive_size > PAGE_SIZE) && (receive_page_offset != page_offset)) { @@ -127,7 +127,7 @@ offsets. Where the receive flexpage offset is constained further, the base address will be raised to become closer to the accessed page. */ - offset_t adjustment = page_offset - receive_page_offset; + length_t adjustment = page_offset - receive_page_offset; return SendFlexpage(base_addr + adjustment, page_order(receive_size), flags); } diff -r 00dc57806375 -r 3bc33e8c5306 mapping/flexpage.h --- a/mapping/flexpage.h Sun Apr 11 19:34:07 2021 +0200 +++ b/mapping/flexpage.h Mon Apr 12 00:12:51 2021 +0200 @@ -19,12 +19,14 @@ /* General flexpage characteristics. */ - offset_t base_addr, size; + address_t base_addr; + length_t size; offset_t base_offset; /* Transient debugging information. */ - offset_t page_addr, page_offset; + address_t page_addr; + length_t page_offset; /* Associate a flexpage with a memory 'region'. */ @@ -46,7 +48,7 @@ void upgrade(flags_t flags); - SendFlexpage to_send(offset_t offset, offset_t hot_spot, flags_t flags, + SendFlexpage to_send(offset_t offset, address_t hot_spot, flags_t flags, offset_t max_offset=0); SendFlexpage to_unmap(); diff -r 00dc57806375 -r 3bc33e8c5306 mapping/ipc.cc --- a/mapping/ipc.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/mapping/ipc.cc Mon Apr 12 00:12:51 2021 +0200 @@ -17,8 +17,8 @@ /* Make a representation of a flexpage for the IPC system. */ -long ipc_prepare_flexpage(Flexpage *flexpage, unsigned long offset, - unsigned long max_offset, l4_addr_t hot_spot, +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, + offset_t max_offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) { SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags, diff -r 00dc57806375 -r 3bc33e8c5306 mapping/ipc.h --- a/mapping/ipc.h Sun Apr 11 19:34:07 2021 +0200 +++ b/mapping/ipc.h Mon Apr 12 00:12:51 2021 +0200 @@ -6,8 +6,8 @@ -long ipc_prepare_flexpage(Flexpage *flexpage, unsigned long offset, - unsigned long max_offset, l4_addr_t hot_spot, +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, + offset_t max_offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region); void ipc_unmap_flexpage(Flexpage *flexpage); diff -r 00dc57806375 -r 3bc33e8c5306 mapping/send_flexpage.h --- a/mapping/send_flexpage.h Sun Apr 11 19:34:07 2021 +0200 +++ b/mapping/send_flexpage.h Mon Apr 12 00:12:51 2021 +0200 @@ -7,11 +7,11 @@ class SendFlexpage { public: - offset_t base_addr; + address_t base_addr; unsigned int order; flags_t flags; - explicit SendFlexpage(offset_t base_addr, unsigned int order, + explicit SendFlexpage(address_t base_addr, unsigned int order, flags_t flags) : base_addr(base_addr), order(order), flags(flags) { diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory.h --- a/memory/memory.h Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory.h Mon Apr 12 00:12:51 2021 +0200 @@ -15,7 +15,7 @@ virtual Region *region() = 0; - virtual offset_t region_size() = 0; + virtual length_t region_size() = 0; virtual void release(Region *region) = 0; }; diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_incremental.cc --- a/memory/memory_incremental.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_incremental.cc Mon Apr 12 00:12:51 2021 +0200 @@ -5,7 +5,7 @@ /* Initialise the memory pool with an optional 'limit' in pages. */ -MemoryIncremental::MemoryIncremental(unsigned int limit, offset_t region_size) +MemoryIncremental::MemoryIncremental(unsigned int limit, length_t region_size) : _limit(limit), _region_size(region_size) { _limited = true; @@ -19,7 +19,7 @@ /* Allocate a block of the given 'size'. */ -Region *MemoryIncremental::allocate(offset_t size) +Region *MemoryIncremental::allocate(length_t size) { /* Attempt to allocate aligned memory. */ @@ -32,17 +32,17 @@ if (posix_memalign(¤t, size, size)) return NULL; - return new Region((offset_t) current, (offset_t) current + size); + return new Region((address_t) current, (address_t) current + size); } /* Allocate a new region of the given 'size' rounded to the nearest page. */ -Region *MemoryIncremental::region(offset_t size) +Region *MemoryIncremental::region(length_t size) { std::lock_guard guard(_lock); - offset_t rounded = round(size, PAGE_SIZE); - offset_t pages = rounded / PAGE_SIZE; + length_t rounded = round(size, PAGE_SIZE); + length_t pages = rounded / PAGE_SIZE; /* Check for sufficient pages. */ @@ -78,8 +78,8 @@ { std::lock_guard guard(_lock); - offset_t rounded = round(region->size(), PAGE_SIZE); - offset_t pages = rounded / PAGE_SIZE; + length_t rounded = round(region->size(), PAGE_SIZE); + length_t pages = rounded / PAGE_SIZE; if (_limited) _limit += pages; diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_incremental.h --- a/memory/memory_incremental.h Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_incremental.h Mon Apr 12 00:12:51 2021 +0200 @@ -17,21 +17,21 @@ std::mutex _lock; unsigned int _limit; - offset_t _region_size; + length_t _region_size; bool _limited; - Region *allocate(offset_t size); + Region *allocate(length_t size); public: - explicit MemoryIncremental(unsigned int limit, offset_t region_size=PAGE_SIZE); + explicit MemoryIncremental(unsigned int limit, length_t region_size=PAGE_SIZE); explicit MemoryIncremental(); - virtual Region *region(offset_t size); + virtual Region *region(length_t size); virtual Region *region(); - virtual offset_t region_size() + virtual length_t region_size() { return _region_size; } virtual void release(Region *region); diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_preallocated.cc --- a/memory/memory_preallocated.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_preallocated.cc Mon Apr 12 00:12:51 2021 +0200 @@ -4,12 +4,12 @@ /* Initialise the memory pool with the given amount in bytes. */ -MemoryPreallocated::MemoryPreallocated(Memory *memory, offset_t amount) +MemoryPreallocated::MemoryPreallocated(Memory *memory, length_t amount) : _memory(memory), _amount(amount) { // NOTE: Handle allocation failure. - offset_t remaining = amount; + length_t remaining = amount; while (remaining) { diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_preallocated.h --- a/memory/memory_preallocated.h Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_preallocated.h Mon Apr 12 00:12:51 2021 +0200 @@ -18,10 +18,10 @@ std::list _regions; Memory *_memory; - offset_t _amount; + length_t _amount; public: - explicit MemoryPreallocated(Memory *memory, offset_t amount); + explicit MemoryPreallocated(Memory *memory, length_t amount); explicit MemoryPreallocated(); @@ -29,7 +29,7 @@ virtual Region *region(); - virtual offset_t region_size() + virtual length_t region_size() { return _memory->region_size(); } virtual void release(Region *region); diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_utils.cc --- a/memory/memory_utils.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_utils.cc Mon Apr 12 00:12:51 2021 +0200 @@ -4,14 +4,14 @@ /* Return page 'n' for the configured page size. */ -offset_t page(unsigned int n) +length_t page(unsigned int n) { return PAGE_SIZE * n; } /* Return the order of 'size', where 2 ** order yields the size. */ -unsigned int page_order(offset_t size) +unsigned int page_order(length_t size) { /* Count zeros from the left, stopping at the first set bit, using the width of the size value (in bits, starting with the width in bytes) to @@ -22,16 +22,21 @@ /* Return 'value' rounded up to the nearest 'increment'. */ -offset_t round(offset_t value, offset_t increment) +length_t round(length_t value, length_t increment) { return trunc(value + increment - 1, increment); } +offset_t round_offset(offset_t value, length_t increment) +{ + return trunc_offset(value + increment - 1, increment); +} + /* Return 'value' rounded up to the nearest multiple of 'increment'. */ -offset_t round_multiple(offset_t value, offset_t increment) +length_t round_multiple(length_t value, length_t increment) { - offset_t last = increment; + length_t last = increment; while (1) { @@ -45,7 +50,12 @@ /* Return 'value' rounded down (or truncated) to the nearest 'increment'. */ -offset_t trunc(offset_t value, offset_t increment) +length_t trunc(length_t value, length_t increment) +{ + return (value / increment) * increment; +} + +offset_t trunc_offset(offset_t value, length_t increment) { return (value / increment) * increment; } @@ -53,9 +63,9 @@ /* Return 'value' rounded down (or truncated) to the nearest multiple of 'increment'. */ -offset_t trunc_multiple(offset_t value, offset_t increment) +length_t trunc_multiple(length_t value, length_t increment) { - offset_t last = increment; + length_t last = increment; while (1) { @@ -70,15 +80,15 @@ /* Find the maximum size aligned region within the region from 'start' to (but not including) 'end', with the given initial 'increment'. */ -offset_t max_multiple(offset_t start, offset_t end, offset_t increment) +length_t max_multiple(length_t start, length_t end, length_t increment) { /* The largest possible aligned region is derived from the region size. */ - offset_t size = trunc_multiple(end - start, increment); + length_t size = trunc_multiple(end - start, increment); /* Apply the alignment to the start. */ - offset_t aligned = round(start, size); + length_t aligned = round(start, size); /* If the region is aligned, return the size. */ @@ -88,7 +98,7 @@ /* If the region is not aligned to the current size, recalculate the aligned size. */ - offset_t aligned_size; + length_t aligned_size; do { diff -r 00dc57806375 -r 3bc33e8c5306 memory/memory_utils.h --- a/memory/memory_utils.h Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/memory_utils.h Mon Apr 12 00:12:51 2021 +0200 @@ -8,18 +8,22 @@ /* Address arithmetic. */ -offset_t page(unsigned int n); +length_t page(unsigned int n); + +unsigned int page_order(length_t size); -unsigned int page_order(offset_t size); +length_t round(length_t value, length_t increment); -offset_t round(offset_t value, offset_t increment); +offset_t round_offset(offset_t value, length_t increment); -offset_t round_multiple(offset_t value, offset_t increment); +length_t round_multiple(length_t value, length_t increment); -offset_t trunc(offset_t value, offset_t increment); +length_t trunc(length_t value, length_t increment); -offset_t trunc_multiple(offset_t value, offset_t increment); +offset_t trunc_offset(offset_t value, length_t increment); -offset_t max_multiple(offset_t start, offset_t end, offset_t increment); +length_t trunc_multiple(length_t value, length_t increment); + +length_t max_multiple(length_t start, length_t end, length_t increment); // vim: tabstop=4 expandtab shiftwidth=4 diff -r 00dc57806375 -r 3bc33e8c5306 memory/region.cc --- a/memory/region.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/region.cc Mon Apr 12 00:12:51 2021 +0200 @@ -23,7 +23,7 @@ /* Initialise a region having the given 'start' and 'end' addresses, with the 'end' being one location beyond the last address in the region. */ -Region::Region(offset_t start, offset_t end) +Region::Region(address_t start, address_t end) : start(start), end(end), state(end - start) { /* Content state. */ @@ -36,7 +36,7 @@ free((void *) start); } -offset_t Region::size() +length_t Region::size() { return end - start; } @@ -64,7 +64,7 @@ /* Simulation methods. */ -char *Region::read(offset_t offset) +char *Region::read(length_t offset) { if (offset < size()) return (char *) start + offset; @@ -72,7 +72,7 @@ return NULL; } -void Region::write(const char *data, offset_t offset) +void Region::write(const char *data, length_t offset) { size_t length = strlen(data); diff -r 00dc57806375 -r 3bc33e8c5306 memory/region.h --- a/memory/region.h Sun Apr 11 19:34:07 2021 +0200 +++ b/memory/region.h Mon Apr 12 00:12:51 2021 +0200 @@ -29,7 +29,7 @@ class Region { public: - offset_t start, end; + address_t start, end; /* Debugging information. */ @@ -37,11 +37,11 @@ /* Methods. */ - explicit Region(offset_t start, offset_t end); + explicit Region(address_t start, address_t end); virtual ~Region(); - offset_t size(); + length_t size(); int compare(Region *other); @@ -51,9 +51,9 @@ /* Simulation methods. */ - char *read(offset_t offset=0); + char *read(length_t offset=0); - void write(const char *data, offset_t offset=0); + void write(const char *data, length_t offset=0); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 00dc57806375 -r 3bc33e8c5306 pipes/pipe_pager.cc --- a/pipes/pipe_pager.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/pipes/pipe_pager.cc Mon Apr 12 00:12:51 2021 +0200 @@ -38,7 +38,7 @@ /* Support paging. */ -long PipePager::map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region) +long PipePager::map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) { return Pager::map(offset, hot_spot, flags, region); } diff -r 00dc57806375 -r 3bc33e8c5306 pipes/pipe_pager.h --- a/pipes/pipe_pager.h Sun Apr 11 19:34:07 2021 +0200 +++ b/pipes/pipe_pager.h Mon Apr 12 00:12:51 2021 +0200 @@ -35,7 +35,7 @@ /* Pager methods. */ - virtual long map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region); + virtual long map(address_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region); /* Pipe methods. */ diff -r 00dc57806375 -r 3bc33e8c5306 tests/dstest_pipe_client.cc --- a/tests/dstest_pipe_client.cc Sun Apr 11 19:34:07 2021 +0200 +++ b/tests/dstest_pipe_client.cc Mon Apr 12 00:12:51 2021 +0200 @@ -31,13 +31,13 @@ -static void show(file_t *file, offset_t step, offset_t sample) +static void show(file_t *file, length_t step, length_t sample) { /* Allocate a buffer for sampling from the file. */ char buf[sample + 1]; - for (offset_t offset = 0; offset < file_populated_span(file); offset += step) + for (length_t offset = 0; offset < file_populated_span(file); offset += step) { printf("show %ld of %ld...\n", offset, file_populated_span(file));