From dc6e0441cc9822c29ee6991bda9a0d74bd6eba21 Mon Sep 17 00:00:00 2001 From: Jon Nettleton Date: Wed, 27 Aug 2014 13:23:34 +0000 Subject: Unmap memory on close We need to make sure to unmap all memory before we close the fd to galcore. This allows the kernel driver to call drv_release and clean up after the process exits. --- src/etnaviv/viv.c | 7 +++++-- src/etnaviv/viv.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/etnaviv/viv.c b/src/etnaviv/viv.c index 0393c21..5e52a87 100644 --- a/src/etnaviv/viv.c +++ b/src/etnaviv/viv.c @@ -186,6 +186,8 @@ int viv_close(struct viv_conn *conn) (void) viv_deallocate_signals(conn); + munmap(conn->mem, conn->mem_length); + close(conn->fd); free(conn); #ifdef ETNAVIV_HOOK @@ -253,7 +255,7 @@ int viv_open(enum viv_hw_type hw_type, struct viv_conn **out) conn->fd = -1; for(const char **pname = galcore_device; *pname && conn->fd < 0; ++pname) { - conn->fd = open(*pname, O_RDWR); + conn->fd = open(*pname, O_RDWR | O_CLOEXEC); } if((err=conn->fd) < 0) goto error; @@ -308,7 +310,8 @@ int viv_open(enum viv_hw_type hw_type, struct viv_conn **out) fprintf(stderr, " Contiguous size: 0x%08x\n", (uint32_t)id.u.QueryVideoMemory.contiguousSize); conn->mem_base = (viv_addr_t)id.u.QueryVideoMemory.contiguousPhysical; - conn->mem = mmap(NULL, id.u.QueryVideoMemory.contiguousSize, PROT_READ|PROT_WRITE, MAP_SHARED, conn->fd, conn->mem_base); + conn->mem_length = id.u.QueryVideoMemory.contiguousSize; + conn->mem = mmap(NULL, conn->mem_length, PROT_READ|PROT_WRITE, MAP_SHARED, conn->fd, conn->mem_base); if(conn->mem == NULL) { err = -1; diff --git a/src/etnaviv/viv.h b/src/etnaviv/viv.h index aeec6be..bd8d3ea 100644 --- a/src/etnaviv/viv.h +++ b/src/etnaviv/viv.h @@ -189,6 +189,7 @@ struct viv_conn { viv_addr_t base_address; void *mem; + size_t mem_length; viv_addr_t mem_base; viv_handle_t process; struct viv_specs chip; -- cgit v1.2.3