Map the shared memory specified by 'id' to the specified virtual address. */
| 265 | |
| 266 | /* Map the shared memory specified by 'id' to the specified virtual address. */ |
| 267 | static void *_lwp_shmat(int id, void *shm_vaddr) |
| 268 | { |
| 269 | int err; |
| 270 | struct rt_lwp *lwp = RT_NULL; |
| 271 | struct lwp_avl_struct *node_key = RT_NULL; |
| 272 | struct lwp_shm_struct *p = RT_NULL; |
| 273 | void *va = shm_vaddr; |
| 274 | |
| 275 | /* The id is used to locate the node_key in the binary tree, and then get the |
| 276 | * shared-memory structure linked to the node_key. We don't use the id to refer |
| 277 | * to the shared-memory structure directly, because the binary tree is used |
| 278 | * to verify the structure is really in use. |
| 279 | */ |
| 280 | node_key = shm_id_to_node(id); |
| 281 | if (!node_key) |
| 282 | { |
| 283 | return RT_NULL; |
| 284 | } |
| 285 | p = (struct lwp_shm_struct *)node_key->data; /* p = _shm_ary[id]; */ |
| 286 | |
| 287 | /* map the shared memory into the address space of the current thread */ |
| 288 | lwp = lwp_self(); |
| 289 | if (!lwp) |
| 290 | { |
| 291 | return RT_NULL; |
| 292 | } |
| 293 | |
| 294 | err = rt_aspace_map(lwp->aspace, &va, p->size, MMU_MAP_U_RWCB, MMF_PREFETCH, |
| 295 | &p->mem_obj, 0); |
| 296 | if (err != RT_EOK) |
| 297 | { |
| 298 | va = RT_NULL; |
| 299 | } |
| 300 | return va; |
| 301 | } |
| 302 | |
| 303 | /* A wrapping function: attach the shared memory to the specified address. */ |
| 304 | void *lwp_shmat(int id, void *shm_vaddr) |
no test coverage detected