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