kernel: do preparation work for copyless read/write

This commit is contained in:
Matheus
2024-09-18 21:17:37 -03:00
parent 1140244816
commit 611f13b562
12 changed files with 134 additions and 47 deletions
+16 -6
View File
@@ -5,6 +5,7 @@
#include <kernel/devfs.h>
#include <hashtable.h>
#include <kernel/poll.h>
#include <kernel/usercopy.h>
#define BUFFER_PACKET_CAPACITY 100
#define BUFFER_SIZE (BUFFER_PACKET_CAPACITY * sizeof(kbpacket_t))
@@ -165,25 +166,34 @@ static int read(int minor, void *buffer, size_t size, uintmax_t offset, int flag
for (int i = 0; i < count; ++i) {
kbpacket_t *buff = (kbpacket_t *)((uintptr_t)buffer + i * sizeof(kbpacket_t));
bool ok = keyboard_get(kb, buff);
kbpacket_t packet;
bool ok = keyboard_get(kb, &packet);
if (ok == false) {
if (i == 0 && (flags & V_FFLAGS_NONBLOCKING) == 0) {
int err = keyboard_wait(kb, buff);
*readc += err ? 0 : sizeof(kbpacket_t);
return err;
int error = keyboard_wait(kb, &packet);
if (error)
return error;
error = USERCOPY_POSSIBLY_TO_USER(buff, &packet, sizeof(kbpacket_t));
*readc += error ? 0 : sizeof(kbpacket_t);
return error;
}
break;
}
int error = USERCOPY_POSSIBLY_TO_USER(buff, &packet, sizeof(kbpacket_t));
if (error)
return error;
*readc += sizeof(kbpacket_t);
}
return 0;
}
static int poll(int minor, polldata_t *data, int events) {
int revents = 0;
keyboard_t *kb = getkb(minor);