From 187775b44b26d31a5aee2f716202f3d27b969040 Mon Sep 17 00:00:00 2001 From: Ian McFarlane Date: Tue, 6 May 2025 15:15:06 -0400 Subject: add unfinished forkman game and syscalls --- user/include/unistd.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'user/include') diff --git a/user/include/unistd.h b/user/include/unistd.h index 4f582d2..c54cd20 100644 --- a/user/include/unistd.h +++ b/user/include/unistd.h @@ -15,6 +15,14 @@ /* System Call Definitions */ +// NOTE: needs to match kernel input.h +struct keycode { + char key; + char flags; +}; + +typedef unsigned short pid_t; + enum { S_SET = 0, S_CUR = 1, @@ -184,6 +192,38 @@ extern void *brk(const void *addr); */ extern void *sbrk(intptr_t increment); +/** + * Allocate a number of pages shared with another PID. Does not map the pages + * into the other process's vtable until the other process calls popsharedmem(). + * + * @param num_pages number of pages to allocate + * @param other_pid pid of other process + * @return pointer to the virtual address which will be accessible by both, + * after popsharedmem() is called. + */ +extern void *allocshared(size_t num_pages, int other_pid); + +/** + * Checks if another process has tried to share memory with us, and return it. + * No size information is returned, it is only guaranteed that there is at least + * one page in the shared allocation. To get around this, the sharer can write + * a size number to the start of the first page. + * + * @return page aligned pointer to the start of the shared pages, or NULL if no + * process has tried to share with us, or NULL if we the shared virtual address + * space is already occupied in the caller's pagetable. + */ +extern void *popsharedmem(void); + +/** + * Get the most recent key event, if there is one. + * + * @param poll the keycode to write out to + * @return 0 if there was no key event, in which case `poll` was not changed, or + * 1 if there was an event and the caller should read from `poll`. + */ +extern int keypoll(struct keycode *poll); + /** * Poweroff the system. * -- cgit v1.2.3-freya