system/memory: Constify various AddressSpace/MemoryRegionCache arguments
v2 cover system/memory: Constify various AddressSpace/MemoryRegionCache arguments
When structures are only accessed read-only, it is safer to mark them const to protect against invalid API (ab)uses. This is also an useful hint to compilers.
v2: Remove 'xlat' patch (Peter)
Philippe Mathieu-Daudé (6):
system/memory: Constify various AddressSpace arguments (checks) system/memory: Constify various AddressSpace arguments (flat-range) system/memory: Constify various AddressSpace arguments (notify) system/memory: Constify various AddressSpace arguments (cache) system/memory: Constify various AddressSpace arguments (access) system/memory: Constify various MemoryRegionCache arguments
include/system/memory.h | 18 +++++++++------- include/system/memory_cached.h | 20 +++++++++--------- include/system/memory_ldst_cached.h.inc | 15 +++++++------ system/memory.c | 16 +++++++------- system/physmem.c | 28 +++++++++++++------------ 5 files changed, 53 insertions(+), 44 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/6 system/memory: Constify various AddressSpace arguments (checks)
From: Philippe Mathieu-Daudé <[email protected]>
Mark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 3 ++- system/physmem.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
include/system/memory.h +2 -1
@@ -2829,7 +2829,8 @@ static inline MemoryRegion *address_space_translate(AddressSpace *as,* @is_write: indicates the transfer direction * @attrs: memory attributes */ -bool address_space_access_valid (AddressSpace *as,hwaddr addr,hwaddr len, +bool address_space_access_valid (const AddressSpace *as, +hwaddr addr,hwaddr len,bool is_write,MemTxAttrs attrs);/**
system/physmem.c +1 -1
@@ -3646,7 +3646,7 @@ static bool flatview_access_valid(FlatView *fv, hwaddr addr, hwaddr len,return true; } -bool address_space_access_valid (AddressSpace *as,hwaddr addr, +bool address_space_access_valid (const AddressSpace *as,hwaddr addr,hwaddr len,bool is_write,MemTxAttrs attrs) {
Signature · 1 line
2.53.0
PATCH v2 2/6 system/memory: Constify various AddressSpace arguments (flat-range)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Mark the AddressSpace structure const when it is only accessed read-only.
--- system/memory.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
system/memory.c +6 -4
@@ -889,7 +889,8 @@ static void address_space_update_ioeventfds(AddressSpace *as)* range `cmr'. Only the part that has intersection of the specified * FlatRange will be sent. */ -static void flat_range_coalesced_io_notify (FlatRange *fr,AddressSpace *as, +static void flat_range_coalesced_io_notify (FlatRange *fr, +const AddressSpace *as,CoalescedMemoryRange *cmr,bool add) {AddrRange tmp;
@@ -913,7 +914,7 @@ static void flat_range_coalesced_io_notify(FlatRange *fr, AddressSpace *as, } } -static void flat_range_coalesced_io_del (FlatRange *fr,AddressSpace *as) +static void flat_range_coalesced_io_del (FlatRange *fr,const AddressSpace *as) {CoalescedMemoryRange *cmr;
@@ -922,7 +923,7 @@ static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as) } } -static void flat_range_coalesced_io_add (FlatRange *fr,AddressSpace *as) +static void flat_range_coalesced_io_add (FlatRange *fr,const AddressSpace *as) {MemoryRegion *mr = fr->mr;CoalescedMemoryRange *cmr;
@@ -940,7 +941,8 @@ static voidflat_range_coalesced_io_notify_listener_add_del (FlatRange *fr, MemoryRegionSection *mrs, MemoryListener *listener, - AddressSpace *as, bool add) + const AddressSpace *as, + bool add) {CoalescedMemoryRange *cmr;MemoryRegion *mr = fr->mr;
Signature · 1 line
2.53.0
PATCH v2 3/6 system/memory: Constify various AddressSpace arguments (notify)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Mark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 2 +- system/memory.c | 6 +++--- system/physmem.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/system/memory.h +1 -1
@@ -2682,7 +2682,7 @@ void address_space_destroy_free(AddressSpace *as);* * @as: an initialized #AddressSpace */ -void address_space_remove_listeners (AddressSpace *as); +void address_space_remove_listeners (const AddressSpace *as);/** * address_space_rw: read from or write to an address space.
system/memory.c +3 -3
@@ -2985,7 +2985,7 @@ void memory_global_dirty_log_stop(unsigned int flags) }static void listener_add_address_space (MemoryListener *listener, -AddressSpace *as) +const AddressSpace *as) {unsigned i;FlatView *view;
@@ -3050,7 +3050,7 @@ static void listener_add_address_space(MemoryListener *listener, }static void listener_del_address_space (MemoryListener *listener, -AddressSpace *as) +const AddressSpace *as) {unsigned i;FlatView *view;
@@ -3155,7 +3155,7 @@ void memory_listener_unregister(MemoryListener *listener) listener->address_space =NULL ; } -void address_space_remove_listeners (AddressSpace *as) +void address_space_remove_listeners (const AddressSpace *as) {while (!QTAILQ_EMPTY (&as->listeners)) {memory_listener_unregister (QTAILQ_FIRST (&as->listeners));
system/physmem.c +1 -1
@@ -3565,7 +3565,7 @@ address_space_unregister_map_client_do(AddressSpaceMapClient *client)g_free (client); } -static void address_space_notify_map_clients_locked (AddressSpace *as) +static void address_space_notify_map_clients_locked (const AddressSpace *as) {AddressSpaceMapClient *client;
Signature · 1 line
2.53.0
PATCH v2 4/6 system/memory: Constify various AddressSpace arguments (cache)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Mark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory_cached.h | 2 +- system/physmem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/system/memory_cached.h +1 -1
@@ -117,7 +117,7 @@ void address_space_stb_cached(MemoryRegionCache *cache,* are relative to @addr. */ int64_t address_space_cache_init (MemoryRegionCache *cache, -AddressSpace *as, +const AddressSpace *as,hwaddr addr,hwaddr len,bool is_write);
system/physmem.c +1 -1
@@ -3829,7 +3829,7 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,#include "memory_ldst.c.inc" int64_t address_space_cache_init (MemoryRegionCache *cache, -AddressSpace *as, +const AddressSpace *as,hwaddr addr,hwaddr len,bool is_write)
Signature · 1 line
2.53.0
PATCH v2 5/6 system/memory: Constify various AddressSpace arguments (access)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Mark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 13 +++++++------ system/physmem.c | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-)
include/system/memory.h +7 -6
@@ -2698,7 +2698,7 @@ void address_space_remove_listeners(const AddressSpace *as);* @len: the number of bytes to read or write * @is_write: indicates the transfer direction */ -MemTxResult address_space_rw (AddressSpace *as,hwaddr addr, +MemTxResult address_space_rw (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len,bool is_write);
@@ -2715,7 +2715,7 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,* @buf: buffer with the data transferred * @len: the number of bytes to write */ -MemTxResult address_space_write (AddressSpace *as,hwaddr addr, +MemTxResult address_space_write (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,const void *buf,hwaddr len);
@@ -2778,7 +2778,8 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,#include "system/memory_ldst_phys.h.inc" #endif -void address_space_flush_icache_range (AddressSpace *as,hwaddr addr,hwaddr len); +void address_space_flush_icache_range (AddressSpace *as, +hwaddr addr,hwaddr len);/* address_space_get_iotlb_entry: translate an address into an IOTLB * entry. Should be called from an RCU critical section.
@@ -2898,7 +2899,7 @@ void address_space_register_map_client(AddressSpace *as, QEMUBH *bh);void address_space_unregister_map_client (AddressSpace *as,QEMUBH *bh);/* Internal functions, part of the implementation of address_space_read. */ -MemTxResult address_space_read_full (AddressSpace *as,hwaddr addr, +MemTxResult address_space_read_full (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len); MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *buf,
@@ -2953,7 +2954,7 @@ static inline bool memory_access_is_direct(const MemoryRegion *mr,* @len: length of the data transferred */ static inline __attribute__((__always_inline__)) -MemTxResult address_space_read (AddressSpace *as,hwaddr addr, +MemTxResult address_space_read (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len) {
@@ -2996,7 +2997,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr,* @len: the number of bytes to fill with the constant byte * @attrs: memory transaction attributes */ -MemTxResult address_space_set (AddressSpace *as,hwaddr addr, +MemTxResult address_space_set (const AddressSpace *as,hwaddr addr,uint8_t c,hwaddr len,MemTxAttrs attrs);/* Coalesced MMIO regions are areas where write operations can be reordered.
system/physmem.c +7 -5
@@ -3416,7 +3416,7 @@ static MemTxResult flatview_read(FlatView *fv, hwaddr addr, mr_addr, l, mr); } -MemTxResult address_space_read_full (AddressSpace *as,hwaddr addr, +MemTxResult address_space_read_full (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len) {MemTxResult result =MEMTX_OK ;
@@ -3431,7 +3431,7 @@ MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,return result; } -MemTxResult address_space_write (AddressSpace *as,hwaddr addr, +MemTxResult address_space_write (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,const void *buf,hwaddr len) {
@@ -3447,7 +3447,8 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr,return result; } -MemTxResult address_space_rw (AddressSpace *as,hwaddr addr,MemTxAttrs attrs, +MemTxResult address_space_rw (const AddressSpace *as, +hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len,bool is_write) {if (is_write) {
@@ -3457,7 +3458,7 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, } } -MemTxResult address_space_set (AddressSpace *as,hwaddr addr, +MemTxResult address_space_set (const AddressSpace *as,hwaddr addr,uint8_t c,hwaddr len,MemTxAttrs attrs) {#define FILLBUF_SIZE 512
@@ -3514,7 +3515,8 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,return MEMTX_OK ; } -void address_space_flush_icache_range (AddressSpace *as,hwaddr addr,hwaddr len) +void address_space_flush_icache_range (AddressSpace *as, +hwaddr addr,hwaddr len) {/* * This function should do the same thing as an icache flush that was
Signature · 1 line
2.53.0
PATCH v2 6/6 system/memory: Constify various MemoryRegionCache arguments
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Mark the MemoryRegionCache structure const when it is only accessed read-only.
--- include/system/memory_cached.h | 18 +++++++++--------- include/system/memory_ldst_cached.h.inc | 15 +++++++++------ system/physmem.c | 10 +++++----- 3 files changed, 23 insertions(+), 20 deletions(-)
include/system/memory_cached.h +9 -9
@@ -51,12 +51,12 @@ struct MemoryRegionCache {#define SUFFIX _cached_slow#define ARG1 cache -#define ARG1_DECL MemoryRegionCache *cache +#define ARG1_DECL const MemoryRegionCache *cache#include "system/memory_ldst.h.inc" /* Inline fast path for direct RAM access. */ static inline -uint8_t address_space_ldub_cached (MemoryRegionCache *cache,hwaddr addr, +uint8_t address_space_ldub_cached (const MemoryRegionCache *cache,hwaddr addr,MemTxAttrs attrs,MemTxResult *result) {assert (addr < cache->len);
@@ -68,7 +68,7 @@ uint8_t address_space_ldub_cached(MemoryRegionCache *cache, hwaddr addr, }static inline -void address_space_stb_cached (MemoryRegionCache *cache, +void address_space_stb_cached (const MemoryRegionCache *cache,hwaddr addr,uint8_t val,MemTxAttrs attrs,MemTxResult *result) {
@@ -93,7 +93,7 @@ void address_space_stb_cached(MemoryRegionCache *cache,#define SUFFIX _cached#define ARG1 cache -#define ARG1_DECL MemoryRegionCache *cache +#define ARG1_DECL const MemoryRegionCache *cache#include "system/memory_ldst_phys.h.inc" /**
@@ -145,7 +145,7 @@ static inline void address_space_cache_init_empty(MemoryRegionCache *cache)* address that was passed to @address_space_cache_init. * @access_len: The number of bytes that were written starting at @addr. */ -void address_space_cache_invalidate (MemoryRegionCache *cache, +void address_space_cache_invalidate (const MemoryRegionCache *cache,hwaddr addr,hwaddr access_len);
@@ -160,9 +160,9 @@ void address_space_cache_destroy(MemoryRegionCache *cache);* Internal functions, part of the implementation of address_space_read_cached * and address_space_write_cached. */ -MemTxResult address_space_read_cached_slow (MemoryRegionCache *cache, +MemTxResult address_space_read_cached_slow (const MemoryRegionCache *cache,hwaddr addr,void *buf,hwaddr len); -MemTxResult address_space_write_cached_slow (MemoryRegionCache *cache, +MemTxResult address_space_write_cached_slow (const MemoryRegionCache *cache,hwaddr addr,const void *buf,hwaddr len);
@@ -175,7 +175,7 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,* @len: length of the data transferred */ static inline MemTxResult -address_space_read_cached (MemoryRegionCache *cache,hwaddr addr, +address_space_read_cached (const MemoryRegionCache *cache,hwaddr addr,void *buf,hwaddr len) {assert (addr < cache->len && len <= cache->len - addr);
@@ -197,7 +197,7 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,* @len: length of the data transferred */ static inline MemTxResult -address_space_write_cached (MemoryRegionCache *cache,hwaddr addr, +address_space_write_cached (const MemoryRegionCache *cache,hwaddr addr,const void *buf,hwaddr len) {assert (addr < cache->len && len <= cache->len - addr);
include/system/memory_ldst_cached.h.inc +9 -6
@@ -24,7 +24,8 @@ #define LD_P(size) \ glue(glue(ld, size), glue(ENDIANNESS, _p)) -static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, +static inline +uint16_t ADDRESS_SPACE_LD_CACHED(uw)(const MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <= cache->len - addr);
@@ -36,7 +37,8 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, } } -static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, +static inline +uint32_t ADDRESS_SPACE_LD_CACHED(l)(const MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 4 <= cache->len - addr);
@@ -48,7 +50,8 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, } } -static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, +static inline +uint64_t ADDRESS_SPACE_LD_CACHED(q)(const MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 8 <= cache->len - addr);
@@ -71,7 +74,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, #define ST_P(size) \ glue(glue(st, size), glue(ENDIANNESS, _p)) -static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, +static inline void ADDRESS_SPACE_ST_CACHED(w)(const MemoryRegionCache *cache, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <= cache->len - addr);
@@ -82,7 +85,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache, } } -static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, +static inline void ADDRESS_SPACE_ST_CACHED(l)(const MemoryRegionCache *cache, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 4 <= cache->len - addr);
@@ -93,7 +96,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache, } } -static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache, +static inline void ADDRESS_SPACE_ST_CACHED(q)(const MemoryRegionCache *cache, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 8 <= cache->len - addr);
system/physmem.c +5 -5
@@ -3878,7 +3878,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,return l; } -void address_space_cache_invalidate (MemoryRegionCache *cache, +void address_space_cache_invalidate (const MemoryRegionCache *cache,hwaddr addr,hwaddr access_len) {
@@ -3909,7 +3909,7 @@ void address_space_cache_destroy(MemoryRegionCache *cache)* address_space_cache_init. */ static inline MemoryRegion *address_space_translate_cached ( -MemoryRegionCache *cache,hwaddr addr,hwaddr *xlat, +const MemoryRegionCache *cache,hwaddr addr,hwaddr *xlat,hwaddr *plen,bool is_write,MemTxAttrs attrs) {MemoryRegionSection section;
@@ -3990,7 +3990,7 @@ static MemTxResult address_space_read_continue_cached(MemTxAttrs attrs,* out of line function when the target is an MMIO or IOMMU region. */ MemTxResult -address_space_read_cached_slow (MemoryRegionCache *cache,hwaddr addr, +address_space_read_cached_slow (const MemoryRegionCache *cache,hwaddr addr,void *buf,hwaddr len) {hwaddr mr_addr, l;
@@ -4007,7 +4007,7 @@ address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr,* out of line function when the target is an MMIO or IOMMU region. */ MemTxResult -address_space_write_cached_slow (MemoryRegionCache *cache,hwaddr addr, +address_space_write_cached_slow (const MemoryRegionCache *cache,hwaddr addr,const void *buf,hwaddr len) {hwaddr mr_addr, l;
@@ -4020,7 +4020,7 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, buf, len, mr_addr, l, mr); } -#define ARG1_DECL MemoryRegionCache *cache +#define ARG1_DECL const MemoryRegionCache *cache#define ARG1 cache#define SUFFIX _cached_slow#define TRANSLATE (...) address_space_translate_cached(cache, __VA_ARGS__)
Signature · 1 line
2.53.0
Quoted 7 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (6):
system/memory: Constify various AddressSpace arguments (checks) system/memory: Constify various AddressSpace arguments (flat-range) system/memory: Constify various AddressSpace arguments (notify) system/memory: Constify various AddressSpace arguments (cache) system/memory: Constify various AddressSpace arguments (access) system/memory: Constify various MemoryRegionCache arguments
r~
Philippe Mathieu-Daudé
AppliedQuoted 8 lines
Philippe Mathieu-Daudé (6):
system/memory: Constify various AddressSpace arguments (checks) system/memory: Constify various AddressSpace arguments (flat-range) system/memory: Constify various AddressSpace arguments (notify) system/memory: Constify various AddressSpace arguments (cache) system/memory: Constify various AddressSpace arguments (access) system/memory: Constify various MemoryRegionCache arguments
Queued, thanks.