From 33fcceb2b6eea629b7136b1bf38e6b8b69c5fa74 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 12 May 2009 18:16:25 +0300 Subject: [PATCH] Added a shared memory test. - libposix error printing now configurable via macro definition - shmget/at/dt tested. --- tasks/libposix/chdir.c | 5 +-- tasks/libposix/close.c | 9 ++--- tasks/libposix/env.c | 1 + tasks/libposix/errno.c | 3 +- tasks/libposix/execve.c | 5 +-- tasks/libposix/exit.c | 3 +- tasks/libposix/fork.c | 9 ++--- tasks/libposix/getpid.c | 1 + tasks/libposix/include/libposix.h | 13 +++++++ tasks/libposix/init.c | 1 + tasks/libposix/lseek.c | 5 +-- tasks/libposix/mkdir.c | 5 +-- tasks/libposix/mmap.c | 13 +++---- tasks/libposix/open.c | 5 +-- tasks/libposix/read.c | 9 ++--- tasks/libposix/shm.c | 13 +++---- tasks/libposix/shpage.c | 7 ++-- tasks/libposix/stat.c | 9 ++--- tasks/libposix/time.c | 1 + tasks/libposix/write.c | 5 +-- tasks/mm0/src/shm.c | 12 ++----- tasks/test0/main.c | 9 ++++- tasks/test0/src/forktest.c | 2 -- tasks/test0/src/shmtest.c | 57 ++++++++++++++++++++----------- 24 files changed, 126 insertions(+), 76 deletions(-) create mode 100644 tasks/libposix/include/libposix.h diff --git a/tasks/libposix/chdir.c b/tasks/libposix/chdir.c index c069382..5169745 100644 --- a/tasks/libposix/chdir.c +++ b/tasks/libposix/chdir.c @@ -4,6 +4,7 @@ * Copyright (C) 2008 Bahadir Balban */ #include +#include #include #include #include @@ -27,12 +28,12 @@ static inline int l4_chdir(const char *pathname) /* Call pager with shmget() request. Check ipc error. */ if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: MKDIR Error: %d.\n", __FUNCTION__, fd); + print_err("%s: MKDIR Error: %d.\n", __FUNCTION__, fd); return fd; } return fd; diff --git a/tasks/libposix/close.c b/tasks/libposix/close.c index 19bf379..2e4fc46 100644 --- a/tasks/libposix/close.c +++ b/tasks/libposix/close.c @@ -12,6 +12,7 @@ #include #include #include INC_GLUE(memory.h) +#include static inline int l4_close(int fd) { @@ -19,12 +20,12 @@ static inline int l4_close(int fd) /* Call pager with close() request. Check ipc error. */ if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_CLOSE)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: CLOSE Error: %d.\n", __FUNCTION__, fd); + print_err("%s: CLOSE Error: %d.\n", __FUNCTION__, fd); return fd; } return fd; @@ -50,12 +51,12 @@ static inline int l4_fsync(int fd) /* Call pager with close() request. Check ipc error. */ if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FSYNC)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: CLOSE Error: %d.\n", __FUNCTION__, fd); + print_err("%s: CLOSE Error: %d.\n", __FUNCTION__, fd); return fd; } return fd; diff --git a/tasks/libposix/env.c b/tasks/libposix/env.c index 7b250ef..69aabee 100644 --- a/tasks/libposix/env.c +++ b/tasks/libposix/env.c @@ -5,6 +5,7 @@ */ #include #include +#include char **__environ; diff --git a/tasks/libposix/errno.c b/tasks/libposix/errno.c index 474e33c..03800ec 100644 --- a/tasks/libposix/errno.c +++ b/tasks/libposix/errno.c @@ -1,11 +1,12 @@ #include #include +#include int errno_variable; void perror(const char *str) { - printf("%s: %d\n", str, errno); + print_err("%s: %d\n", str, errno); } int *__errno_location(void) diff --git a/tasks/libposix/execve.c b/tasks/libposix/execve.c index ec0ea0a..a698c7d 100644 --- a/tasks/libposix/execve.c +++ b/tasks/libposix/execve.c @@ -17,6 +17,7 @@ #include #include #include INC_GLUE(memory.h) +#include struct sys_execve_args { @@ -36,12 +37,12 @@ static inline int l4_execve(const char *pathname, char *const argv[], char *cons /* Call pager with open() request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXECVE)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: OPEN Error: %d.\n", __FUNCTION__, err); + print_err("%s: OPEN Error: %d.\n", __FUNCTION__, err); return err; } diff --git a/tasks/libposix/exit.c b/tasks/libposix/exit.c index 79083ad..5708360 100644 --- a/tasks/libposix/exit.c +++ b/tasks/libposix/exit.c @@ -4,6 +4,7 @@ #include #include #include +#include static inline void __attribute__ ((noreturn)) l4_exit(int status) { @@ -15,7 +16,7 @@ static inline void __attribute__ ((noreturn)) l4_exit(int status) ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXIT); /* This call should not fail or return */ - printf("%s: L4 IPC returned: %d.\n", __FUNCTION__, ret); + print_err("%s: L4 IPC returned: %d.\n", __FUNCTION__, ret); BUG(); } diff --git a/tasks/libposix/fork.c b/tasks/libposix/fork.c index a2f17a5..dccd4cb 100644 --- a/tasks/libposix/fork.c +++ b/tasks/libposix/fork.c @@ -13,6 +13,7 @@ #include #include INC_GLUE(memory.h) #include +#include static inline int l4_fork(void) { @@ -20,12 +21,12 @@ static inline int l4_fork(void) /* Call pager with open() request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FORK)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: OPEN Error: %d.\n", __FUNCTION__, err); + print_err("%s: OPEN Error: %d.\n", __FUNCTION__, err); return err; } return err; @@ -74,12 +75,12 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...) /* Perform an ipc but with different return logic. See implementation. */ if ((ret = arch_clone(PAGER_TID, PAGER_TID)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret); return ret; } if ((ret = l4_get_retval()) < 0) { - printf("%s: CLONE Error: %d.\n", __FUNCTION__, ret); + print_err("%s: CLONE Error: %d.\n", __FUNCTION__, ret); return ret; } return ret; diff --git a/tasks/libposix/getpid.c b/tasks/libposix/getpid.c index 67ac8ca..d4f9287 100644 --- a/tasks/libposix/getpid.c +++ b/tasks/libposix/getpid.c @@ -3,6 +3,7 @@ #include #include #include +#include pid_t getpid(void) { diff --git a/tasks/libposix/include/libposix.h b/tasks/libposix/include/libposix.h new file mode 100644 index 0000000..d0f05db --- /dev/null +++ b/tasks/libposix/include/libposix.h @@ -0,0 +1,13 @@ +#ifndef __LIBPOSIX_H__ +#define __LIBPOSIX_H__ + +/* Abort debugging conditions */ +// #define LIBPOSIX_ERROR_MESSAGES +#if defined (LIBPOSIX_ERROR_MESSAGES) +#define print_err(...) printf(__VA_ARGS__) +#else +#define print_err(...) +#endif + + +#endif /* __LIBPOSIX_H__ */ diff --git a/tasks/libposix/init.c b/tasks/libposix/init.c index ca5d44c..d9c0a35 100644 --- a/tasks/libposix/init.c +++ b/tasks/libposix/init.c @@ -5,6 +5,7 @@ */ #include #include +#include void posix_service_init(void) { diff --git a/tasks/libposix/lseek.c b/tasks/libposix/lseek.c index 68a6e7d..f72794d 100644 --- a/tasks/libposix/lseek.c +++ b/tasks/libposix/lseek.c @@ -10,6 +10,7 @@ #include #include #include +#include static inline off_t l4_lseek(int fildes, off_t offset, int whence) { @@ -21,12 +22,12 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence) /* Call pager with shmget() request. Check ipc error. */ if ((offres = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_LSEEK)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, offres); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, offres); return offres; } /* Check if syscall itself was successful */ if ((offres = l4_get_retval()) < 0) { - printf("%s: OPEN Error: %d.\n", __FUNCTION__, (int)offres); + print_err("%s: OPEN Error: %d.\n", __FUNCTION__, (int)offres); return offres; } diff --git a/tasks/libposix/mkdir.c b/tasks/libposix/mkdir.c index 2ea78e4..c25342b 100644 --- a/tasks/libposix/mkdir.c +++ b/tasks/libposix/mkdir.c @@ -18,6 +18,7 @@ #include #include #include INC_GLUE(memory.h) +#include static inline int l4_mkdir(const char *pathname, mode_t mode) { @@ -30,12 +31,12 @@ static inline int l4_mkdir(const char *pathname, mode_t mode) /* Call pager with shmget() request. Check ipc error. */ if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_MKDIR)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: MKDIR Error: %d.\n", __FUNCTION__, fd); + print_err("%s: MKDIR Error: %d.\n", __FUNCTION__, fd); return fd; } return fd; diff --git a/tasks/libposix/mmap.c b/tasks/libposix/mmap.c index 5855b6c..9c4bac1 100644 --- a/tasks/libposix/mmap.c +++ b/tasks/libposix/mmap.c @@ -11,6 +11,7 @@ #include #include #include +#include /* FIXME: Implement the same separation that is in read.c write.c etc. such that * l4_syscall returns negative value and then the actual posix glue sets the errno @@ -43,12 +44,12 @@ static inline void *l4_mmap(void *start, size_t length, int prot, int flags, int /* Call pager with MMAP request. Check ipc error. */ if ((ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MMAP)) < 0) { - printf("%s: IPC Error: %d.\n", __FUNCTION__, ret); + print_err("%s: IPC Error: %d.\n", __FUNCTION__, ret); return PTR_ERR(ret); } if (IS_ERR(ret = l4_get_retval())) - printf("%s: MMAP Error: %d.\n", __FUNCTION__, ret); + print_err("%s: MMAP Error: %d.\n", __FUNCTION__, ret); return (void *)ret; } @@ -79,13 +80,13 @@ int l4_munmap(void *start, size_t length) /* Call pager with MMAP request. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MUNMAP)) < 0) { - printf("%s: IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: MUNMAP Error: %d.\n", __FUNCTION__, err); + print_err("%s: MUNMAP Error: %d.\n", __FUNCTION__, err); return err; } return 0; @@ -111,12 +112,12 @@ int l4_msync(void *start, size_t length, int flags) /* Call pager with MMAP request. */ if ((errno = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MSYNC)) < 0) { - printf("%s: IPC Error: %d.\n", __FUNCTION__, errno); + print_err("%s: IPC Error: %d.\n", __FUNCTION__, errno); return -1; } /* Check if syscall itself was successful */ if ((errno = l4_get_retval()) < 0) { - printf("%s: MSYNC Error: %d.\n", __FUNCTION__, errno); + print_err("%s: MSYNC Error: %d.\n", __FUNCTION__, errno); return -1; } return 0; diff --git a/tasks/libposix/open.c b/tasks/libposix/open.c index f267709..b12fb05 100644 --- a/tasks/libposix/open.c +++ b/tasks/libposix/open.c @@ -19,6 +19,7 @@ #include #include INC_GLUE(memory.h) #include +#include static inline int l4_open(const char *pathname, int flags, mode_t mode) { @@ -31,12 +32,12 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode) /* Call pager with open() request. Check ipc error. */ if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_OPEN)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: OPEN Error: %d, for path %s\n", + print_err("%s: OPEN Error: %d, for path %s\n", __FUNCTION__, fd, pathname); return fd; } diff --git a/tasks/libposix/read.c b/tasks/libposix/read.c index 283c25c..5dd9c88 100644 --- a/tasks/libposix/read.c +++ b/tasks/libposix/read.c @@ -16,6 +16,7 @@ #include #include INC_GLUE(memory.h) #include +#include static inline int l4_readdir(int fd, void *buf, size_t count) { @@ -27,12 +28,12 @@ static inline int l4_readdir(int fd, void *buf, size_t count) /* Call pager with readdir() request. Check ipc error. */ if ((cnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_READDIR)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt); return cnt; } /* Check if syscall itself was successful */ if ((cnt = l4_get_retval()) < 0) { - printf("%s: READDIR Error: %d.\n", __FUNCTION__, (int)cnt); + print_err("%s: READDIR Error: %d.\n", __FUNCTION__, (int)cnt); return cnt; } @@ -51,12 +52,12 @@ static inline int l4_read(int fd, void *buf, size_t count) /* Call pager with read() request. Check ipc error. */ if ((cnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_READ)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, cnt); return cnt; } /* Check if syscall itself was successful */ if ((cnt = l4_get_retval()) < 0) { - printf("%s: READ Error: %d.\n", __FUNCTION__, (int)cnt); + print_err("%s: READ Error: %d.\n", __FUNCTION__, (int)cnt); return cnt; } diff --git a/tasks/libposix/shm.c b/tasks/libposix/shm.c index 4cb7a9e..6094e74 100644 --- a/tasks/libposix/shm.c +++ b/tasks/libposix/shm.c @@ -12,6 +12,7 @@ #include #include #include +#include int l4_shmget(l4id_t key, int size, int shmflg) { @@ -23,12 +24,12 @@ int l4_shmget(l4id_t key, int size, int shmflg) /* Call pager with shmget() request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMGET)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if (IS_ERR(err = l4_get_retval())) { - printf("%s: SHMGET Error: %d.\n", __FUNCTION__, err); + print_err("%s: SHMGET Error: %d.\n", __FUNCTION__, err); return err; } @@ -46,12 +47,12 @@ void *l4_shmat(l4id_t shmid, const void *shmaddr, int shmflg) /* Call pager with shmget() request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMAT)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return PTR_ERR(err); } /* Check if syscall itself was successful */ if (IS_ERR(err = l4_get_retval())) { - printf("%s: SHMAT Error: %d.\n", __FUNCTION__, err); + print_err("%s: SHMAT Error: %d.\n", __FUNCTION__, err); return PTR_ERR(err); } @@ -67,12 +68,12 @@ int l4_shmdt(const void *shmaddr) /* Call pager with shmget() request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMDT)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return -1; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: SHMDT Error: %d.\n", __FUNCTION__, err); + print_err("%s: SHMDT Error: %d.\n", __FUNCTION__, err); return -1; } return 0; diff --git a/tasks/libposix/shpage.c b/tasks/libposix/shpage.c index fc931a7..cb3997a 100644 --- a/tasks/libposix/shpage.c +++ b/tasks/libposix/shpage.c @@ -14,6 +14,7 @@ #include #include #include +#include /* * Shared page initialisation of posix-like tasks. @@ -47,13 +48,13 @@ static void *shared_page_address(void) /* 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); + print_err("%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", + print_err("%s: Request UTCB Address Error: %d.\n", __FUNCTION__, (int)addr); return addr; } @@ -80,7 +81,7 @@ int shared_page_init(void) /* Obtain our shared page address */ shared_page = shared_page_address(); - //printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__, + //print_err("%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 */ diff --git a/tasks/libposix/stat.c b/tasks/libposix/stat.c index bafe519..34e98cb 100644 --- a/tasks/libposix/stat.c +++ b/tasks/libposix/stat.c @@ -19,6 +19,7 @@ #include #include INC_GLUE(memory.h) #include +#include static inline int l4_fstat(int fd, void *buffer) { @@ -30,12 +31,12 @@ static inline int l4_fstat(int fd, void *buffer) /* Call pager with open() request. Check ipc error. */ if ((err = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_FSTAT)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: FSTAT Error: %d.\n", __FUNCTION__, err); + print_err("%s: FSTAT Error: %d.\n", __FUNCTION__, err); return err; } return err; @@ -73,13 +74,13 @@ static inline int l4_stat(const char *pathname, void *buffer) /* Call vfs with stat() request. Check ipc error. */ if ((err = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_STAT)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); return err; } /* Check if syscall itself was successful */ if ((err = l4_get_retval()) < 0) { - printf("%s: STAT Error: %d.\n", __FUNCTION__, err); + print_err("%s: STAT Error: %d.\n", __FUNCTION__, err); return err; } diff --git a/tasks/libposix/time.c b/tasks/libposix/time.c index 189905e..0341bd7 100644 --- a/tasks/libposix/time.c +++ b/tasks/libposix/time.c @@ -2,6 +2,7 @@ #include #include #include +#include int gettimeofday(struct timeval *tv, struct timezone *tz) { diff --git a/tasks/libposix/write.c b/tasks/libposix/write.c index 7214359..60d1cb6 100644 --- a/tasks/libposix/write.c +++ b/tasks/libposix/write.c @@ -10,6 +10,7 @@ #include #include #include +#include static inline int l4_write(int fd, const void *buf, size_t count) { @@ -21,12 +22,12 @@ static inline int l4_write(int fd, const void *buf, size_t count) /* Call pager with write() request. Check ipc error. */ if ((wrcnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_WRITE)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt); + print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt); return wrcnt; } /* Check if syscall itself was successful */ if ((wrcnt = l4_get_retval()) < 0) { - printf("%s: WRITE Error: %d.\n", __FUNCTION__, (int)wrcnt); + print_err("%s: WRITE Error: %d.\n", __FUNCTION__, (int)wrcnt); return wrcnt; } diff --git a/tasks/mm0/src/shm.c b/tasks/mm0/src/shm.c index 68a588a..d718768 100644 --- a/tasks/mm0/src/shm.c +++ b/tasks/mm0/src/shm.c @@ -155,17 +155,11 @@ int do_shmdt(struct tcb *task, struct vm_file *shm) int sys_shmdt(struct tcb *task, const void *shmaddr) { struct vm_file *shm_file, *n; - int err; - list_for_each_entry_safe(shm_file, n, &global_vm_files.list, list) { + list_for_each_entry_safe(shm_file, n, &global_vm_files.list, list) if (shm_file->type == VM_FILE_SHM && - shm_file_to_desc(shm_file)->shm_addr == shmaddr) { - if ((err = do_shmdt(task, shm_file) < 0)) - return err; - else - break; - } - } + shm_file_to_desc(shm_file)->shm_addr == shmaddr) + return do_shmdt(task, shm_file); return -EINVAL; } diff --git a/tasks/test0/main.c b/tasks/test0/main.c index 284677a..fd34ac1 100644 --- a/tasks/test0/main.c +++ b/tasks/test0/main.c @@ -22,9 +22,14 @@ void wait_pager(l4id_t partner) // printf("Pager synced with us.\n"); } +pid_t parent_of_all; + void main(void) { - printf("\n%s: Started with thread id %d\n", __TASKNAME__, self_tid()); + + printf("\n%s: Started with thread id %d\n", __TASKNAME__, getpid()); + + parent_of_all = getpid(); wait_pager(0); @@ -34,6 +39,8 @@ void main(void) mmaptest(); + shmtest(); + forktest(); fileio(); diff --git a/tasks/test0/src/forktest.c b/tasks/test0/src/forktest.c index 72ed85d..19b64a2 100644 --- a/tasks/test0/src/forktest.c +++ b/tasks/test0/src/forktest.c @@ -10,13 +10,11 @@ int global = 0; -pid_t parent_of_all; int forktest(void) { pid_t myid; - parent_of_all = getpid(); /* 16 forks */ for (int i = 0; i < 4; i++) diff --git a/tasks/test0/src/shmtest.c b/tasks/test0/src/shmtest.c index 2499bbb..742c2e5 100644 --- a/tasks/test0/src/shmtest.c +++ b/tasks/test0/src/shmtest.c @@ -9,6 +9,7 @@ #include #include #include +#include int shmtest(void) { @@ -17,35 +18,53 @@ int shmtest(void) void *bases[2] = { 0 , 0 }; int shmids[2]; - printf("Initiating shmget()\n"); + test_printf("Initiating shmget()\n"); for (int i = 0; i < 2; i++) { if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) { - printf("Call failed.\n"); - perror("SHMGET"); + test_printf("SHMGET", errno); + goto out_err; } else - printf("SHMID returned: %d\n", shmids[i]); + test_printf("SHMID returned: %d\n", shmids[i]); } - printf("Now shmat()\n"); + test_printf("Now shmat()\n"); for (int i = 0; i < 2; i++) { - if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1) - perror("SHMAT"); - else - printf("SHM base address returned: %p\n", bases[i]); + if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1) { + test_printf("SHMAT", errno); + goto out_err; + } else + test_printf("SHM base address returned: %p\n", bases[i]); } - printf("Now shmdt()\n"); + /* Write to the bases */ + *((unsigned int *)bases[0]) = 0xDEADBEEF; + *((unsigned int *)bases[1]) = 0xFEEDBEEF; + + test_printf("Now shmdt()\n"); for (int i = 0; i < 2; i++) { - if (shmdt(bases[i]) < 0) - perror("SHMDT"); - else - printf("SHM detached OK.\n"); + if (shmdt(bases[i]) < 0) { + test_printf("SHMDT", errno); + goto out_err; + } else + test_printf("SHM detached OK.\n"); } - printf("Now shmat() again\n"); + test_printf("Now shmat() again\n"); for (int i = 0; i < 2; i++) { - if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1) - perror("SHMAT"); - else - printf("SHM base address returned: %p\n", bases[i]); + bases[i] = shmat(shmids[i], NULL, 0); + + /* SHMAT should fail since no refs were left in last detach */ + if ((int)bases[i] != -1) { + test_printf("SHM base address returned: %p, " + "but it should have failed\n", bases[i]); + goto out_err; + } } + if (getpid() == parent_of_all) + printf("SHM TEST -- PASSED --\n"); + return 0; + +out_err: + printf("SHM TEST -- FAILED --\n"); + return 0; + }