mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-30 00:00:15 +01:00
check LWIP_FD_BIT before syscall will be forwarded to uhyve
This commit is contained in:
parent
4906a04022
commit
22991d27c2
1 changed files with 27 additions and 29 deletions
|
@ -131,17 +131,8 @@ typedef struct {
|
|||
|
||||
ssize_t sys_read(int fd, char* buf, size_t len)
|
||||
{
|
||||
if (is_uhyve()) {
|
||||
uhyve_read_t uhyve_args = {fd, (char*) virt_to_phys((size_t) buf), len, -1};
|
||||
|
||||
uhyve_send(UHYVE_PORT_READ, (unsigned)virt_to_phys((size_t)&uhyve_args));
|
||||
|
||||
return uhyve_args.ret;
|
||||
}
|
||||
|
||||
sys_read_t sysargs = {__NR_read, fd, len};
|
||||
ssize_t j, ret;
|
||||
int s;
|
||||
|
||||
// do we have an LwIP file descriptor?
|
||||
if (fd & LWIP_FD_BIT) {
|
||||
|
@ -152,13 +143,21 @@ ssize_t sys_read(int fd, char* buf, size_t len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (is_uhyve()) {
|
||||
uhyve_read_t uhyve_args = {fd, (char*) virt_to_phys((size_t) buf), len, -1};
|
||||
|
||||
uhyve_send(UHYVE_PORT_READ, (unsigned)virt_to_phys((size_t)&uhyve_args));
|
||||
|
||||
return uhyve_args.ret;
|
||||
}
|
||||
|
||||
spinlock_irqsave_lock(&lwip_lock);
|
||||
if (libc_sd < 0) {
|
||||
spinlock_irqsave_unlock(&lwip_lock);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
s = libc_sd;
|
||||
int s = libc_sd;
|
||||
lwip_write(s, &sysargs, sizeof(sysargs));
|
||||
|
||||
lwip_read(s, &j, sizeof(j));
|
||||
|
@ -203,18 +202,9 @@ typedef struct {
|
|||
ssize_t sys_write(int fd, const char* buf, size_t len)
|
||||
{
|
||||
if (BUILTIN_EXPECT(!buf, 0))
|
||||
return -1;
|
||||
|
||||
if (is_uhyve()) {
|
||||
uhyve_write_t uhyve_args = {fd, (const char*) virt_to_phys((size_t) buf), len};
|
||||
|
||||
uhyve_send(UHYVE_PORT_WRITE, (unsigned)virt_to_phys((size_t)&uhyve_args));
|
||||
|
||||
return uhyve_args.len;
|
||||
}
|
||||
return -EINVAL;
|
||||
|
||||
ssize_t i, ret;
|
||||
int s;
|
||||
sys_write_t sysargs = {__NR_write, fd, len};
|
||||
|
||||
// do we have an LwIP file descriptor?
|
||||
|
@ -226,6 +216,14 @@ ssize_t sys_write(int fd, const char* buf, size_t len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (is_uhyve()) {
|
||||
uhyve_write_t uhyve_args = {fd, (const char*) virt_to_phys((size_t) buf), len};
|
||||
|
||||
uhyve_send(UHYVE_PORT_WRITE, (unsigned)virt_to_phys((size_t)&uhyve_args));
|
||||
|
||||
return uhyve_args.len;
|
||||
}
|
||||
|
||||
spinlock_irqsave_lock(&lwip_lock);
|
||||
if (libc_sd < 0)
|
||||
{
|
||||
|
@ -239,7 +237,7 @@ ssize_t sys_write(int fd, const char* buf, size_t len)
|
|||
return len;
|
||||
}
|
||||
|
||||
s = libc_sd;
|
||||
int s = libc_sd;
|
||||
lwip_write(s, &sysargs, sizeof(sysargs));
|
||||
|
||||
i=0;
|
||||
|
@ -386,14 +384,6 @@ typedef struct {
|
|||
|
||||
int sys_close(int fd)
|
||||
{
|
||||
if (is_uhyve()) {
|
||||
uhyve_close_t uhyve_close = {fd, -1};
|
||||
|
||||
uhyve_send(UHYVE_PORT_CLOSE, (unsigned)virt_to_phys((size_t) &uhyve_close));
|
||||
|
||||
return uhyve_close.ret;
|
||||
}
|
||||
|
||||
int ret, s;
|
||||
sys_close_t sysargs = {__NR_close, fd};
|
||||
|
||||
|
@ -406,6 +396,14 @@ int sys_close(int fd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (is_uhyve()) {
|
||||
uhyve_close_t uhyve_close = {fd, -1};
|
||||
|
||||
uhyve_send(UHYVE_PORT_CLOSE, (unsigned)virt_to_phys((size_t) &uhyve_close));
|
||||
|
||||
return uhyve_close.ret;
|
||||
}
|
||||
|
||||
spinlock_irqsave_lock(&lwip_lock);
|
||||
if (libc_sd < 0) {
|
||||
ret = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue