xiaoxiang781216 commented on code in PR #8026:
URL: https://github.com/apache/nuttx/pull/8026#discussion_r1065590789
##########
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:
but why not reuse mumap implementation? BTW, will you refine shm driver in
the upcoming patch?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]