minix/kernel/system/do_setalarm.c
Tomas Hruby cca24d06d8 This patch removes the global variables who_p and who_e from the
kernel (sys task).  The main reason is that these would have to become
cpu local variables on SMP.  Once the system task is not a task but a
genuine part of the kernel there is even less reason to have these
extra variables as proc_ptr will already contain all neccessary
information. In addition converting who_e to the process pointer and
back again all the time will be avoided.

Although proc_ptr will contain all important information, accessing it
as a cpu local variable will be fairly expensive, hence the value
would be assigned to some on stack local variable. Therefore it is
better to add the 'caller' argument to the syscall handlers to pass
the value on stack anyway. It also clearly denotes on who's behalf is
the syscall being executed.

This patch also ANSIfies the syscall function headers.

Last but not least, it also fixes a potential bug in virtual_copy_f()
in case the check is disabled. So far the function in case of a
failure could possible reuse an old who_p in case this function had
not been called from the system task.

virtual_copy_f() takes the caller as a parameter too. In case the
checking is disabled, the caller must be NULL and non NULL if it is
enabled as we must be able to suspend the caller.
2010-02-03 09:04:48 +00:00

71 lines
2.5 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_SETALARM
*
* The parameters for this kernel call are:
* m2_l1: ALRM_EXP_TIME (alarm's expiration time)
* m2_i2: ALRM_ABS_TIME (expiration time is absolute?)
* m2_l1: ALRM_TIME_LEFT (return seconds left of previous)
*/
#include "../system.h"
#include <minix/endpoint.h>
#if USE_SETALARM
FORWARD _PROTOTYPE( void cause_alarm, (timer_t *tp) );
/*===========================================================================*
* do_setalarm *
*===========================================================================*/
PUBLIC int do_setalarm(struct proc * caller, message * m_ptr)
{
/* A process requests a synchronous alarm, or wants to cancel its alarm. */
long exp_time; /* expiration time for this alarm */
int use_abs_time; /* use absolute or relative time */
timer_t *tp; /* the process' timer structure */
clock_t uptime; /* placeholder for current uptime */
/* Extract shared parameters from the request message. */
exp_time = m_ptr->ALRM_EXP_TIME; /* alarm's expiration time */
use_abs_time = m_ptr->ALRM_ABS_TIME; /* flag for absolute time */
if (! (priv(caller)->s_flags & SYS_PROC)) return(EPERM);
/* Get the timer structure and set the parameters for this alarm. */
tp = &(priv(caller)->s_alarm_timer);
tmr_arg(tp)->ta_int = m_ptr->m_source;
tp->tmr_func = cause_alarm;
/* Return the ticks left on the previous alarm. */
uptime = get_uptime();
if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) {
m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime);
} else {
m_ptr->ALRM_TIME_LEFT = 0;
}
/* Finally, (re)set the timer depending on the expiration time. */
if (exp_time == 0) {
reset_timer(tp);
} else {
tp->tmr_exp_time = (use_abs_time) ? exp_time : exp_time + get_uptime();
set_timer(tp, tp->tmr_exp_time, tp->tmr_func);
}
return(OK);
}
/*===========================================================================*
* cause_alarm *
*===========================================================================*/
PRIVATE void cause_alarm(tp)
timer_t *tp;
{
/* Routine called if a timer goes off and the process requested a synchronous
* alarm. The process number is stored in timer argument 'ta_int'. Notify that
* process with a notification message from CLOCK.
*/
int proc_nr_e = tmr_arg(tp)->ta_int; /* get process number */
lock_notify(CLOCK, proc_nr_e); /* notify process */
}
#endif /* USE_SETALARM */