|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/2] libs/gnttab: do not use alloca(3)
The semantics of alloca(3) is not very nice. If the stack overflows,
program behaviour is undefined.
Remove the use of alloca(3) and always use mmap.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
tools/libs/gnttab/linux.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c
index 7b0fba4..535ce34 100644
--- a/tools/libs/gnttab/linux.c
+++ b/tools/libs/gnttab/linux.c
@@ -102,18 +102,12 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
if (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN)
domids_stride = 0;
- if ( map_size <= PAGE_SIZE )
- map = alloca(sizeof(*map) +
- (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref));
- else
+ map = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
+ if ( map == MAP_FAILED )
{
- map = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
- if ( map == MAP_FAILED )
- {
- GTERROR(xgt->logger, "mmap of map failed");
- return NULL;
- }
+ GTERROR(xgt->logger, "mmap of map failed");
+ return NULL;
}
for ( i = 0; i < count; i++ )
@@ -187,8 +181,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
}
out:
- if ( map_size > PAGE_SIZE )
- munmap(map, map_size);
+ munmap(map, map_size);
return addr;
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |