ACK: [PATCH][RESEND] lib: fwts_mmap: add fwts_page_size()

Alex Hung alex.hung at canonical.com
Wed Oct 24 09:32:26 UTC 2012


On 10/21/2012 08:32 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Add a helper function fwts_page_size() to determine the system
> page size.  Default to 4096 if sysconf() does not help us.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/include/fwts_mmap.h |    2 ++
>   src/lib/src/fwts_mmap.c     |   25 ++++++++++++++++++-------
>   2 files changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/src/lib/include/fwts_mmap.h b/src/lib/include/fwts_mmap.h
> index 62d8f1c..4a76489 100644
> --- a/src/lib/include/fwts_mmap.h
> +++ b/src/lib/include/fwts_mmap.h
> @@ -20,8 +20,10 @@
>   #ifndef __FWTS_MMAP_H__
>   #define __FWTS_MMAP_H__
>
> +#include <stddef.h>
>   #include <sys/mman.h>
>
> +size_t fwts_page_size(void);
>   void *fwts_mmap(const off_t start, const size_t size);
>   int fwts_munmap(void *mem, const size_t size);
>
> diff --git a/src/lib/src/fwts_mmap.c b/src/lib/src/fwts_mmap.c
> index c47960d..cee0854 100644
> --- a/src/lib/src/fwts_mmap.c
> +++ b/src/lib/src/fwts_mmap.c
> @@ -24,7 +24,22 @@
>
>   #include "fwts.h"
>
> -#define PAGE_SIZE	4096
> +#define FWTS_DEFAULT_PAGE_SIZE  (4096)
> +
> +/*
> + *  fwts_page_size()
> + *	determine system page size, guess if we can't
> + *	get it from sysconf().
> + */
> +size_t fwts_page_size(void)
> +{
> +	size_t page_size;
> +
> +	page_size = sysconf(_SC_PAGESIZE);
> +
> +	/* If sysconf() returns -1, default it 4K */
> +	return page_size == -1 ? FWTS_DEFAULT_PAGE_SIZE : page_size;
> +}
>
>   /*
>    *  fwts_mmap()
> @@ -40,9 +55,7 @@ void *fwts_mmap(const off_t start, const size_t size)
>   	void *mem;
>   	void *ret = FWTS_MAP_FAILED;
>
> - 	if ((page_size = sysconf(_SC_PAGE_SIZE)) == -1)
> -		page_size = PAGE_SIZE;	/* Guess */
> -
> +	page_size = fwts_page_size();
>   	offset = ((size_t)start) & (page_size - 1);
>   	length = (size_t)size + offset;
>
> @@ -66,9 +79,7 @@ int fwts_munmap(void *mem, const size_t size)
>   	int page_size;
>   	off_t offset;
>
> - 	if ((page_size = sysconf(_SC_PAGE_SIZE)) == -1)
> -		page_size = PAGE_SIZE;	/* Guess */
> -
> +	page_size = fwts_page_size();
>   	offset = ((off_t)(mem)) & (page_size - 1);
>
>   	if (munmap(mem - offset, size + offset) < 0)
>

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list