//----------------------------------------------------------------------------------------------------// // @func - sys_shmat //! @desc //! Attach to shared memory segment //! - Lookup shared memory segment based on shmid and return pointer to start of the segment //! @param //! - shmid is the ID of the segment //! - shmaddr is the address specification of the segment (ignored) //! - shmflg is the attach flag (ignored) //! @return //! - Return the address of the segment on success and NULL on error. //! errno set to, //! EINVAL if shmid refers to an invalid shared memory segment //! @note //! - The shmaddr specification is discarded. We support attaches only to the start of the segment. //! No memory mapping of any kind is done. //! - shmflg is ignored because it applies to shmaddr //----------------------------------------------------------------------------------------------------// void* sys_shmat (int shmid, const void *shmaddr, int flag) { if ((shmid < 0) || (shmid >= N_SHM) || (shm_heap[shmid].shm_id == -1)) { kerrno = EINVAL; return NULL; } shm_heap[shmid].shm_nattch++ ; shm_heap[shmid].shm_lpid = sys_get_currentPID(); return (void*)(shm_heap[shmid].shm_addr) ; }
//----------------------------------------------------------------------------------------------------// // @func - sys_sleep //! @desc //! Suspend current process for specified number of ticks //! 1 tick = one timer interrupt received by the kernel //! @param //! - ms is the number of milliseconds to sleep this task. //! @return //! - Number of milliseconds unslept for. 0 - complete success //! @note //! - None //----------------------------------------------------------------------------------------------------// unsigned sys_sleep (unsigned int ms) { pid_t cpid = sys_get_currentPID(); if (add_tmr (cpid, ms) == -1) return ms; current_process->state = PROC_DELAY; suspend (); // Awaken here after timeout return 0; }