Server ports are points where a server will receive a message. They can receive
a message from any number of client ports.
Client ports are points where a client can send a message. A client port always points
- to a single, specific, server port.
+ to a single server port.
---------------------------
Data types:
-port_t = uint64_t;
+pid_t = int64_t;
+sport_t = int64_t;
+cport_t = int64_t;
+port_t = int64_t; // Either a server port or a client port.
+struct handler {
+ pid_t pid;
+ cport_t port;
+};
---------------------------
The system calls:
Input and output registers in order: %rdi, %rsi, %rdx, %r10, %r8, %r9.
-In %rax, the error code of the operation is stored. If it is non-zero,
- none of the other registers have defined values.
+In %rax, the syscall id is specified.
+If the operation succeeds, %rax contains the result (think SystemV ABI) (≥ 0). If it fails, %rax contains the opposite of the error code. (< 0)
Error codes:
- 0: ERR_NONE: no error
- 1: ERR_MANY_P: too many ports
- 2: ERR_NOT_P: port doesn't exist -- developper error, i.e. a program bug
- 3: ERR_CLOSED_P: port closed
- 4: ERR_WRONG_P: wrong port type -- developper error, i.e. a program bug
- 5: ERR_MEM_NOT_OWNED: send non-owned vaddr -- developper error, i.e. a program bug
- 6: ERR_IN_HANDLER: recv without reply -- developper error, i.e. a program bug
- 6: ERR_NIN_HANDLER: reply without recv -- developper error, i.e. a program bug
-
-mksport: () -> port_t
- Creates a server port, with no associated clients. This absence of
- clients does *not* cause any wait calls to end their wait.
- *Possible errors:* ERR_MANY_P
-mkcport: port_t -> port_t
+ 0: ERR_NONE: no error
+ 0: ERR_USER: server-defined error
+
+sport_t make_sport();
+ Creates a server port, with no associated clients.
+cport_t make_cport(sport_t);
Creates a client port associated with the given server port.
- *Possible errors:* ERR_MANY_P, ERR_NOT_P, ERR_WRONG_P
-cpcport: port_t -> port_t
+cport_t copy_cport(cport_t);
Takes a client port, and returns a new client port that points to the same server port.
- *Possible errors:* ERR_MANY_P, ERR_NOT_P, ERR_WRONG_P
-close: p: port_t -> ()
+
+bool has_cports(sport_t);
+ Takes a server port, and returns the number of clients linked to it.
+void close(port_t);
Close a port. It no longer exists in this process.
If it was a server port, any use of any of its client ports for the purpose
of communication will fail with ERR_CLOSED_P.
If it was a client port,
If it wasn't the server's last client, nothing happens.
- If it was, however, the server will be notified by way of unfreezing
- a wait call (but that's it).
- *Possible errors:* ERR_NOT_P
-call: (port_t, d1: uint64_t, d2: uint64_t, tp: port_t, mem: void*, mem_len: uint64_t)
- -> (d1: uint64_t, d2: uint64_t, tp: port_t, mem: void*, mem_len: uint64_t)
- Takes a client port, and sends data to the corresponding server port.
- d1 and d2 are copied.
- The argument tp must be either 0 or a client port.
- If it is 0, then the value transmitted is simply 0.
- If it is non-0, then it is removed from the current process' namespace
- and added (without necessarily the same id) to the called process. The
- value transmitted will be that new port id.
- If mem_len is 0, there are no restrictions on the value of mem. In that case,
- nothing happens, and then transmitted values are mem = NULL and mem_len = 0.
- If mem_len is greater than 0, then it is required that the pages containing vadresses
- [mem; mem + mem_len[ be all owned by the calling process. They are removed from
- its page mappings, and added to the called process'. The new virtual address is
- transmitted in mem, with the same mem_len.
- *Possible errors:* ERR_NOT_P, ERR_CLOSED_P, ERR_WRONG_P, ERR_MEM_NOT_OWNED
-recv: port_t -> (d1: uint64_t, d2: uint64_t, tp: port_t, mem: void*, mem_len: uint64_t)
- Takes a server port. Blocks until this server port is called, then receives the
- message as described in call.
- *Possible errors:* ERR_NOT_P, ERR_WRONG_P, ERR_IN_HANDLER
-reply: (d1: uint64_t, d2: uint64_t, tp: port_t, mem: void*, mem_len: uint64_t) -> ()
- Sends a message back to the port that the latest recv got its message from,
- as described in call.
- *Possible errors:* ERR_NOT_P, ERR_WRONG_P, ERR_MEM_NOT_OWNED, ERR_NIN_HANDLER
-wait: () -> port_t
- Block until one of the server ports of this process is called or loses its last client.
+ If it was, however, the server will be notified by way of singnalling on the next wait call.
+Program termination implicitly calls close on all the program's ports.
+
+sport_t wait();
+ Block until one of the server ports of this process receives a message or loses its last client.
Returns the server port in question.
- *This syscall cannot fail.*
-hascports: port_t -> bool
- Takes a server port, and returns the number of clients linked to it.
- *Possible errors:* ERR_NOT_P, ERR_WRONG_P
+
+{int64_t out_s, uint64_t user_error_code} call(cport_t p, int64_t in_s, const void* in, cport_t* io_p, int64_t out_s, void* out);
+ Blocks until the server refered to by p replies, or reports an error.
+handler receive(sport_t p);
+ Block until any client sends a message to the port p.
+int64_t receive_size(handler client);
+ Get the size of the message that client is sending.
+cport_t receive_message(handler client, int64_t out_s, void* out);
+ Gets the data of the message that client is sending.
+ If the client is sending a port as well, return it, return 0 otherwise.
+
+void reply(handler caller, int64_t in_s, const void* in, cport_t in_p);
+ Invalidates caller.
+ Replies to the caller with the data of length in_s in `in`.
+ If in_p is non-0, a copy of it is sent as well.
+void forward(cport_t to, handler caller, int64_t sub_begin, int64_t sub_len);
+ Invalidates caller.
+ Transfers message to `to` (reply will go to the original client still).
+ 0 ≤ sub_begin ≤ receive_size(client) and 0 ≤ sub_len ≤ receive_size(client) - sub_begin.
+ The data transferred will only be that in data[sub_begin; sub_begin + sub_len[, ∅ if sub_len == 0.
+void error(handler caller, uint64_t error_code);
+ Invalidates caller.
+ Call gets ERR_USER, with the second value set to error_code.