提交 60205a16 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

some more c++, using gnu extensions

上级 2a47dd2b
...@@ -684,10 +684,10 @@ dirlink(struct inode *dp, char *name, u32 inum) ...@@ -684,10 +684,10 @@ dirlink(struct inode *dp, char *name, u32 inum)
// skipelem("", name) = skipelem("////", name) = 0 // skipelem("", name) = skipelem("////", name) = 0
// //
static int static int
skipelem(char **rpath, char *name) skipelem(const char **rpath, char *name)
{ {
char *path = *rpath; const char *path = *rpath;
char *s; const char *s;
int len; int len;
while(*path == '/') while(*path == '/')
...@@ -714,7 +714,7 @@ skipelem(char **rpath, char *name) ...@@ -714,7 +714,7 @@ skipelem(char **rpath, char *name)
// If parent != 0, return the inode for the parent and copy the final // If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes. // path element into name, which must have room for DIRSIZ bytes.
static struct inode* static struct inode*
namex(char *path, int nameiparent, char *name) namex(const char *path, int nameiparent, char *name)
{ {
struct inode *ip, *next; struct inode *ip, *next;
int r; int r;
...@@ -759,7 +759,7 @@ namex(char *path, int nameiparent, char *name) ...@@ -759,7 +759,7 @@ namex(char *path, int nameiparent, char *name)
} }
struct inode* struct inode*
namei(char *path) namei(const char *path)
{ {
char name[DIRSIZ]; char name[DIRSIZ];
struct inode *r = namex(path, 0, name); struct inode *r = namex(path, 0, name);
......
...@@ -100,7 +100,7 @@ int filewrite(struct file*, char*, int n); ...@@ -100,7 +100,7 @@ int filewrite(struct file*, char*, int n);
int namecmp(const char*, const char*); int namecmp(const char*, const char*);
struct inode* dirlookup(struct inode*, char*); struct inode* dirlookup(struct inode*, char*);
struct inode* ialloc(u32, short); struct inode* ialloc(u32, short);
struct inode* namei(char*); struct inode* namei(const char*);
void iput(struct inode*); void iput(struct inode*);
struct inode* iget(u32 dev, u32 inum); struct inode* iget(u32 dev, u32 inum);
void ilock(struct inode*, int writer); void ilock(struct inode*, int writer);
...@@ -208,7 +208,7 @@ struct nskey { ...@@ -208,7 +208,7 @@ struct nskey {
} u; } u;
}; };
#define KI(v) (struct nskey){.type=nskey_int,.u.i=v} #define KI(v) (struct nskey){type: nskey_int, u: { i: v }}
#define KII(x,y) (struct nskey){.type=nskey_ii,.u.ii.a=x,.u.ii.b=y} #define KII(x,y) (struct nskey){.type=nskey_ii,.u.ii.a=x,.u.ii.b=y}
#define KS(v) (struct nskey){.type=nskey_str,.u.s=v} #define KS(v) (struct nskey){.type=nskey_str,.u.s=v}
#define KD(v) (struct nskey){.type=nskey_dirname,.u.dirname=v} #define KD(v) (struct nskey){.type=nskey_dirname,.u.dirname=v}
...@@ -412,8 +412,10 @@ long sys_bind(int, void*, int); ...@@ -412,8 +412,10 @@ long sys_bind(int, void*, int);
long sys_listen(int, int); long sys_listen(int, int);
long sys_accept(int, void*, void*); long sys_accept(int, void*, void*);
// other exported functions // other exported/imported functions
void cmain(u64 mbmagic, u64 mbaddr); void cmain(u64 mbmagic, u64 mbaddr);
void mpboot(void); void mpboot(void);
void trapret(void);
void threadstub(void);
void threadhelper(void (*fn)(void *), void *arg);
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
#include "fs.h" #include "fs.h"
#include <stddef.h> #include <stddef.h>
}
// name spaces // name spaces
// XXX maybe use open hash table, no chain, better cache locality // XXX maybe use open hash table, no chain, better cache locality
...@@ -54,7 +56,7 @@ nsalloc(int allowdup) ...@@ -54,7 +56,7 @@ nsalloc(int allowdup)
{ {
struct ns *ns = 0; struct ns *ns = 0;
ns = kmalloc(sizeof(struct ns)); ns = (struct ns*) kmalloc(sizeof(struct ns));
if (ns == 0) if (ns == 0)
panic("nsalloc"); panic("nsalloc");
memset(ns, 0, sizeof(struct ns)); memset(ns, 0, sizeof(struct ns));
...@@ -102,7 +104,7 @@ elemalloc(struct nskey *k) ...@@ -102,7 +104,7 @@ elemalloc(struct nskey *k)
panic("key type"); panic("key type");
} }
e = kmalloc(sz); e = (elem*) kmalloc(sz);
if (e == 0) if (e == 0)
return 0; return 0;
memset(e, 0, sz); memset(e, 0, sz);
......
extern "C" {
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "mmu.h" #include "mmu.h"
...@@ -11,8 +12,7 @@ ...@@ -11,8 +12,7 @@
#include "kmtrace.h" #include "kmtrace.h"
#include "vm.h" #include "vm.h"
#include "sched.h" #include "sched.h"
}
extern void threadstub(void);
int __mpalign__ idle[NCPU]; int __mpalign__ idle[NCPU];
struct ns *nspid __mpalign__; struct ns *nspid __mpalign__;
...@@ -139,7 +139,7 @@ exit(void) ...@@ -139,7 +139,7 @@ exit(void)
// Kernel threads might not have a cwd // Kernel threads might not have a cwd
if (myproc()->cwd != NULL) { if (myproc()->cwd != NULL) {
iput(myproc()->cwd); iput(myproc()->cwd);
myproc()->cwd = NULL; myproc()->cwd = 0;
} }
// Pass abandoned children to init. // Pass abandoned children to init.
...@@ -185,11 +185,10 @@ freeproc(struct proc *p) ...@@ -185,11 +185,10 @@ freeproc(struct proc *p)
static struct proc* static struct proc*
allocproc(void) allocproc(void)
{ {
extern void trapret(void);
struct proc *p; struct proc *p;
char *sp; char *sp;
p = kmalloc(sizeof(struct proc)); p = (proc*) kmalloc(sizeof(struct proc));
if (p == 0) return 0; if (p == 0) return 0;
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
...@@ -212,7 +211,7 @@ allocproc(void) ...@@ -212,7 +211,7 @@ allocproc(void)
panic("allocproc: ns_insert"); panic("allocproc: ns_insert");
// Allocate kernel stack if possible. // Allocate kernel stack if possible.
if((p->kstack = ksalloc(slab_stack)) == 0){ if((p->kstack = (char*) ksalloc(slab_stack)) == 0){
if (ns_remove(nspid, KI(p->pid), p) == 0) if (ns_remove(nspid, KI(p->pid), p) == 0)
panic("allocproc: ns_remove"); panic("allocproc: ns_remove");
freeproc(p); freeproc(p);
...@@ -271,7 +270,7 @@ inituser(void) ...@@ -271,7 +270,7 @@ inituser(void)
p->tf->rip = 0x0; // beginning of initcode.S p->tf->rip = 0x0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name)); safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = NULL; // forkret will fix in the process's context p->cwd = 0; // forkret will fix in the process's context
acquire(&p->lock); acquire(&p->lock);
addrun(p); addrun(p);
release(&p->lock); release(&p->lock);
...@@ -495,13 +494,13 @@ kill(int pid) ...@@ -495,13 +494,13 @@ kill(int pid)
void *procdump(void *vk, void *v, void *arg) void *procdump(void *vk, void *v, void *arg)
{ {
static char *states[] = { static const char *states[] = {
[UNUSED] = "unused", /* [UNUSED] = */ "unused",
[EMBRYO] = "embryo", /* [EMBRYO] = */ "embryo",
[SLEEPING] = "sleep ", /* [SLEEPING] = */ "sleep ",
[RUNNABLE] = "runble", /* [RUNNABLE] = */ "runble",
[RUNNING] = "run ", /* [RUNNING] = */ "run ",
[ZOMBIE] = "zombie" /* [ZOMBIE] = */ "zombie"
}; };
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
const char *name = "(no name)"; const char *name = "(no name)";
...@@ -555,7 +554,7 @@ fork(int flags) ...@@ -555,7 +554,7 @@ fork(int flags)
// Copy process state from p. // Copy process state from p.
if((np->vmap = vmap_copy(myproc()->vmap, cow)) == 0){ if((np->vmap = vmap_copy(myproc()->vmap, cow)) == 0){
ksfree(slab_stack, np->kstack); ksfree(slab_stack, np->kstack);
np->kstack = NULL; np->kstack = 0;
np->state = UNUSED; np->state = UNUSED;
if (ns_remove(nspid, KI(np->pid), np) == 0) if (ns_remove(nspid, KI(np->pid), np) == 0)
panic("fork: ns_remove"); panic("fork: ns_remove");
...@@ -616,7 +615,7 @@ wait(void) ...@@ -616,7 +615,7 @@ wait(void)
SLIST_REMOVE(&myproc()->childq, p, proc, child_next); SLIST_REMOVE(&myproc()->childq, p, proc, child_next);
release(&myproc()->lock); release(&myproc()->lock);
ksfree(slab_stack, p->kstack); ksfree(slab_stack, p->kstack);
p->kstack = NULL; p->kstack = 0;
vmap_decref(p->vmap); vmap_decref(p->vmap);
p->state = UNUSED; p->state = UNUSED;
if (ns_remove(nspid, KI(p->pid), p) == 0) if (ns_remove(nspid, KI(p->pid), p) == 0)
...@@ -660,18 +659,18 @@ threadalloc(void (*fn)(void *), void *arg) ...@@ -660,18 +659,18 @@ threadalloc(void (*fn)(void *), void *arg)
p = allocproc(); p = allocproc();
if (p == NULL) if (p == NULL)
return NULL; return 0;
p->vmap = vmap_alloc(); p->vmap = vmap_alloc();
if (p->vmap == NULL) { if (p->vmap == NULL) {
freeproc(p); freeproc(p);
return NULL; return 0;
} }
p->context->rip = (u64)threadstub; p->context->rip = (u64)threadstub;
p->context->r12 = (u64)fn; p->context->r12 = (u64)fn;
p->context->r13 = (u64)arg; p->context->r13 = (u64)arg;
p->parent = myproc(); p->parent = myproc();
p->cwd = NULL; p->cwd = 0;
return p; return p;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论