miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
libc.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2026 Christian Spoo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef _USER_LIBC_H_
24#define _USER_LIBC_H_
25
26typedef unsigned long size_t;
27typedef long ssize_t;
28typedef long pid_t;
29
30/* Syscall wrappers implemented in syscall.asm */
31ssize_t write(int fd, const void *buf, size_t count);
32ssize_t read(int fd, void *buf, size_t count);
33int open(const char *path); /* O_RDONLY, no flags needed for kernel */
34int close(int fd);
35void exit(int code) __attribute__((noreturn));
36pid_t fork(void);
37int exec(const char *path); /* simplified: no argv -- shell passes command name only */
38
39/* wait() wraps _libc_wait because 'wait' is a reserved mnemonic in NASM */
40pid_t _libc_wait(int *status);
41static inline pid_t wait(int *status) { return _libc_wait(status); }
42
43/* waitpid(): wait for specific child pid. Use this instead of wait() to avoid
44 * passing a status pointer where the kernel expects a child TID. */
45pid_t waitpid(pid_t pid, int *status, int options);
46
47#endif /* _USER_LIBC_H_ */
long ssize_t
Definition cc.h:39
int open(const char *path)
void exit(int code) __attribute__((noreturn))
Definition syscalls.c:197
pid_t waitpid(pid_t pid, int *status, int options)
Definition syscalls.c:336
static pid_t wait(int *status)
Definition libc.h:41
int exec(const char *path)
Definition syscalls.c:267
pid_t fork(void)
Definition syscalls.c:263
int close(int fd)
Definition syscalls.c:174
ssize_t write(int fd, const void *buf, size_t count)
Definition syscalls.c:129
ssize_t read(int fd, void *buf, size_t count)
Definition syscalls.c:144
pid_t _libc_wait(int *status)
Definition syscalls.c:349
int fd
Definition syscall_fs.c:0
uint64_t size_t
Definition types.h:40
int32_t pid_t
Definition types.h:43
typedef __attribute__