mirror of
https://github.com/drasko/codezero.git
synced 2026-07-22 07:05:24 +02:00
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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
6
tasks/libposix/include/posix/posix_init.h
Normal file
6
tasks/libposix/include/posix/posix_init.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef __POSIX_INIT_H__
|
||||
#define __POSIX_INIT_H__
|
||||
|
||||
void posix_init(void);
|
||||
|
||||
#endif /* __POSIX_INIT_H__ */
|
||||
45
tasks/libposix/include/posix/shpage.h
Normal file
45
tasks/libposix/include/posix/shpage.h
Normal 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__ */
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
96
tasks/libposix/shpage.c
Normal 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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user