os_readdir() now using utcb as dirent buffer.

This commit is contained in:
Bahadir Balban
2008-04-13 16:32:34 +01:00
parent 2efffdfa88
commit 7b2f9f96cf
11 changed files with 46 additions and 21 deletions

View File

@@ -257,6 +257,13 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
/* Get the task */ /* Get the task */
BUG_ON(!(t = find_task(sender))); BUG_ON(!(t = find_task(sender)));
/* Check address is in task's utcb */
if ((unsigned long)buf < t->utcb_address ||
(unsigned long)buf > t->utcb_address + PAGE_SIZE) {
l4_ipc_return(-EINVAL);
return 0;
}
/* Convert fd to vnum. */ /* Convert fd to vnum. */
BUG_ON((vnum = t->fd[fd]) < 0); BUG_ON((vnum = t->fd[fd]) < 0);

View File

@@ -141,8 +141,8 @@ int task_utcb_attach(struct tcb *t)
if ((unsigned long)shmaddr != t->utcb_address) if ((unsigned long)shmaddr != t->utcb_address)
return -EINVAL; return -EINVAL;
//printf("%s: Mapped utcb of task %d @ 0x%x\n", printf("%s: Mapped utcb of task %d @ 0x%x\n",
// __TASKNAME__, t->tid, shmaddr); __TASKNAME__, t->tid, shmaddr);
return 0; return 0;

View File

@@ -9,6 +9,9 @@
#include <l4lib/types.h> #include <l4lib/types.h>
#include <l4/macros.h> #include <l4/macros.h>
#include INC_GLUE(message.h) #include INC_GLUE(message.h)
#include INC_GLUE(memory.h)
#include <string.h>
#include <stdio.h>
/* /*
* NOTE: In syslib.h the first few mrs are used by data frequently * NOTE: In syslib.h the first few mrs are used by data frequently
@@ -43,6 +46,25 @@ static inline void write_mr(unsigned int offset, unsigned int val)
{ {
l4_get_utcb()->mr[offset] = 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 void copy_to_utcb(void *arg, int offset, int size)
{
BUG_ON(size > PAGE_SIZE);
memcpy(utcb_page, arg, size);
}
static inline void copy_from_utcb(void *buf, int offset, int size)
{
BUG_ON(size > PAGE_SIZE);
memcpy(buf, utcb_page + offset, size);
}
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
#endif /* __ARM_UTCB_H__ */ #endif /* __ARM_UTCB_H__ */

View File

@@ -90,8 +90,8 @@ int utcb_init(void)
/* Obtain our utcb page address */ /* Obtain our utcb page address */
utcb_page = l4_utcb_page(); utcb_page = l4_utcb_page();
//printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__, printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
// (unsigned long)utcb_page); (unsigned long)utcb_page);
/* Use it as a key to create a shared memory region */ /* Use it as a key to create a shared memory region */
BUG_ON((shmid = shmget((key_t)utcb_page, BUG_ON((shmid = shmget((key_t)utcb_page,

View File

@@ -18,23 +18,12 @@
#include <l4/macros.h> #include <l4/macros.h>
#include INC_GLUE(memory.h) #include INC_GLUE(memory.h)
/*
* 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.
*/
void *copy_to_utcb(void *arg, int size)
{
BUG_ON(size > PAGE_SIZE);
memcpy(utcb_page, arg, size);
}
static inline int l4_open(const char *pathname, int flags, mode_t mode) static inline int l4_open(const char *pathname, int flags, mode_t mode)
{ {
int fd; int fd;
// write_mr(L4SYS_ARG0, (unsigned long)pathname); // write_mr(L4SYS_ARG0, (unsigned long)pathname);
copy_to_utcb((void *)pathname, strlen(pathname)); copy_to_utcb((void *)pathname, 0, strlen(pathname));
write_mr(L4SYS_ARG0, (unsigned long)utcb_page); write_mr(L4SYS_ARG0, (unsigned long)utcb_page);
write_mr(L4SYS_ARG1, flags); write_mr(L4SYS_ARG1, flags);
write_mr(L4SYS_ARG2, (u32)mode); write_mr(L4SYS_ARG2, (u32)mode);

View File

@@ -5,19 +5,23 @@
*/ */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <l4lib/arch/syscalls.h> #include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h> #include <l4lib/arch/syslib.h>
#include <l4lib/ipcdefs.h> #include <l4lib/ipcdefs.h>
#include <l4lib/os/posix/readdir.h> #include <l4lib/os/posix/readdir.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
static inline int l4_readdir(int fd, void *buf, size_t count) static inline int l4_readdir(int fd, void *buf, size_t count)
{ {
size_t cnt; size_t cnt;
write_mr(L4SYS_ARG0, fd); write_mr(L4SYS_ARG0, fd);
write_mr(L4SYS_ARG1, (unsigned long)buf); write_mr(L4SYS_ARG1, (unsigned long)utcb_page);
write_mr(L4SYS_ARG2, count); write_mr(L4SYS_ARG2, count);
/* Call pager with readdir() request. Check ipc error. */ /* Call pager with readdir() request. Check ipc error. */
@@ -31,6 +35,8 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
return cnt; return cnt;
} }
copy_from_utcb(buf, 0, cnt);
return cnt; return cnt;
} }

View File

@@ -14,7 +14,7 @@
#include <arch/mm.h> #include <arch/mm.h>
#include <lib/spinlock.h> #include <lib/spinlock.h>
// #define DEBUG_FAULT_HANDLING #define DEBUG_FAULT_HANDLING
#ifdef DEBUG_FAULT_HANDLING #ifdef DEBUG_FAULT_HANDLING
#define dprintf(...) printf(__VA_ARGS__) #define dprintf(...) printf(__VA_ARGS__)
#else #else

View File

@@ -9,7 +9,6 @@
#include <mmap.h> #include <mmap.h>
#include <utcb.h> #include <utcb.h>
#include <vm_area.h> #include <vm_area.h>
#include <l4/lib/string.h>
#include <kmalloc/kmalloc.h> #include <kmalloc/kmalloc.h>
#include <l4lib/arch/syscalls.h> #include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h> #include <l4lib/arch/syslib.h>

View File

@@ -1,6 +1,8 @@
#ifndef __TEST0_TESTS_H__ #ifndef __TEST0_TESTS_H__
#define __TEST0_TESTS_H__ #define __TEST0_TESTS_H__
#define __TASKNAME__ "test0"
int shmtest(void); int shmtest(void);
int mmaptest(void); int mmaptest(void);
int dirtest(void); int dirtest(void);

View File

@@ -11,7 +11,6 @@
#include <l4lib/ipcdefs.h> #include <l4lib/ipcdefs.h>
#include <tests.h> #include <tests.h>
#define __TASKNAME__ "test0"
void wait_pager(l4id_t partner) void wait_pager(l4id_t partner)
{ {

View File

@@ -12,6 +12,7 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <l4lib/os/posix/readdir.h> #include <l4lib/os/posix/readdir.h>
#include <tests.h>
#define DENTS_TOTAL 50 #define DENTS_TOTAL 50
@@ -116,7 +117,7 @@ int lsdir(char *path)
printf("OPEN OK.\n"); printf("OPEN OK.\n");
if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) { if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) {
perror("GETDENTS"); printf("%s: GETDENTS failed.\n", __TASKNAME__);
return 0; return 0;
} else { } else {
printf("GETDENTS OK.\n"); printf("GETDENTS OK.\n");