mirror of
https://github.com/drasko/codezero.git
synced 2026-07-20 22:25:24 +02:00
Errno is set by the posix calls read/write/open/close etc. rather than their l4_xxx equivalent.
mmap.c is the only one not done yet.
This commit is contained in:
@@ -20,15 +20,14 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence)
|
|||||||
write_mr(L4SYS_ARG2, whence);
|
write_mr(L4SYS_ARG2, whence);
|
||||||
|
|
||||||
/* Call pager with shmget() request. Check ipc error. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_LSEEK)) < 0) {
|
if ((offres = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_LSEEK)) < 0) {
|
||||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno);
|
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, offres);
|
||||||
return -1;
|
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);
|
printf("%s: OPEN Error: %d.\n", __FUNCTION__, (int)offres);
|
||||||
errno = (int)offres;
|
return offres;
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return offres;
|
return offres;
|
||||||
@@ -36,6 +35,15 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence)
|
|||||||
|
|
||||||
off_t lseek(int fildes, off_t offset, int whence)
|
off_t lseek(int fildes, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
return l4_lseek(fildes, offset, whence);
|
int ret = l4_lseek(fildes, offset, whence);
|
||||||
|
|
||||||
|
/* If error, return positive error code */
|
||||||
|
if (ret < 0) {
|
||||||
|
errno = -ret;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* else return value */
|
||||||
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@
|
|||||||
#include <l4lib/arch/syslib.h>
|
#include <l4lib/arch/syslib.h>
|
||||||
#include <l4lib/ipcdefs.h>
|
#include <l4lib/ipcdefs.h>
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
* rather than the l4_syscall sets it itself
|
||||||
|
*/
|
||||||
|
|
||||||
struct mmap_descriptor {
|
struct mmap_descriptor {
|
||||||
void *start;
|
void *start;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
|||||||
@@ -23,22 +23,21 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode)
|
|||||||
write_mr(L4SYS_ARG2, (u32)mode);
|
write_mr(L4SYS_ARG2, (u32)mode);
|
||||||
|
|
||||||
/* Call pager with shmget() request. Check ipc error. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((errno = 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__, errno);
|
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
|
||||||
return -1;
|
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.\n", __FUNCTION__, fd);
|
printf("%s: OPEN Error: %d.\n", __FUNCTION__, fd);
|
||||||
errno = fd;
|
return fd;
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int open(const char *pathname, int oflag, ...)
|
int open(const char *pathname, int oflag, ...)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
mode_t mode = 0;
|
mode_t mode = 0;
|
||||||
|
|
||||||
if (oflag & O_CREAT) {
|
if (oflag & O_CREAT) {
|
||||||
@@ -47,6 +46,15 @@ int open(const char *pathname, int oflag, ...)
|
|||||||
mode = va_arg(arg, mode_t);
|
mode = va_arg(arg, mode_t);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
}
|
}
|
||||||
return l4_open(pathname, oflag, mode);
|
ret = l4_open(pathname, oflag, mode);
|
||||||
|
|
||||||
|
/* If error, return positive error code */
|
||||||
|
if (ret < 0) {
|
||||||
|
errno = -ret;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* else return value */
|
||||||
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,14 @@ static inline int l4_write(int fd, const void *buf, size_t count)
|
|||||||
write_mr(L4SYS_ARG2, count);
|
write_mr(L4SYS_ARG2, count);
|
||||||
|
|
||||||
/* Call pager with shmget() request. Check ipc error. */
|
/* Call pager with shmget() request. Check ipc error. */
|
||||||
if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_WRITE)) < 0) {
|
if ((wrcnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_WRITE)) < 0) {
|
||||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno);
|
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt);
|
||||||
return -1;
|
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);
|
printf("%s: WRITE Error: %d.\n", __FUNCTION__, (int)wrcnt);
|
||||||
errno = (int)wrcnt;
|
return wrcnt;
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return wrcnt;
|
return wrcnt;
|
||||||
@@ -36,9 +35,19 @@ static inline int l4_write(int fd, const void *buf, size_t count)
|
|||||||
|
|
||||||
ssize_t write(int fd, const void *buf, size_t count)
|
ssize_t write(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!count)
|
if (!count)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return l4_write(fd, buf, count);
|
ret = l4_write(fd, buf, count);
|
||||||
|
|
||||||
|
/* If error, return positive error code */
|
||||||
|
if (ret < 0) {
|
||||||
|
errno = -ret;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* else return value */
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user