jlaitine commented on code in PR #8026: URL: https://github.com/apache/nuttx/pull/8026#discussion_r1065468467
########## 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: There are two ways to unmap the shm region by the user. sysv "shmdt" call (see "man shmdt"), and "unmap" call. - sysv "shmdt" call is always done during normal user process execution - unmap call could be done during normal process execution (but normally you'd use the shmdt if using this interface) - unmap call can be done during proceess exit, if user has left the memory unmapped, or process dies unexpectedly shmdt_priv is the common function which does the actual work for all cases. -- 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