-
Notifications
You must be signed in to change notification settings - Fork 5
feat(syscall): add uname syscall + uname userland program #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
FlareCoding
merged 7 commits into
stellux-3.0-prototyping
from
cursor/uname-syscall-76e8
Apr 1, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
994b5b2
feat(syscall): add uname syscall for both x86_64 and aarch64
cursoragent e0ac322
style: remove anonymous namespace from sys_uname.cpp
cursoragent 47d704e
feat(syscall): source uname version from STLX_VERSION in config.mk
cursoragent cf7c6a2
docs: simplify STLX_VERSION comment in config.mk
cursoragent 6f5e84e
style: remove redundant privilege docstring from sys_uname
cursoragent 99819e8
feat(userland): add uname utility with Linux-compatible flag interface
cursoragent 0b4b613
fix(syscall): add #else #error guard for unsupported arch in sys_uname
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include "syscall/handlers/sys_uname.h" | ||
| #include "mm/uaccess.h" | ||
| #include "common/string.h" | ||
|
|
||
| constexpr size_t UTS_FIELD_LEN = 65; | ||
|
|
||
| struct new_utsname { | ||
| char sysname[UTS_FIELD_LEN]; | ||
| char nodename[UTS_FIELD_LEN]; | ||
| char release[UTS_FIELD_LEN]; | ||
| char version[UTS_FIELD_LEN]; | ||
| char machine[UTS_FIELD_LEN]; | ||
| char domainname[UTS_FIELD_LEN]; | ||
| }; | ||
|
|
||
| __PRIVILEGED_CODE static void fill_field(char* dst, const char* src) { | ||
| size_t len = string::strnlen(src, UTS_FIELD_LEN - 1); | ||
| string::memcpy(dst, src, len); | ||
| string::memset(dst + len, 0, UTS_FIELD_LEN - len); | ||
| } | ||
|
|
||
| DEFINE_SYSCALL1(uname, u_buf) { | ||
| if (u_buf == 0) { | ||
| return syscall::EFAULT; | ||
| } | ||
|
|
||
| new_utsname kbuf; | ||
|
|
||
| fill_field(kbuf.sysname, "Stellux"); | ||
| fill_field(kbuf.nodename, "stellux"); | ||
| fill_field(kbuf.release, STLX_VERSION); | ||
| fill_field(kbuf.version, "Stellux " STLX_VERSION); | ||
| #if defined(__x86_64__) | ||
| fill_field(kbuf.machine, "x86_64"); | ||
| #elif defined(__aarch64__) | ||
| fill_field(kbuf.machine, "aarch64"); | ||
| #else | ||
| #error "unsupported architecture for uname" | ||
| #endif | ||
| fill_field(kbuf.domainname, "(none)"); | ||
|
|
||
| int32_t rc = mm::uaccess::copy_to_user( | ||
| reinterpret_cast<void*>(u_buf), &kbuf, sizeof(kbuf)); | ||
| if (rc != mm::uaccess::OK) { | ||
| return syscall::EFAULT; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #ifndef STELLUX_SYSCALL_HANDLERS_SYS_UNAME_H | ||
| #define STELLUX_SYSCALL_HANDLERS_SYS_UNAME_H | ||
|
|
||
| #include "syscall/syscall_table.h" | ||
|
|
||
| DECLARE_SYSCALL(uname); | ||
|
|
||
| #endif // STELLUX_SYSCALL_HANDLERS_SYS_UNAME_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| APP_NAME := uname | ||
| include ../../mk/app.mk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <sys/utsname.h> | ||
|
|
||
| #define FLAG_S (1 << 0) | ||
| #define FLAG_N (1 << 1) | ||
| #define FLAG_R (1 << 2) | ||
| #define FLAG_V (1 << 3) | ||
| #define FLAG_M (1 << 4) | ||
| #define FLAG_ALL (FLAG_S | FLAG_N | FLAG_R | FLAG_V | FLAG_M) | ||
|
|
||
| static void usage(void) { | ||
| printf("Usage: uname [OPTION]...\n" | ||
| "Print system information.\n\n" | ||
| " -a all information\n" | ||
| " -s kernel name\n" | ||
| " -n network node hostname\n" | ||
| " -r kernel release\n" | ||
| " -v kernel version\n" | ||
| " -m machine hardware name\n" | ||
| " --help display this help\n"); | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| setvbuf(stdout, NULL, _IONBF, 0); | ||
|
|
||
| unsigned flags = 0; | ||
|
|
||
| for (int i = 1; i < argc; i++) { | ||
| if (strcmp(argv[i], "--help") == 0) { | ||
| usage(); | ||
| return 0; | ||
| } | ||
| if (argv[i][0] != '-' || argv[i][1] == '\0') { | ||
| printf("uname: invalid option '%s'\n", argv[i]); | ||
| return 1; | ||
| } | ||
| for (const char* p = argv[i] + 1; *p; p++) { | ||
| switch (*p) { | ||
| case 'a': flags |= FLAG_ALL; break; | ||
| case 's': flags |= FLAG_S; break; | ||
| case 'n': flags |= FLAG_N; break; | ||
| case 'r': flags |= FLAG_R; break; | ||
| case 'v': flags |= FLAG_V; break; | ||
| case 'm': flags |= FLAG_M; break; | ||
| default: | ||
| printf("uname: invalid option '-%c'\n", *p); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (flags == 0) | ||
| flags = FLAG_S; | ||
|
|
||
| struct utsname buf; | ||
| if (uname(&buf) != 0) { | ||
| printf("uname: uname syscall failed\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| int need_space = 0; | ||
| const char* fields[] = { buf.sysname, buf.nodename, buf.release, | ||
| buf.version, buf.machine }; | ||
| unsigned field_flags[] = { FLAG_S, FLAG_N, FLAG_R, FLAG_V, FLAG_M }; | ||
|
|
||
| for (int i = 0; i < 5; i++) { | ||
| if (flags & field_flags[i]) { | ||
| if (need_space) putchar(' '); | ||
| fputs(fields[i], stdout); | ||
| need_space = 1; | ||
| } | ||
| } | ||
| putchar('\n'); | ||
|
|
||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.