PatchworkOS
Loading...
Searching...
No Matches
proc.h
Go to the documentation of this file.
1#ifndef _SYS_PROC_H
2#define _SYS_PROC_H 1
3
4#include <stdatomic.h>
5#include <stdint.h>
6
7#if defined(__cplusplus)
8extern "C"
9{
10#endif
11
12#include "_internal/ERR.h"
13#include "_internal/NULL.h"
14#include "_internal/clock_t.h"
15#include "_internal/config.h"
16#include "_internal/fd_t.h"
17#include "_internal/pid_t.h"
18#include "_internal/tid_t.h"
19
42#define PRIORITY_MAX 64
43#define PRIORITY_MAX_USER 32
44#define PRIORITY_MIN 0
45
54typedef struct
55{
59
75#define SPAWN_NONE 0
76#define SPAWN_INHERIT_PRIORITY (1 << 0)
77
82#define SPAWN_FD_END \
83 (spawn_fd_t) \
84 { \
85 .child = FD_NONE, .parent = FD_NONE \
86 }
87
88typedef struct
89{
92 uint8_t _padding[128 - sizeof(priority_t) - sizeof(spawn_flags_t)];
94
95#ifdef static_assert
96static_assert(sizeof(spawn_attr_t) == 128);
97#endif
98
114pid_t spawn(const char** argv, const spawn_fd_t* fds, const char* cwd, spawn_attr_t* attr);
115
123pid_t getpid(void);
124
132tid_t gettid(void);
133
140#define PAGE_SIZE 0x1000
141
151#define BYTES_TO_PAGES(amount) (((amount) + PAGE_SIZE - 1) / PAGE_SIZE)
152
161#define PAGE_SIZE_OF(object) BYTES_TO_PAGES(sizeof(object))
162
169typedef enum
170{
172 PROT_READ = (1 << 0),
173 PROT_WRITE = (1 << 1)
175
192void* mmap(fd_t fd, void* address, uint64_t length, prot_t prot);
193
203uint64_t munmap(void* address, uint64_t length);
204
217uint64_t mprotect(void* address, uint64_t length, prot_t prot);
218
225typedef enum
226{
229} futex_op_t;
230
238#define FUTEX_ALL UINT64_MAX
239
253uint64_t futex(atomic_uint64_t* addr, uint64_t val, futex_op_t op, clock_t timeout);
254
262clock_t uptime(void);
263
273uint64_t nanosleep(clock_t timeout);
274
283typedef struct
284{
285 atomic_uint64_t value;
286} sync_t;
287
288#if defined(__cplusplus)
289}
290#endif
291
292#endif
293
pid_t spawn(const char **argv, const spawn_fd_t *fds, const char *cwd, spawn_attr_t *attr)
System call for creating child processes.
Definition spawn.c:6
uint64_t spawn_flags_t
Spawn behaviour flags.
Definition proc.h:74
uint64_t mprotect(void *address, uint64_t length, prot_t prot)
System call to change the protection flags of memory.
Definition mprotect.c:6
futex_op_t
Futex operation enum.
Definition proc.h:226
tid_t gettid(void)
System call to retrieve the current tid.
Definition gettid.c:6
void * mmap(fd_t fd, void *address, uint64_t length, prot_t prot)
System call to map memory from a file.
Definition mmap.c:6
uint64_t futex(atomic_uint64_t *addr, uint64_t val, futex_op_t op, clock_t timeout)
System call for fast user space mutual exclusion.
Definition futex.c:6
uint64_t munmap(void *address, uint64_t length)
System call to unmap mapped memory.
Definition munmap.c:6
clock_t uptime(void)
System call for retreving the time since boot.
Definition uptime.c:6
prot_t
Memory protection flags.
Definition proc.h:170
pid_t getpid(void)
System call to retrieve the current pid.
Definition getpid.c:6
uint8_t priority_t
Priority type.
Definition proc.h:41
uint64_t nanosleep(clock_t timeout)
System call for sleeping.
Definition nanosleep.c:6
@ FUTEX_WAKE
The futex operation for waking up a amount of threads specified by the val argument.
Definition proc.h:228
@ FUTEX_WAIT
The futex operating for waiting until the value pointed to by addr is not equal to val.
Definition proc.h:227
@ PROT_READ
Memory can be read from.
Definition proc.h:172
@ PROT_WRITE
Memory can be written to.
Definition proc.h:173
@ PROT_NONE
None.
Definition proc.h:171
__UINT64_TYPE__ tid_t
Thread Identifier.
Definition tid_t.h:12
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
__UINT64_TYPE__ pid_t
Process Identifier.
Definition pid_t.h:11
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static uintptr_t address
Definition hpet.c:12
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
priority_t priority
Definition proc.h:91
spawn_flags_t flags
Definition proc.h:90
Stucture used to duplicate fds in spawn().
Definition proc.h:55
fd_t child
The destination file descriptor in the child.
Definition proc.h:56
fd_t parent
The source file descriptor in the parent.
Definition proc.h:57
Synchronization object.
Definition proc.h:284
atomic_uint64_t value
The value of the sync object.
Definition proc.h:285