pex: maybe finally fix this

This commit is contained in:
K. Lange 2021-06-02 18:35:50 +09:00
parent e22d6d84a4
commit 3a69b8b5d7
2 changed files with 19 additions and 7 deletions

View File

@ -22,6 +22,7 @@
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
#include <kernel/assert.h>
#include <kernel/types.h>
#include <kernel/printf.h>
#include <kernel/string.h>
@ -67,7 +68,12 @@ typedef struct server_write_header {
} header_t;
static void receive_packet(pex_ex_t * exchange, fs_node_t * socket, packet_t ** out) {
read_fs(socket, 0, sizeof(struct packet *), (uint8_t*)out);
int r;
do {
r = read_fs(socket, 0, sizeof(struct packet *), (uint8_t*)out);
} while (r == 0);
assert(r == sizeof(struct packet*));
assert((uintptr_t)*out >= 0xFFFFff0000000000UL && (uintptr_t)*out < 0xffffff1fc0000000UL);
}
static void send_to_server(pex_ex_t * p, pex_client_t * c, size_t size, void * data) {
@ -121,10 +127,12 @@ static uint64_t read_server(fs_node_t * node, uint64_t offset, uint64_t size, ui
pex_ex_t * p = (pex_ex_t *)node->device;
debug_print(INFO, "[pex] server read(...)");
packet_t * packet;
packet_t * packet = NULL;
receive_packet(p, p->server_pipe, &packet);
if (!packet) return -1;
debug_print(INFO, "Server recevied packet of size %zu, was waiting for at most %lu", packet->size, size);
if (packet->size + sizeof(packet_t) > size) {
@ -188,10 +196,12 @@ static uint64_t read_client(fs_node_t * node, uint64_t offset, uint64_t size, ui
debug_print(INFO, "[pex] client read(...)");
packet_t * packet;
packet_t * packet = NULL;
receive_packet(c->parent, c->pipe, &packet);
if (!packet) return -1;
if (packet->size > size) {
printf("pex: Client is not reading enough bytes to hold packet of size %zu\n", packet->size);
return -1;

View File

@ -120,11 +120,13 @@ uint64_t read_pipe(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buf
size_t collected = 0;
while (collected == 0) {
spin_lock(pipe->lock_read);
if (pipe_unread(pipe) >= size) {
while (pipe_unread(pipe) > 0 && collected < size) {
buffer[collected] = pipe->buffer[pipe->read_ptr];
pipe_increment_read(pipe);
collected++;
}
}
spin_unlock(pipe->lock_read);
wakeup_queue(pipe->wait_queue_writers);
/* Deschedule and switch */