system/memory: Constify various AddressSpace/MemoryRegionCache arguments
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.
Philippe Mathieu-Daudé (8):
system/memory: Constify various AddressSpace arguments (flatview) system/memory: Constify various AddressSpace arguments (checks) system/memory: Constify various AddressSpace arguments (xlat) 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 | 32 +++++++++--------- include/system/memory_cached.h | 20 +++++------ system/memory-internal.h | 5 +-- include/system/memory_ldst_cached.h.inc | 15 +++++---- system/memory.c | 18 +++++----- system/physmem.c | 44 ++++++++++++++----------- 6 files changed, 73 insertions(+), 61 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/8 system/memory: Constify various AddressSpace arguments (flatview)
Mark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 2 +- system/memory-internal.h | 5 +++-- system/memory.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
include/system/memory.h +1 -1
@@ -1201,7 +1201,7 @@ struct FlatView {MemoryRegion *root; }; -static inline FlatView *address_space_to_flatview (AddressSpace *as) +static inline FlatView *address_space_to_flatview (const AddressSpace *as) {return qatomic_rcu_read (&as->current_map); }
system/memory-internal.h +3 -2
@@ -20,12 +20,13 @@ static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)return fv->dispatch; } -static inline AddressSpaceDispatch *address_space_to_dispatch (AddressSpace *as) +static inline +AddressSpaceDispatch *address_space_to_dispatch (const AddressSpace *as) {return flatview_to_dispatch (address_space_to_flatview (as)); } -FlatView *address_space_get_flatview (AddressSpace *as); +FlatView *address_space_get_flatview (const AddressSpace *as);void flatview_unref (FlatView *view);extern const MemoryRegionOps unassigned_mem_ops;
system/memory.c +1 -1
@@ -819,7 +819,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as, } } -FlatView *address_space_get_flatview (AddressSpace *as) +FlatView *address_space_get_flatview (const AddressSpace *as) {FlatView *view;
Signature · 1 line
2.53.0
PATCH 2/8 system/memory: Constify various AddressSpace arguments (checks)
In reply to Philippe Mathieu-DaudéMark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 5 +++-- system/physmem.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-)
include/system/memory.h +3 -2
@@ -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);/**
@@ -2839,7 +2840,7 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,* @as: #AddressSpace to be accessed * @addr: address within that address space */ -bool address_space_is_io (AddressSpace *as,hwaddr addr); +bool address_space_is_io (const AddressSpace *as,hwaddr addr);/* address_space_map: map a physical memory region into a host virtual address *
system/physmem.c +2 -2
@@ -3652,7 +3652,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) {
@@ -3663,7 +3663,7 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr,return flatview_access_valid (fv, addr, len, is_write, attrs); } -bool address_space_is_io (AddressSpace *as,hwaddr addr) +bool address_space_is_io (const AddressSpace *as,hwaddr addr) {MemoryRegion *mr;
Signature · 1 line
2.53.0
PATCH 3/8 system/memory: Constify various AddressSpace arguments (xlat)
In reply to Philippe Mathieu-DaudéMark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 4 ++-- system/physmem.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-)
include/system/memory.h +2 -2
@@ -2783,7 +2783,7 @@ 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. */ -IOMMUTLBEntry address_space_get_iotlb_entry (AddressSpace *as,hwaddr addr, +IOMMUTLBEntry address_space_get_iotlb_entry (const AddressSpace *as,hwaddr addr,bool is_write,MemTxAttrs attrs);/* address_space_translate: translate an address range into an address space
@@ -2804,7 +2804,7 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr *len, bool is_write, MemTxAttrs attrs); -static inline MemoryRegion *address_space_translate (AddressSpace *as, +static inline MemoryRegion *address_space_translate (const AddressSpace *as,hwaddr addr,hwaddr *xlat,hwaddr *len,bool is_write,MemTxAttrs attrs)
system/physmem.c +6 -4
@@ -528,19 +528,21 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv, }/* Called from RCU critical section */ -IOMMUTLBEntry address_space_get_iotlb_entry (AddressSpace *as,hwaddr addr, +IOMMUTLBEntry address_space_get_iotlb_entry (const AddressSpace *as,hwaddr addr,bool is_write,MemTxAttrs attrs) {MemoryRegionSection section;hwaddr xlat, page_mask; +AddressSpace target_as = *as; +AddressSpace *ptarget_as = &target_as;/* * This can never be MMIO, and we don't really care about plen, * but page mask. */ section =flatview_do_translate (address_space_to_flatview (as), addr, &xlat, -NULL , &page_mask, is_write, false, &as, - attrs); +NULL , &page_mask, is_write, false, + &ptarget_as, attrs);/* Illegal translation */ if (section.mr == &io_mem_unassigned) {
@@ -552,7 +554,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, section.offset_within_region;return (IOMMUTLBEntry ) { - .target_as = as, + .target_as = &target_as, .iova = addr & ~page_mask, .translated_addr = xlat & ~page_mask, .addr_mask = page_mask,
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 3/8] system/memory: Constify various AddressSpace arguments (xlat)
Quoted 35 lines · Philippe Mathieu-Daudé
Mark the AddressSpace structure const when it is only accessed read-only.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/memory.h | 4 ++-- system/physmem.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-)include/system/memory.h +2
-2@@ -2783,7 +2783,7 @@ 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. */ -IOMMUTLBEntry address_space_get_iotlb_entry (AddressSpace *as,hwaddr addr, +IOMMUTLBEntry address_space_get_iotlb_entry (const AddressSpace *as,hwaddr addr,bool is_write,MemTxAttrs attrs);/* address_space_translate: translate an address range into an address space @@ -2804,7 +2804,7 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr *len, bool is_write, MemTxAttrs attrs); -static inline MemoryRegion *address_space_translate (AddressSpace *as, +static inline MemoryRegion *address_space_translate (const AddressSpace *as,hwaddr addr,hwaddr *xlat,hwaddr *len,bool is_write,MemTxAttrs attrs)system/physmem.c +0
-0
system/physmem.c static MemoryRegionSection flatview_do_translate(FlatView *fv, · line 536
Quoted 10 lines
system/physmem.c +2
-1@@ -528,19 +528,21 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv, }/* Called from RCU critical section */ -IOMMUTLBEntry address_space_get_iotlb_entry (AddressSpace *as,hwaddr addr, +IOMMUTLBEntry address_space_get_iotlb_entry (const AddressSpace *as,hwaddr addr,bool is_write,MemTxAttrs attrs) {MemoryRegionSection section;hwaddr xlat, page_mask; +AddressSpace target_as = *as;
Is this one an overkill? It'll deep copy everything of AS..
Quoted 26 lines
system/physmem.c +4
-3+AddressSpace *ptarget_as = &target_as;/* * This can never be MMIO, and we don't really care about plen, * but page mask. */ section =flatview_do_translate (address_space_to_flatview (as), addr, &xlat, -NULL , &page_mask, is_write, false, &as, - attrs); +NULL , &page_mask, is_write, false, + &ptarget_as, attrs);/* Illegal translation */ if (section.mr == &io_mem_unassigned) {@@ -552,7 +554,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, section.offset_within_region;return (IOMMUTLBEntry ) { - .target_as = as, + .target_as = &target_as, .iova = addr & ~page_mask, .translated_addr = xlat & ~page_mask, .addr_mask = page_mask,Signature · 1 line
2.53.0
Signature · 1 line
Peter Xu
PATCH 4/8 system/memory: Constify various AddressSpace arguments (flat-range)
In reply to Philippe Mathieu-Daudé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
@@ -888,7 +888,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;
@@ -912,7 +913,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;
@@ -921,7 +922,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;
@@ -939,7 +940,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 5/8 system/memory: Constify various AddressSpace arguments (notify)
In reply to Philippe Mathieu-Daudé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
@@ -2978,7 +2978,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;
@@ -3043,7 +3043,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;
@@ -3148,7 +3148,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
@@ -3573,7 +3573,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 6/8 system/memory: Constify various AddressSpace arguments (cache)
In reply to Philippe Mathieu-Daudé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
@@ -3837,7 +3837,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 7/8 system/memory: Constify various AddressSpace arguments (access)
In reply to Philippe Mathieu-DaudéMark the AddressSpace structure const when it is only accessed read-only.
--- include/system/memory.h | 19 ++++++++++--------- system/physmem.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 16 deletions(-)
include/system/memory.h +10 -9
@@ -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);
@@ -2741,7 +2741,7 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr,* @buf: buffer with the data transferred * @len: the number of bytes to write */ -MemTxResult address_space_write_rom (AddressSpace *as,hwaddr addr, +MemTxResult address_space_write_rom (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,const void *buf,hwaddr len);
@@ -2768,17 +2768,18 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,#define SUFFIX #define ARG1 as -#define ARG1_DECL AddressSpace *as +#define ARG1_DECL const AddressSpace *as#include "system/memory_ldst.h.inc" #ifndef TARGET_NOT_USING_LEGACY_LDST_PHYS_API #define SUFFIX #define ARG1 as -#define ARG1_DECL AddressSpace *as +#define ARG1_DECL const AddressSpace *as#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 (const 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 +9 -7
@@ -3424,7 +3424,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 ;
@@ -3439,7 +3439,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) {
@@ -3455,7 +3455,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) {
@@ -3465,7 +3466,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
@@ -3497,7 +3498,7 @@ void cpu_physical_memory_write(hwaddr addr, const void *buf, hwaddr len) }/* used for ROM loading : can write in RAM and ROM */ -MemTxResult address_space_write_rom (AddressSpace *as,hwaddr addr, +MemTxResult address_space_write_rom (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,const void *buf,hwaddr len) {
@@ -3522,7 +3523,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 (const AddressSpace *as, +hwaddr addr,hwaddr len) {/* * This function should do the same thing as an icache flush that was
@@ -3828,7 +3830,7 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,return address_space_unmap (&address_space_memory, buffer, len, is_write, access_len); } -#define ARG1_DECL AddressSpace *as +#define ARG1_DECL const AddressSpace *as#define ARG1 as#define SUFFIX #define TRANSLATE (...) address_space_translate(as, __VA_ARGS__)
Signature · 1 line
2.53.0
PATCH 8/8 system/memory: Constify various MemoryRegionCache arguments
In reply to Philippe Mathieu-Daudé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
@@ -3886,7 +3886,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) {
@@ -3917,7 +3917,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;
@@ -3998,7 +3998,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;
@@ -4015,7 +4015,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;
@@ -4028,7 +4028,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 14 lines · Philippe Mathieu-Daudé
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.
Philippe Mathieu-Daudé (8):
system/memory: Constify various AddressSpace arguments (flatview) system/memory: Constify various AddressSpace arguments (checks) system/memory: Constify various AddressSpace arguments (xlat) 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
Quoted 8 lines
include/system/memory.h | 32 +++++++++--------- include/system/memory_cached.h | 20 +++++------ system/memory-internal.h | 5 +-- include/system/memory_ldst_cached.h.inc | 15 +++++---- system/memory.c | 18 +++++----- system/physmem.c | 44 ++++++++++++++----------- 6 files changed, 73 insertions(+), 61 deletions(-)
Series: