mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-07-13 08:09:21 +00:00
Update userspace
This commit is contained in:
@ -1,69 +0,0 @@
|
||||
#ifndef __FENNIX_LIBC_AUX_H__
|
||||
#define __FENNIX_LIBC_AUX_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define AT_NULL 0
|
||||
#define AT_IGNORE 1
|
||||
#define AT_EXECFD 2
|
||||
#define AT_PHDR 3
|
||||
#define AT_PHENT 4
|
||||
#define AT_PHNUM 5
|
||||
#define AT_PAGESZ 6
|
||||
#define AT_BASE 7
|
||||
#define AT_FLAGS 8
|
||||
#define AT_ENTRY 9
|
||||
#define AT_NOTELF 10
|
||||
#define AT_UID 11
|
||||
#define AT_EUID 12
|
||||
#define AT_GID 13
|
||||
#define AT_EGID 14
|
||||
#define AT_PLATFORM 15
|
||||
#define AT_HWCAP 16
|
||||
#define AT_CLKTCK 17
|
||||
#define AT_SECURE 23
|
||||
#define AT_BASE_PLATFORM 24
|
||||
#define AT_RANDOM 25
|
||||
#define AT_HWCAP2 26
|
||||
#define AT_EXECFN 31
|
||||
#define AT_SYSINFO 32
|
||||
#define AT_SYSINFO_EHDR 33
|
||||
#define AT_L1I_CACHESHAPE 34
|
||||
#define AT_L1D_CACHESHAPE 35
|
||||
#define AT_L2_CACHESHAPE 36
|
||||
#define AT_L3_CACHESHAPE 37
|
||||
#define AT_L1I_CACHESIZE 40
|
||||
#define AT_L1I_CACHEGEOMETRY 41
|
||||
#define AT_L1D_CACHESIZE 42
|
||||
#define AT_L1D_CACHEGEOMETRY 43
|
||||
#define AT_L2_CACHESIZE 44
|
||||
#define AT_L2_CACHEGEOMETRY 45
|
||||
#define AT_L3_CACHESIZE 46
|
||||
#define AT_L3_CACHEGEOMETRY 47
|
||||
#define AT_MINSIGSTKSZ 51
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t a_type;
|
||||
union
|
||||
{
|
||||
uint32_t a_val;
|
||||
} a_un;
|
||||
} Elf32_auxv_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t a_type;
|
||||
union
|
||||
{
|
||||
uint64_t a_val;
|
||||
} a_un;
|
||||
} Elf64_auxv_t;
|
||||
|
||||
#ifdef __LP64__
|
||||
#define Elf_auxv_t Elf64_auxv_t
|
||||
#else
|
||||
#define Elf_auxv_t Elf32_auxv_t
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_LIBC_AUX_H__
|
@ -1,103 +1,6 @@
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "aux.h"
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
void test_args(int argc, char *argv[], char *envp[])
|
||||
int main(int, char *[], char *[])
|
||||
{
|
||||
printf("%p %p %p\n", (void *)(uint64_t)&argc, (void *)&argv, (void *)&envp);
|
||||
printf("I have %d arguments\n", argc);
|
||||
for (int i = 0; i < argc; i++)
|
||||
printf("argv[%d] = (%p) %s\n", i, argv[i], argv[i]);
|
||||
|
||||
int envc = 0;
|
||||
while (envp[envc] != NULL)
|
||||
envc++;
|
||||
|
||||
printf("I have %d environment variables\n", envc);
|
||||
for (int i = 0; i < envc; i++)
|
||||
printf("envp[%d] = (%p) %s\n", i, envp[i], envp[i]);
|
||||
|
||||
Elf64_auxv_t *auxv;
|
||||
char **e = envp;
|
||||
|
||||
while (*e++ != NULL)
|
||||
;
|
||||
|
||||
for (auxv = (Elf64_auxv_t *)e; auxv->a_type != AT_NULL; auxv++)
|
||||
printf("auxv: %ld %#lx\n", auxv->a_type, auxv->a_un.a_val);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("Hello, World!\n");
|
||||
// while (1);
|
||||
// test_args(argc, argv, envp);
|
||||
FILE *test = fopen("/test.txt", "r");
|
||||
if (test == NULL)
|
||||
{
|
||||
printf("Failed to open file\n");
|
||||
return -0xF11e;
|
||||
}
|
||||
|
||||
printf("Test.txt contents: ");
|
||||
char ch;
|
||||
while (1)
|
||||
{
|
||||
ch = fgetc(test);
|
||||
if (ch == EOF)
|
||||
{
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
putchar(ch);
|
||||
}
|
||||
fclose(test);
|
||||
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == 0) // Child process
|
||||
{
|
||||
pid_t pid2 = fork();
|
||||
if (pid == 0) // Child process
|
||||
{
|
||||
char *shebang_args[] = {"/test.sh", NULL};
|
||||
execv(shebang_args[0], shebang_args);
|
||||
}
|
||||
|
||||
printf("Creating shell process\n");
|
||||
char *args[] = {"/bin/echo", "Hello, World!", NULL};
|
||||
execv(args[0], args);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (pid > 0)
|
||||
{
|
||||
printf("Waiting for child process %d to exit\n", pid);
|
||||
int status;
|
||||
wait(&status);
|
||||
int exited = WIFEXITED(status);
|
||||
if (exited)
|
||||
{
|
||||
int exit_code = WEXITSTATUS(status);
|
||||
printf("Child process exited with code: %d\n", exit_code);
|
||||
return exit_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Execution failed. (%d)\n", exited);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\eFF0000Failed to create the process.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user