diff --git a/conts/libl4/include/l4lib/arch-arm/utcb.h b/conts/libl4/include/l4lib/arch-arm/utcb.h index 674ca7e..a6171eb 100644 --- a/conts/libl4/include/l4lib/arch-arm/utcb.h +++ b/conts/libl4/include/l4lib/arch-arm/utcb.h @@ -11,6 +11,7 @@ #ifndef __ASSEMBLY__ #include #include +#include #include INC_GLUE(message.h) #include INC_GLUE(memory.h) #include @@ -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__ */ diff --git a/conts/posix/libposix/SConscript b/conts/posix/libposix/SConscript index 0ad256e..cda7781 100644 --- a/conts/posix/libposix/SConscript +++ b/conts/posix/libposix/SConscript @@ -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) diff --git a/conts/posix/libposix/chdir.c b/conts/posix/libposix/chdir.c index 5169745..77b8dad 100644 --- a/conts/posix/libposix/chdir.c +++ b/conts/posix/libposix/chdir.c @@ -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; } diff --git a/conts/posix/libposix/fork.c b/conts/posix/libposix/fork.c index 4072bf8..ef1726a 100644 --- a/conts/posix/libposix/fork.c +++ b/conts/posix/libposix/fork.c @@ -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; } diff --git a/conts/posix/libposix/mkdir.c b/conts/posix/libposix/mkdir.c index c25342b..856ca62 100644 --- a/conts/posix/libposix/mkdir.c +++ b/conts/posix/libposix/mkdir.c @@ -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; } diff --git a/conts/posix/libposix/open.c b/conts/posix/libposix/open.c index b12fb05..0231f26 100644 --- a/conts/posix/libposix/open.c +++ b/conts/posix/libposix/open.c @@ -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; } diff --git a/conts/posix/libposix/read.c b/conts/posix/libposix/read.c index 5dd9c88..dfe37f1 100644 --- a/conts/posix/libposix/read.c +++ b/conts/posix/libposix/read.c @@ -18,16 +18,26 @@ #include #include +/* + * 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; } diff --git a/conts/posix/libposix/stat.c b/conts/posix/libposix/stat.c index 1ba5c0e..ed27bee 100644 --- a/conts/posix/libposix/stat.c +++ b/conts/posix/libposix/stat.c @@ -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; } diff --git a/conts/posix/mm0/main.c b/conts/posix/mm0/main.c index 9b11b5d..0939f89 100644 --- a/conts/posix/mm0/main.c +++ b/conts/posix/mm0/main.c @@ -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]); diff --git a/include/l4/glue/arm/message.h b/include/l4/glue/arm/message.h index e49238e..24210f6 100644 --- a/include/l4/glue/arm/message.h +++ b/include/l4/glue/arm/message.h @@ -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__) diff --git a/include/l4/lib/math.h b/include/l4/lib/math.h index d5ce96e..2752f6d 100644 --- a/include/l4/lib/math.h +++ b/include/l4/lib/math.h @@ -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,