Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/consport.c
Show All 26 Lines | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/select.h> | #include <sys/select.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <capsicum_helpers.h> | #include <capsicum_helpers.h> | ||||
#endif | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <termios.h> | #include <termios.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | ttywrite(unsigned char wb) | ||||
(void) write(STDOUT_FILENO, &wb, 1); | (void) write(STDOUT_FILENO, &wb, 1); | ||||
} | } | ||||
static int | static int | ||||
console_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, | console_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, | ||||
uint32_t *eax, void *arg) | uint32_t *eax, void *arg) | ||||
{ | { | ||||
static int opened; | static int opened; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | cap_rights_t rights; | ||||
cap_ioctl_t cmds[] = { TIOCGETA, TIOCSETA, TIOCGWINSZ }; | cap_ioctl_t cmds[] = { TIOCGETA, TIOCSETA, TIOCGWINSZ }; | ||||
#endif | |||||
if (bytes == 2 && in) { | if (bytes == 2 && in) { | ||||
*eax = BVM_CONS_SIG; | *eax = BVM_CONS_SIG; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Guests might probe this port to look for old ISA devices | * Guests might probe this port to look for old ISA devices | ||||
* using single-byte reads. Return 0xff for those. | * using single-byte reads. Return 0xff for those. | ||||
*/ | */ | ||||
if (bytes == 1 && in) { | if (bytes == 1 && in) { | ||||
*eax = 0xff; | *eax = 0xff; | ||||
return (0); | return (0); | ||||
} | } | ||||
if (bytes != 4) | if (bytes != 4) | ||||
return (-1); | return (-1); | ||||
if (!opened) { | if (!opened) { | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ, | cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ, | ||||
CAP_WRITE); | CAP_WRITE); | ||||
if (caph_rights_limit(STDIN_FILENO, &rights) == -1) | if (caph_rights_limit(STDIN_FILENO, &rights) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
if (caph_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1) | if (caph_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
#endif | |||||
ttyopen(); | ttyopen(); | ||||
opened = 1; | opened = 1; | ||||
} | } | ||||
if (in) | if (in) | ||||
*eax = ttyread(); | *eax = ttyread(); | ||||
else | else | ||||
ttywrite(*eax); | ttywrite(*eax); | ||||
Show All 20 Lines |