2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call implemented in this file:
|
2005-07-14 17:12:12 +02:00
|
|
|
* m_type: SYS_SETALARM
|
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
2005-07-14 17:12:12 +02:00
|
|
|
* m2_l1: ALRM_EXP_TIME (alarm's expiration time)
|
|
|
|
* m2_i2: ALRM_ABS_TIME (expiration time is absolute?)
|
2005-07-19 14:21:36 +02:00
|
|
|
* m2_l1: ALRM_TIME_LEFT (return seconds left of previous)
|
2005-07-14 17:12:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../system.h"
|
|
|
|
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#include <minix/endpoint.h>
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#if USE_SETALARM
|
|
|
|
|
|
|
|
FORWARD _PROTOTYPE( void cause_alarm, (timer_t *tp) );
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_setalarm *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int do_setalarm(m_ptr)
|
|
|
|
message *m_ptr; /* pointer to request message */
|
|
|
|
{
|
|
|
|
/* A process requests a synchronous alarm, or wants to cancel its alarm. */
|
2005-07-29 17:26:23 +02:00
|
|
|
register struct proc *rp; /* pointer to requesting process */
|
2005-07-14 17:12:12 +02:00
|
|
|
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 */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
rp = proc_addr(who_p);
|
2005-07-29 17:26:23 +02:00
|
|
|
if (! (priv(rp)->s_flags & SYS_PROC)) return(EPERM);
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Get the timer structure and set the parameters for this alarm. */
|
2005-07-29 17:26:23 +02:00
|
|
|
tp = &(priv(rp)->s_alarm_timer);
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
tmr_arg(tp)->ta_int = m_ptr->m_source;
|
2005-07-19 14:21:36 +02:00
|
|
|
tp->tmr_func = cause_alarm;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Return the ticks left on the previous alarm. */
|
2005-07-19 14:21:36 +02:00
|
|
|
uptime = get_uptime();
|
2005-08-05 19:02:37 +02:00
|
|
|
if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) {
|
2005-07-14 17:12:12 +02:00
|
|
|
m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime);
|
2005-08-05 19:02:37 +02:00
|
|
|
} else {
|
|
|
|
m_ptr->ALRM_TIME_LEFT = 0;
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
|
2005-07-21 20:36:40 +02:00
|
|
|
/* Finally, (re)set the timer depending on the expiration time. */
|
2005-07-14 17:12:12 +02:00
|
|
|
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
|
2005-07-19 14:21:36 +02:00
|
|
|
* process with a notification message from CLOCK.
|
2005-07-14 17:12:12 +02:00
|
|
|
*/
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int proc_nr_e = tmr_arg(tp)->ta_int; /* get process number */
|
|
|
|
lock_notify(CLOCK, proc_nr_e); /* notify process */
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_SETALARM */
|