Skip to content

Commit 7bb46d6

Browse files
committed
upd: BusyBox, lot more of syscalls; fix: existing syscall corrections in ret vals, etc. for BusyBox.
1 parent 229550a commit 7bb46d6

2,505 files changed

Lines changed: 346404 additions & 149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The project focuses on clean design, correctness, and real hardware interaction.
7171
- **Compilers**[TinyCC](https://github.com/TinyCC/tinycc), [SmallerC](https://github.com/alexfru/SmallerC)
7272
- **Scripting**[Lua 5.5.0](https://www.lua.org/)
7373
- **Networking** — wget, zen package manager
74-
- **Misc** — hello, init
74+
- **Misc** — hello, init, busybox
7575

7676

7777
**The `ZenOS.vhd` in the repository usually already has these compiled and ready.**
@@ -142,6 +142,12 @@ socat
142142

143143
---
144144

145+
## License
146+
147+
- **ZenOS** is released under the terms of the **MIT License** : Read **[LICENSE](https://github.com/Z-Proj/ZenOS/blob/main/LICENSE)** for the full document.
148+
149+
---
150+
145151
## Showcase (may be outdated)
146152

147153
<table>

ZenOS.vhd

0 Bytes
Binary file not shown.

docs/CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
- [TinyCC](https://github.com/TinyCC/tinycc) — Tiny C Compiler
2929
- [SmallerC](https://github.com/alexfru/SmallerC) — C to assembly compiler
3030
- [FIGlet](https://github.com/cmatsuoka/figlet) — Large ASCII text renderer
31+
- [BusyBox](https://busybox.net/) — The Swiss Army Knife of Embedded Linux
3132
- [DOOM](https://github.com/id-Software/DOOM), and the [generic platform layer](https://github.com/ozkl/doomgeneric) — 3D FPS action game.

docs/TODO.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
## What I have planned next for Zen:
22

3-
> Porting Pixman... or even better, Blend2D to Zen
4-
5-
> Rewriting the Harp compositor to use that backend library
6-
7-
> Making harp more stable and correct, then:
8-
9-
> Porting a simple UI library to Zen: Nuklear is what I have planned, other choices that rarely I might try are MicroUI, Slint, LVGL, but probably not.
3+
> Getting more BusyBox applets.

docs/shots/log.png

-145 KB
Binary file not shown.

docs/shots/qemu.png

-190 KB
Binary file not shown.

mlibc/options/posix/include/sched.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _SCHED_H
44

55
#include <abi-bits/pid_t.h>
6+
#include <bits/cpu_set.h>
67
#include <bits/threads.h>
78
#include <bits/size_t.h>
89
#include <mlibc-config.h>
@@ -40,11 +41,13 @@ int sched_setscheduler(pid_t __pid, int __policy, const struct sched_param *__pa
4041
int sched_getparam(pid_t __pid, struct sched_param *__param);
4142
int sched_setparam(pid_t __pid, const struct sched_param *__param);
4243

44+
int sched_setaffinity(pid_t __pid, size_t __cpusetsize, const cpu_set_t *__mask);
45+
int sched_getaffinity(pid_t __pid, size_t __cpusetsize, cpu_set_t *__mask);
46+
4347
#endif /* !__MLIBC_ABI_ONLY */
4448

4549
#ifdef __cplusplus
4650
}
4751
#endif
4852

4953
#endif /* _SCHED_H */
50-

mlibc/sysdeps/zenos/generic/generic.cpp

Lines changed: 147 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <fcntl.h>
66
#include <limits.h>
77
#include <poll.h>
8+
#include <sched.h>
89
#include <stddef.h>
910
#include <stdint.h>
1011
#include <string.h>
@@ -13,6 +14,8 @@
1314
#include <sys/select.h>
1415
#include <sys/socket.h>
1516
#include <sys/stat.h>
17+
#include <sys/statvfs.h>
18+
#include <sys/sysinfo.h>
1619
#include <sys/uio.h>
1720
#include <sys/utsname.h>
1821
#include <termios.h>
@@ -67,6 +70,21 @@ static void translate_stat(const zenos_stat &in, struct stat *out) {
6770
out->st_ctim.tv_sec = in.ctime_sec;
6871
}
6972

73+
static void translate_statvfs(const zenos_statfs &in, struct statvfs *out) {
74+
memset(out, 0, sizeof(*out));
75+
out->f_bsize = in.f_bsize;
76+
out->f_frsize = in.f_frsize ? in.f_frsize : in.f_bsize;
77+
out->f_blocks = in.f_blocks;
78+
out->f_bfree = in.f_bfree;
79+
out->f_bavail = in.f_bavail;
80+
out->f_files = in.f_files;
81+
out->f_ffree = in.f_ffree;
82+
out->f_favail = in.f_ffree;
83+
out->f_fsid = in.f_fsid;
84+
out->f_flag = in.f_flags;
85+
out->f_namemax = in.f_namelen;
86+
}
87+
7088
static int compute_argc(char *const argv[]) {
7189
if(!argv)
7290
return 0;
@@ -362,9 +380,31 @@ int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat
362380
return 0;
363381
}
364382

383+
int sys_statvfs(const char *path, struct statvfs *out) {
384+
zenos_statfs zst{};
385+
long ret = zenos_do_syscall2(ZENOS_SYSCALL_STATFS,
386+
reinterpret_cast<long>(path), reinterpret_cast<long>(&zst));
387+
int e = sc_error(ret);
388+
if(e)
389+
return e;
390+
translate_statvfs(zst, out);
391+
return 0;
392+
}
393+
394+
int sys_fstatvfs(int fd, struct statvfs *out) {
395+
zenos_statfs zst{};
396+
long ret = zenos_do_syscall2(ZENOS_SYSCALL_FSTATFS,
397+
fd, reinterpret_cast<long>(&zst));
398+
int e = sc_error(ret);
399+
if(e)
400+
return e;
401+
translate_statvfs(zst, out);
402+
return 0;
403+
}
404+
365405
int sys_dup(int fd, int flags, int *newfd) {
366406
(void)flags;
367-
return finish_fd(zenos_do_syscall1(ZENOS_SYSCALL_DUP, fd), newfd);
407+
return finish_fd(zenos_do_syscall2(ZENOS_SYSCALL_DUP, fd, 0), newfd);
368408
}
369409

370410
int sys_dup2(int fd, int flags, int newfd) {
@@ -392,20 +432,22 @@ int sys_fcntl(int fd, int request, va_list args, int *result) {
392432
case F_DUPFD:
393433
case F_DUPFD_CLOEXEC: {
394434
int minfd = va_arg(args, int);
395-
if(minfd > 0)
396-
return ENOSYS;
397-
int newfd;
398-
int e = sys_dup(fd, 0, &newfd);
399-
if(e)
400-
return e;
401-
*result = newfd;
402-
return 0;
435+
return finish_fd(zenos_do_syscall2(ZENOS_SYSCALL_DUP, fd, minfd), result);
403436
}
404437
default:
405438
return ENOSYS;
406439
}
407440
}
408441

442+
int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events) {
443+
long ret = zenos_do_syscall3(ZENOS_SYSCALL_POLL,
444+
reinterpret_cast<long>(fds), count, timeout);
445+
if(int e = sc_error(ret))
446+
return e;
447+
*num_events = static_cast<int>(ret);
448+
return 0;
449+
}
450+
409451
int sys_readv(int fd, const struct iovec *iovs, int iovc, ssize_t *bytes_read) {
410452
ssize_t total = 0;
411453
for(int i = 0; i < iovc; i++) {
@@ -598,6 +640,73 @@ pid_t sys_getpid() {
598640
return zenos_do_syscall0(ZENOS_SYSCALL_GETPID);
599641
}
600642

643+
pid_t sys_getppid() {
644+
return zenos_do_syscall0(ZENOS_SYSCALL_GETPPID);
645+
}
646+
647+
int sys_getpgid(pid_t pid, pid_t *pgid) {
648+
*pgid = pid ? pid : sys_getpid();
649+
return 0;
650+
}
651+
652+
int sys_getsid(pid_t pid, pid_t *sid) {
653+
*sid = pid ? pid : sys_getpid();
654+
return 0;
655+
}
656+
657+
int sys_setpgid(pid_t pid, pid_t pgid) {
658+
(void)pid;
659+
(void)pgid;
660+
return 0;
661+
}
662+
663+
uid_t sys_getuid() {
664+
return zenos_do_syscall0(ZENOS_SYSCALL_GETUID);
665+
}
666+
667+
gid_t sys_getgid() {
668+
return zenos_do_syscall0(ZENOS_SYSCALL_GETGID);
669+
}
670+
671+
uid_t sys_geteuid() {
672+
return zenos_do_syscall0(ZENOS_SYSCALL_GETEUID);
673+
}
674+
675+
gid_t sys_getegid() {
676+
return zenos_do_syscall0(ZENOS_SYSCALL_GETEGID);
677+
}
678+
679+
int sys_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask) {
680+
long ret = zenos_do_syscall3(ZENOS_SYSCALL_SCHED_GETAFFINITY,
681+
pid, cpusetsize, reinterpret_cast<long>(mask));
682+
return sc_error(ret);
683+
}
684+
685+
int sys_sysinfo(struct sysinfo *info) {
686+
zenos_sysinfo zi{};
687+
long ret = zenos_do_syscall1(ZENOS_SYSCALL_SYSINFO, reinterpret_cast<long>(&zi));
688+
int e = sc_error(ret);
689+
if(e)
690+
return e;
691+
692+
memset(info, 0, sizeof(*info));
693+
info->uptime = zi.uptime;
694+
info->loads[0] = zi.loads[0];
695+
info->loads[1] = zi.loads[1];
696+
info->loads[2] = zi.loads[2];
697+
info->totalram = zi.totalram;
698+
info->freeram = zi.freeram;
699+
info->sharedram = zi.sharedram;
700+
info->bufferram = zi.bufferram;
701+
info->totalswap = zi.totalswap;
702+
info->freeswap = zi.freeswap;
703+
info->procs = zi.procs;
704+
info->totalhigh = zi.totalhigh;
705+
info->freehigh = zi.freehigh;
706+
info->mem_unit = zi.mem_unit;
707+
return 0;
708+
}
709+
601710
int sys_kill(int pid, int signal) {
602711
long ret = zenos_do_syscall2(ZENOS_SYSCALL_KILL, pid, signal);
603712
return sc_error(ret);
@@ -641,6 +750,35 @@ int sys_fdatasync(int fd) {
641750
return sys_fsync(fd);
642751
}
643752

753+
int sys_chmod(const char *pathname, mode_t mode) {
754+
(void)mode;
755+
struct stat st{};
756+
return sys_stat(fsfd_target::path, -1, pathname, 0, &st);
757+
}
758+
759+
int sys_fchmod(int fd, mode_t mode) {
760+
(void)mode;
761+
struct stat st{};
762+
return sys_stat(fsfd_target::fd, fd, nullptr, 0, &st);
763+
}
764+
765+
int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags) {
766+
(void)flags;
767+
if(fd != AT_FDCWD)
768+
return ENOSYS;
769+
return sys_chmod(pathname, mode);
770+
}
771+
772+
int sys_fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags) {
773+
(void)owner;
774+
(void)group;
775+
(void)flags;
776+
if(dirfd != AT_FDCWD)
777+
return ENOSYS;
778+
struct stat st{};
779+
return sys_stat(fsfd_target::path, -1, pathname, 0, &st);
780+
}
781+
644782
int sys_clone(void *tcb, pid_t *pid_out, void *stack) {
645783
(void)tcb;
646784
(void)pid_out;

0 commit comments

Comments
 (0)