[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH] lib/ukalloc: fix wrong return value in uk_malloc_ifpages



Hi Simon,

On 08/24/2018 03:55 PM, Simon Kuenzer wrote:
Hey Florian,

On 24.08.2018 13:23, Florian Schmidt wrote:
uk_malloc_ifpages returned the wrong pointer, because it added
sizeof(size_t) to a pointer of type size_t. Hence, the return value
wasn't offset from intptr by size_t bytes, but by size_t*size_t bytes.

This patch makes intptr a void* in places in which its property as
size_t* isn't used.

Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
  lib/ukalloc/alloc.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
index 52e9a77..2f5e364 100644
--- a/lib/ukalloc/alloc.c
+++ b/lib/ukalloc/alloc.c
@@ -167,7 +167,7 @@ static inline size_t uk_alloc_size_to_order(size_t size)
  void *uk_malloc_ifpages(struct uk_alloc *a, size_t size)
  {
-    size_t *intptr;
+    void *intptr;
      size_t order;
      size_t realsize = sizeof(order) + size;
@@ -181,7 +181,7 @@ void *uk_malloc_ifpages(struct uk_alloc *a, size_t size)
      if (!intptr)
          return NULL;
-    *intptr = order;
+    *(size_t *)intptr = order;
      return intptr + sizeof(order);

Hum... pointer arithmetics on your calculation of your returned value was causing the problem. I somehow do not like that the solution is placed somewhere else in the function to make the return statement correct.
What if you would have done this on the return?:

return (void *)((uintptr_t)intptr + sizeof(order))

Or you could declare intptr as uintptr_t. I think this is clearer to understand what it going on.

Hmm... I actually want to get away from making this pointer a size_t*, because it's really pointing to much more than that. The size_t is just the internal information, the whole memory chunk that is passed to the caller follows. Hence I would not go back to that. If you feel more comfortable making this a uintptr_t than a void* though, I'm fine with that.

I'll send a v2 in a few.

Cheers,
Florian

--
Dr. Florian Schmidt
フローリアン・シュミット
Research Scientist,
Systems and Machine Learning Group
NEC Laboratories Europe
Kurfürsten-Anlage 36, D-69115 Heidelberg
Tel.     +49 (0)6221 4342-265
Fax:     +49 (0)6221 4342-155
e-mail:  florian.schmidt@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.