xiaoxiang781216 commented on code in PR #8026: URL: https://github.com/apache/nuttx/pull/8026#discussion_r1065702612
########## mm/shm/shmdt.c: ########## @@ -178,4 +164,55 @@ int shmdt(FAR const void *shmaddr) return ERROR; } +int shmdt(FAR const void *shmaddr) +{ + FAR struct tcb_s *tcb; + FAR struct mm_map_entry_s *entry; + FAR struct task_group_s *group; + int shmid; + int ret; + + /* Get the TCB and group containing our virtual memory allocator */ + + tcb = nxsched_self(); + DEBUGASSERT(tcb && tcb->group); + group = tcb->group; + + /* Get exclusive access to process' mm_map */ + + ret = mm_map_lock(); + if (ret == OK) + { + /* Perform the reverse lookup to get the shmid corresponding to this + * shmaddr. The mapping is matched with just shmaddr == map->vaddr. + */ + + entry = mm_map_find(shmaddr, 1); + if (!entry || entry->vaddr != shmaddr) + { + ret = -EINVAL; + shmerr("ERROR: No region matching this virtual address: %p\n", + shmaddr); + + mm_map_unlock(); + return -EINVAL; + } + + shmid = entry->priv.i; + + /* Indicate that there is no longer any mapping for this region. */ + + if (mm_map_remove(get_group_mm(group), entry) < 0) + { + shmerr("ERROR: mm_map_remove() failed\n"); + } + + mm_map_unlock(); + + ret = shmdt_priv(tcb->group, shmaddr, shmid); Review Comment: Yes, I think it will be much better if we can: 1. Share the same code base for both posix and system-v shm interface(e.g. shmget->shm_open, shmat->mmap, shmctl->ioctl, shmdt->shm_unlink). 2. Share the same code path between posix shm and other drivers (e.g., fb and video). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org