From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Graf Date: Mon, 18 Jun 2018 17:23:14 +0200 Subject: [U-Boot] [PATCH v4 20/21] sandbox: Always allocate aligned buffers In-Reply-To: <20180618152315.34233-1-agraf@suse.de> References: <20180618152315.34233-1-agraf@suse.de> Message-ID: <20180618152315.34233-21-agraf@suse.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de In some code paths we check whether host virtual addresses are sane. That only works if at least alignments between host and U-Boot address spaces match. So let's always map U-Boot addresses with 64kb alignment. That should be enough to ensure that the actual RAM ends up in a different page from the header on all architectures. Signed-off-by: Alexander Graf --- arch/sandbox/cpu/os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 9fa79a8843..4dc6483922 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; + size_t alloc_length = length + (64 * 1024); - hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE, + hdr = mmap(NULL, alloc_length, 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 + (64 * 1024); } void os_free(void *ptr) -- 2.12.3