jlaitine commented on code in PR #8026: URL: https://github.com/apache/nuttx/pull/8026#discussion_r1065630233
########## 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: System-V shm driver (mm/shm/) have to naturally implement the system-v interfaces (shmget, shmat, shmdt etc...). Of course, when that interface creates memory mappings, we have then two ways of deleting the mappings (posix unmap & system-v shmdt). But I see what you mean, we could just implement shm_unmap and call that from the shmdt. It would maybe make the code a bit cleaner, but I tried to avoid changing existing shm driver too much. For me, system-v interfaces are obsolete... We can try to clean up the system-v shm interface, but I'd like to rather bring in the posix shm interface next, which I find more useful and interesting. -- 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