Removed all references th shared page from libposix

Added UTCB functions for full ipc that copy buffer or string payloads
in secondary message registers.

Some posix syscalls now use these utcb functions to copy pathnames.
This commit is contained in:
Bahadir Balban
2009-10-07 22:59:34 +03:00
parent 96cd0949b6
commit cb561ab262
11 changed files with 70 additions and 34 deletions

View File

@@ -11,6 +11,7 @@
#ifndef __ASSEMBLY__
#include <l4lib/types.h>
#include <l4/macros.h>
#include <l4/lib/math.h>
#include INC_GLUE(message.h)
#include INC_GLUE(memory.h)
#include <string.h>
@@ -41,10 +42,11 @@ extern struct utcb **kip_utcb_ref;
static inline struct utcb *l4_get_utcb()
{
/*
* By double dereferencing, we get the private TLS (aka UTCB). First
* reference is to the KIP's utcb offset, second is to the utcb itself,
* to which the KIP's utcb reference had been updated during context
* switch.
* By double dereferencing, we get the private TLS
* (aka UTCB). First reference is to the KIP's utcb
* offset, second is to the utcb itself, to which
* the KIP's utcb reference had been updated during
* context switch.
*/
return *kip_utcb_ref;
}
@@ -66,6 +68,36 @@ static inline void write_mr(unsigned int offset, unsigned int val)
l4_get_utcb()->mr_rest[offset - MR_TOTAL] = val;
}
static inline void *utcb_full_buffer()
{
return &l4_get_utcb()->mr_rest[0];
}
static inline char *utcb_full_strcpy_from(const char *src)
{
return strncpy((char *)&l4_get_utcb()->mr_rest[0], src,
L4_UTCB_FULL_BUFFER_SIZE);
}
static inline void *utcb_full_memcpy_from(const char *src, int size)
{
return memcpy(&l4_get_utcb()->mr_rest[0], src,
min(size, L4_UTCB_FULL_BUFFER_SIZE));
}
static inline char *utcb_full_strcpy_to(char *dst)
{
return strncpy(dst, (char *)&l4_get_utcb()->mr_rest[0],
L4_UTCB_FULL_BUFFER_SIZE);
}
static inline void *utcb_full_memcpy_to(char *dst, int size)
{
return memcpy(dst, &l4_get_utcb()->mr_rest[0],
min(size, L4_UTCB_FULL_BUFFER_SIZE));
}
#endif /* !__ASSEMBLY__ */
#endif /* __ARM_UTCB_H__ */

View File

@@ -8,7 +8,7 @@ Import('env')
e = env.Clone()
e.Append(CPPPATH = ['include', 'include/posix'])
e.Replace(CCFLAGS = ['-g', '-nostdlib', '-Wall', '-ffreestanding', '-std=gnu99'])
e.Replace(CCFLAGS = ['-g', '-nostdlib', '-Wall', '-Werror', '-ffreestanding', '-std=gnu99'])
objects = e.StaticObject(Glob('*.c'))
libposix = e.StaticLibrary('posix', objects)

View File

@@ -22,12 +22,12 @@ static inline int l4_chdir(const char *pathname)
{
int fd;
// write_mr(L4SYS_ARG0, (unsigned long)pathname);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
utcb_full_strcpy_from(pathname);
write_mr(L4SYS_ARG0, (unsigned long)utcb_full_buffer());
/* Call pager with shmget() request. Check ipc error. */
if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 0) {
if ((fd = l4_sendrecv_full(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
return fd;
}

View File

@@ -42,13 +42,6 @@ int fork(void)
return -1;
}
/*
* If we're a child, we need to initialise the default
* shared page via libposix_init()
*/
if (ret == 0)
shared_page_init();
return ret;
}

View File

@@ -25,12 +25,12 @@ static inline int l4_mkdir(const char *pathname, mode_t mode)
int fd;
// write_mr(L4SYS_ARG0, (unsigned long)pathname);
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
utcb_full_strcpy_from(pathname);
write_mr(L4SYS_ARG0, (unsigned long)utcb_full_buffer());
write_mr(L4SYS_ARG1, (u32)mode);
/* Call pager with shmget() request. Check ipc error. */
if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_MKDIR)) < 0) {
if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_MKDIR)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
return fd;
}

View File

@@ -25,13 +25,12 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode)
{
int fd;
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);
utcb_full_strcpy_from(pathname);
write_mr(L4SYS_ARG0, flags);
write_mr(L4SYS_ARG1, (u32)mode);
/* Call pager with open() request. Check ipc error. */
if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_OPEN)) < 0) {
if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_OPEN)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
return fd;
}

View File

@@ -18,16 +18,26 @@
#include <shpage.h>
#include <libposix.h>
/*
* TODO:
*
* Do this as follows:
*
* A short ipc l4_send() to indicate request
* An extended l4_receive_extended() to get back extended buffer.
*
* Or do it just like read()
*/
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)shared_page);
write_mr(L4SYS_ARG1, (unsigned long)buf);
write_mr(L4SYS_ARG2, count);
/* Call pager with readdir() request. Check ipc error. */
if ((cnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_READDIR)) < 0) {
if ((cnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_READDIR)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt);
return cnt;
}
@@ -38,7 +48,6 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
}
copy_from_shpage(buf, 0, cnt);
return cnt;
}

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(VFS_TID, VFS_TID, L4_IPC_TAG_FSTAT)) < 0) {
if ((err = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_FSTAT)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
return err;
}
@@ -66,16 +66,16 @@ static inline int l4_stat(const char *pathname, void *buffer)
int err;
struct kstat ks;
copy_to_shpage((void *)pathname, 0, strlen(pathname) + 1);
utcb_full_strcpy_from(pathname);
/* Pathname address on utcb page */
write_mr(L4SYS_ARG0, (unsigned long)shared_page);
write_mr(L4SYS_ARG0, (unsigned long)utcb_full_buffer());
/* Pass on buffer that should receive stat */
write_mr(L4SYS_ARG1, (unsigned long)&ks);
/* Call vfs with stat() request. Check ipc error. */
if ((err = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_STAT)) < 0) {
if ((err = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_STAT)) < 0) {
print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
return err;
}

View File

@@ -156,7 +156,7 @@ void handle_requests(void)
/* FIXME: Fix all these syscalls to read any buffer data from the caller task's utcb. */
/* FS0 System calls */
case L4_IPC_TAG_OPEN:
ret = sys_open(sender, (void *)mr[0], (int)mr[1], (unsigned int)mr[2]);
ret = sys_open(sender, utcb_full_buffer(), (int)mr[0], (unsigned int)mr[1]);
break;
case L4_IPC_TAG_MKDIR:
ret = sys_mkdir(sender, (const char *)mr[0], (unsigned int)mr[1]);

View File

@@ -84,6 +84,9 @@
#define L4_IPC_EXTENDED_MAX_SIZE (SZ_1K*2)
/* Primaries aren't used for memcopy. Those ops use this as a parameter */
#define L4_UTCB_FULL_BUFFER_SIZE (MR_REST * sizeof(int))
#include INC_GLUE(memlayout.h)
#if defined (__KERNEL__)

View File

@@ -1,8 +1,8 @@
#ifndef __LIB_MATH_H__
#define __LIB_MATH_H__
#define min(x, y) (((x) < (y)) ? x : y)
#define max(x, y) (((x) > (y)) ? x : y)
#define min(x, y) (((x) < (y)) ? (x) : (y))
#define max(x, y) (((x) > (y)) ? (x) : (y))
/* Tests if ranges a-b intersect with range c-d */
static inline int set_intersection(unsigned long a, unsigned long b,