diff mbox series

[U-Boot,v9,09/18] sandbox: Align RAM buffer to the machine page size

Message ID 20180808095433.230882-10-sjg@chromium.org
State Superseded, archived
Delegated to: Alexander Graf
Headers show
Series efi: Enable sandbox support for EFI loader | expand

Commit Message

Simon Glass Aug. 8, 2018, 9:54 a.m. UTC
At present the sandbox RAM buffer is not aligned to any particular
address boundary. This makes the internal pointers somewhat random with
respect to the associated RAM buffer addresses.

Align the buffer to the page size of the machine to help with this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v9: None
Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/sandbox/cpu/os.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Alexander Graf Aug. 26, 2018, 5:01 p.m. UTC | #1
On 08.08.18 11:54, Simon Glass wrote:
> At present the sandbox RAM buffer is not aligned to any particular
> address boundary. This makes the internal pointers somewhat random with
> respect to the associated RAM buffer addresses.
> 
> Align the buffer to the page size of the machine to help with this.

Please describe in the patch description that you pad the cookie that
os_malloc writes to a page boundary. It's pretty hard to grasp that from
the current patch description :)


Alex

> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v9: None
> Changes in v8: None
> Changes in v7: None
> Changes in v6: None
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
> 
>  arch/sandbox/cpu/os.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 5839932b005..a1a982af2de 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -143,14 +143,15 @@ void os_tty_raw(int fd, bool allow_sigs)
>  void *os_malloc(size_t length)
>  {
>  	struct os_mem_hdr *hdr;
> +	int page_size = getpagesize();
>  
> -	hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE,
> -		   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	hdr = mmap(NULL, length + page_size,
> +		   PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  	if (hdr == MAP_FAILED)
>  		return NULL;
>  	hdr->length = length;
>  
> -	return hdr + 1;
> +	return (void *)hdr + page_size;
>  }
>  
>  void os_free(void *ptr)
>
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 5839932b005..a1a982af2de 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -143,14 +143,15 @@  void os_tty_raw(int fd, bool allow_sigs)
 void *os_malloc(size_t length)
 {
 	struct os_mem_hdr *hdr;
+	int page_size = getpagesize();
 
-	hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE,
-		   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	hdr = mmap(NULL, length + page_size,
+		   PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if (hdr == MAP_FAILED)
 		return NULL;
 	hdr->length = length;
 
-	return hdr + 1;
+	return (void *)hdr + page_size;
 }
 
 void os_free(void *ptr)