add networkI/O (unstable)
This commit is contained in:
parent
5c7e9f38ec
commit
27b7c6aa6e
6 changed files with 62 additions and 56 deletions
|
@ -2,7 +2,7 @@ TOPDIR = $(shell pwd)
|
|||
ARCH = x86
|
||||
NAME = metalsvm
|
||||
LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif
|
||||
DRIVERDIRS = drivers/net drivers/char drivers/stdin drivers/stdout drivers/stderr drivers/net_char
|
||||
DRIVERDIRS = drivers/net drivers/char drivers/stdin drivers/stdout drivers/stderr drivers/netchar
|
||||
KERNDIRS = libkern kernel mm fs arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS)
|
||||
SUBDIRS = $(KERNDIRS)
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
/* Implementation of a simple stdout device */
|
||||
|
||||
static ssize_t net_stdout_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
static ssize_t netchar_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
int ret;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
|
@ -53,7 +53,7 @@ static ssize_t net_stdout_read(fildes_t* file, uint8_t* buffer, size_t size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t net_stdout_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
static ssize_t netchar_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
int ret;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
|
@ -66,12 +66,12 @@ static ssize_t net_stdout_write(fildes_t* file, uint8_t* buffer, size_t size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int net_stdout_open(fildes_t* file, const char* name)
|
||||
static int netchar_open(fildes_t* file, const char* name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int net_stdout_close(vfs_node_t* node) //////////////change this in File!!!
|
||||
static int netchar_close(vfs_node_t* node) //////////////change this in File!!!
|
||||
{
|
||||
int ret;
|
||||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
|
@ -84,7 +84,7 @@ static int net_stdout_close(vfs_node_t* node) //////////////change this in File!
|
|||
return ret;
|
||||
}
|
||||
|
||||
int net_stdout_init(vfs_node_t* node, const char* name)
|
||||
int netchar_init(vfs_node_t* node, const char* name)
|
||||
{
|
||||
uint32_t i, j;
|
||||
vfs_node_t* new_node;
|
||||
|
@ -107,10 +107,10 @@ int net_stdout_init(vfs_node_t* node, const char* name)
|
|||
|
||||
memset(new_node, 0x00, sizeof(vfs_node_t));
|
||||
new_node->type = FS_CHARDEVICE;
|
||||
new_node->open = &net_stdout_open;
|
||||
new_node->close = &net_stdout_close;
|
||||
new_node->read = &net_stdout_read;
|
||||
new_node->write = &net_stdout_write;
|
||||
new_node->open = &netchar_open;
|
||||
new_node->close = &netchar_close;
|
||||
new_node->read = &netchar_read;
|
||||
new_node->write = &netchar_write;
|
||||
spinlock_init(&new_node->lock);
|
||||
|
||||
blist= &node->block_list;
|
|
@ -439,6 +439,9 @@ int initrd_init(void)
|
|||
stdout_init(tmp, "stdout");
|
||||
/* create the standart error-output device "stderr" */
|
||||
stderr_init(tmp, "stderr");
|
||||
/* create the standart device "netchar" */
|
||||
netchar_init(tmp, "netchar");
|
||||
|
||||
|
||||
/* For every module.. */
|
||||
#ifdef CONFIG_MULTIBOOT
|
||||
|
|
|
@ -40,11 +40,6 @@
|
|||
#include <lwip/inet.h>
|
||||
#include <lwip/err.h>
|
||||
|
||||
/*
|
||||
* We set the a bit LWIP_FD_BIT to determine,
|
||||
* if the descriptor belongs to LwIP or MetalSVM.
|
||||
*/
|
||||
#define LWIP_FD_BIT (1 << 28)
|
||||
#endif
|
||||
|
||||
static int sys_open(const char* name, int flags, int mode)
|
||||
|
@ -52,7 +47,7 @@ static int sys_open(const char* name, int flags, int mode)
|
|||
int fd, check;
|
||||
fildes_t* file = NULL;
|
||||
|
||||
for (fd = 3; fd < NR_OPEN; fd++) {
|
||||
for (fd = 0; fd < NR_OPEN; fd++) {
|
||||
if (per_core(current_task)->fildes_table[fd].node == NULL) {
|
||||
file = &(per_core(current_task)->fildes_table[fd]);
|
||||
file->offset = 0;
|
||||
|
@ -77,22 +72,16 @@ static int sys_open(const char* name, int flags, int mode)
|
|||
#if defined(CONFIG_LWIP) && LWIP_SOCKET
|
||||
static int sys_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int fd, check;
|
||||
int fd;
|
||||
fildes_t* file = NULL;
|
||||
|
||||
for (fd = 3; fd < NR_OPEN; fd++) {
|
||||
for (fd = 0; fd < NR_OPEN; fd++) {
|
||||
if (per_core(current_task)->fildes_table[fd].node == NULL) {
|
||||
file = &(per_core(current_task)->fildes_table[fd]);
|
||||
file->offset = domain;
|
||||
file->mode = type;
|
||||
file->flags = protocol;
|
||||
file->node = task_table[i].fildes_table[0].node = findnode_fs("/dev/net_char");
|
||||
//check = open_fs(file, (char*) name); //////////////////////////////////////send to node!!!!TODO!!!
|
||||
if (check < 0) {
|
||||
/* lwip connection error! */
|
||||
file->node = NULL;
|
||||
return -errno;
|
||||
}
|
||||
file->offset = lwip_socket(domain, type, protocol);
|
||||
file->mode = 0;
|
||||
file->flags = 0;
|
||||
file->node = findnode_fs("/dev/netchar");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +91,32 @@ static int sys_socket(int domain, int type, int protocol)
|
|||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int sys_accept(int s, struct sockaddr* addr, socklen_t* addrlen)
|
||||
{
|
||||
int fd;
|
||||
fildes_t* file = NULL;
|
||||
|
||||
for (fd = 0; fd < NR_OPEN; fd++) {
|
||||
if (per_core(current_task)->fildes_table[fd].node == NULL) {
|
||||
file = &(per_core(current_task)->fildes_table[fd]);
|
||||
file->offset = lwip_accept(s, addr, addrlen);
|
||||
file->mode = 0;
|
||||
file->flags = 0;
|
||||
file->node = findnode_fs("/dev/netchar");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fd >= NR_OPEN) {
|
||||
return -EMFILE;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static int sys_close(int fd)
|
||||
{
|
||||
fildes_t* file = &(per_core(current_task)->fildes_table[fd]);
|
||||
|
@ -266,12 +279,12 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
case __NR_closesocket: {
|
||||
int fd = va_arg(vl, int);
|
||||
|
||||
if (BUILTIN_EXPECT(!(fd), 0)) {
|
||||
if (fd < 0) {
|
||||
ret = -ENOTSOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lwip_close(&(per_core(current_task)->fildes_table[fd]->offset));
|
||||
ret = lwip_close(per_core(current_task)->fildes_table[fd].offset);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
break;
|
||||
|
@ -289,12 +302,12 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
const struct sockaddr* name = va_arg(vl, const struct sockaddr*);
|
||||
socklen_t namelen = va_arg(vl, socklen_t);
|
||||
|
||||
if (BUILTIN_EXPECT(!(&(per_core(current_task)->fildes_table[fd]->offset)), 0)) {
|
||||
if (per_core(current_task)->fildes_table[fd].offset < 0) {
|
||||
ret = -ENOTSOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lwip_connect(&(per_core(current_task)->fildes_table[fd]->offset), name, namelen);
|
||||
ret = lwip_connect(per_core(current_task)->fildes_table[fd].offset, name, namelen);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
break;
|
||||
|
@ -304,26 +317,25 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
const struct sockaddr* name = va_arg(vl, const struct sockaddr*);
|
||||
socklen_t namelen = va_arg(vl, socklen_t);
|
||||
|
||||
if (BUILTIN_EXPECT(!(&(per_core(current_task)->fildes_table[fd]->offset)), 0)) {
|
||||
if (per_core(current_task)->fildes_table[fd].offset < 0) {
|
||||
ret = -ENOTSOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lwip_bind(&(per_core(current_task)->fildes_table[fd]->offset), name, namelen);
|
||||
ret = lwip_bind(per_core(current_task)->fildes_table[fd].offset, name, namelen);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
break;
|
||||
}
|
||||
case __NR_listen:{
|
||||
case __NR_listen: {
|
||||
int fd = va_arg(vl, int);
|
||||
int backlog = va_arg(vl, int);
|
||||
|
||||
if (BUILTIN_EXPECT(!(&(per_core(current_task)->fildes_table[fd]->offset)), 0)) {
|
||||
if (per_core(current_task)->fildes_table[fd].offset < 0) {
|
||||
ret = -ENOTSOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lwip_listen(&(per_core(current_task)->fildes_table[fd]->offset), backlog);
|
||||
ret = lwip_listen(per_core(current_task)->fildes_table[fd].offset, backlog);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
break;
|
||||
|
@ -333,15 +345,12 @@ int syscall_handler(uint32_t sys_nr, ...)
|
|||
struct sockaddr* addr = va_arg(vl, struct sockaddr*);
|
||||
socklen_t* addrlen = va_arg(vl, socklen_t*);
|
||||
|
||||
if (BUILTIN_EXPECT(!(&(per_core(current_task)->fildes_table[fd]->offset)), 0)) {
|
||||
if (per_core(current_task)->fildes_table[fd].offset < 0) {
|
||||
ret = -ENOTSOCK;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = lwip_accept(&(per_core(current_task)->fildes_table[fd]->offset), addr, addrlen);
|
||||
if (ret >= 0)
|
||||
ret |= LWIP_FD_BIT;
|
||||
else
|
||||
ret = sys_accept(per_core(current_task)->fildes_table[fd].offset, addr, addrlen);
|
||||
if (ret < 0)
|
||||
ret = -errno;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -441,16 +441,11 @@ static int load_task(load_args_t* largs)
|
|||
if (!file->node)
|
||||
return -EINVAL;
|
||||
|
||||
<<<<<<< HEAD
|
||||
read_fs(file, (uint8_t*)&header, sizeof(elf_header_t));
|
||||
=======
|
||||
err = read_fs(node, (uint8_t*)&header, sizeof(elf_header_t), 0);
|
||||
if (err < 0) {
|
||||
kprintf("read_fs failed: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
>>>>>>> master
|
||||
if (BUILTIN_EXPECT(header.ident.magic != ELF_MAGIC, 0))
|
||||
goto invalid;
|
||||
|
||||
|
|
|
@ -252,10 +252,10 @@ void* client_task(void* e)
|
|||
|
||||
int test_init(void)
|
||||
{
|
||||
char* argv[] = {"/bin/mshell", NULL};
|
||||
// char* argv[] = {"/bin/mshell", NULL};
|
||||
// char* argv[] = {"/bin/tests", NULL};
|
||||
// char* server_argv[] = {"/bin/server", "6789", NULL};
|
||||
// char* client_argv[] = {"/bin/client", "127.0.0.1", "6789", NULL};
|
||||
char* server_argv[] = {"/bin/server", "6789", NULL};
|
||||
char* client_argv[] = {"/bin/client", "127.0.0.1", "6789", NULL};
|
||||
|
||||
//sem_init(&producing, 1);
|
||||
//sem_init(&consuming, 0);
|
||||
|
@ -280,12 +280,11 @@ int test_init(void)
|
|||
//create_kernel_task(NULL, consumer, NULL);
|
||||
//create_kernel_task(NULL, mail_ping, NULL);
|
||||
//create_user_task(NULL, "/bin/hello", argv);
|
||||
create_user_task(NULL, "/bin/mshell", argv);
|
||||
//create_user_task(NULL, "/bin/jacobi", argv);
|
||||
//create_user_task(NULL, "/bin/mshell", argv);
|
||||
//create_user_task(NULL, "/bin/jacobi", argv);
|
||||
create_user_task(NULL, "/bin/server", server_argv);
|
||||
//sleep(5);
|
||||
//create_user_task(NULL, "/bin/client", client_argv);
|
||||
sleep(5);
|
||||
create_user_task(NULL, "/bin/client", client_argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue