PatchworkOS
Loading...
Searching...
No Matches
Notes

Signal style inter-process communication. More...

Data Structures

struct  note_t
 Note structure. More...
 
struct  note_queue_t
 Per-thread note queue. More...
 

Macros

#define NOTE_MAX_BUFFER   64
 Maximum size of a notes buffer.
 

Enumerations

enum  note_queue_flag_t {
  NOTE_QUEUE_NONE = 0 ,
  NOTE_QUEUE_RECIEVED_KILL = 1 << 0
}
 Note queue flags. More...
 

Functions

void note_queue_init (note_queue_t *queue)
 Initialize a note queue.
 
uint64_t note_queue_length (note_queue_t *queue)
 Get the length of a note queue.
 
uint64_t note_queue_write (note_queue_t *queue, const void *buffer, uint64_t count)
 Write a note to a note queue.
 
void note_interrupt_handler (interrupt_frame_t *frame, cpu_t *self)
 Note interrupt handler.
 

Detailed Description

Signal style inter-process communication.

Notes are exposed in the /proc/[pid]/note file. Notes are used for inter-process communication (IPC) in a way similar to signals in Unix-like operating systems. However, they allow for a buffer of data to be sent instead of just an integer. In theory anything could be sent as a note.

Using Notes

Notes are sent by writing to the /proc/[pid]/note file of the target process. The data written to the file is sent as a note to one of the threads in the target process.

Receiving Notes

TODO: Receiving notes, software interrupts, etc.

Special Notes

Certain notes will cause the kernel to take special actions and, for the sake of concistency, we define some notes that all user processes should handle in a standard way. The values for these notes are intended to mirror UNIX signals where applicable. Below is a list of all of these special notes:

Macro Definition Documentation

◆ NOTE_MAX_BUFFER

#define NOTE_MAX_BUFFER   64

Maximum size of a notes buffer.

Definition at line 46 of file note.h.

Enumeration Type Documentation

◆ note_queue_flag_t

Note queue flags.

Enumerator
NOTE_QUEUE_NONE 
NOTE_QUEUE_RECIEVED_KILL 

Its vital that a kill note gets handled, even if we run out of memory. Since these notes have a predefined value and we dont care if they get sent multiple times, we can simplify the system such that when the note queue recieves a kill note instead of pushing it to the queue we just set the corresponding flag.

The thread will never know the difference.

Definition at line 52 of file note.h.

Function Documentation

◆ note_interrupt_handler()

void note_interrupt_handler ( interrupt_frame_t frame,
cpu_t self 
)

◆ note_queue_init()

void note_queue_init ( note_queue_t queue)

Initialize a note queue.

Parameters
queueThe queue to initialize.

Definition at line 22 of file note.c.

References note_queue_t::flags, note_queue_t::length, note_queue_t::lock, lock_init(), NOTE_QUEUE_NONE, note_queue_t::readIndex, and note_queue_t::writeIndex.

Referenced by thread_init().

◆ note_queue_length()

uint64_t note_queue_length ( note_queue_t queue)

Get the length of a note queue.

Parameters
queueThe queue to query.
Returns
The length of the queue.

Definition at line 31 of file note.c.

References note_queue_t::flags, note_queue_t::length, note_queue_t::lock, LOCK_SCOPE, and NOTE_QUEUE_RECIEVED_KILL.

Referenced by syscall_handler(), and thread_is_note_pending().

◆ note_queue_write()

uint64_t note_queue_write ( note_queue_t queue,
const void *  buffer,
uint64_t  count 
)

Write a note to a note queue.

Parameters
queueThe destination queue.
bufferThe buffer to write.
countThe number of bytes to write.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 37 of file note.c.

References assert, note_t::buffer, buffer, CONFIG_MAX_NOTES, count, EINVAL, ERR, errno, note_queue_t::flags, process_t::id, note_t::length, note_queue_t::length, note_queue_t::lock, LOCK_SCOPE, memcpy(), NOTE_MAX_BUFFER, note_queue_compare_buffers(), NOTE_QUEUE_RECIEVED_KILL, note_queue_t::notes, NULL, note_queue_t::readIndex, sched_process(), note_t::sender, and note_queue_t::writeIndex.

Referenced by thread_send_note().