2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains the device dependent part of the drivers for the
|
|
|
|
* following special files:
|
|
|
|
* /dev/ram - RAM disk
|
|
|
|
* /dev/mem - absolute memory
|
|
|
|
* /dev/kmem - kernel virtual memory
|
|
|
|
* /dev/null - null device (data sink)
|
2005-04-29 17:36:43 +02:00
|
|
|
* /dev/boot - boot device loaded from boot image
|
|
|
|
* /dev/zero - null byte stream generator
|
2010-01-05 20:39:27 +01:00
|
|
|
* /dev/imgrd - boot image RAM disk
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* Changes:
|
2005-04-29 17:36:43 +02:00
|
|
|
* Apr 29, 2005 added null byte generator (Jorrit N. Herder)
|
|
|
|
* Apr 09, 2005 added support for boot device (Jorrit N. Herder)
|
2005-04-21 16:53:53 +02:00
|
|
|
* Jul 26, 2004 moved RAM driver to user-space (Jorrit N. Herder)
|
|
|
|
* Apr 20, 1992 device dependent/independent split (Kees J. Bot)
|
|
|
|
*/
|
|
|
|
|
2010-03-22 22:25:22 +01:00
|
|
|
#include <minix/drivers.h>
|
|
|
|
#include <minix/driver.h>
|
2005-06-03 15:55:06 +02:00
|
|
|
#include <sys/ioc_memory.h>
|
2006-07-13 16:50:23 +02:00
|
|
|
#include <minix/ds.h>
|
2008-12-11 15:42:23 +01:00
|
|
|
#include <minix/vm.h>
|
2011-02-10 16:39:56 +01:00
|
|
|
#include <machine/param.h>
|
2008-12-11 15:42:23 +01:00
|
|
|
#include <sys/mman.h>
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/const.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/type.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/vm.h>
|
2005-09-30 14:57:30 +02:00
|
|
|
|
2006-02-15 12:18:21 +01:00
|
|
|
#include "local.h"
|
|
|
|
|
2009-03-19 14:48:19 +01:00
|
|
|
/* ramdisks (/dev/ram*) */
|
|
|
|
#define RAMDISKS 6
|
|
|
|
|
|
|
|
#define RAM_DEV_LAST (RAM_DEV_FIRST+RAMDISKS-1)
|
|
|
|
|
|
|
|
#define NR_DEVS (7+RAMDISKS) /* number of minor devices */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-04-29 17:36:43 +02:00
|
|
|
PRIVATE struct device m_geom[NR_DEVS]; /* base and size of each device */
|
2008-12-11 18:33:13 +01:00
|
|
|
PRIVATE vir_bytes m_vaddrs[NR_DEVS];
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE int m_device; /* current device */
|
2005-06-03 15:55:06 +02:00
|
|
|
PRIVATE struct kinfo kinfo; /* kernel information */
|
|
|
|
|
|
|
|
extern int errno; /* error number for PM calls */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-09-22 15:57:21 +02:00
|
|
|
PRIVATE int openct[NR_DEVS];
|
|
|
|
|
2005-09-11 19:09:11 +02:00
|
|
|
FORWARD _PROTOTYPE( char *m_name, (void) );
|
|
|
|
FORWARD _PROTOTYPE( struct device *m_prepare, (int device) );
|
2009-12-02 10:57:48 +01:00
|
|
|
FORWARD _PROTOTYPE( int m_transfer, (int proc_nr, int opcode,
|
|
|
|
u64_t position, iovec_t *iov, unsigned nr_req) );
|
2005-09-11 19:09:11 +02:00
|
|
|
FORWARD _PROTOTYPE( int m_do_open, (struct driver *dp, message *m_ptr) );
|
2009-09-22 15:57:21 +02:00
|
|
|
FORWARD _PROTOTYPE( int m_do_close, (struct driver *dp, message *m_ptr) );
|
2009-12-02 10:57:48 +01:00
|
|
|
FORWARD _PROTOTYPE( int m_ioctl, (struct driver *dp, message *m_ptr) );
|
2005-09-11 19:09:11 +02:00
|
|
|
FORWARD _PROTOTYPE( void m_geometry, (struct partition *entry) );
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Entry points to this driver. */
|
|
|
|
PRIVATE struct driver m_dtab = {
|
|
|
|
m_name, /* current device's name */
|
|
|
|
m_do_open, /* open or mount */
|
2009-09-22 15:57:21 +02:00
|
|
|
m_do_close, /* nothing on a close */
|
2005-04-21 16:53:53 +02:00
|
|
|
m_ioctl, /* specify ram disk geometry */
|
|
|
|
m_prepare, /* prepare for I/O on a given minor device */
|
|
|
|
m_transfer, /* do the I/O */
|
|
|
|
nop_cleanup, /* no need to clean up */
|
|
|
|
m_geometry, /* memory device "geometry" */
|
2005-08-03 17:22:41 +02:00
|
|
|
nop_alarm,
|
2005-07-08 19:23:44 +02:00
|
|
|
nop_cancel,
|
|
|
|
nop_select,
|
2005-08-25 10:19:11 +02:00
|
|
|
NULL,
|
2005-07-08 19:23:44 +02:00
|
|
|
NULL
|
2005-04-21 16:53:53 +02:00
|
|
|
};
|
|
|
|
|
2005-04-29 17:36:43 +02:00
|
|
|
/* Buffer for the /dev/zero null byte feed. */
|
|
|
|
#define ZERO_BUF_SIZE 1024
|
2005-06-03 15:55:06 +02:00
|
|
|
PRIVATE char dev_zero[ZERO_BUF_SIZE];
|
2005-04-29 17:36:43 +02:00
|
|
|
|
2005-05-19 11:36:44 +02:00
|
|
|
#define click_to_round_k(n) \
|
|
|
|
((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF functions and variables. */
|
|
|
|
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
FORWARD _PROTOTYPE( int sef_cb_init_fresh, (int type, sef_init_info_t *info) );
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* main *
|
|
|
|
*===========================================================================*/
|
2005-08-25 14:35:59 +02:00
|
|
|
PUBLIC int main(void)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF local startup. */
|
|
|
|
sef_local_startup();
|
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/* Call the generic receive loop. */
|
2009-12-02 10:57:48 +01:00
|
|
|
driver_task(&m_dtab, DRIVER_STD);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
return(OK);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void sef_local_startup()
|
|
|
|
{
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/* Register init callbacks. */
|
|
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_lu(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_restart(sef_cb_init_fresh);
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* Register live update callbacks. */
|
|
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready);
|
|
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard);
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_init_fresh *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
|
|
|
|
{
|
|
|
|
/* Initialize the memory driver. */
|
|
|
|
int i, s;
|
|
|
|
|
|
|
|
/* Initialize all minor devices one by one. */
|
|
|
|
if (OK != (s=sys_getkinfo(&kinfo))) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("Couldn't get kernel information: %d", s);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Map in kernel memory for /dev/kmem. */
|
|
|
|
m_geom[KMEM_DEV].dv_base = cvul64(kinfo.kmem_base);
|
|
|
|
m_geom[KMEM_DEV].dv_size = cvul64(kinfo.kmem_size);
|
|
|
|
if((m_vaddrs[KMEM_DEV] = vm_map_phys(SELF, (void *) kinfo.kmem_base,
|
|
|
|
kinfo.kmem_size)) == MAP_FAILED) {
|
|
|
|
printf("MEM: Couldn't map in /dev/kmem.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Ramdisk image built into the memory driver */
|
|
|
|
m_geom[IMGRD_DEV].dv_base= cvul64(0);
|
|
|
|
m_geom[IMGRD_DEV].dv_size= cvul64(imgrd_size);
|
|
|
|
m_vaddrs[IMGRD_DEV] = (vir_bytes) imgrd;
|
|
|
|
|
|
|
|
/* Initialize /dev/zero. Simply write zeros into the buffer. */
|
|
|
|
for (i=0; i<ZERO_BUF_SIZE; i++) {
|
|
|
|
dev_zero[i] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < NR_DEVS; i++)
|
|
|
|
openct[i] = 0;
|
|
|
|
|
|
|
|
/* Set up memory range for /dev/mem. */
|
|
|
|
m_geom[MEM_DEV].dv_base = cvul64(0);
|
|
|
|
m_geom[MEM_DEV].dv_size = cvul64(0xffffffff);
|
|
|
|
|
|
|
|
m_vaddrs[MEM_DEV] = (vir_bytes) MAP_FAILED; /* we are not mapping this in. */
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* m_name *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE char *m_name()
|
|
|
|
{
|
|
|
|
/* Return a name for the current device. */
|
|
|
|
static char name[] = "memory";
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* m_prepare *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE struct device *m_prepare(device)
|
|
|
|
int device;
|
|
|
|
{
|
|
|
|
/* Prepare for I/O on a device: check if the minor device number is ok. */
|
2010-05-10 15:26:00 +02:00
|
|
|
if (device < 0 || device >= NR_DEVS) return(NULL);
|
2005-04-21 16:53:53 +02:00
|
|
|
m_device = device;
|
|
|
|
|
|
|
|
return(&m_geom[device]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* m_transfer *
|
|
|
|
*===========================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PRIVATE int m_transfer(proc_nr, opcode, pos64, iov, nr_req)
|
2005-04-21 16:53:53 +02:00
|
|
|
int proc_nr; /* process doing the request */
|
2007-02-07 17:22:19 +01:00
|
|
|
int opcode; /* DEV_GATHER_S or DEV_SCATTER_S */
|
2006-11-27 15:21:43 +01:00
|
|
|
u64_t pos64; /* offset on device to read or write */
|
2005-04-21 16:53:53 +02:00
|
|
|
iovec_t *iov; /* pointer to read or write request vector */
|
|
|
|
unsigned nr_req; /* length of request vector */
|
|
|
|
{
|
2005-05-19 11:36:44 +02:00
|
|
|
/* Read or write one the driver's minor devices. */
|
2005-04-29 17:36:43 +02:00
|
|
|
unsigned count, left, chunk;
|
2006-06-20 10:56:15 +02:00
|
|
|
vir_bytes user_vir, vir_offset = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
struct device *dv;
|
|
|
|
unsigned long dv_size;
|
2006-06-20 10:56:15 +02:00
|
|
|
int s, r;
|
2006-11-27 15:21:43 +01:00
|
|
|
off_t position;
|
2008-12-11 18:33:13 +01:00
|
|
|
vir_bytes dev_vaddr;
|
2006-06-20 10:56:15 +02:00
|
|
|
|
2007-04-24 15:27:33 +02:00
|
|
|
/* ZERO_DEV and NULL_DEV are infinite in size. */
|
|
|
|
if (m_device != ZERO_DEV && m_device != NULL_DEV && ex64hi(pos64) != 0)
|
2006-11-27 15:21:43 +01:00
|
|
|
return OK; /* Beyond EOF */
|
|
|
|
position= cv64ul(pos64);
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Get minor device number and check for /dev/null. */
|
2005-05-19 11:36:44 +02:00
|
|
|
dv = &m_geom[m_device];
|
2005-04-21 16:53:53 +02:00
|
|
|
dv_size = cv64ul(dv->dv_size);
|
2008-12-11 18:33:13 +01:00
|
|
|
dev_vaddr = m_vaddrs[m_device];
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
while (nr_req > 0) {
|
2005-04-29 17:36:43 +02:00
|
|
|
|
|
|
|
/* How much to transfer and where to / from. */
|
2005-04-21 16:53:53 +02:00
|
|
|
count = iov->iov_size;
|
|
|
|
user_vir = iov->iov_addr;
|
|
|
|
|
2005-05-19 11:36:44 +02:00
|
|
|
switch (m_device) {
|
2005-04-29 17:36:43 +02:00
|
|
|
|
|
|
|
/* No copying; ignore request. */
|
2005-04-21 16:53:53 +02:00
|
|
|
case NULL_DEV:
|
2007-02-07 17:22:19 +01:00
|
|
|
if (opcode == DEV_GATHER_S) return(OK); /* always at EOF */
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
2009-03-19 14:48:19 +01:00
|
|
|
/* Virtual copying. For RAM disks, kernel memory and internal FS. */
|
|
|
|
default:
|
2005-04-29 17:36:43 +02:00
|
|
|
case KMEM_DEV:
|
2009-03-19 14:48:19 +01:00
|
|
|
case RAM_DEV_OLD:
|
2008-12-11 18:33:13 +01:00
|
|
|
case IMGRD_DEV:
|
2009-03-19 14:48:19 +01:00
|
|
|
/* Bogus number. */
|
|
|
|
if(m_device < 0 || m_device >= NR_DEVS) {
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
2008-12-11 18:33:13 +01:00
|
|
|
if(!dev_vaddr || dev_vaddr == (vir_bytes) MAP_FAILED) {
|
|
|
|
printf("MEM: dev %d not initialized\n", m_device);
|
|
|
|
return EIO;
|
|
|
|
}
|
2005-04-29 17:36:43 +02:00
|
|
|
if (position >= dv_size) return(OK); /* check for EOF */
|
|
|
|
if (position + count > dv_size) count = dv_size - position;
|
2008-12-11 18:33:13 +01:00
|
|
|
if (opcode == DEV_GATHER_S) { /* copy actual data */
|
2006-06-20 10:56:15 +02:00
|
|
|
r=sys_safecopyto(proc_nr, user_vir, vir_offset,
|
2008-12-11 18:33:13 +01:00
|
|
|
dev_vaddr + position, count, D);
|
2005-04-29 17:36:43 +02:00
|
|
|
} else {
|
2006-06-20 10:56:15 +02:00
|
|
|
r=sys_safecopyfrom(proc_nr, user_vir, vir_offset,
|
2008-12-11 18:33:13 +01:00
|
|
|
dev_vaddr + position, count, D);
|
2006-06-20 10:56:15 +02:00
|
|
|
}
|
|
|
|
if(r != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("I/O copy failed: %d", r);
|
2005-04-29 17:36:43 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-09 17:03:19 +01:00
|
|
|
/* Physical copying. Only used to access entire memory.
|
|
|
|
* Transfer one 'page window' at a time.
|
|
|
|
*/
|
2005-04-29 17:36:43 +02:00
|
|
|
case MEM_DEV:
|
2007-03-09 17:03:19 +01:00
|
|
|
{
|
|
|
|
u32_t pagestart, page_off;
|
|
|
|
static u32_t pagestart_mapped;
|
|
|
|
static int any_mapped = 0;
|
2008-12-11 15:42:23 +01:00
|
|
|
static char *vaddr;
|
2007-03-09 17:03:19 +01:00
|
|
|
int r;
|
|
|
|
u32_t subcount;
|
2008-12-11 18:33:13 +01:00
|
|
|
phys_bytes mem_phys;
|
2007-03-09 17:03:19 +01:00
|
|
|
|
|
|
|
if (position >= dv_size)
|
2007-02-16 16:57:05 +01:00
|
|
|
return(OK); /* check for EOF */
|
2007-03-09 17:03:19 +01:00
|
|
|
if (position + count > dv_size)
|
2007-02-16 16:57:05 +01:00
|
|
|
count = dv_size - position;
|
2008-12-11 18:33:13 +01:00
|
|
|
mem_phys = position;
|
2007-03-09 17:03:19 +01:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
page_off = mem_phys % I386_PAGE_SIZE;
|
2007-03-09 17:03:19 +01:00
|
|
|
pagestart = mem_phys - page_off;
|
|
|
|
|
|
|
|
/* All memory to the map call has to be page-aligned.
|
|
|
|
* Don't have to map same page over and over.
|
|
|
|
*/
|
|
|
|
if(!any_mapped || pagestart_mapped != pagestart) {
|
2008-12-11 15:42:23 +01:00
|
|
|
if(any_mapped) {
|
|
|
|
if(vm_unmap_phys(SELF, vaddr, I386_PAGE_SIZE) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("vm_unmap_phys failed");
|
2008-12-11 15:42:23 +01:00
|
|
|
any_mapped = 0;
|
|
|
|
}
|
|
|
|
vaddr = vm_map_phys(SELF, (void *) pagestart, I386_PAGE_SIZE);
|
|
|
|
if(vaddr == MAP_FAILED)
|
|
|
|
r = ENOMEM;
|
|
|
|
else
|
|
|
|
r = OK;
|
|
|
|
if(r != OK) {
|
|
|
|
printf("memory: vm_map_phys failed\n");
|
2007-03-09 17:03:19 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
any_mapped = 1;
|
|
|
|
pagestart_mapped = pagestart;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how much to be done within this page. */
|
2008-11-19 13:26:10 +01:00
|
|
|
subcount = I386_PAGE_SIZE-page_off;
|
2007-03-09 17:03:19 +01:00
|
|
|
if(subcount > count)
|
|
|
|
subcount = count;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2007-02-07 17:22:19 +01:00
|
|
|
if (opcode == DEV_GATHER_S) { /* copy data */
|
2007-03-09 17:03:19 +01:00
|
|
|
s=sys_safecopyto(proc_nr, user_vir,
|
2008-12-11 15:42:23 +01:00
|
|
|
vir_offset, (vir_bytes) vaddr+page_off, subcount, D);
|
2005-04-21 16:53:53 +02:00
|
|
|
} else {
|
2007-03-09 17:03:19 +01:00
|
|
|
s=sys_safecopyfrom(proc_nr, user_vir,
|
2008-12-11 15:42:23 +01:00
|
|
|
vir_offset, (vir_bytes) vaddr+page_off, subcount, D);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2007-03-09 17:03:19 +01:00
|
|
|
if(s != OK)
|
|
|
|
return s;
|
|
|
|
count = subcount;
|
2005-04-29 17:36:43 +02:00
|
|
|
break;
|
2007-03-09 17:03:19 +01:00
|
|
|
}
|
2005-04-29 17:36:43 +02:00
|
|
|
|
|
|
|
/* Null byte stream generator. */
|
|
|
|
case ZERO_DEV:
|
2007-02-07 17:22:19 +01:00
|
|
|
if (opcode == DEV_GATHER_S) {
|
2006-06-20 10:56:15 +02:00
|
|
|
size_t suboffset = 0;
|
2005-04-29 17:36:43 +02:00
|
|
|
left = count;
|
|
|
|
while (left > 0) {
|
|
|
|
chunk = (left > ZERO_BUF_SIZE) ? ZERO_BUF_SIZE : left;
|
2006-06-20 10:56:15 +02:00
|
|
|
s=sys_safecopyto(proc_nr, user_vir,
|
|
|
|
vir_offset+suboffset, (vir_bytes) dev_zero, chunk, D);
|
|
|
|
if(s != OK)
|
2010-09-09 18:13:02 +02:00
|
|
|
return s;
|
2005-04-29 17:36:43 +02:00
|
|
|
left -= chunk;
|
2006-06-20 10:56:15 +02:00
|
|
|
suboffset += chunk;
|
2005-04-29 17:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Book the number of bytes transferred. */
|
|
|
|
position += count;
|
2006-06-20 10:56:15 +02:00
|
|
|
vir_offset += count;
|
|
|
|
if ((iov->iov_size -= count) == 0) { iov++; nr_req--; vir_offset = 0; }
|
2005-04-29 17:36:43 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-09-11 19:09:11 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* m_do_open *
|
|
|
|
*===========================================================================*/
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE int m_do_open(dp, m_ptr)
|
|
|
|
struct driver *dp;
|
|
|
|
message *m_ptr;
|
|
|
|
{
|
2005-11-04 18:16:54 +01:00
|
|
|
int r;
|
|
|
|
|
2005-10-20 22:26:02 +02:00
|
|
|
/* Check device number on open. */
|
2010-05-10 15:26:00 +02:00
|
|
|
if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
|
2005-11-04 18:16:54 +01:00
|
|
|
if (m_device == MEM_DEV)
|
|
|
|
{
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
r = sys_enable_iop(m_ptr->USER_ENDPT);
|
2005-11-04 18:16:54 +01:00
|
|
|
if (r != OK)
|
|
|
|
{
|
|
|
|
printf("m_do_open: sys_enable_iop failed for %d: %d\n",
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
m_ptr->USER_ENDPT, r);
|
2005-11-04 18:16:54 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:57:21 +02:00
|
|
|
|
|
|
|
if(m_device < 0 || m_device >= NR_DEVS) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("wrong m_device: %d", m_device);
|
2009-09-22 15:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
openct[m_device]++;
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* m_do_close *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int m_do_close(dp, m_ptr)
|
|
|
|
struct driver *dp;
|
|
|
|
message *m_ptr;
|
|
|
|
{
|
2010-05-10 15:26:00 +02:00
|
|
|
if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
|
2009-09-22 15:57:21 +02:00
|
|
|
|
|
|
|
if(m_device < 0 || m_device >= NR_DEVS) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("wrong m_device: %d", m_device);
|
2009-09-22 15:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(openct[m_device] < 1) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("closed too often");
|
2009-09-22 15:57:21 +02:00
|
|
|
}
|
|
|
|
openct[m_device]--;
|
|
|
|
|
2011-02-10 16:39:56 +01:00
|
|
|
/* Special case: free initial ramdisk after it's been unmounted once. */
|
|
|
|
if(m_device == IMGRD_DEV && openct[m_device] == 0 && m_vaddrs[IMGRD_DEV]) {
|
|
|
|
vir_bytes vaddr, vlen;
|
|
|
|
vaddr = m_vaddrs[IMGRD_DEV];
|
|
|
|
vlen = imgrd_size;
|
|
|
|
/* Align `inwards' so as to not unmap more than the initial
|
|
|
|
* ramdisk image.
|
|
|
|
*/
|
|
|
|
if(vaddr % PAGE_SIZE) {
|
|
|
|
vir_bytes o = PAGE_SIZE - (vaddr % PAGE_SIZE);
|
|
|
|
vlen -= o;
|
|
|
|
vaddr += o;
|
|
|
|
}
|
|
|
|
if(vlen % PAGE_SIZE) {
|
|
|
|
vlen -= vlen % PAGE_SIZE;
|
|
|
|
}
|
2011-07-16 03:11:10 +02:00
|
|
|
minix_munmap((void *) vaddr, vlen);
|
2011-02-10 16:39:56 +01:00
|
|
|
m_geom[IMGRD_DEV].dv_base= cvul64(0);
|
|
|
|
m_geom[IMGRD_DEV].dv_size= cvul64(0);
|
|
|
|
m_vaddrs[IMGRD_DEV] = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* m_ioctl *
|
|
|
|
*===========================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PRIVATE int m_ioctl(dp, m_ptr)
|
2005-05-19 11:36:44 +02:00
|
|
|
struct driver *dp; /* pointer to driver structure */
|
|
|
|
message *m_ptr; /* pointer to control message */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-19 11:36:44 +02:00
|
|
|
/* I/O controls for the memory driver. Currently there is one I/O control:
|
|
|
|
* - MIOCRAMSIZE: to set the size of the RAM disk.
|
|
|
|
*/
|
2005-04-21 16:53:53 +02:00
|
|
|
struct device *dv;
|
|
|
|
|
|
|
|
switch (m_ptr->REQUEST) {
|
|
|
|
case MIOCRAMSIZE: {
|
2006-02-15 12:18:21 +01:00
|
|
|
/* Someone wants to create a new RAM disk with the given size. */
|
|
|
|
u32_t ramdev_size;
|
2009-03-19 14:48:19 +01:00
|
|
|
int s, dev;
|
|
|
|
void *mem;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-02-15 12:18:21 +01:00
|
|
|
/* A ramdisk can be created only once, and only on RAM disk device. */
|
2009-03-19 14:48:19 +01:00
|
|
|
dev = m_ptr->DEVICE;
|
|
|
|
if(dev < 0 || dev >= NR_DEVS) {
|
|
|
|
printf("MEM: MIOCRAMSIZE: %d not a valid device\n", dev);
|
|
|
|
}
|
|
|
|
if((dev < RAM_DEV_FIRST || dev > RAM_DEV_LAST) && dev != RAM_DEV_OLD) {
|
|
|
|
printf("MEM: MIOCRAMSIZE: %d not a ramdisk\n", dev);
|
|
|
|
}
|
2010-05-10 15:26:00 +02:00
|
|
|
if ((dv = m_prepare(dev)) == NULL) return(ENXIO);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-02-15 12:18:21 +01:00
|
|
|
/* Get request structure */
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
s= sys_safecopyfrom(m_ptr->m_source, (vir_bytes)m_ptr->IO_GRANT,
|
2006-06-20 10:56:15 +02:00
|
|
|
0, (vir_bytes)&ramdev_size, sizeof(ramdev_size), D);
|
2006-02-15 12:18:21 +01:00
|
|
|
if (s != OK)
|
|
|
|
return s;
|
2009-03-19 14:48:19 +01:00
|
|
|
if(m_vaddrs[dev] && !cmp64(dv->dv_size, cvul64(ramdev_size))) {
|
|
|
|
return(OK);
|
|
|
|
}
|
2009-09-22 15:57:21 +02:00
|
|
|
/* openct is 1 for the ioctl(). */
|
|
|
|
if(openct[dev] != 1) {
|
|
|
|
printf("MEM: MIOCRAMSIZE: %d in use (count %d)\n",
|
|
|
|
dev, openct[dev]);
|
|
|
|
return(EBUSY);
|
|
|
|
}
|
2009-03-19 14:48:19 +01:00
|
|
|
if(m_vaddrs[dev]) {
|
2009-09-22 15:57:21 +02:00
|
|
|
u32_t size;
|
|
|
|
if(ex64hi(dv->dv_size)) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("huge old ramdisk");
|
2009-09-22 15:57:21 +02:00
|
|
|
}
|
|
|
|
size = ex64lo(dv->dv_size);
|
2011-07-16 03:11:10 +02:00
|
|
|
minix_munmap((void *) m_vaddrs[dev], size);
|
2009-09-22 15:57:21 +02:00
|
|
|
m_vaddrs[dev] = (vir_bytes) NULL;
|
2009-03-19 14:48:19 +01:00
|
|
|
}
|
2006-03-13 16:41:07 +01:00
|
|
|
|
|
|
|
#if DEBUG
|
2009-03-19 14:48:19 +01:00
|
|
|
printf("MEM:%d: allocating ramdisk of size 0x%x\n", dev, ramdev_size);
|
2006-03-13 16:41:07 +01:00
|
|
|
#endif
|
2006-02-15 12:18:21 +01:00
|
|
|
|
2005-04-29 17:36:43 +02:00
|
|
|
/* Try to allocate a piece of memory for the RAM disk. */
|
2011-07-16 03:11:10 +02:00
|
|
|
if((mem = minix_mmap(NULL, ramdev_size, PROT_READ|PROT_WRITE,
|
2010-06-28 20:12:32 +02:00
|
|
|
MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) {
|
2008-12-11 18:33:13 +01:00
|
|
|
printf("MEM: failed to get memory for ramdisk\n");
|
2005-06-06 11:30:44 +02:00
|
|
|
return(ENOMEM);
|
2010-06-28 20:12:32 +02:00
|
|
|
}
|
2005-10-20 22:26:02 +02:00
|
|
|
|
2009-03-19 14:48:19 +01:00
|
|
|
m_vaddrs[dev] = (vir_bytes) mem;
|
|
|
|
|
2005-10-20 22:26:02 +02:00
|
|
|
dv->dv_size = cvul64(ramdev_size);
|
2009-03-19 14:48:19 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2009-12-02 10:57:48 +01:00
|
|
|
return(do_diocntl(&m_dtab, m_ptr));
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-09-11 19:09:11 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* m_geometry *
|
|
|
|
*===========================================================================*/
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE void m_geometry(entry)
|
|
|
|
struct partition *entry;
|
|
|
|
{
|
|
|
|
/* Memory devices don't have a geometry, but the outside world insists. */
|
|
|
|
entry->cylinders = div64u(m_geom[m_device].dv_size, SECTOR_SIZE) / (64 * 32);
|
|
|
|
entry->heads = 64;
|
|
|
|
entry->sectors = 32;
|
|
|
|
}
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
|