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:
Bahadir Balban
2009-10-17 18:48:30 +03:00
parent d19c5c26fd
commit 7ba7a2e796
33 changed files with 109 additions and 187 deletions

26
conts/libc/include/atoi.h Normal file
View 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 atoi(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

View File

@@ -62,4 +62,7 @@
#define L4_IPC_TAG_NOTIFY_FORK 46 /* Pager notifies vfs of process fork */
#define L4_IPC_TAG_NOTIFY_EXIT 47 /* Pager notifies vfs of process exit */
#define L4_IPC_TAG_PAGER_OPEN_BYPATH 48 /* Pager opens a vfs file by pathname */
extern l4id_t pagerid;
#endif /* __IPCDEFS_H__ */

View File

@@ -27,6 +27,8 @@ __l4_mutex_control_t __l4_mutex_control = 0;
struct kip *kip;
l4id_t pagerid;
/*
* Reference to private UTCB of this thread.
* Used only for pushing/reading ipc message registers.

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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));

View File

@@ -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;
}

View File

@@ -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();

View 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

View File

@@ -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__);

View File

@@ -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);

View File

@@ -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();

View File

@@ -1,55 +0,0 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, shelve, sys
from os.path import *
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
from config.projpaths import *
from config.configuration import *
config = configuration_retrieve()
arch = config.arch
LIBL4_RELDIR = 'conts/libl4'
KERNEL_INCLUDE = join(PROJROOT, 'include')
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR)
# Locally important paths are here
LIBC_RELDIR = 'conts/libc'
LIBC_DIR = join(PROJROOT, LIBC_RELDIR)
LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR)
LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \
join(LIBC_DIR, 'include/arch' + '/' + arch)]
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
'-std=gnu99', '-Wall', '-Werror'], \
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\
ASFLAGS = ['-D__ASSEMBLY__'], \
PROGSUFFIX = '.elf', # The suffix to use for final executable\
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\
LIBS = ['gcc', 'libl4', 'c-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBC_INCLUDE],
LIBPATH = [LIBL4_LIBPATH, LIBC_LIBPATH],
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
src = Glob('*.[cS]')
src += Glob('src/*.[cS]')
objs = env.Object(src)
prog = env.Program('main.elf', objs)
Depends(prog, 'include/linker.lds')

View File

@@ -1,21 +0,0 @@
/*
* Container entry point for pager
*
* Copyright (C) 2007-2009 B Labs Ltd.
*/
#include <l4lib/init.h>
#include <l4lib/utcb.h>
void main(void);
void __container_init(void)
{
/* Generic L4 initialisation */
__l4_init();
/* Entry to main */
main();
}

View File

@@ -1,13 +0,0 @@
/*
* Autogenerated hello world print function
*/
#include <stdio.h>
#include <container.h>
int print_hello_world(void)
{
printf("%s: Hello world from %s!\n", __CONTAINER__, __CONTAINER_NAME__);
return 0;
}

View File

@@ -1,34 +0,0 @@
/*
* Example working linker script for this container.
*
* Copyright (C) 2009 B Labs Ltd.
*/
vma_start = 0x0;
lma_start = 0x1000000;
offset = vma_start - lma_start;
ENTRY(_start)
SECTIONS
{
. = vma_start;
.text : AT (ADDR(.text) - offset) {
/*
* NOTE:
* crt0.S must be in .text.head. This is necessary because
* the kernel does not know any _start address, it assumes
* the start address of pager region as the start address.
*/
*(.text.head) *(.text)
}
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
. = ALIGN(4K);
.data : AT (ADDR(.data) - offset) { *(.data) }
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
. += 0x1000;
. = ALIGN(8);
__stack = .;
}

View File

@@ -1,16 +0,0 @@
/*
* Main function for this container
*/
#include <l4lib/arch/syslib.h>
#include <l4lib/arch/syscalls.h>
#include <l4/api/space.h>
extern int print_hello_world(void);
int main(void)
{
print_hello_world();
return 0;
}

View File

View File

@@ -71,14 +71,6 @@ struct kip {
struct kernel_descriptor kdesc;
} __attribute__((__packed__));
/*
* Task id defs for priviledged server tasks. These are dynamically allocated
* from the id pool, but still the pool should allocate them in this order.
*/
#define PAGER_TID 0
#define VFS_TID 1
#define BLKDEV_TID 2
#define __PAGERNAME__ "mm0"
#define __VFSNAME__ "fs0"
#define __BLKDEVNAME__ "blkdev0"