Removed allocation of utcb shared pages by mm0 completely.

- Now libl4 has no references to utcb page or shmat etc.
- Pager does not deal with special case utcb page allocation.
  It instead allocates a shared page from shm memory pool.
- All tasks working to original standard.

Next:
- Add per-thread utcb allocation from the kernel
- Add larger register file for standard ipc
- Add long ipc (up to 1Kb)
This commit is contained in:
Bahadir Balban
2009-04-22 14:48:43 +03:00
parent 203f053878
commit 54a9b2901d
18 changed files with 207 additions and 124 deletions

View File

@@ -88,7 +88,7 @@ _start:
ldr sp, =__stack
bl platform_init
bl __l4_init
bl main
bl __container_init
1:
b 1b

View File

@@ -33,7 +33,7 @@ struct task_fs_data {
struct tcb {
l4id_t tid;
struct list_head list;
unsigned long utcb_address;
unsigned long shpage_address;
struct task_fd_head *files;
struct task_fs_data *fs_data;
};
@@ -41,7 +41,7 @@ struct tcb {
/* Structures used when receiving new task info from pager */
struct task_data {
unsigned long tid;
unsigned long utcb_address;
unsigned long shpage_address;
};
struct task_data_head {

View File

@@ -486,8 +486,8 @@ int sys_readdir(struct tcb *t, int fd, void *buf, int count)
// printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
/* Check address is in task's utcb */
if ((unsigned long)buf < t->utcb_address ||
(unsigned long)buf > t->utcb_address + PAGE_SIZE)
if ((unsigned long)buf < t->shpage_address ||
(unsigned long)buf > t->shpage_address + PAGE_SIZE)
return -EINVAL;
if (fd < 0 || fd > TASK_FILES_MAX || t->files->fd[fd] == NILFD)

View File

@@ -20,6 +20,8 @@
#include <syscalls.h>
#include <globals.h>
extern void *shared_page;
struct global_list global_tasks = {
.list = { &global_tasks.list, &global_tasks.list },
.total = 0,
@@ -118,7 +120,7 @@ void copy_tcb(struct tcb *to, struct tcb *from, unsigned int share_flags)
}
/* Allocate a task struct and initialise it */
struct tcb *tcb_create(struct tcb *orig, l4id_t tid, unsigned long utcb,
struct tcb *tcb_create(struct tcb *orig, l4id_t tid, unsigned long shpage,
unsigned int share_flags)
{
struct tcb *task;
@@ -131,7 +133,7 @@ struct tcb *tcb_create(struct tcb *orig, l4id_t tid, unsigned long utcb,
return task;
task->tid = tid;
task->utcb_address = utcb;
task->shpage_address = shpage;
/*
* If there's an original task that means this will be a full
@@ -177,18 +179,18 @@ int task_utcb_attach(struct tcb *t)
void *shmaddr;
/* Use it as a key to create a shared memory region */
if ((shmid = shmget((key_t)t->utcb_address, PAGE_SIZE, 0)) == -1)
if ((shmid = shmget((key_t)t->shpage_address, PAGE_SIZE, 0)) == -1)
goto out_err;
/* Attach to the region */
if ((int)(shmaddr = shmat(shmid, (void *)t->utcb_address, 0)) == -1)
if ((int)(shmaddr = shmat(shmid, (void *)t->shpage_address, 0)) == -1)
goto out_err;
/* Ensure address is right */
if ((unsigned long)shmaddr != t->utcb_address)
if ((unsigned long)shmaddr != t->shpage_address)
return -EINVAL;
// printf("%s: Mapped utcb of task %d @ 0x%x\n",
// printf("%s: Mapped shared page of task %d @ 0x%x\n",
// __TASKNAME__, t->tid, shmaddr);
return 0;
@@ -204,7 +206,7 @@ out_err:
* the information on the resulting child task.
*/
int pager_notify_fork(struct tcb *sender, l4id_t parentid,
l4id_t childid, unsigned long utcb_address,
l4id_t childid, unsigned long shpage_address,
unsigned int flags)
{
struct tcb *child, *parent;
@@ -213,7 +215,7 @@ int pager_notify_fork(struct tcb *sender, l4id_t parentid,
BUG_ON(!(parent = find_task(parentid)));
/* Create a child vfs tcb using given parent and copy flags */
if (IS_ERR(child = tcb_create(parent, childid, utcb_address, flags)))
if (IS_ERR(child = tcb_create(parent, childid, shpage_address, flags)))
return (int)child;
global_add_task(child);
@@ -261,9 +263,9 @@ struct task_data_head *receive_pager_taskdata(void)
/* Data is expected in the utcb page */
// printf("%s: %d Total tasks.\n", __FUNCTION__,
// ((struct task_data_head *)utcb_page)->total);
// ((struct task_data_head *)shared_page)->total);
return (struct task_data_head *)utcb_page;
return (struct task_data_head *)shared_page;
}
@@ -274,7 +276,7 @@ int init_task_structs(struct task_data_head *tdata_head)
for (int i = 0; i < tdata_head->total; i++) {
/* New tcb with fields sent by pager */
if (IS_ERR(t = tcb_create(0, tdata_head->tdata[i].tid,
tdata_head->tdata[i].utcb_address,
tdata_head->tdata[i].shpage_address,
0)))
return (int)t;

View File

@@ -30,7 +30,6 @@ struct utcb {
} __attribute__((__packed__));
extern struct utcb utcb;
extern void *utcb_page;
static inline struct utcb *l4_get_utcb()
{
@@ -48,30 +47,6 @@ static inline void write_mr(unsigned int offset, unsigned int val)
l4_get_utcb()->mr[offset] = val;
}
/*
* Arguments that are too large to fit in message registers are
* copied onto another area that is still on the utcb, and the servers
* map-in the task utcb and read those arguments from there.
*/
static inline int copy_to_utcb(void *arg, int offset, int size)
{
if (offset + size > PAGE_SIZE)
return -1;
memcpy(utcb_page + offset, arg, size);
return 0;
}
static inline int copy_from_utcb(void *buf, int offset, int size)
{
if (offset + size > PAGE_SIZE)
return -1;
memcpy(buf, utcb_page + offset, size);
return 0;
}
#endif /* !__ASSEMBLY__ */
#endif /* __ARM_UTCB_H__ */

View File

@@ -10,8 +10,6 @@
#include <l4/macros.h>
#include INC_GLUE(memlayout.h)
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
__l4_ipc_t __l4_ipc = 0;
__l4_map_t __l4_map = 0;

View File

@@ -3,6 +3,7 @@
*
* Copyright (C) 2008 Bahadir Balban
*/
#include <shpage.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
@@ -21,8 +22,8 @@ static inline int l4_chdir(const char *pathname)
int fd;
// write_mr(L4SYS_ARG0, (unsigned long)pathname);
copy_to_utcb((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
/* Call pager with shmget() request. Check ipc error. */
if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 0) {

View File

@@ -12,6 +12,7 @@
#include <l4lib/utcb.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
#include <posix_init.h>
static inline int l4_fork(void)
{
@@ -40,9 +41,12 @@ int fork(void)
return -1;
}
/* If we're a child, we need to initialise the utcb page */
/*
* If we're a child, we need to initialise the default
* shared page via posix_init()
*/
if (ret == 0)
utcb_init();
posix_init();
return ret;
}

View File

@@ -0,0 +1,6 @@
#ifndef __POSIX_INIT_H__
#define __POSIX_INIT_H__
void posix_init(void);
#endif /* __POSIX_INIT_H__ */

View File

@@ -0,0 +1,45 @@
/*
* A default shared page is used by every thread
* to pass large data for system calls.
*
* This file contains relevant shpage definitions.
*/
#ifndef __LIBPOSIX_SHPAGE_H__
#define __LIBPOSIX_SHPAGE_H__
#include <l4/macros.h>
#include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h>
#include <l4lib/ipcdefs.h>
#include <l4lib/utcb.h>
#include INC_GLUE(memory.h)
extern void *shared_page;
int shared_page_init(void);
/*
* Arguments that are too large to fit in message registers are
* copied onto another area that is still on the utcb, and the servers
* map-in the task utcb and read those arguments from there.
*/
static inline int copy_to_shpage(void *arg, int offset, int size)
{
if (offset + size > PAGE_SIZE)
return -1;
memcpy(shared_page + offset, arg, size);
return 0;
}
static inline int copy_from_shpage(void *buf, int offset, int size)
{
if (offset + size > PAGE_SIZE)
return -1;
memcpy(buf, shared_page + offset, size);
return 0;
}
#endif /* __LIBPOSIX_SHPAGE_H__ */

View File

@@ -1,79 +1,30 @@
/*
* Shared page initialisation of posix-like tasks.
* Main entry point for posix services and applications.
*
* POSIX tasks currently use a default shared page for communciation.
* This could have been also done by long ipc calls.
* Copyright (C) 2007-2009 Bahadir Balban
*/
/*
* Shared page for this task. Used for passing data among ipc
* parties when message registers are not big enough. Every thread
* has right to own one, and it has an address unique to every
* thread. It must be explicitly mapped by both parties of the ipc
* in order to be useful.
*/
void *shared_page;
#include <shpage.h>
#include <posix_init.h>
/*
* Obtains a unique address for the task's shared page. Note this
* just returns the address. This address is used as an shm key
* to map it via shmget()/shmat() later on.
*/
static void *shared_page_address(void)
void posix_init(void)
{
void *addr;
int err;
/* We're asking it for ourself. */
write_mr(L4SYS_ARG0, self_tid());
/* Call pager with utcb address request. Check ipc error. */
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
L4_IPC_TAG_DEFAULT_SHPAGE)) < 0) {
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
return PTR_ERR(err);
}
/* Check if syscall itself was successful */
if (IS_ERR(addr = (void *)l4_get_retval())) {
printf("%s: Request UTCB Address Error: %d.\n",
__FUNCTION__, (int)addr);
return addr;
}
return addr;
/* Non-pager tasks initialise their shared communication page */
if (self_tid() != PAGER_TID)
shared_page_init();
}
int main(void);
/*
* Initialises a non-pager task's default shared memory page
* using posix semantics. Used during task initialisation
* and by child tasks after a fork.
* Entry point for posix services container.
*
* This is executed by all posix system services and tasks
* that run in this container.
*/
int shared_page_init(void)
void __container_init(void)
{
int shmid;
void *shmaddr;
/*
* Initialise shared page only if we're not the pager.
* The pager does it differently for itself.
*/
BUG_ON(self_tid() == PAGER_TID);
/* Obtain our utcb page address */
utcb_page = l4_utcb_page();
//printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
// (unsigned long)utcb_page);
/* Use it as a key to create a shared memory region */
BUG_ON((shmid = shmget((key_t)utcb_page,
PAGE_SIZE, IPC_CREAT)) < 0);
/* Attach to the region */
BUG_ON((shmaddr = shmat(shmid, utcb_page, 0)) < 0);
BUG_ON(shmaddr != utcb_page);
return 0;
posix_init();
main();
}

View File

@@ -3,6 +3,7 @@
*
* Copyright (C) 2008 Bahadir Balban
*/
#include <shpage.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
@@ -23,8 +24,8 @@ static inline int l4_mkdir(const char *pathname, mode_t mode)
int fd;
// write_mr(L4SYS_ARG0, (unsigned long)pathname);
copy_to_utcb((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
write_mr(L4SYS_ARG1, (u32)mode);
/* Call pager with shmget() request. Check ipc error. */

View File

@@ -3,6 +3,7 @@
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
@@ -17,13 +18,14 @@
#include <fcntl.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
#include <shpage.h>
static inline int l4_open(const char *pathname, int flags, mode_t mode)
{
int fd;
copy_to_utcb((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
write_mr(L4SYS_ARG1, flags);
write_mr(L4SYS_ARG2, (u32)mode);

View File

@@ -3,6 +3,7 @@
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -14,14 +15,14 @@
#include <l4lib/os/posix/readdir.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
#include <shpage.h>
static inline int l4_readdir(int fd, void *buf, size_t count)
{
int cnt;
write_mr(L4SYS_ARG0, fd);
write_mr(L4SYS_ARG1, (unsigned long)utcb_page);
write_mr(L4SYS_ARG1, (unsigned long)shared_page);
write_mr(L4SYS_ARG2, count);
/* Call pager with readdir() request. Check ipc error. */
@@ -36,7 +37,7 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
}
copy_from_utcb(buf, 0, cnt);
copy_from_shpage(buf, 0, cnt);
return cnt;
}

96
tasks/libposix/shpage.c Normal file
View File

@@ -0,0 +1,96 @@
/*
* Initialise posix-related structures.
*
* Copyright (C) 2007-2009 Bahadir Balban
*/
#include <l4lib/kip.h>
#include <l4lib/arch/syslib.h>
#include <l4lib/arch/utcb.h>
#include <l4lib/ipcdefs.h>
#include <l4/macros.h>
#include INC_GLUE(memlayout.h)
#include <stdio.h>
#include <shpage.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <shpage.h>
/*
* Shared page initialisation of posix-like tasks.
*
* POSIX tasks currently use a default shared page for communciation.
* This could have been also done by long ipc calls.
*/
/*
* Shared page for this task. Used for passing data among ipc
* parties when message registers are not big enough. Every thread
* has right to own one, and it has an address unique to every
* thread. It must be explicitly mapped by both parties of the ipc
* in order to be useful.
*/
void *shared_page;
/*
* Obtains a unique address for the task's shared page. Note this
* just returns the address. This address is used as an shm key
* to map it via shmget()/shmat() later on.
*/
static void *shared_page_address(void)
{
void *addr;
int err;
/* We're asking it for ourself. */
write_mr(L4SYS_ARG0, self_tid());
/* Call pager with utcb address request. Check ipc error. */
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
L4_IPC_TAG_SHPAGE)) < 0) {
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
return PTR_ERR(err);
}
/* Check if syscall itself was successful */
if (IS_ERR(addr = (void *)l4_get_retval())) {
printf("%s: Request UTCB Address Error: %d.\n",
__FUNCTION__, (int)addr);
return addr;
}
return addr;
}
/*
* Initialises a non-pager task's default shared memory page
* using posix semantics. Used during task initialisation
* and by child tasks after a fork.
*/
int shared_page_init(void)
{
int shmid;
void *shmaddr;
/*
* Initialise shared page only if we're not the pager.
* The pager does it differently for itself.
*/
BUG_ON(self_tid() == PAGER_TID);
/* Obtain our shared page address */
shared_page = shared_page_address();
//printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
// (unsigned long)shared_page);
/* Use it as a key to create a shared memory region */
BUG_ON((shmid = shmget((key_t)shared_page,
PAGE_SIZE, IPC_CREAT)) < 0);
/* Attach to the region */
BUG_ON((shmaddr = shmat(shmid, shared_page, 0)) < 0);
BUG_ON(shmaddr != shared_page);
return 0;
}

View File

@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
#include <shpage.h>
static inline int l4_fstat(int fd, void *buffer)
{
@@ -62,10 +63,10 @@ static inline int l4_stat(const char *pathname, void *buffer)
int err;
struct kstat ks;
copy_to_utcb((void *)pathname, 0, strlen(pathname) + 1);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
/* Pathname address on utcb page */
write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
/* Pass on buffer that should receive stat */
write_mr(L4SYS_ARG1, (unsigned long)&ks);

View File

@@ -7,7 +7,7 @@
/* Structures to use when sending new task information to vfs */
struct task_data {
unsigned long tid;
unsigned long utcb_address;
unsigned long shpage_address;
};
struct task_data_head {

View File

@@ -624,7 +624,7 @@ int vfs_send_task_data(struct tcb *vfs)
/* Write per-task data for all tasks */
list_for_each_entry(t, &global_tasks.list, list) {
tdata_head->tdata[li].tid = t->tid;
tdata_head->tdata[li].utcb_address = (unsigned long)t->shared_page;
tdata_head->tdata[li].shpage_address = (unsigned long)t->shared_page;
li++;
}