my solution to lab 6

This commit is contained in:
winPond
2019-07-17 16:08:06 +08:00
parent 8147d99448
commit c62da1c86d
534 changed files with 60875 additions and 6513 deletions

View File

@@ -42,6 +42,7 @@ enum {
enum EnvType {
ENV_TYPE_USER = 0,
ENV_TYPE_FS, // File system server
ENV_TYPE_NS, // Network server
};
struct Env {

View File

@@ -27,6 +27,10 @@ struct FdFile {
int id;
};
struct FdSock {
int sockid;
};
struct Fd {
int fd_dev_id;
off_t fd_offset;
@@ -34,6 +38,8 @@ struct Fd {
union {
// File server files
struct FdFile fd_file;
// Network sockets
struct FdSock fd_sock;
};
};
@@ -52,6 +58,7 @@ int fd_lookup(int fdnum, struct Fd **fd_store);
int dev_lookup(int devid, struct Dev **dev_store);
extern struct Dev devfile;
extern struct Dev devsock;
extern struct Dev devcons;
extern struct Dev devpipe;

View File

@@ -20,6 +20,8 @@
#include <inc/fs.h>
#include <inc/fd.h>
#include <inc/args.h>
#include <inc/malloc.h>
#include <inc/ns.h>
#define USED(x) (void)(x)
@@ -57,6 +59,9 @@ int sys_page_map(envid_t src_env, void *src_pg,
int sys_page_unmap(envid_t env, void *pg);
int sys_ipc_try_send(envid_t to_env, uint32_t value, void *pg, int perm);
int sys_ipc_recv(void *rcv_pg);
unsigned int sys_time_msec(void);
int sys_pkt_try_send(void * buf, size_t len);
int sys_pkt_try_receive(void *rev_buf, size_t *len);
// This must be inlined. Exercise for reader: why?
static inline envid_t __attribute__((always_inline))
@@ -99,6 +104,24 @@ int sync(void);
// pageref.c
int pageref(void *addr);
// sockets.c
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int bind(int s, struct sockaddr *name, socklen_t namelen);
int shutdown(int s, int how);
int connect(int s, const struct sockaddr *name, socklen_t namelen);
int listen(int s, int backlog);
int socket(int domain, int type, int protocol);
// nsipc.c
int nsipc_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int nsipc_bind(int s, struct sockaddr *name, socklen_t namelen);
int nsipc_shutdown(int s, int how);
int nsipc_close(int s);
int nsipc_connect(int s, const struct sockaddr *name, socklen_t namelen);
int nsipc_listen(int s, int backlog);
int nsipc_recv(int s, void *mem, int len, unsigned int flags);
int nsipc_send(int s, const void *buf, int size, unsigned int flags);
int nsipc_socket(int domain, int type, int protocol);
// spawn.c
envid_t spawn(const char *program, const char **argv);

7
lab/inc/malloc.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef JOS_INC_MALLOC_H
#define JOS_INC_MALLOC_H 1
void *malloc(size_t size);
void free(void *addr);
#endif

View File

@@ -42,7 +42,7 @@
* | Invalid Memory (*) | --/-- KSTKGAP |
* +------------------------------+ |
* : . : |
* : . : |
* 注意PTSIZE 与 PGSIZE: . : |
* MMIOLIM ------> +------------------------------+ 0xefc00000 --+
* | Memory-mapped I/O | RW/-- PTSIZE
* ULIM, MMIOBASE --> +------------------------------+ 0xef800000

106
lab/inc/ns.h Normal file
View File

@@ -0,0 +1,106 @@
// See COPYRIGHT for copyright information.
#ifndef JOS_INC_NS_H
#define JOS_INC_NS_H
#include <inc/types.h>
#include <inc/mmu.h>
#include <lwip/sockets.h>
struct jif_pkt {
int jp_len;
char jp_data[0];
};
// Definitions for requests from clients to network server
enum {
// The following messages pass a page containing an Nsipc.
// Accept returns a Nsret_accept on the request page.
NSREQ_ACCEPT = 1,
NSREQ_BIND,
NSREQ_SHUTDOWN,
NSREQ_CLOSE,
NSREQ_CONNECT,
NSREQ_LISTEN,
// Recv returns a Nsret_recv on the request page.
NSREQ_RECV,
NSREQ_SEND,
NSREQ_SOCKET,
// The following two messages pass a page containing a struct jif_pkt
NSREQ_INPUT,
// NSREQ_OUTPUT, unlike all other messages, is sent *from* the
// network server, to the output environment
NSREQ_OUTPUT,
// The following message passes no page
NSREQ_TIMER,
};
union Nsipc {
struct Nsreq_accept {
int req_s;
socklen_t req_addrlen;
} accept;
struct Nsret_accept {
struct sockaddr ret_addr;
socklen_t ret_addrlen;
} acceptRet;
struct Nsreq_bind {
int req_s;
struct sockaddr req_name;
socklen_t req_namelen;
} bind;
struct Nsreq_shutdown {
int req_s;
int req_how;
} shutdown;
struct Nsreq_close {
int req_s;
} close;
struct Nsreq_connect {
int req_s;
struct sockaddr req_name;
socklen_t req_namelen;
} connect;
struct Nsreq_listen {
int req_s;
int req_backlog;
} listen;
struct Nsreq_recv {
int req_s;
int req_len;
unsigned int req_flags;
} recv;
struct Nsret_recv {
char ret_buf[0];
} recvRet;
struct Nsreq_send {
int req_s;
int req_size;
unsigned int req_flags;
char req_buf[0];
} send;
struct Nsreq_socket {
int req_domain;
int req_type;
int req_protocol;
} socket;
struct jif_pkt pkt;
// Ensure Nsipc is one page
char _pad[PGSIZE];
};
#endif // !JOS_INC_NS_H

View File

@@ -17,7 +17,10 @@ enum {
SYS_yield,
SYS_ipc_try_send,
SYS_ipc_recv,
NSYSCALLS
SYS_time_msec,
SYS_pkt_try_send,
SYS_pkt_try_recv,
NSYSCALLS,
};
#endif /* !JOS_INC_SYSCALL_H */