mirror of
https://github.com/drasko/codezero.git
synced 2026-02-28 09:43:14 +01:00
Added a simplified ascii_to_int() implementation.
Removed dependency on hard-coded pager id. Pager id is now passed as an environment string `pagerid' to tasks. Alternatively, this could take space in the utcb of each task.
This commit is contained in:
@@ -25,7 +25,7 @@ static inline int l4_chdir(const char *pathname)
|
||||
utcb_full_strcpy_from(pathname);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_CHDIR)) < 0) {
|
||||
if ((fd = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_CHDIR)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static inline int l4_close(int fd)
|
||||
write_mr(L4SYS_ARG0, fd);
|
||||
|
||||
/* Call pager with close() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_CLOSE)) < 0) {
|
||||
if ((fd = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_CLOSE)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||
return fd;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ static inline int l4_fsync(int fd)
|
||||
write_mr(L4SYS_ARG0, fd);
|
||||
|
||||
/* Call pager with close() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FSYNC)) < 0) {
|
||||
if ((fd = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_FSYNC)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
char **__environ;
|
||||
|
||||
|
||||
/*
|
||||
* Search for given name in name=value string pairs located
|
||||
* in the environment segment, and return the pointer to value
|
||||
|
||||
@@ -36,7 +36,7 @@ static inline int l4_execve(const char *pathname, char *const argv[], char *cons
|
||||
|
||||
|
||||
/* Call pager with open() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXECVE)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_EXECVE)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ static inline void __attribute__ ((noreturn)) l4_exit(int status)
|
||||
write_mr(L4SYS_ARG0, status);
|
||||
|
||||
/* Call pager with exit() request and block on its receive phase */
|
||||
ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXIT);
|
||||
ret = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_EXIT);
|
||||
|
||||
/* This call should not fail or return */
|
||||
print_err("%s: L4 IPC returned: %d.\n", __FUNCTION__, ret);
|
||||
|
||||
@@ -20,7 +20,7 @@ static inline int l4_fork(void)
|
||||
int err;
|
||||
|
||||
/* Call pager with open() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FORK)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_FORK)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...)
|
||||
write_mr(L4SYS_ARG1, flags);
|
||||
|
||||
/* Perform an ipc but with different return logic. See implementation. */
|
||||
if ((ret = arch_clone(PAGER_TID, PAGER_TID, 0)) < 0) {
|
||||
if ((ret = arch_clone(pagerid, pagerid, 0)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence)
|
||||
write_mr(L4SYS_ARG2, whence);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((offres = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_LSEEK)) < 0) {
|
||||
if ((offres = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_LSEEK)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, offres);
|
||||
return offres;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ static inline int l4_mkdir(const char *pathname, mode_t mode)
|
||||
write_mr(L4SYS_ARG0, (u32)mode);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_MKDIR)) < 0) {
|
||||
if ((fd = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_MKDIR)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ static inline void *l4_mmap(void *start, size_t length, int prot, int flags, int
|
||||
write_mr(L4SYS_ARG0, (unsigned long)&desc);
|
||||
|
||||
/* Call pager with MMAP request. Check ipc error. */
|
||||
if ((ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MMAP)) < 0) {
|
||||
if ((ret = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MMAP)) < 0) {
|
||||
print_err("%s: IPC Error: %d.\n", __FUNCTION__, ret);
|
||||
return PTR_ERR(ret);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ int l4_munmap(void *start, size_t length)
|
||||
write_mr(L4SYS_ARG1, length);
|
||||
|
||||
/* Call pager with MMAP request. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MUNMAP)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MUNMAP)) < 0) {
|
||||
print_err("%s: IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ int l4_msync(void *start, size_t length, int flags)
|
||||
write_mr(L4SYS_ARG2, flags);
|
||||
|
||||
/* Call pager with MMAP request. */
|
||||
if ((errno = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MSYNC)) < 0) {
|
||||
if ((errno = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MSYNC)) < 0) {
|
||||
print_err("%s: IPC Error: %d.\n", __FUNCTION__, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode)
|
||||
write_mr(L4SYS_ARG1, (u32)mode);
|
||||
|
||||
/* Call pager with open() request. Check ipc error. */
|
||||
if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_OPEN)) < 0) {
|
||||
if ((fd = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_OPEN)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
|
||||
write_mr(L4SYS_ARG1, count);
|
||||
|
||||
/* Call pager with readdir() request. Check ipc error. */
|
||||
if ((err = l4_send(PAGER_TID, L4_IPC_TAG_READDIR)) < 0) {
|
||||
if ((err = l4_send(pagerid, L4_IPC_TAG_READDIR)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Call pager with readdir() request. Check ipc error. */
|
||||
if ((err = l4_receive_extended(PAGER_TID,
|
||||
if ((err = l4_receive_extended(pagerid,
|
||||
L4_IPC_EXTENDED_MAX_SIZE,
|
||||
buf)) < 0) {
|
||||
print_err("%s: L4 Extended IPC error: %d.\n", __FUNCTION__, err);
|
||||
@@ -68,7 +68,7 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
|
||||
write_mr(L4SYS_ARG2, count);
|
||||
|
||||
/* Call pager with readdir() request. Check ipc error. */
|
||||
if ((cnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_READDIR)) < 0) {
|
||||
if ((cnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_READDIR)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
|
||||
return cnt;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ static inline int l4_read(int fd, void *buf, size_t count)
|
||||
write_mr(L4SYS_ARG2, count);
|
||||
|
||||
/* Call pager with read() request. Check ipc error. */
|
||||
if ((cnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_READ)) < 0) {
|
||||
if ((cnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_READ)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ int l4_shmget(l4id_t key, int size, int shmflg)
|
||||
write_mr(L4SYS_ARG2, shmflg);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMGET)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_SHMGET)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ void *l4_shmat(l4id_t shmid, const void *shmaddr, int shmflg)
|
||||
write_mr(L4SYS_ARG2, shmflg);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMAT)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_SHMAT)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return PTR_ERR(err);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ int l4_shmdt(const void *shmaddr)
|
||||
write_mr(L4SYS_ARG0, (unsigned long)shmaddr);
|
||||
|
||||
/* Call pager with shmget() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMDT)) < 0) {
|
||||
if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_SHMDT)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ static void *shared_page_address(void)
|
||||
write_mr(L4SYS_ARG0, self_tid());
|
||||
|
||||
/* Call pager with utcb address request. Check ipc error. */
|
||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
|
||||
if ((err = l4_sendrecv(pagerid, pagerid,
|
||||
L4_IPC_TAG_SHPAGE)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return PTR_ERR(err);
|
||||
@@ -76,7 +76,7 @@ int shared_page_init(void)
|
||||
* Initialise shared page only if we're not the pager.
|
||||
* The pager does it differently for itself.
|
||||
*/
|
||||
BUG_ON(self_tid() == PAGER_TID);
|
||||
BUG_ON(self_tid() == pagerid);
|
||||
|
||||
/* Obtain our shared page address */
|
||||
shared_page = shared_page_address();
|
||||
|
||||
@@ -30,7 +30,7 @@ static inline int l4_fstat(int fd, void *buffer)
|
||||
write_mr(L4SYS_ARG1, (unsigned long)buffer);
|
||||
|
||||
/* Call pager with open() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_FSTAT)) < 0) {
|
||||
if ((err = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_FSTAT)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ static inline int l4_stat(const char *pathname, void *buffer)
|
||||
write_mr(L4SYS_ARG1, (unsigned long)&ks);
|
||||
|
||||
/* Call vfs with stat() request. Check ipc error. */
|
||||
if ((err = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_STAT)) < 0) {
|
||||
if ((err = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_STAT)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ static inline int l4_write(int fd, const void *buf, size_t count)
|
||||
write_mr(L4SYS_ARG2, count);
|
||||
|
||||
/* Call pager with write() request. Check ipc error. */
|
||||
if ((wrcnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_WRITE)) < 0) {
|
||||
if ((wrcnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_WRITE)) < 0) {
|
||||
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt);
|
||||
return wrcnt;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ int init_execve(char *filepath)
|
||||
struct exec_file_desc efd;
|
||||
struct tcb *new_task, *self;
|
||||
struct args_struct args, env;
|
||||
char *env_string = "pagerid=0";
|
||||
char env_string[30];
|
||||
int err;
|
||||
int fd;
|
||||
|
||||
@@ -52,6 +52,8 @@ int init_execve(char *filepath)
|
||||
.tgid = TASK_ID_INVALID,
|
||||
};
|
||||
|
||||
sprintf(env_string, "pagerid=%d", self_tid());
|
||||
|
||||
/* Set up args_struct */
|
||||
args.argc = 1;
|
||||
args.argv = alloca(sizeof(args.argv));
|
||||
|
||||
@@ -434,8 +434,6 @@ struct tcb *task_create(struct tcb *parent, struct task_ids *ids,
|
||||
*
|
||||
* (low) |->argc|argv[0]|argv[1]|...|argv[argc] = 0|envp[0]|envp[1]|...|NULL| (high)
|
||||
*
|
||||
* IOW:
|
||||
*
|
||||
* argc
|
||||
* argv pointers
|
||||
* null
|
||||
@@ -447,8 +445,10 @@ struct tcb *task_create(struct tcb *parent, struct task_ids *ids,
|
||||
* space, heap seems to get used in uClibc.
|
||||
*
|
||||
*/
|
||||
int task_copy_args_to_user(char *user_stack, unsigned long user_ptr,
|
||||
struct args_struct *args, struct args_struct *env)
|
||||
int task_copy_args_to_user(char *user_stack,
|
||||
unsigned long user_ptr,
|
||||
struct args_struct *args,
|
||||
struct args_struct *env)
|
||||
{
|
||||
char **argv_start, **envp_start;
|
||||
|
||||
@@ -503,6 +503,7 @@ int task_copy_args_to_user(char *user_stack, unsigned long user_ptr,
|
||||
| ((unsigned long)user_stack &
|
||||
PAGE_MASK));
|
||||
|
||||
/* Update location */
|
||||
user_stack += strlen(env->argv[i]) + 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,12 @@ int main(int argc, char *argv[]);
|
||||
int __container_init(int argc, char **argv)
|
||||
{
|
||||
void *envp = &argv[argc + 1];
|
||||
char *pagerval;
|
||||
|
||||
if ((char *)envp == *argv)
|
||||
envp = &argv[argc];
|
||||
|
||||
__libposix_init(envp);
|
||||
|
||||
pagerval = getenv("pagerid");
|
||||
|
||||
/* Generic L4 thread initialisation */
|
||||
__l4_init();
|
||||
|
||||
|
||||
26
conts/posix/test0/include/atoi.h
Normal file
26
conts/posix/test0/include/atoi.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __ATOI_H__
|
||||
#define __ATOI_H__
|
||||
|
||||
static inline int power(int exp, int mul)
|
||||
{
|
||||
int total = 1;
|
||||
|
||||
while (exp > 0) {
|
||||
total *= mul;
|
||||
exp--;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static inline int ascii_to_int(char *str)
|
||||
{
|
||||
int size = strlen(str);
|
||||
int iter = size - 1;
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
num += ((int)str[iter - i] - 48) * power(i, 10);
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <tests.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <atoi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void wait_pager(l4id_t partner)
|
||||
{
|
||||
@@ -24,6 +26,7 @@ void wait_pager(l4id_t partner)
|
||||
}
|
||||
|
||||
pid_t parent_of_all;
|
||||
pid_t pagerid;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -32,6 +35,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
parent_of_all = getpid();
|
||||
|
||||
pagerid = ascii_to_int(getenv("pagerid"));
|
||||
|
||||
wait_pager(0);
|
||||
|
||||
printf("\n%s: Running POSIX API tests.\n", __TASKNAME__);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <alloca.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
@@ -22,10 +23,11 @@ int exectest(pid_t parent_of_all)
|
||||
void *exec_start = (void *)_start_test_exec;
|
||||
unsigned long size = _end_test_exec - _start_test_exec;
|
||||
char filename[128];
|
||||
char env_string[30];
|
||||
char env_string1[30];
|
||||
char env_string2[30];
|
||||
int left, cnt;
|
||||
char *argv[5];
|
||||
char *envp[2];
|
||||
char *envp[3];
|
||||
|
||||
memset(filename, 0, 128);
|
||||
sprintf(filename, "/home/bahadir/execfile%d", getpid());
|
||||
@@ -90,10 +92,14 @@ int exectest(pid_t parent_of_all)
|
||||
argv[3] = "FOURTH ARG";
|
||||
argv[4] = 0;
|
||||
|
||||
memset(env_string, 0, 30);
|
||||
sprintf(env_string, "parent_of_all=%d", parent_of_all);
|
||||
envp[0] = env_string;
|
||||
envp[1] = 0; /* This is important as the array needs to end with a null */
|
||||
memset(env_string1, 0, 30);
|
||||
memset(env_string2, 0, 30);
|
||||
sprintf(env_string1, "parent_of_all=%d", parent_of_all);
|
||||
sprintf(env_string2, "pagerid=%d", pagerid);
|
||||
|
||||
envp[0] = env_string1;
|
||||
envp[1] = env_string2;
|
||||
envp[2] = 0; /* This is important as the array needs to end with a null */
|
||||
|
||||
/* Execute the file */
|
||||
err = execve(filename, argv, envp);
|
||||
|
||||
@@ -25,7 +25,7 @@ void ipc_full_test(void)
|
||||
}
|
||||
|
||||
/* Call the pager */
|
||||
if ((ret = l4_sendrecv_full(PAGER_TID, PAGER_TID,
|
||||
if ((ret = l4_sendrecv_full(pagerid, pagerid,
|
||||
L4_IPC_TAG_SYNC_FULL)) < 0) {
|
||||
printf("%s: Failed with %d\n", __FUNCTION__, ret);
|
||||
BUG();
|
||||
|
||||
Reference in New Issue
Block a user