RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / c / hello-musl.c
857 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* hello-musl: the first Foundry OS C program (milestone M2), plain C on musl.
 *
 * Built by `make` with toolchain/foundry-cc, i.e. gcc + our musl as a
 * static-PIE (see docs/porting.md), and installed as /bin/hello-musl.
 * On Rustbelt it prints "hello from musl on Rustbelt 0.20.0 (...)"; the
 * same binary also runs on a Linux PC ("hello from musl on Linux 6.x").
 */
#include <elf.h>
#include <stdio.h>
#include <sys/utsname.h>

extern const char __ehdr_start[]; /* our own ELF header, wherever we were loaded */

int main(void)
{
	const Elf64_Ehdr *me = (const void *)__ehdr_start;
	const char *kind = me->e_type == ET_DYN ? "static-PIE" : "ET_EXEC";
	struct utsname u;
	if (uname(&u) == 0)
		printf("hello from musl on %s %s (Foundry OS, %s)\n", u.sysname, u.release, kind);
	else
		printf("hello from musl (Foundry OS, %s)\n", kind);
	return 0;
}