From bd9b180b27390e9590af56a7a444143b7a86e6d7 Mon Sep 17 00:00:00 2001 From: laokz Date: Tue, 1 Dec 2020 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSYSV=20shm=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=9AOsShmRegionFree=E7=89=A9=E7=90=86=E9=A1=B5=E8=A7=A3?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E3=80=81=E5=85=B1=E4=BA=AB=E6=AE=B5=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=9D=A1=E4=BB=B6=EF=BC=8CShmGet=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=A0=87=E5=BF=97=E6=A3=80=E6=9F=A5=EF=BC=8CShmatVmmAlloc?= =?UTF-8?q?=E5=AF=B9=E5=B7=B2=E5=AD=98=E5=9C=A8=E6=98=A0=E5=B0=84=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/base/vm/shm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/kernel/base/vm/shm.c b/kernel/base/vm/shm.c index 129fd4d0..4f63799c 100644 --- a/kernel/base/vm/shm.c +++ b/kernel/base/vm/shm.c @@ -337,10 +337,14 @@ VOID OsShmRegionFree(LosVmSpace *space, LosVmMapRegion *region) return; } + LOS_ArchMmuUnmap(&space->archMmu, region->range.base, region->range.size >> PAGE_SHIFT); ShmPagesRefDec(seg); seg->ds.shm_nattch--; - if (seg->ds.shm_nattch <= 0) { + if (seg->ds.shm_nattch <= 0 && (seg->status & SHM_SEG_REMOVE)) { ShmFreeSeg(seg); + } else { + seg->ds.shm_dtime = time(NULL); + seg->ds.shm_lpid = LOS_GetCurrProcessID();/* may not be the space's PID. */ } SYSV_SHM_UNLOCK(); } @@ -411,7 +415,7 @@ INT32 ShmGet(key_t key, size_t size, INT32 shmflg) SYSV_SHM_LOCK(); if ((((UINT32)shmflg & IPC_CREAT) == 0) && - (((UINT32)shmflg & IPC_EXCL) == 0)) { + (((UINT32)shmflg & IPC_EXCL) == 1)) { ret = -EINVAL; goto ERROR; } @@ -487,13 +491,15 @@ LosVmMapRegion *ShmatVmmAlloc(struct shmIDSource *seg, const VOID *shmaddr, } else { vaddr = (VADDR_T)(UINTPTR)shmaddr; } - if ((shmflg & SHM_REMAP)) { - vaddr = (VADDR_T)LOS_MMap(vaddr, seg->ds.shm_segsz, prot, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); - region = LOS_RegionFind(space, vaddr); - } else { - region = LOS_RegionAlloc(space, vaddr, seg->ds.shm_segsz, regionFlags, 0); + if (!(shmflg & SHM_REMAP) && (LOS_RegionFind(space, vaddr) || + LOS_RegionFind(space, vaddr + seg->ds.shm_segsz - 1) || + LOS_RegionRangeFind(space, vaddr, seg->ds.shm_segsz - 1))) { + ret = EINVAL; + goto ERROR; } + vaddr = (VADDR_T)LOS_MMap(vaddr, seg->ds.shm_segsz, prot, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + region = LOS_RegionFind(space, vaddr); } if (region == NULL) { @@ -718,10 +724,10 @@ INT32 ShmDt(const VOID *shmaddr) if ((seg->ds.shm_nattch <= 0) && (seg->status & SHM_SEG_REMOVE)) { ShmFreeSeg(seg); + } else { + seg->ds.shm_dtime = time(NULL); + seg->ds.shm_lpid = LOS_GetCurrProcessID(); } - - seg->ds.shm_dtime = time(NULL); - seg->ds.shm_lpid = LOS_GetCurrProcessID(); SYSV_SHM_UNLOCK(); (VOID)LOS_MuxRelease(&space->regionMux); return 0;