static inline void *_rt_shm_alloc(unsigned long name, int size, int suprt) { void *adr; // suprt = USE_GFP_ATOMIC; // to force some testing if (!(adr = rt_get_adr_cnt(name)) && size > 0 && suprt >= 0 && RT_SHM_OP_PERM()) { size = ((size - 1) & PAGE_MASK) + PAGE_SIZE; if ((adr = suprt ? rkmalloc(&size, SUPRT[suprt]) : rvmalloc(size))) { if (!rt_register(name, adr, suprt ? -size : size, 0)) { if (suprt) { rkfree(adr, size); } else { rvfree(adr, size); } return 0; } memset(ALIGN2PAGE(adr), 0, size); } } return ALIGN2PAGE(adr); }
void *rt_named_malloc(unsigned long name, int size) { void *mem_ptr; if ((mem_ptr = rt_get_adr_cnt(name))) { return mem_ptr; } if ((mem_ptr = _rt_halloc(size, &rt_smp_linux_task->heap[GLOBAL]))) { if (rt_register(name, mem_ptr, IS_HPCK, 0)) { return mem_ptr; } rt_hfree(mem_ptr); } return NULL; }
static inline void *rt_named_halloc_typed(unsigned long name, int size, int htype) { RT_TASK *task; void *mem_ptr; RTAI_TASK(return NULL); if ((mem_ptr = rt_get_adr_cnt(name))) { return task->heap[htype].uadr + (mem_ptr - task->heap[htype].kadr); } if ((mem_ptr = _rt_halloc(size, &task->heap[htype]))) { if (rt_register(name, task->heap[htype].kadr + (mem_ptr - task->heap[htype].uadr), IS_HPCK, 0)) { return mem_ptr; } _rt_hfree(mem_ptr, &task->heap[htype]); } return NULL; }
/** * @brief Initializes a specifically typed (fifo queued, priority queued * or resource queued) mailbox identified by a name. * * _rt_typed_named_mbx_init initializes a mailbox of type @e qtype * and size @e size identified by @e name. Named mailboxed * are useful for use among different processes, kernel/user space and * in distributed applications, see netrpc. * * @param mbx_name is the mailbox name; since it can be a clumsy identifier, * services are provided to convert 6 characters identifiers to unsigned long * (see nam2num()). * * @param size corresponds to the size of the mailbox. * * @param qtype corresponds to the queueing policy: FIFO_Q, PRIO_Q or RES_Q. * * @return On success the pointer to the allocated mbx is returned. * On failure, NULL is returned. * * See also: notes under rt_mbx_init() and rt_typed_mbx_init(). */ RTAI_SYSCALL_MODE MBX *_rt_typed_named_mbx_init(unsigned long mbx_name, int size, int qtype) { MBX *mbx; if ((mbx = rt_get_adr_cnt(mbx_name))) { return mbx; } if ((mbx = rt_malloc(sizeof(MBX)))) { rt_typed_mbx_init(mbx, size, qtype); if (rt_register(mbx_name, mbx, IS_MBX, 0)) { return mbx; } rt_mbx_delete(mbx); } rt_free(mbx); return (MBX *)0; }
RTAI_SYSCALL_MODE RT_MSGQ *_rt_named_msgq_init(unsigned long msgq_name, int nmsg, int msg_size) { RT_MSGQ *msgq; if ((msgq = rt_get_adr_cnt(msgq_name))) { return msgq; } if ((msgq = rt_malloc(sizeof(RT_MSGQ)))) { rt_msgq_init(msgq, nmsg, msg_size); if (rt_register(msgq_name, msgq, IS_MBX, 0)) { return msgq; } rt_msgq_delete(msgq); } rt_free(msgq); return NULL; }
static void rtai_shm_vm_open(struct vm_area_struct *vma) { rt_get_adr_cnt((unsigned long)vma->vm_private_data); }