Patchwork lib: fwts_alloc: use plain old mmap on 32 bit machines (LP: #1204065)

login
register
mail settings
Submitter Colin King
Date July 26, 2013, 3:15 p.m.
Message ID <1374851712-29896-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/262187/
State Accepted
Headers show

Comments

Colin King - July 26, 2013, 3:15 p.m.
From: Colin Ian King <colin.king@canonical.com>

For 32 bit machines, we know that we're going to get a 32 bit mmap'd
address, so there is no need to lark about with forcing a low 32 bit
allocation.  We only really need to fret about this for 64 bit systems.
So, just do a normal mmap for 32 bit.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_alloc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Alex Hung - July 29, 2013, 8:18 a.m.
On 07/26/2013 11:15 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> For 32 bit machines, we know that we're going to get a 32 bit mmap'd
> address, so there is no need to lark about with forcing a low 32 bit
> allocation.  We only really need to fret about this for 64 bit systems.
> So, just do a normal mmap for 32 bit.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_alloc.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_alloc.c b/src/lib/src/fwts_alloc.c
> index 5ea759a..667e8fd 100644
> --- a/src/lib/src/fwts_alloc.c
> +++ b/src/lib/src/fwts_alloc.c
> @@ -122,10 +122,15 @@ void *fwts_low_calloc(const size_t nmemb, const size_t size)
>   	ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
>   		MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
>   #else
> -	/* We don't have a native MAP_32BIT, so bodge our own */
> -	ret = fwts_low_mmap(n);
> +	if (sizeof(void *) == 4) {
> +		/* 32 bit mmap by default */
> +		ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
> +			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	} else {
> +		/* We don't have a native MAP_32BIT, so bodge our own */
> +		ret = fwts_low_mmap(n);
> +	}
>   #endif
> -
>   	if (ret == MAP_FAILED)
>   		return NULL;
>
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - Aug. 1, 2013, 9:22 a.m.
On 07/26/2013 11:15 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> For 32 bit machines, we know that we're going to get a 32 bit mmap'd
> address, so there is no need to lark about with forcing a low 32 bit
> allocation.  We only really need to fret about this for 64 bit systems.
> So, just do a normal mmap for 32 bit.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_alloc.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_alloc.c b/src/lib/src/fwts_alloc.c
> index 5ea759a..667e8fd 100644
> --- a/src/lib/src/fwts_alloc.c
> +++ b/src/lib/src/fwts_alloc.c
> @@ -122,10 +122,15 @@ void *fwts_low_calloc(const size_t nmemb, const size_t size)
>   	ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
>   		MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
>   #else
> -	/* We don't have a native MAP_32BIT, so bodge our own */
> -	ret = fwts_low_mmap(n);
> +	if (sizeof(void *) == 4) {
> +		/* 32 bit mmap by default */
> +		ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
> +			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	} else {
> +		/* We don't have a native MAP_32BIT, so bodge our own */
> +		ret = fwts_low_mmap(n);
> +	}
>   #endif
> -
>   	if (ret == MAP_FAILED)
>   		return NULL;
>
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_alloc.c b/src/lib/src/fwts_alloc.c
index 5ea759a..667e8fd 100644
--- a/src/lib/src/fwts_alloc.c
+++ b/src/lib/src/fwts_alloc.c
@@ -122,10 +122,15 @@  void *fwts_low_calloc(const size_t nmemb, const size_t size)
 	ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
 #else
-	/* We don't have a native MAP_32BIT, so bodge our own */
-	ret = fwts_low_mmap(n);
+	if (sizeof(void *) == 4) {
+		/* 32 bit mmap by default */
+		ret = mmap(NULL, n, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	} else {
+		/* We don't have a native MAP_32BIT, so bodge our own */
+		ret = fwts_low_mmap(n);
+	}
 #endif
-
 	if (ret == MAP_FAILED)
 		return NULL;