mirror of
https://github.com/drasko/codezero.git
synced 2026-02-27 09:13:13 +01:00
Added a shared memory test.
- libposix error printing now configurable via macro definition - shmget/at/dt tested.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
* Copyright (C) 2008 Bahadir Balban
|
* Copyright (C) 2008 Bahadir Balban
|
||||||
*/
|
*/
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -27,12 +28,12 @@ static inline int l4_chdir(const char *pathname)
|
|||||||
|
|
||||||
/* Call pager with shmget() request. Check ipc error. */
|
/* 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(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;
|
return fd;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((fd = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <l4lib/utcb.h>
|
#include <l4lib/utcb.h>
|
||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
static inline int l4_close(int fd)
|
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. */
|
/* Call pager with close() request. Check ipc error. */
|
||||||
if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_CLOSE)) < 0) {
|
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;
|
return fd;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((fd = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
@@ -50,12 +51,12 @@ static inline int l4_fsync(int fd)
|
|||||||
|
|
||||||
/* Call pager with close() request. Check ipc error. */
|
/* Call pager with close() request. Check ipc error. */
|
||||||
if ((fd = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FSYNC)) < 0) {
|
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;
|
return fd;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((fd = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
char **__environ;
|
char **__environ;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
int errno_variable;
|
int errno_variable;
|
||||||
|
|
||||||
void perror(const char *str)
|
void perror(const char *str)
|
||||||
{
|
{
|
||||||
printf("%s: %d\n", str, errno);
|
print_err("%s: %d\n", str, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
int *__errno_location(void)
|
int *__errno_location(void)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
|
|
||||||
struct sys_execve_args {
|
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. */
|
/* Call pager with open() request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXECVE)) < 0) {
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <l4lib/ipcdefs.h>
|
#include <l4lib/ipcdefs.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
static inline void __attribute__ ((noreturn)) l4_exit(int status)
|
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);
|
ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_EXIT);
|
||||||
|
|
||||||
/* This call should not fail or return */
|
/* 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();
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
static inline int l4_fork(void)
|
static inline int l4_fork(void)
|
||||||
{
|
{
|
||||||
@@ -20,12 +21,12 @@ static inline int l4_fork(void)
|
|||||||
|
|
||||||
/* Call pager with open() request. Check ipc error. */
|
/* Call pager with open() request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FORK)) < 0) {
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
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. */
|
/* Perform an ipc but with different return logic. See implementation. */
|
||||||
if ((ret = arch_clone(PAGER_TID, PAGER_TID)) < 0) {
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <l4lib/arch/syslib.h>
|
#include <l4lib/arch/syslib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
pid_t getpid(void)
|
pid_t getpid(void)
|
||||||
{
|
{
|
||||||
|
|||||||
13
tasks/libposix/include/libposix.h
Normal file
13
tasks/libposix/include/libposix.h
Normal file
@@ -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__ */
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
#include <posix_init.h>
|
#include <posix_init.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
void posix_service_init(void)
|
void posix_service_init(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#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 <libposix.h>
|
||||||
|
|
||||||
static inline off_t l4_lseek(int fildes, off_t offset, int whence)
|
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. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((offres = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_LSEEK)) < 0) {
|
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;
|
return offres;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((offres = l4_get_retval()) < 0) {
|
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;
|
return offres;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
static inline int l4_mkdir(const char *pathname, mode_t mode)
|
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. */
|
/* 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(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;
|
return fd;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((fd = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#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 <libposix.h>
|
||||||
|
|
||||||
/* FIXME: Implement the same separation that is in read.c write.c etc. such that
|
/* 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
|
* 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. */
|
/* Call pager with MMAP request. Check ipc error. */
|
||||||
if ((ret = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MMAP)) < 0) {
|
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);
|
return PTR_ERR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ERR(ret = l4_get_retval()))
|
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;
|
return (void *)ret;
|
||||||
}
|
}
|
||||||
@@ -79,13 +80,13 @@ int l4_munmap(void *start, size_t length)
|
|||||||
|
|
||||||
/* Call pager with MMAP request. */
|
/* Call pager with MMAP request. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MUNMAP)) < 0) {
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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 err;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -111,12 +112,12 @@ int l4_msync(void *start, size_t length, int flags)
|
|||||||
|
|
||||||
/* Call pager with MMAP request. */
|
/* Call pager with MMAP request. */
|
||||||
if ((errno = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_MSYNC)) < 0) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((errno = l4_get_retval()) < 0) {
|
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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -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. */
|
/* 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(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;
|
return fd;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((fd = l4_get_retval()) < 0) {
|
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);
|
__FUNCTION__, fd, pathname);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.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)
|
||||||
{
|
{
|
||||||
@@ -27,12 +28,12 @@ static inline int l4_readdir(int fd, void *buf, size_t count)
|
|||||||
|
|
||||||
/* Call pager with readdir() request. Check ipc error. */
|
/* 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(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;
|
return cnt;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((cnt = l4_get_retval()) < 0) {
|
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;
|
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. */
|
/* Call pager with read() request. Check ipc error. */
|
||||||
if ((cnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_READ)) < 0) {
|
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;
|
return cnt;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((cnt = l4_get_retval()) < 0) {
|
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;
|
return cnt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <l4lib/arch/syslib.h>
|
#include <l4lib/arch/syslib.h>
|
||||||
#include <l4lib/ipcdefs.h>
|
#include <l4lib/ipcdefs.h>
|
||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
int l4_shmget(l4id_t key, int size, int shmflg)
|
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. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMGET)) < 0) {
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if (IS_ERR(err = l4_get_retval())) {
|
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;
|
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. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMAT)) < 0) {
|
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);
|
return PTR_ERR(err);
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if (IS_ERR(err = l4_get_retval())) {
|
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);
|
return PTR_ERR(err);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -67,12 +68,12 @@ int l4_shmdt(const void *shmaddr)
|
|||||||
|
|
||||||
/* Call pager with shmget() request. Check ipc error. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_SHMDT)) < 0) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shared page initialisation of posix-like tasks.
|
* 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. */
|
/* Call pager with utcb address request. Check ipc error. */
|
||||||
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
|
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
|
||||||
L4_IPC_TAG_SHPAGE)) < 0) {
|
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);
|
return PTR_ERR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if (IS_ERR(addr = (void *)l4_get_retval())) {
|
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);
|
__FUNCTION__, (int)addr);
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ int shared_page_init(void)
|
|||||||
/* Obtain our shared page address */
|
/* Obtain our shared page address */
|
||||||
shared_page = 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);
|
// (unsigned long)shared_page);
|
||||||
|
|
||||||
/* Use it as a key to create a shared memory region */
|
/* Use it as a key to create a shared memory region */
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <l4/macros.h>
|
#include <l4/macros.h>
|
||||||
#include INC_GLUE(memory.h)
|
#include INC_GLUE(memory.h)
|
||||||
#include <shpage.h>
|
#include <shpage.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
static inline int l4_fstat(int fd, void *buffer)
|
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. */
|
/* 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(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;
|
return err;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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;
|
||||||
}
|
}
|
||||||
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. */
|
/* 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(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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <l4lib/arch/syscalls.h>
|
#include <l4lib/arch/syscalls.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <libposix.h>
|
||||||
|
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#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 <libposix.h>
|
||||||
|
|
||||||
static inline int l4_write(int fd, const void *buf, size_t count)
|
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. */
|
/* Call pager with write() request. Check ipc error. */
|
||||||
if ((wrcnt = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_WRITE)) < 0) {
|
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;
|
return wrcnt;
|
||||||
}
|
}
|
||||||
/* Check if syscall itself was successful */
|
/* Check if syscall itself was successful */
|
||||||
if ((wrcnt = l4_get_retval()) < 0) {
|
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;
|
return wrcnt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,17 +155,11 @@ int do_shmdt(struct tcb *task, struct vm_file *shm)
|
|||||||
int sys_shmdt(struct tcb *task, const void *shmaddr)
|
int sys_shmdt(struct tcb *task, const void *shmaddr)
|
||||||
{
|
{
|
||||||
struct vm_file *shm_file, *n;
|
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 &&
|
if (shm_file->type == VM_FILE_SHM &&
|
||||||
shm_file_to_desc(shm_file)->shm_addr == shmaddr) {
|
shm_file_to_desc(shm_file)->shm_addr == shmaddr)
|
||||||
if ((err = do_shmdt(task, shm_file) < 0))
|
return do_shmdt(task, shm_file);
|
||||||
return err;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,14 @@ void wait_pager(l4id_t partner)
|
|||||||
// printf("Pager synced with us.\n");
|
// printf("Pager synced with us.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t parent_of_all;
|
||||||
|
|
||||||
void main(void)
|
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);
|
wait_pager(0);
|
||||||
|
|
||||||
@@ -34,6 +39,8 @@ void main(void)
|
|||||||
|
|
||||||
mmaptest();
|
mmaptest();
|
||||||
|
|
||||||
|
shmtest();
|
||||||
|
|
||||||
forktest();
|
forktest();
|
||||||
|
|
||||||
fileio();
|
fileio();
|
||||||
|
|||||||
@@ -10,13 +10,11 @@
|
|||||||
|
|
||||||
int global = 0;
|
int global = 0;
|
||||||
|
|
||||||
pid_t parent_of_all;
|
|
||||||
|
|
||||||
int forktest(void)
|
int forktest(void)
|
||||||
{
|
{
|
||||||
pid_t myid;
|
pid_t myid;
|
||||||
|
|
||||||
parent_of_all = getpid();
|
|
||||||
|
|
||||||
/* 16 forks */
|
/* 16 forks */
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int shmtest(void)
|
int shmtest(void)
|
||||||
{
|
{
|
||||||
@@ -17,35 +18,53 @@ int shmtest(void)
|
|||||||
void *bases[2] = { 0 , 0 };
|
void *bases[2] = { 0 , 0 };
|
||||||
int shmids[2];
|
int shmids[2];
|
||||||
|
|
||||||
printf("Initiating shmget()\n");
|
test_printf("Initiating shmget()\n");
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) {
|
if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) {
|
||||||
printf("Call failed.\n");
|
test_printf("SHMGET", errno);
|
||||||
perror("SHMGET");
|
goto out_err;
|
||||||
} else
|
} 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++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
|
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1) {
|
||||||
perror("SHMAT");
|
test_printf("SHMAT", errno);
|
||||||
else
|
goto out_err;
|
||||||
printf("SHM base address returned: %p\n", bases[i]);
|
} 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++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if (shmdt(bases[i]) < 0)
|
if (shmdt(bases[i]) < 0) {
|
||||||
perror("SHMDT");
|
test_printf("SHMDT", errno);
|
||||||
else
|
goto out_err;
|
||||||
printf("SHM detached OK.\n");
|
} 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++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
|
bases[i] = shmat(shmids[i], NULL, 0);
|
||||||
perror("SHMAT");
|
|
||||||
else
|
/* SHMAT should fail since no refs were left in last detach */
|
||||||
printf("SHM base address returned: %p\n", bases[i]);
|
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;
|
return 0;
|
||||||
|
|
||||||
|
out_err:
|
||||||
|
printf("SHM TEST -- FAILED --\n");
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user