minix/servers/vm/fork.c
David van Moolenbroek 6b3f4dc157 Input infrastructure, INPUT server, PCKBD driver
This commit separates the low-level keyboard driver from TTY, putting
it in a separate driver (PCKBD). The commit also separates management
of raw input devices from TTY, and puts it in a separate server
(INPUT). All keyboard and mouse input from hardware is sent by drivers
to the INPUT server, which either sends it to a process that has
opened a raw input device, or otherwise forwards it to TTY for
standard processing.

Design by Dirk Vogt. Prototype by Uli Kastlunger.

Additional changes made to the prototype:

- the event communication is now based on USB HID codes; all input
  drivers have to use USB codes to describe events;
- all TTY keymaps have been converted to USB format, with the effect
  that a single keymap covers all keys; there is no (static) escaped
  keymap anymore;
- further keymap tweaks now allow remapping of literally all keys;
- input device renumbering and protocol rewrite;
- INPUT server rewrite, with added support for cancel and select;
- PCKBD reimplementation, including PC/AT-to-USB translation;
- support for manipulating keyboard LEDs has been added;
- keyboard and mouse multiplexer devices have been added to INPUT,
  primarily so that an X server need only open two devices;
- a new "libinputdriver" library abstracts away protocol details from
  input drivers, and should be used by all future input drivers;
- both INPUT and PCKBD can be restarted;
- TTY is now scheduled by KERNEL, so that it won't be punished for
  running a lot; without this, simply running "yes" on the console
  kills the system;
- the KIOCBELL IOCTL has been moved to /dev/console;
- support for the SCANCODES termios setting has been removed;
- obsolete keymap compression has been removed;
- the obsolete Olivetti M24 keymap has been removed.

Change-Id: I3a672fb8c4fd566734e4b46d3994b4b7fc96d578
2014-03-01 09:04:55 +01:00

117 lines
2.7 KiB
C

#define _SYSTEM 1
#include <minix/callnr.h>
#include <minix/com.h>
#include <minix/config.h>
#include <minix/const.h>
#include <minix/ds.h>
#include <minix/endpoint.h>
#include <minix/minlib.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/sysutil.h>
#include <minix/syslib.h>
#include <minix/debug.h>
#include <minix/bitmap.h>
#include <string.h>
#include <errno.h>
#include <env.h>
#include <assert.h>
#include "glo.h"
#include "vm.h"
#include "proto.h"
#include "util.h"
#include "sanitycheck.h"
#include "region.h"
/*===========================================================================*
* do_fork *
*===========================================================================*/
int do_fork(message *msg)
{
int r, proc, childproc;
struct vmproc *vmp, *vmc;
pt_t origpt;
vir_bytes msgaddr;
SANITYCHECK(SCL_FUNCTIONS);
if(vm_isokendpt(msg->VMF_ENDPOINT, &proc) != OK) {
printf("VM: bogus endpoint VM_FORK %d\n", msg->VMF_ENDPOINT);
SANITYCHECK(SCL_FUNCTIONS);
return EINVAL;
}
childproc = msg->VMF_SLOTNO;
if(childproc < 0 || childproc >= NR_PROCS) {
printf("VM: bogus slotno VM_FORK %d\n", msg->VMF_SLOTNO);
SANITYCHECK(SCL_FUNCTIONS);
return EINVAL;
}
vmp = &vmproc[proc]; /* parent */
vmc = &vmproc[childproc]; /* child */
assert(vmc->vm_slot == childproc);
/* The child is basically a copy of the parent. */
origpt = vmc->vm_pt;
*vmc = *vmp;
vmc->vm_slot = childproc;
region_init(&vmc->vm_regions_avl);
vmc->vm_endpoint = NONE; /* In case someone tries to use it. */
vmc->vm_pt = origpt;
#if VMSTATS
vmc->vm_bytecopies = 0;
#endif
if(pt_new(&vmc->vm_pt) != OK) {
return ENOMEM;
}
SANITYCHECK(SCL_DETAIL);
if(map_proc_copy(vmc, vmp) != OK) {
printf("VM: fork: map_proc_copy failed\n");
pt_free(&vmc->vm_pt);
return(ENOMEM);
}
/* Only inherit these flags. */
vmc->vm_flags &= VMF_INUSE;
/* Deal with ACLs. */
acl_fork(vmc);
/* Tell kernel about the (now successful) FORK. */
if((r=sys_fork(vmp->vm_endpoint, childproc,
&vmc->vm_endpoint, PFF_VMINHIBIT, &msgaddr)) != OK) {
panic("do_fork can't sys_fork: %d", r);
}
if((r=pt_bind(&vmc->vm_pt, vmc)) != OK)
panic("fork can't pt_bind: %d", r);
{
vir_bytes vir;
/* making these messages writable is an optimisation
* and its return value needn't be checked.
*/
vir = msgaddr;
if (handle_memory(vmc, vir, sizeof(message), 1, NULL, 0, 0) != OK)
panic("do_fork: handle_memory for child failed\n");
vir = msgaddr;
if (handle_memory(vmp, vir, sizeof(message), 1, NULL, 0, 0) != OK)
panic("do_fork: handle_memory for parent failed\n");
}
/* Inform caller of new child endpoint. */
msg->VMF_CHILD_ENDPOINT = vmc->vm_endpoint;
SANITYCHECK(SCL_FUNCTIONS);
return OK;
}