提交 5d6e4065 创建 作者: Austin Clements's avatar Austin Clements

Make sys_write prototype agree with user space, which takes a const void*

Most of this is propagating the const-ness through the myriad write functions.
上级 a7d4b8fe
...@@ -14,7 +14,7 @@ struct file : public referenced, public rcu_freed { ...@@ -14,7 +14,7 @@ struct file : public referenced, public rcu_freed {
int stat(struct stat*); int stat(struct stat*);
int read(char *addr, int n); int read(char *addr, int n);
ssize_t pread(char *addr, size_t n, off_t offset); ssize_t pread(char *addr, size_t n, off_t offset);
int write(char *addr, int n); int write(const char *addr, int n);
enum { FD_NONE, FD_PIPE, FD_INODE, FD_SOCKET } type; enum { FD_NONE, FD_PIPE, FD_INODE, FD_SOCKET } type;
...@@ -75,7 +75,7 @@ struct inode : public rcu_freed { ...@@ -75,7 +75,7 @@ struct inode : public rcu_freed {
struct devsw { struct devsw {
int (*read)(struct inode*, char*, u32, u32); int (*read)(struct inode*, char*, u32, u32);
int (*write)(struct inode*, char*, u32, u32); int (*write)(struct inode*, const char*, u32, u32);
void (*stat)(struct inode*, struct stat*); void (*stat)(struct inode*, struct stat*);
}; };
......
...@@ -38,7 +38,7 @@ long sys_sbrk(int); ...@@ -38,7 +38,7 @@ long sys_sbrk(int);
long sys_nsleep(u64); long sys_nsleep(u64);
long sys_unlink(const char*); long sys_unlink(const char*);
long sys_wait(void); long sys_wait(void);
long sys_write(int, char*, int); long sys_write(int, const void*, int);
long sys_uptime(void); long sys_uptime(void);
long sys_map(uptr, u64); long sys_map(uptr, u64);
long sys_unmap(uptr, u64); long sys_unmap(uptr, u64);
......
...@@ -95,7 +95,7 @@ void iupdate(struct inode*); ...@@ -95,7 +95,7 @@ void iupdate(struct inode*);
void iunlock(struct inode*); void iunlock(struct inode*);
int readi(struct inode*, char*, u32, u32); int readi(struct inode*, char*, u32, u32);
void stati(struct inode*, struct stat*); void stati(struct inode*, struct stat*);
int writei(struct inode*, char*, u32, u32); int writei(struct inode*, const char*, u32, u32);
struct inode* idup(struct inode*); struct inode* idup(struct inode*);
struct inode* nameiparent(inode *cwd, const char*, char*); struct inode* nameiparent(inode *cwd, const char*, char*);
int dirlink(struct inode*, const char*, u32); int dirlink(struct inode*, const char*, u32);
...@@ -160,7 +160,7 @@ void piceoi(void); ...@@ -160,7 +160,7 @@ void piceoi(void);
int pipealloc(struct file**, struct file**); int pipealloc(struct file**, struct file**);
void pipeclose(struct pipe*, int); void pipeclose(struct pipe*, int);
int piperead(struct pipe*, char*, int); int piperead(struct pipe*, char*, int);
int pipewrite(struct pipe*, char*, int); int pipewrite(struct pipe*, const char*, int);
// proc.c // proc.c
struct proc* copyproc(struct proc*); struct proc* copyproc(struct proc*);
...@@ -248,4 +248,3 @@ void trapret(void); ...@@ -248,4 +248,3 @@ void trapret(void);
void threadstub(void); void threadstub(void);
void threadhelper(void (*fn)(void *), void *arg); void threadhelper(void (*fn)(void *), void *arg);
void trap(struct trapframe *tf); void trap(struct trapframe *tf);
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
void netclose(int sock); void netclose(int sock);
int netread(int, char *, int); int netread(int, char *, int);
int netwrite(int, char *, int); int netwrite(int, const char *, int);
long netsocket(int, int, int); long netsocket(int, int, int);
long netbind(int, void *, int); long netbind(int, void *, int);
long netlisten(int, int); long netlisten(int, int);
......
...@@ -210,7 +210,7 @@ panic(const char *fmt, ...) ...@@ -210,7 +210,7 @@ panic(const char *fmt, ...)
} }
static int static int
consolewrite(struct inode *ip, char *buf, u32 off, u32 n) consolewrite(struct inode *ip, const char *buf, u32 off, u32 n)
{ {
int i; int i;
......
...@@ -102,7 +102,7 @@ file::pread(char *addr, size_t n, off_t off) ...@@ -102,7 +102,7 @@ file::pread(char *addr, size_t n, off_t off)
} }
int int
file::write(char *addr, int n) file::write(const char *addr, int n)
{ {
int r; int r;
......
...@@ -569,7 +569,7 @@ readi(struct inode *ip, char *dst, u32 off, u32 n) ...@@ -569,7 +569,7 @@ readi(struct inode *ip, char *dst, u32 off, u32 n)
// PAGEBREAK! // PAGEBREAK!
// Write data to inode. // Write data to inode.
int int
writei(struct inode *ip, char *src, u32 off, u32 n) writei(struct inode *ip, const char *src, u32 off, u32 n)
{ {
u32 tot, m; u32 tot, m;
struct buf *bp; struct buf *bp;
......
...@@ -346,7 +346,7 @@ netclose(int sock) ...@@ -346,7 +346,7 @@ netclose(int sock)
} }
int int
netwrite(int sock, char *ubuf, int len) netwrite(int sock, const char *ubuf, int len)
{ {
void *kbuf; void *kbuf;
int cc; int cc;
...@@ -436,7 +436,7 @@ netclose(int sock) ...@@ -436,7 +436,7 @@ netclose(int sock)
} }
int int
netwrite(int sock, char *buf, int len) netwrite(int sock, const char *buf, int len)
{ {
return -1; return -1;
} }
......
...@@ -81,7 +81,7 @@ pipeclose(struct pipe *p, int writable) ...@@ -81,7 +81,7 @@ pipeclose(struct pipe *p, int writable)
//PAGEBREAK: 40 //PAGEBREAK: 40
int int
pipewrite(struct pipe *p, char *addr, int n) pipewrite(struct pipe *p, const char *addr, int n)
{ {
int i; int i;
......
...@@ -220,7 +220,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n) ...@@ -220,7 +220,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
} }
static int static int
sampwrite(struct inode *ip, char *buf, u32 off, u32 n) sampwrite(struct inode *ip, const char *buf, u32 off, u32 n)
{ {
struct sampconf *conf; struct sampconf *conf;
......
...@@ -218,7 +218,7 @@ lockstat_read(struct inode *ip, char *dst, u32 off, u32 n) ...@@ -218,7 +218,7 @@ lockstat_read(struct inode *ip, char *dst, u32 off, u32 n)
} }
static int static int
lockstat_write(struct inode *ip, char *buf, u32 off, u32 n) lockstat_write(struct inode *ip, const char *buf, u32 off, u32 n)
{ {
int cmd = buf[0] - '0'; int cmd = buf[0] - '0';
......
...@@ -71,13 +71,13 @@ sys_pread(int fd, void *ubuf, size_t count, off_t offset) ...@@ -71,13 +71,13 @@ sys_pread(int fd, void *ubuf, size_t count, off_t offset)
} }
long long
sys_write(int fd, char *p, int n) sys_write(int fd, const void *p, int n)
{ {
sref<file> f; sref<file> f;
if (!getfile(fd, &f) || argcheckptr(p, n) < 0) if (!getfile(fd, &f) || argcheckptr(p, n) < 0)
return -1; return -1;
return f->write(p, n); return f->write(static_cast<const char*>(p), n);
} }
long long
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论