Handle process arguments
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <system/system.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <errors.h>
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <uprintf.h>
|
||||
|
||||
extern void main(void);
|
||||
|
||||
@ -14,9 +19,36 @@ void bss_clear(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static char **_args;
|
||||
static size_t _argslen;
|
||||
|
||||
char **args(void) {
|
||||
return _args;
|
||||
}
|
||||
|
||||
size_t argslen(void) {
|
||||
return _argslen;
|
||||
}
|
||||
|
||||
// ulib initialization goes here
|
||||
void _premain(void) {
|
||||
bss_clear();
|
||||
|
||||
_argslen = processctl(-1, PCTL_ARGLEN, 0, 0, 0);
|
||||
_args = dlmalloc(_argslen * sizeof(*_args));
|
||||
if (_args == NULL) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < _argslen; i++) {
|
||||
_args[i] = dlmalloc(PROC_ARG_MAX);
|
||||
if (_args[i] == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (processctl(-1, PCTL_ARGV, (uint64_t)_args, _argslen, 0) != E_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
main();
|
||||
}
|
||||
|
||||
|
7
ulib/args.h
Normal file
7
ulib/args.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef ULIB_ARGS_H_
|
||||
#define ULIB_ARGS_H_
|
||||
|
||||
char **args(void);
|
||||
size_t argslen(void);
|
||||
|
||||
#endif // ULIB_ARGS_H_
|
@ -11,8 +11,8 @@ int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t
|
||||
return syscall(SYS_IOCTL, ioh, cmd, arg1, arg2, arg3, 0);
|
||||
}
|
||||
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1) {
|
||||
return syscall(SYS_PROCESSCTL, pid, cmd, arg1, 0, 0, 0);
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
|
||||
return syscall(SYS_PROCESSCTL, pid, cmd, arg1, arg2, arg3, 0);
|
||||
}
|
||||
|
||||
int32_t ipcpipe(uint64_t pid, uint64_t pipenum, uint64_t cmd, uint8_t *buffer, size_t len) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
void debugprint(const char *string);
|
||||
int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1);
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
int32_t ipcpipe(uint64_t pid, uint64_t pipenum, uint64_t cmd, uint8_t *buffer, size_t len);
|
||||
int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint8_t **out);
|
||||
int32_t mman_unmap(uint8_t *addr);
|
||||
|
Reference in New Issue
Block a user