translate-all: use g_malloc0 for all page descriptor allocations
PATCH 1/1 translate-all: use g_malloc0 for all page descriptor allocations
Since commit
b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"
the exception we make here for usermode has been unnecessary. Get rid of it.
--- translate-all.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
translate-all.c +2 -16
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)void **lp;int i; -#if defined(CONFIG_USER_ONLY ) -/* We can't use g_malloc because it may recurse into a locked mutex. */ -# define ALLOC (P ,SIZE ) \ - do { \ - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ - } while (0) -#else -# define ALLOC (P ,SIZE ) \ - do { P = g_malloc0(SIZE); } while (0) -#endif -/* Level 1. Always allocated. */ lp = l1_map + ((index >>V_L1_SHIFT ) & (V_L1_SIZE -1 ));
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (p,sizeof (void *) *V_L2_SIZE ); + p =g_malloc0 (sizeof (void *) *V_L2_SIZE ); *lp = p; }
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (pd,sizeof (PageDesc) *V_L2_SIZE ); + pd =g_malloc0 (sizeof (PageDesc) *V_L2_SIZE ); *lp = pd; } -#undef ALLOC -return pd + (index & (V_L2_SIZE -1 )); }
Signature · 1 line
1.9.1
Quoted 36 lines · Emilio G. Cota
Since commit
b7b5233a"bsd-user/mmap.c: Don't try to override g_malloc/g_free"the exception we make here for usermode has been unnecessary. Get rid of it.
Signed-off-by Emilio G. Cota <[email protected]>--- translate-all.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)translate-all.c +0
-12@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)void **lp;int i; -#if defined(CONFIG_USER_ONLY ) -/* We can't use g_malloc because it may recurse into a locked mutex. */ -# define ALLOC (P ,SIZE ) \ - do { \ - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ - } while (0) -#else -# define ALLOC (P ,SIZE ) \ - do { P = g_malloc0(SIZE); } while (0) -#endif -/* Level 1. Always allocated. */ lp = l1_map + ((index >>V_L1_SHIFT ) & (V_L1_SIZE -1 ));
translate-all.c static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) · line 403
Quoted 5 lines
translate-all.c +1
-1@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (p,sizeof (void *) *V_L2_SIZE ); + p =g_malloc0 (sizeof (void *) *V_L2_SIZE );
Using g_new0 would be even better. :)
Paolo
Quoted 18 lines
translate-all.c +1
-3*lp = p; }@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (pd,sizeof (PageDesc) *V_L2_SIZE ); + pd =g_malloc0 (sizeof (PageDesc) *V_L2_SIZE ); *lp = pd; } -#undef ALLOC -return pd + (index & (V_L2_SIZE -1 )); }
PATCH v2 1/1 translate-all: use glib for all page descriptor allocations
Since commit
b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"
the exception we make here for usermode has been unnecessary. Get rid of it.
--- translate-all.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
translate-all.c +2 -16
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)void **lp;int i; -#if defined(CONFIG_USER_ONLY ) -/* We can't use g_malloc because it may recurse into a locked mutex. */ -# define ALLOC (P ,SIZE ) \ - do { \ - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ - } while (0) -#else -# define ALLOC (P ,SIZE ) \ - do { P = g_malloc0(SIZE); } while (0) -#endif -/* Level 1. Always allocated. */ lp = l1_map + ((index >>V_L1_SHIFT ) & (V_L1_SIZE -1 ));
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (p,sizeof (void *) *V_L2_SIZE ); + p =g_malloc0 (sizeof (void *) *V_L2_SIZE ); *lp = p; }
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (pd,sizeof (PageDesc) *V_L2_SIZE ); + pd =g_malloc0 (sizeof (PageDesc) *V_L2_SIZE ); *lp = pd; } -#undef ALLOC -return pd + (index & (V_L2_SIZE -1 )); }
Signature · 1 line
1.9.1
PATCH v3 1/1 translate-all: use glib for all page descriptor allocations
In reply to Paolo BonziniSince commit
b7b5233a "bsd-user/mmap.c: Don't try to override g_malloc/g_free"
the exception we make here for usermode has been unnecessary. Get rid of it.
--- translate-all.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
translate-all.c +2 -16
@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)void **lp;int i; -#if defined(CONFIG_USER_ONLY ) -/* We can't use g_malloc because it may recurse into a locked mutex. */ -# define ALLOC (P ,SIZE ) \ - do { \ - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ - } while (0) -#else -# define ALLOC (P ,SIZE ) \ - do { P = g_malloc0(SIZE); } while (0) -#endif -/* Level 1. Always allocated. */ lp = l1_map + ((index >>V_L1_SHIFT ) & (V_L1_SIZE -1 ));
@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (p,sizeof (void *) *V_L2_SIZE ); + p = g_new0(void *, V_L2_SIZE); *lp = p; }
@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (pd,sizeof (PageDesc) *V_L2_SIZE ); + pd =g_new0 (PageDesc,V_L2_SIZE ); *lp = pd; } -#undef ALLOC -return pd + (index & (V_L2_SIZE -1 )); }
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v3] translate-all: use glib for all page descriptor allocations
Quoted 49 lines · Emilio G. Cota
Since commit
b7b5233a"bsd-user/mmap.c: Don't try to override g_malloc/g_free"the exception we make here for usermode has been unnecessary. Get rid of it.
Signed-off-by Emilio G. Cota <[email protected]>--- translate-all.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)translate-all.c +1
-13@@ -389,18 +389,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)void **lp;int i; -#if defined(CONFIG_USER_ONLY ) -/* We can't use g_malloc because it may recurse into a locked mutex. */ -# define ALLOC (P ,SIZE ) \ - do { \ - P = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, \ - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ - } while (0) -#else -# define ALLOC (P ,SIZE ) \ - do { P = g_malloc0(SIZE); } while (0) -#endif -/* Level 1. Always allocated. */ lp = l1_map + ((index >>V_L1_SHIFT ) & (V_L1_SIZE -1 ));@@ -412,7 +400,7 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; } -ALLOC (p,sizeof (void *) *V_L2_SIZE ); + p = g_new0(void *, V_L2_SIZE); *lp = p; }@@ -424,12 +412,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)if (!alloc) {return NULL ; }
translate-all.c static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) · line 421
Quoted 10 lines
translate-all.c +1
-3-ALLOC (pd,sizeof (PageDesc) *V_L2_SIZE ); + pd =g_new0 (PageDesc,V_L2_SIZE ); *lp = pd; } -#undef ALLOC -return pd + (index & (V_L2_SIZE -1 )); }
Thanks, looks good.
Paolo