From 423ebb1da15e69b78aed13d431360de6fb15a4cb Mon Sep 17 00:00:00 2001 From: Yanjun Liao Date: Fri, 15 Mar 2024 17:32:31 +0800 Subject: [PATCH] fix[ext_dma]: fix mmap permission error Change-Id: Ic7ae7c8de978752f8437f2d0b700014ea6817c56 Signed-off-by: Yanjun Liao --- osal/allocator/allocator_ext_dma.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osal/allocator/allocator_ext_dma.c b/osal/allocator/allocator_ext_dma.c index b3aeb102..482470ae 100644 --- a/osal/allocator/allocator_ext_dma.c +++ b/osal/allocator/allocator_ext_dma.c @@ -19,6 +19,7 @@ #include "mpp_mem.h" #include "mpp_debug.h" +#include "mpp_common.h" #include "allocator_ext_dma.h" @@ -87,6 +88,7 @@ static MPP_RET allocator_ext_dma_import(void *ctx, MppBufferInfo *info) static MPP_RET allocator_ext_dma_mmap(void *ctx, MppBufferInfo *info) { void *ptr = NULL; + int flags = 0; unsigned long offset = 0L; mpp_assert(ctx); mpp_assert(info->size); @@ -99,8 +101,11 @@ static MPP_RET allocator_ext_dma_mmap(void *ctx, MppBufferInfo *info) * It is insecure to access the first memory page, * usually system doesn't allow this behavior. */ - ptr = mmap(NULL, info->size, PROT_READ | PROT_WRITE, - MAP_SHARED, info->fd, offset); + flags = PROT_READ; + if (fcntl(info->fd, F_GETFL) & O_RDWR) + flags |= PROT_WRITE; + + ptr = mmap(NULL, info->size, flags, MAP_SHARED, info->fd, offset); if (ptr == MAP_FAILED) return MPP_ERR_NULL_PTR;