@samitouri / QOSamiQemu / commits / f016021ff5

system/ramblock: Constify various RAMBlock arguments

Mark the RAMBlock structure const when is only accessed read-only. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/20260309183536.88976-2-philmd@linaro.org Signed-off-by: Peter Xu <peterx@redhat.com>

Philippe Mathieu-Daudé committed Mar 9, 2026 at 19:35 UTC f016021ff59d12765eb630c75fd44bb6ed471b72
4 files changed +32 -32
include/system/ramblock.h
+14 -14
@@ -154,26 +154,26 @@ RAMBlock *qemu_ram_block_by_name(const char *name);
154 */
155 RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
156 ram_addr_t *offset);
157 -ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host);
157 +ram_addr_t qemu_ram_block_host_offset(const RAMBlock *rb, void *host);
158 void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
159 void qemu_ram_unset_idstr(RAMBlock *block);
160 -const char *qemu_ram_get_idstr(RAMBlock *rb);
161 -void *qemu_ram_get_host_addr(RAMBlock *rb);
162 -ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
163 -ram_addr_t qemu_ram_get_fd_offset(RAMBlock *rb);
164 -ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
165 -ram_addr_t qemu_ram_get_max_length(RAMBlock *rb);
166 -bool qemu_ram_is_shared(RAMBlock *rb);
167 -bool qemu_ram_is_noreserve(RAMBlock *rb);
168 -bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
160 +const char *qemu_ram_get_idstr(const RAMBlock *rb);
161 +void *qemu_ram_get_host_addr(const RAMBlock *rb);
162 +ram_addr_t qemu_ram_get_offset(const RAMBlock *rb);
163 +ram_addr_t qemu_ram_get_fd_offset(const RAMBlock *rb);
164 +ram_addr_t qemu_ram_get_used_length(const RAMBlock *rb);
165 +ram_addr_t qemu_ram_get_max_length(const RAMBlock *rb);
166 +bool qemu_ram_is_shared(const RAMBlock *rb);
167 +bool qemu_ram_is_noreserve(const RAMBlock *rb);
168 +bool qemu_ram_is_uf_zeroable(const RAMBlock *rb);
169 void qemu_ram_set_uf_zeroable(RAMBlock *rb);
170 -bool qemu_ram_is_migratable(RAMBlock *rb);
170 +bool qemu_ram_is_migratable(const RAMBlock *rb);
171 void qemu_ram_set_migratable(RAMBlock *rb);
172 void qemu_ram_unset_migratable(RAMBlock *rb);
173 -bool qemu_ram_is_named_file(RAMBlock *rb);
174 -int qemu_ram_get_fd(RAMBlock *rb);
173 +bool qemu_ram_is_named_file(const RAMBlock *rb);
174 +int qemu_ram_get_fd(const RAMBlock *rb);
175
176 -size_t qemu_ram_pagesize(RAMBlock *block);
176 +size_t qemu_ram_pagesize(const RAMBlock *block);
177 size_t qemu_ram_pagesize_largest(void);
178 #include "exec/target_page.h"
179 #include "exec/hwaddr.h"
stubs/physmem.c
+1 -1
@@ -7,7 +7,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
7 return NULL;
8 }
9
10 -int qemu_ram_get_fd(RAMBlock *rb)
10 +int qemu_ram_get_fd(const RAMBlock *rb)
11 {
12 return -1;
13 }
stubs/ram-block.c
+3 -3
@@ -3,17 +3,17 @@
3 #include "system/ramblock.h"
4 #include "system/memory.h"
5
6 -void *qemu_ram_get_host_addr(RAMBlock *rb)
6 +void *qemu_ram_get_host_addr(const RAMBlock *rb)
7 {
8 return 0;
9 }
10
11 -ram_addr_t qemu_ram_get_offset(RAMBlock *rb)
11 +ram_addr_t qemu_ram_get_offset(const RAMBlock *rb)
12 {
13 return 0;
14 }
15
16 -ram_addr_t qemu_ram_get_used_length(RAMBlock *rb)
16 +ram_addr_t qemu_ram_get_used_length(const RAMBlock *rb)
17 {
18 return 0;
19 }
system/physmem.c
+14 -14
@@ -1859,48 +1859,48 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size)
1859 }
1860 }
1861
1862 -const char *qemu_ram_get_idstr(RAMBlock *rb)
1862 +const char *qemu_ram_get_idstr(const RAMBlock *rb)
1863 {
1864 return rb->idstr;
1865 }
1866
1867 -void *qemu_ram_get_host_addr(RAMBlock *rb)
1867 +void *qemu_ram_get_host_addr(const RAMBlock *rb)
1868 {
1869 return rb->host;
1870 }
1871
1872 -ram_addr_t qemu_ram_get_offset(RAMBlock *rb)
1872 +ram_addr_t qemu_ram_get_offset(const RAMBlock *rb)
1873 {
1874 return rb->offset;
1875 }
1876
1877 -ram_addr_t qemu_ram_get_fd_offset(RAMBlock *rb)
1877 +ram_addr_t qemu_ram_get_fd_offset(const RAMBlock *rb)
1878 {
1879 return rb->fd_offset;
1880 }
1881
1882 -ram_addr_t qemu_ram_get_used_length(RAMBlock *rb)
1882 +ram_addr_t qemu_ram_get_used_length(const RAMBlock *rb)
1883 {
1884 return rb->used_length;
1885 }
1886
1887 -ram_addr_t qemu_ram_get_max_length(RAMBlock *rb)
1887 +ram_addr_t qemu_ram_get_max_length(const RAMBlock *rb)
1888 {
1889 return rb->max_length;
1890 }
1891
1892 -bool qemu_ram_is_shared(RAMBlock *rb)
1892 +bool qemu_ram_is_shared(const RAMBlock *rb)
1893 {
1894 return rb->flags & RAM_SHARED;
1895 }
1896
1897 -bool qemu_ram_is_noreserve(RAMBlock *rb)
1897 +bool qemu_ram_is_noreserve(const RAMBlock *rb)
1898 {
1899 return rb->flags & RAM_NORESERVE;
1900 }
1901
1902 /* Note: Only set at the start of postcopy */
1903 -bool qemu_ram_is_uf_zeroable(RAMBlock *rb)
1903 +bool qemu_ram_is_uf_zeroable(const RAMBlock *rb)
1904 {
1905 return rb->flags & RAM_UF_ZEROPAGE;
1906 }
@@ -1910,7 +1910,7 @@ void qemu_ram_set_uf_zeroable(RAMBlock *rb)
1910 rb->flags |= RAM_UF_ZEROPAGE;
1911 }
1912
1913 -bool qemu_ram_is_migratable(RAMBlock *rb)
1913 +bool qemu_ram_is_migratable(const RAMBlock *rb)
1914 {
1915 return rb->flags & RAM_MIGRATABLE;
1916 }
@@ -1925,12 +1925,12 @@ void qemu_ram_unset_migratable(RAMBlock *rb)
1925 rb->flags &= ~RAM_MIGRATABLE;
1926 }
1927
1928 -bool qemu_ram_is_named_file(RAMBlock *rb)
1928 +bool qemu_ram_is_named_file(const RAMBlock *rb)
1929 {
1930 return rb->flags & RAM_NAMED_FILE;
1931 }
1932
1933 -int qemu_ram_get_fd(RAMBlock *rb)
1933 +int qemu_ram_get_fd(const RAMBlock *rb)
1934 {
1935 return rb->fd;
1936 }
@@ -1987,7 +1987,7 @@ static char *cpr_name(MemoryRegion *mr)
1987 }
1988 }
1989
1990 -size_t qemu_ram_pagesize(RAMBlock *rb)
1990 +size_t qemu_ram_pagesize(const RAMBlock *rb)
1991 {
1992 return rb->page_size;
1993 }
@@ -2772,7 +2772,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
2772 }
2773
2774 /* Return the offset of a hostpointer within a ramblock */
2775 -ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host)
2775 +ram_addr_t qemu_ram_block_host_offset(const RAMBlock *rb, void *host)
2776 {
2777 ram_addr_t res = (uint8_t *)host - (uint8_t *)rb->host;
2778 assert((uintptr_t)host >= (uintptr_t)rb->host);