tty: remove tty event queues
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#define TTY_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? (dev)->chr.c_tty : NULL)
|
#define TTY_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? (dev)->chr.c_tty : NULL)
|
||||||
#define TTY_DRIVER(drv) ((struct tty_driver *)((char *)drv - offsetof(struct tty_driver, tty_base)))
|
#define TTY_DRIVER(drv) ((struct tty_driver *)((char *)drv - offsetof(struct tty_driver, tty_base)))
|
||||||
|
|
||||||
#define TTY_EVENT_QUEUE_SIZE 4
|
|
||||||
#define TTY_INPUT_QUEUE_SIZE 256
|
#define TTY_INPUT_QUEUE_SIZE 256
|
||||||
|
|
||||||
struct kext;
|
struct kext;
|
||||||
@@ -93,7 +92,7 @@ struct tty_driver {
|
|||||||
|
|
||||||
struct tty_ldisc {
|
struct tty_ldisc {
|
||||||
char name[OBJECT_NAME_MAX];
|
char name[OBJECT_NAME_MAX];
|
||||||
void(*process_events)(struct device *);
|
void(*write)(struct device *, const struct input_event *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tty_device {
|
struct tty_device {
|
||||||
@@ -106,8 +105,6 @@ struct tty_device {
|
|||||||
|
|
||||||
struct tty_ldisc *tty_ldisc;
|
struct tty_ldisc *tty_ldisc;
|
||||||
|
|
||||||
/* raw input events sent to the TTY */
|
|
||||||
struct ringbuffer tty_events;
|
|
||||||
/* input characters processed from tty_events, returned by tty_read() */
|
/* input characters processed from tty_events, returned by tty_read() */
|
||||||
struct ringbuffer tty_input;
|
struct ringbuffer tty_input;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,21 +55,13 @@ struct device *tty_device_create(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
kern_status_t status = ringbuffer_init(&tty_dev->tty_events, TTY_EVENT_QUEUE_SIZE * sizeof(struct input_event));
|
kern_status_t status = ringbuffer_init(&tty_dev->tty_input, TTY_INPUT_QUEUE_SIZE * sizeof(char));
|
||||||
if (status != KERN_OK) {
|
if (status != KERN_OK) {
|
||||||
kfree(tty_dev);
|
kfree(tty_dev);
|
||||||
object_deref(char_device_object(cdev));
|
object_deref(char_device_object(cdev));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ringbuffer_init(&tty_dev->tty_input, TTY_INPUT_QUEUE_SIZE * sizeof(char));
|
|
||||||
if (status != KERN_OK) {
|
|
||||||
ringbuffer_deinit(&tty_dev->tty_events);
|
|
||||||
kfree(tty_dev);
|
|
||||||
object_deref(char_device_object(cdev));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tty_dev->tty_ldisc = tty_default_line_discipline();
|
tty_dev->tty_ldisc = tty_default_line_discipline();
|
||||||
|
|
||||||
cdev->c_ops = &tty_ops;
|
cdev->c_ops = &tty_ops;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <socks/input.h>
|
#include <socks/input.h>
|
||||||
#include <socks/libc/ctype.h>
|
#include <socks/libc/ctype.h>
|
||||||
|
|
||||||
static void process_events(struct device *tty);
|
static void default_ldisc_write(struct device *, const struct input_event *);
|
||||||
|
|
||||||
static char keycode_chars[] = {
|
static char keycode_chars[] = {
|
||||||
[KEY_UNKNOWN] = ' ',
|
[KEY_UNKNOWN] = ' ',
|
||||||
@@ -234,10 +234,10 @@ static char keycode_chars_shift[] = {
|
|||||||
|
|
||||||
static struct tty_ldisc default_ldisc = {
|
static struct tty_ldisc default_ldisc = {
|
||||||
.name = "n_tty",
|
.name = "n_tty",
|
||||||
.process_events = process_events,
|
.write = default_ldisc_write,
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum tty_modifier_key get_modifier_key(struct input_event *ev)
|
static enum tty_modifier_key get_modifier_key(const struct input_event *ev)
|
||||||
{
|
{
|
||||||
switch (ev->ev_key.key) {
|
switch (ev->ev_key.key) {
|
||||||
case KEY_LEFT_CTRL:
|
case KEY_LEFT_CTRL:
|
||||||
@@ -254,7 +254,7 @@ static enum tty_modifier_key get_modifier_key(struct input_event *ev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modkey, struct input_event *ev)
|
static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modkey, const struct input_event *ev)
|
||||||
{
|
{
|
||||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convert_ev_to_chars(struct device *tty, struct input_event *ev)
|
static void convert_ev_to_chars(struct device *tty, const struct input_event *ev)
|
||||||
{
|
{
|
||||||
if (ev->ev_key.state == INPUT_KEYSTATE_UP) {
|
if (ev->ev_key.state == INPUT_KEYSTATE_UP) {
|
||||||
return;
|
return;
|
||||||
@@ -311,25 +311,14 @@ static void convert_ev_to_chars(struct device *tty, struct input_event *ev)
|
|||||||
tty_write(tty, echo, echo_len, &nr_written, S_NOBLOCK);
|
tty_write(tty, echo, echo_len, &nr_written, S_NOBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_events(struct device *tty)
|
static void default_ldisc_write(struct device *tty, const struct input_event *ev)
|
||||||
{
|
{
|
||||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
enum tty_modifier_key modkeys = get_modifier_key(ev);
|
||||||
struct ringbuffer *events = &ttydev->tty_events;
|
|
||||||
|
|
||||||
struct input_event ev;
|
|
||||||
|
|
||||||
size_t w = ringbuffer_read(events, sizeof ev, &ev, S_NOBLOCK);
|
|
||||||
|
|
||||||
if (w != sizeof ev || ev.ev_type != INPUT_TYPE_KEY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum tty_modifier_key modkeys = get_modifier_key(&ev);
|
|
||||||
|
|
||||||
if (modkeys != TTY_KEY_OTHER) {
|
if (modkeys != TTY_KEY_OTHER) {
|
||||||
handle_modifier_keys(tty, modkeys, &ev);
|
handle_modifier_keys(tty, modkeys, ev);
|
||||||
} else {
|
} else {
|
||||||
convert_ev_to_chars(tty, &ev);
|
convert_ev_to_chars(tty, ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,34 +92,12 @@ kern_status_t tty_write(struct device *tty, const void *buf, size_t len, size_t
|
|||||||
return KERN_OK;
|
return KERN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_events(struct device *tty)
|
|
||||||
{
|
|
||||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
|
||||||
|
|
||||||
if (!ttydev->tty_ldisc || !ttydev->tty_ldisc->process_events) {
|
|
||||||
struct input_event ev;
|
|
||||||
while (ringbuffer_unread(&ttydev->tty_events)) {
|
|
||||||
ringbuffer_read(&ttydev->tty_events, sizeof ev, &ev, S_NOBLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ttydev->tty_ldisc->process_events(tty);
|
|
||||||
}
|
|
||||||
|
|
||||||
kern_status_t tty_report_event(struct device *tty, const struct input_event *ev)
|
kern_status_t tty_report_event(struct device *tty, const struct input_event *ev)
|
||||||
{
|
{
|
||||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||||
size_t w = ringbuffer_write(&ttydev->tty_events, sizeof *ev, ev, S_NOBLOCK);
|
|
||||||
|
|
||||||
if (w != sizeof *ev) {
|
|
||||||
return KERN_WOULD_BLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ringbuffer_unread(&ttydev->tty_events) > 0) {
|
|
||||||
process_events(tty);
|
|
||||||
|
|
||||||
|
if (ttydev->tty_ldisc || ttydev->tty_ldisc->write) {
|
||||||
|
ttydev->tty_ldisc->write(tty, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return KERN_OK;
|
return KERN_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user