[glib/wip/gvariant-kdbus] GBytes: two memfd tweaks
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gvariant-kdbus] GBytes: two memfd tweaks
- Date: Thu, 4 Dec 2014 01:37:50 +0000 (UTC)
commit 98f143767a09ca3d293caad5d496079f956235f6
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Dec 3 17:13:43 2014 -0500
GBytes: two memfd tweaks
1) mmap() of a 0-sized region is EINVAL, so don't try that
2) MAP_SHARED on a sealed memfd fails for some reason, so use
MAP_PRIVATE instead
glib/gbytes.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/glib/gbytes.c b/glib/gbytes.c
index 266e257..9d89139 100644
--- a/glib/gbytes.c
+++ b/glib/gbytes.c
@@ -200,8 +200,15 @@ g_bytes_new_take_zero_copy_fd (gint fd)
/* We already checked this is a memfd... */
g_assert_se (fstat (fd, &buf) == 0);
+ if (buf.st_size == 0)
+ {
+ g_assert_se (close (fd) == 0);
+
+ return g_bytes_new (NULL, 0);
+ }
+
bytes = g_bytes_allocate (sizeof (GBytesData), fd, buf.st_size);
- bytes->data = mmap (NULL, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ bytes->data = mmap (NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (bytes->data == MAP_FAILED)
/* this is similar to malloc() failing, so do the same... */
g_error ("mmap() on memfd failed: %s\n", g_strerror (errno));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]