diff options
author | Jon Nettleton <jon.nettleton@gmail.com> | 2014-08-27 13:23:34 +0000 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-08-27 15:50:26 +0200 |
commit | dc6e0441cc9822c29ee6991bda9a0d74bd6eba21 (patch) | |
tree | e5c5146130f7d4f60de1f6c213e14e1d9bf6e500 | |
parent | e33b72a6760d464ef76cf8c98f1331c41654a513 (diff) | |
download | etna_viv-dc6e0441cc9822c29ee6991bda9a0d74bd6eba21.tar.gz etna_viv-dc6e0441cc9822c29ee6991bda9a0d74bd6eba21.tar.xz |
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.
-rw-r--r-- | src/etnaviv/viv.c | 7 | ||||
-rw-r--r-- | 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; |