68 lines
2.2 KiB
C
68 lines
2.2 KiB
C
/* Calcite, src/kernel/ipc-dgram.h
|
|
* Copyright 2025-2026 Benji Dial
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "scheduler.h"
|
|
|
|
#include <kernel-public/ipc.h>
|
|
|
|
//must be a multiple of 4
|
|
#define IPC_DGRAM_BOX_BUFFER_LENGTH 1024
|
|
|
|
struct ipc_dgram_box {
|
|
|
|
int is_receiver_held;
|
|
int is_private;
|
|
int private_sides;
|
|
|
|
int is_someone_waiting_to_receive;
|
|
struct continuation_info waiting_to_receive;
|
|
|
|
struct continuation_queue waiting_to_send;
|
|
|
|
int buffer_read_pointer;
|
|
int buffer_read_available;
|
|
|
|
//packets are of the form:
|
|
// int size;
|
|
// uint8_t packet[size];
|
|
// uint8_t padding[size % 4 == 0 ? 0 : 4 - size % 4];
|
|
uint8_t buffer[IPC_DGRAM_BOX_BUFFER_LENGTH];
|
|
|
|
};
|
|
|
|
struct ipc_dgram_box *get_ipc_dgram_box(const char *address);
|
|
|
|
//waits until a packet is available, then returns the size of that packet.
|
|
//returns -1 if someone is already waiting.
|
|
int get_ipc_dgram_size(struct ipc_dgram_box *box);
|
|
|
|
//should only be called just after get_ipc_dgram_size
|
|
//(i.e. with no intervening continuation resumptions)
|
|
void receive_ipc_dgram(struct ipc_dgram_box *box, void *buffer);
|
|
|
|
//only returns IPR_SUCCESS or IPR_TOO_BIG
|
|
enum ipc_dgram_result send_ipc_dgram(struct ipc_dgram_box *box, const void *data, int bytes);
|
|
|
|
uint64_t syscall_ipc_create_private_dgram_pipe();
|
|
enum ipc_dgram_result syscall_ipc_create_private_dgram_receiver(
|
|
uint64_t id, ipc_dgram_receiver_handle_t *handle_out);
|
|
enum ipc_dgram_result syscall_ipc_create_private_dgram_sender(
|
|
uint64_t id, ipc_dgram_sender_handle_t *handle_out);
|
|
|
|
void destroy_ipc_dgram_box(struct ipc_dgram_box *box);
|