Convert NULLs to C++ nullptrs, remove #include <stddef.h>, add -nostdinc to CFLAGS

上级 96f5a9e8
......@@ -26,15 +26,12 @@ NM = $(TOOLPREFIX)nm
OBJCOPY = $(TOOLPREFIX)objcopy
STRIP = $(TOOLPREFIX)strip
# XXX(sbw)
# -nostdinc
INCLUDES = -Iinclude -I$(QEMUSRC) -include param.h -include include/compiler.h
COMFLAGS = -static -g -MD -m64 -O3 -Wall -Werror -DHW_$(HW) -DXV6 \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer -fms-extensions \
-mno-sse -mcx16 -mno-red-zone $(INCLUDES)
COMFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
CFLAGS := $(COMFLAGS) -std=c99 $(CFLAGS)
CFLAGS := $(COMFLAGS) -std=c99 -nostdinc $(CFLAGS)
CXXFLAGS := $(COMFLAGS) -std=c++0x -Wno-sign-compare -fno-exceptions -fno-rtti -fcheck-new -nostdinc++ $(CXXFLAGS)
ASFLAGS = -Iinclude -I$(O)/include -m64 -gdwarf-2 -MD -DHW_$(HW) -include param.h
LDFLAGS = -m elf_x86_64
......
......@@ -209,7 +209,7 @@ parse(const char *b, char **rurl)
len = b - url;
r = (char *) malloc(len+1);
if (r == NULL)
if (r == nullptr)
return -1;
memmove(r, url, len);
r[len] = 0;
......
......@@ -36,7 +36,7 @@ kernlet_pread(int fd, size_t count, off_t off)
t0 = rdtsc();
msgid = ipc_msg_alloc();
if (msgid == NULL_MSGID) {
if (msgid == nullptr_MSGID) {
fprintf(2, "kernlet_pread: ipc_alloc_msg failed");
return;
}
......@@ -44,7 +44,7 @@ kernlet_pread(int fd, size_t count, off_t off)
if (count > PGSIZE)
die("kernlet_pread: count oops");
pageid = ipc_page_alloc();
if (pageid == NULL_PAGEID) {
if (pageid == nullptr_PAGEID) {
fprintf(2, "kernlet_pread: ipc_alloc_page failed");
return;
}
......
......@@ -7,8 +7,8 @@ typedef u32 msgid_t;
#define IPC_CTLSIZE 4096
#define IPC_PGSIZE 4096
#define IPC_NMSG 16
#define NULL_MSGID (-1)
#define NULL_PAGEID (-1)
#define nullptr_MSGID (-1)
#define nullptr_PAGEID (-1)
#define IPC_NPAGE ((KSHAREDSIZE/IPC_PGSIZE) - 1)
struct ipcmsg {
......
#ifndef NULL
#define NULL ((void *)0)
#endif
#define MIN(_a, _b) \
({ \
__typeof__(_a) __a = (_a); \
......
......@@ -22,7 +22,7 @@ char* strncpy(char *s, const char *t, int n);
#define mtlabel(type, addr, bytes, str, n) \
mtrace_label_register(type, addr, bytes, str, n, RET_IP())
#define mtunlabel(type, addr) \
mtrace_label_register(type, addr, 0, NULL, 0, RET_IP())
mtrace_label_register(type, addr, 0, nullptr, 0, RET_IP())
// Tell mtrace about locking
#define mtlock(ptr) \
......
......@@ -179,7 +179,7 @@ struct name { \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
{ nullptr }
#define SLIST_ENTRY(type) \
struct { \
......@@ -189,7 +189,7 @@ struct { \
/*
* Singly-linked List functions.
*/
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_EMPTY(head) ((head)->slh_first == nullptr)
#define SLIST_FIRST(head) ((head)->slh_first)
......@@ -205,7 +205,7 @@ struct { \
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
for ((varp) = &SLIST_FIRST((head)); \
((var) = *(varp)) != NULL; \
((var) = *(varp)) != nullptr; \
(varp) = &SLIST_NEXT((var), field))
#define SLIST_INIT(head) do { \
......@@ -252,7 +252,7 @@ struct name { \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
{ nullptr, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
......@@ -270,7 +270,7 @@ struct { \
} \
} while (0)
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
#define STAILQ_EMPTY(head) ((head)->stqh_first == nullptr)
#define STAILQ_FIRST(head) ((head)->stqh_first)
......@@ -286,31 +286,31 @@ struct { \
(var) = (tvar))
#define STAILQ_INIT(head) do { \
STAILQ_FIRST((head)) = NULL; \
STAILQ_FIRST((head)) = nullptr; \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == nullptr)\
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
STAILQ_NEXT((tqelm), field) = (elm); \
} while (0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == nullptr) \
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
STAILQ_FIRST((head)) = (elm); \
} while (0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
STAILQ_NEXT((elm), field) = NULL; \
STAILQ_NEXT((elm), field) = nullptr; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
} while (0)
#define STAILQ_LAST(head, type, field) \
(STAILQ_EMPTY((head)) ? \
NULL : \
nullptr : \
((struct type *)(void *) \
((char *)((head)->stqh_last) - __offsetof(struct type, field))))
......@@ -325,7 +325,7 @@ struct { \
while (STAILQ_NEXT(curelm, field) != (elm)) \
curelm = STAILQ_NEXT(curelm, field); \
if ((STAILQ_NEXT(curelm, field) = \
STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == nullptr)\
(head)->stqh_last = &STAILQ_NEXT((curelm), field);\
} \
TRASHIT((elm)->field.stqe_next); \
......@@ -333,12 +333,12 @@ struct { \
#define STAILQ_REMOVE_HEAD(head, field) do { \
if ((STAILQ_FIRST((head)) = \
STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
STAILQ_NEXT(STAILQ_FIRST((head)), field)) == nullptr) \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \
if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == nullptr) \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
......@@ -351,7 +351,7 @@ struct name { \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
{ nullptr }
#define LIST_ENTRY(type) \
struct { \
......@@ -365,14 +365,14 @@ struct { \
#if (defined(_KERNEL) && defined(INVARIANTS)) || defined(QUEUE_MACRO_DEBUG)
#define QMD_LIST_CHECK_HEAD(head, field) do { \
if (LIST_FIRST((head)) != NULL && \
if (LIST_FIRST((head)) != nullptr && \
LIST_FIRST((head))->field.le_prev != \
&LIST_FIRST((head))) \
panic("Bad list head %p first->prev != head", (head)); \
} while (0)
#define QMD_LIST_CHECK_NEXT(elm, field) do { \
if (LIST_NEXT((elm), field) != NULL && \
if (LIST_NEXT((elm), field) != nullptr && \
LIST_NEXT((elm), field)->field.le_prev != \
&((elm)->field.le_next)) \
panic("Bad link elm %p next->prev != elm", (elm)); \
......@@ -388,7 +388,7 @@ struct { \
#define QMD_LIST_CHECK_PREV(elm, field)
#endif /* (_KERNEL && INVARIANTS) || QUEUE_MACRO_DEBUG */
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#define LIST_EMPTY(head) ((head)->lh_first == nullptr)
#define LIST_FIRST(head) ((head)->lh_first)
......@@ -408,7 +408,7 @@ struct { \
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
QMD_LIST_CHECK_NEXT(listelm, field); \
if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != nullptr)\
LIST_NEXT((listelm), field)->field.le_prev = \
&LIST_NEXT((elm), field); \
LIST_NEXT((listelm), field) = (elm); \
......@@ -425,7 +425,7 @@ struct { \
#define LIST_INSERT_HEAD(head, elm, field) do { \
QMD_LIST_CHECK_HEAD((head), field); \
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != nullptr) \
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
LIST_FIRST((head)) = (elm); \
(elm)->field.le_prev = &LIST_FIRST((head)); \
......@@ -436,7 +436,7 @@ struct { \
#define LIST_REMOVE(elm, field) do { \
QMD_LIST_CHECK_NEXT(elm, field); \
QMD_LIST_CHECK_PREV(elm, field); \
if (LIST_NEXT((elm), field) != NULL) \
if (LIST_NEXT((elm), field) != nullptr) \
LIST_NEXT((elm), field)->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = LIST_NEXT((elm), field); \
......@@ -455,7 +455,7 @@ struct name { \
}
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
{ nullptr, &(head).tqh_first }
#define TAILQ_ENTRY(type) \
struct { \
......@@ -478,7 +478,7 @@ struct { \
} \
} while (0)
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#define TAILQ_EMPTY(head) ((head)->tqh_first == nullptr)
#define TAILQ_FIRST(head) ((head)->tqh_first)
......@@ -503,13 +503,13 @@ struct { \
(var) = (tvar))
#define TAILQ_INIT(head) do { \
TAILQ_FIRST((head)) = NULL; \
TAILQ_FIRST((head)) = nullptr; \
(head)->tqh_last = &TAILQ_FIRST((head)); \
QMD_TRACE_HEAD(head); \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != nullptr)\
TAILQ_NEXT((elm), field)->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else { \
......@@ -532,7 +532,7 @@ struct { \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != nullptr) \
TAILQ_FIRST((head))->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else \
......@@ -544,7 +544,7 @@ struct { \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
TAILQ_NEXT((elm), field) = NULL; \
TAILQ_NEXT((elm), field) = nullptr; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
......@@ -561,7 +561,7 @@ struct { \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_REMOVE(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field)) != NULL) \
if ((TAILQ_NEXT((elm), field)) != nullptr) \
TAILQ_NEXT((elm), field)->field.tqe_prev = \
(elm)->field.tqe_prev; \
else { \
......
// This file exists to build lwip
......@@ -39,7 +39,7 @@ pread_allocwork(struct inode *ip, size_t count, off_t off,
struct ipcmsg *msg, void *ubuf)
{
struct work *w = allocwork();
if (w == NULL)
if (w == nullptr)
return 0;
w->rip = (void*) pread_work;
......@@ -79,7 +79,7 @@ sys_async(int fd, size_t count, off_t off,
f->ip->ref++;
w = pread_allocwork(f->ip, count, off, msg, ubuf);
if (w == NULL) {
if (w == nullptr) {
iput(f->ip);
return -1;
}
......
......@@ -163,7 +163,7 @@ cilk_push(void (*fn)(uptr, uptr), u64 arg0, u64 arg1)
struct cilkthread *th;
th = (struct cilkthread *) kalloc();
if (th == NULL) {
if (th == nullptr) {
fn(arg0, arg1);
return;
}
......@@ -189,7 +189,7 @@ cilk_trywork(void)
pushcli();
th = __cilk_pop(cilk_cur());
if (th != NULL) {
if (th != nullptr) {
__cilk_run(th);
popcli();
return 1;
......@@ -201,7 +201,7 @@ cilk_trywork(void)
continue;
th = __cilk_steal(&queue[i]);
if (th != NULL) {
if (th != nullptr) {
__cilk_run(th);
popcli();
return 1;
......@@ -233,12 +233,12 @@ cilk_end(void)
struct cilkthread *th;
int i;
while ((th = __cilk_pop(cilk_cur())) != NULL)
while ((th = __cilk_pop(cilk_cur())) != nullptr)
__cilk_run(th);
for (i = 0; i < NCPU; i++) {
th = __cilk_steal(&queue[i]);
if (th != NULL) {
if (th != nullptr) {
__cilk_run(th);
break;
}
......
......@@ -16,7 +16,6 @@
#include "lib.h"
#include <stdarg.h>
#include "fmt.hh"
#include <stddef.h>
#include "sperf.hh"
#define BACKSPACE 0x100
......@@ -144,7 +143,7 @@ puts(const char *s)
ep = p+strlen(s);
for (; p < ep; p++)
writecons(*p, NULL);
writecons(*p, nullptr);
}
......@@ -162,13 +161,13 @@ void __noret__
kerneltrap(struct trapframe *tf)
{
const char *name = "(no name)";
void *kstack = NULL;
void *kstack = nullptr;
int pid = 0;
cli();
acquire(&cons.lock);
if (myproc() != NULL) {
if (myproc() != nullptr) {
if (myproc()->name && myproc()->name[0] != 0)
name = myproc()->name;
pid = myproc()->pid;
......
......@@ -241,7 +241,7 @@ crange::del_index(range *p0, range **e, int l)
if (!(*e)->next[l].mark()) // don't remove unmarked ranges from index
return r;
if (l == 0) return 0; // but not on level 0; they are locked when removed
// crange_check(cr, NULL);
// crange_check(cr, nullptr);
while (*e && (*e)->next[l].mark()) {
#if 0
if (l != (*e)->curlevel) {
......@@ -276,7 +276,7 @@ crange::add_index(int l, range *e, range *p1, markptr<range> s1)
{
if (l >= e->nlevel-1) return;
if (e->next[l+1].mark()) return;
// crange_check(cr, NULL);
// crange_check(cr, nullptr);
if (std::atomic_compare_exchange_strong(&e->curlevel, &l, l+1)) {
assert(e->curlevel < e->nlevel);
// this is the core inserting at level l+1, but some core may be deleting
......
......@@ -143,7 +143,7 @@ allocrx(void)
if (desc->wrx_status & WRX_ST_DD)
panic("allocrx");
buf = netalloc();
if (buf == NULL)
if (buf == nullptr)
panic("Oops");
desc->wrx_addr = v2p(buf);
......
......@@ -13,7 +13,6 @@
#include "elf.hh"
#include "cpu.hh"
#include "prof.hh"
#include <stddef.h>
#define USTACKPAGES 2
#define BRK (USERTOP >> 1)
......@@ -33,7 +32,7 @@ dosegment(uptr a0, u64 a1)
{
struct eargs *args = (eargs*) a0;
u64 off = a1;
struct vmnode *vmn = NULL;
struct vmnode *vmn = nullptr;
struct proghdr ph;
prof_start(dosegment_prof);
......@@ -71,7 +70,7 @@ bad:
static void dostack(uptr a0, u64 a1)
{
struct vmnode *vmn = NULL;
struct vmnode *vmn = nullptr;
struct eargs *args = (eargs*) a0;
int argc;
uptr sp;
......@@ -124,7 +123,7 @@ bad:
static void doheap(uptr a0, u64 a1)
{
struct vmnode *vmn = NULL;
struct vmnode *vmn = nullptr;
struct eargs *args = (eargs*) a0;
prof_start(doheap_prof);
......@@ -145,8 +144,8 @@ bad:
int
exec(const char *path, char **argv)
{
struct inode *ip = NULL;
struct vmap *vmp = NULL;
struct inode *ip = nullptr;
struct vmap *vmp = nullptr;
struct elfhdr elf;
struct proghdr ph;
u64 off;
......@@ -182,7 +181,7 @@ exec(const char *path, char **argv)
for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
Elf64_Word type;
if(readi(ip, (char*)&type,
off+offsetof(struct proghdr, type),
off+__offsetof(struct proghdr, type),
sizeof(type)) != sizeof(type))
goto bad;
if(type != ELF_PROG_LOAD)
......
......@@ -177,7 +177,7 @@ gc_delayed(rcu_freed *e)
void
gc_begin_epoch(void)
{
if (myproc() == NULL) return;
if (myproc() == nullptr) return;
u64 v = myproc()->epoch++;
if (v & 0xff)
return;
......@@ -189,7 +189,7 @@ gc_begin_epoch(void)
void
gc_end_epoch(void)
{
if (myproc() == NULL) return;
if (myproc() == nullptr) return;
u64 e = --myproc()->epoch;
if ((e & 0xff) == 0 && gc_state[mycpu()->id].ndelayed > NGC)
cv_wakeup(&gc_state[mycpu()->id].cv);
......
......@@ -10,7 +10,6 @@
#include "condvar.h"
#include "proc.hh"
#include "vm.hh"
#include <stddef.h>
using namespace std;
......@@ -28,10 +27,10 @@ retry:
next = (pgmap*) p2v(PTE_ADDR(entry));
} else {
if (!create)
return NULL;
return nullptr;
next = (pgmap*) kalloc();
if (!next)
return NULL;
return nullptr;
memset(next, 0, PGSIZE);
if (!cmpxch(entryp, entry, v2p(next) | PTE_P | PTE_W | flags)) {
kfree((void*) next);
......@@ -48,14 +47,14 @@ atomic<pme_t>*
walkpgdir(pgmap *pml4, u64 va, int create)
{
auto pdp = descend(pml4, va, PTE_U, create, 3);
if (pdp == NULL)
return NULL;
if (pdp == nullptr)
return nullptr;
auto pd = descend(pdp, va, PTE_U, create, 2);
if (pd == NULL)
return NULL;
if (pd == nullptr)
return nullptr;
auto pt = descend(pd, va, PTE_U, create, 1);
if (pt == NULL)
return NULL;
if (pt == nullptr)
return nullptr;
return &pt->e[PX(0,va)];
}
......@@ -97,7 +96,7 @@ setupkshared(pgmap *pml4, char *kshared)
{
for (u64 off = 0; off < KSHAREDSIZE; off+=4096) {
atomic<pme_t> *pte = walkpgdir(pml4, (u64) (KSHARED+off), 1);
if (pte == NULL)
if (pte == nullptr)
panic("setupkshared: oops");
*pte = v2p(kshared+off) | PTE_P | PTE_U | PTE_W;
}
......@@ -122,7 +121,7 @@ switchvm(struct proc *p)
SEGDESC(base, (sizeof(mycpu()->ts)-1), SEG_P|SEG_TSS64A);
mycpu()->gdt[(TSSSEG>>3)+1] = (struct segdesc) SEGDESCHI(base);
mycpu()->ts.rsp[0] = (u64) myproc()->kstack + KSTACKSIZE;
mycpu()->ts.iomba = (u16)offsetof(struct taskstate, iopb);
mycpu()->ts.iomba = (u16)__offsetof(struct taskstate, iopb);
ltr(TSSSEG);
if (p->vmap != 0 && p->vmap->pml4 != 0)
lcr3(v2p(p->vmap->pml4)); // switch to new address space
......@@ -184,7 +183,7 @@ inittls(void)
writemsr(MSR_GS_BASE, (u64)&c->cpu);
writemsr(MSR_GS_KERNBASE, (u64)&c->cpu);
c->cpu = c;
c->proc = NULL;
c->proc = nullptr;
c->kmem = &kmems[cpunum()];
}
......
......@@ -16,6 +16,9 @@ idleloop(void)
//extern void testwq(void);
//testwq();
extern void benchwq(void);
benchwq();
// Enabling mtrace calls in scheduler generates many mtrace_call_entrys.
// mtrace_call_set(1, cpu->id);
//mtstart(scheduler, idlep);
......
......@@ -43,7 +43,7 @@ memsize(void *va)
paddr pa = v2p(va);
e = memsearch(pa);
if (e == NULL)
if (e == nullptr)
return -1;
return (e->base+e->length) - pa;
}
......@@ -55,7 +55,7 @@ memnext(void *va, u64 inc)
paddr pa = v2p(va);
e = memsearch(pa);
if (e == NULL)
if (e == nullptr)
return (void *)-1;
pa += inc;
......
......@@ -100,7 +100,7 @@ start_timer(struct timer_thread *t, void (*func)(void),
initcondvar(&t->waitcv, name);
initlock(&t->waitlk, name, LOCKSTAT_NET);
p = threadalloc(net_timer, t);
if (p == NULL)
if (p == nullptr)
panic("net: start_timer");
acquire(&p->lock);
......@@ -187,7 +187,7 @@ initnet_worker(void *x)
lwip_core_lock();
memset(&nif, 0, sizeof(nif));
lwip_init(&nif, NULL, 0, 0, 0);
lwip_init(&nif, nullptr, 0, 0, 0);
dhcp_start(&nif);
......@@ -249,11 +249,11 @@ initnet(void)
{
struct proc *t;
devsw[NETIF].write = NULL;
devsw[NETIF].write = nullptr;
devsw[NETIF].read = netifread;
t = threadalloc(initnet_worker, NULL);
if (t == NULL)
t = threadalloc(initnet_worker, nullptr);
if (t == nullptr)
panic("initnet: threadalloc");
acquire(&t->lock);
......@@ -279,7 +279,7 @@ netbind(int sock, void *xaddr, int xaddrlen)
long r;
addr = kmalloc(xaddrlen);
if (addr == NULL)
if (addr == nullptr)
return -1;
if (umemcpy(addr, xaddr, xaddrlen))
......@@ -315,7 +315,7 @@ netaccept(int sock, void *xaddr, void *xaddrlen)
return -1;
addr = kmalloc(len);
if (addr == NULL)
if (addr == nullptr)
return -1;
lwip_core_lock();
......@@ -353,7 +353,7 @@ netwrite(int sock, char *ubuf, int len)
int r;
kbuf = kalloc();
if (kbuf == NULL)
if (kbuf == nullptr)
return -1;
cc = MIN(len, PGSIZE);
......@@ -376,7 +376,7 @@ netread(int sock, char *ubuf, int len)
int r;
kbuf = kalloc();
if (kbuf == NULL)
if (kbuf == nullptr)
return -1;
cc = MIN(len, PGSIZE);
......
......@@ -77,7 +77,6 @@ proc::set_state(enum procstate s)
panic("ZOMBIE -> %u", s);
}
state_ = s;
}
// Give up the CPU for one scheduling round.
......@@ -100,7 +99,7 @@ forkret(void)
// Just for the first process. can't do it earlier
// b/c file system code needs a process context
// in which to call cv_sleep().
if(myproc()->cwd == NULL) {
if(myproc()->cwd == nullptr) {
mtstart(forkret, myproc());
myproc()->cwd = namei("/");
mtstop(myproc());
......@@ -131,7 +130,7 @@ exit(void)
}
// Kernel threads might not have a cwd
if (myproc()->cwd != NULL) {
if (myproc()->cwd != nullptr) {
iput(myproc()->cwd);
myproc()->cwd = 0;
}
......@@ -154,7 +153,7 @@ exit(void)
// Parent might be sleeping in wait().
acquire(&(myproc()->lock));
// Kernel threads might not have a parent
if (myproc()->parent != NULL)
if (myproc()->parent != nullptr)
cv_wakeup(&(myproc()->parent->cv));
if (wakeupinit)
cv_wakeup(&bootproc->cv);
......@@ -522,11 +521,11 @@ threadalloc(void (*fn)(void *), void *arg)
struct proc *p;
p = allocproc();
if (p == NULL)
if (p == nullptr)
return 0;
p->vmap = new vmap();
if (p->vmap == NULL) {
if (p->vmap == nullptr) {
freeproc(p);
return 0;
}
......@@ -545,7 +544,7 @@ threadpin(void (*fn)(void*), void *arg, const char *name, int cpu)
struct proc *p;
p = threadalloc(fn, arg);
if (p == NULL)
if (p == nullptr)
panic("threadpin: alloc");
snprintf(p->name, sizeof(p->name), "%s", name);
......
......@@ -185,7 +185,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
u64 cc;
hdr = (logheader*) kmalloc(len);
if (hdr == NULL)
if (hdr == nullptr)
return -1;
hdr->ncpus = NCPU;
i = 0;
......@@ -261,7 +261,7 @@ initsamp(void)
lcr4(cr4 | CR4_PCE);
void *p = ksalloc(slab_perf);
if (p == NULL)
if (p == nullptr)
panic("initprof: ksalloc");
pmulog[cpunum()].event = (pmuevent*) p;
pmulog[cpunum()].capacity = PERFSIZE / sizeof(struct pmuevent);
......
......@@ -11,7 +11,6 @@
#include "kmtrace.hh"
#include "sched.hh"
#include "vm.hh"
#include <stddef.h>
enum { sched_debug = 0 };
......@@ -137,7 +136,7 @@ steal(void)
// then p->lock can result in deadlock. So we acquire
// q->lock, scan for a process, drop q->lock, acquire p->lock,
// and then check that it's still ok to steal p.
steal = NULL;
steal = nullptr;
if (tryacquire(&q->lock) == 0)
continue;
STAILQ_FOREACH(p, &q->q, runqlink) {
......@@ -178,7 +177,7 @@ schednext(void)
{
// No locks, interrupts enabled
struct runq *q;
struct proc *p = NULL;
struct proc *p = nullptr;
pushcli();
q = &runq[mycpu()->id];
......
......@@ -45,7 +45,7 @@ locking(struct spinlock *lk)
#endif
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL)
if (lockstat_enable && lk->stat != nullptr)
mylockstat(lk)->locking_ts = rdtsc();
#endif
......@@ -64,7 +64,7 @@ locked(struct spinlock *lk, u64 retries)
#endif
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL) {
if (lockstat_enable && lk->stat != nullptr) {
struct cpulockstat *s = mylockstat(lk);
if (retries > 0)
s->contends++;
......@@ -92,7 +92,7 @@ releasing(struct spinlock *lk)
#endif
#if LOCKSTAT
if (lockstat_enable && lk->stat != NULL) {
if (lockstat_enable && lk->stat != nullptr) {
struct cpulockstat *s = mylockstat(lk);
u64 ts = rdtsc();
s->locking += ts - s->locking_ts;
......@@ -112,12 +112,12 @@ holding(struct spinlock *lock)
#if LOCKSTAT
LIST_HEAD(lockstat_list, klockstat);
static struct lockstat_list lockstat_list = { (struct klockstat*) NULL };
static struct lockstat_list lockstat_list = { (struct klockstat*) nullptr };
static struct spinlock lockstat_lock = {
locked: 0,
#if SPINLOCK_DEBUG
name: "lockstat",
cpu: (struct cpu*) NULL,
cpu: (struct cpu*) nullptr,
#endif
};
......@@ -144,7 +144,7 @@ lockstat_init(struct spinlock *lk)
static void
lockstat_stop(struct spinlock *lk)
{
if (lk->stat != NULL)
if (lk->stat != nullptr)
lk->stat->magic = 0;
}
......@@ -183,14 +183,14 @@ lockstat_read(struct inode *ip, char *dst, u32 off, u32 n)
return -1;
acquire(&lockstat_lock);
if (cache.off == off && cache.stat != NULL) {
if (cache.off == off && cache.stat != nullptr) {
cur = cache.off;
stat = cache.stat;
} else {
cur = 0;
stat = LIST_FIRST(&lockstat_list);
}
for (; stat != NULL; stat = LIST_NEXT(stat, link)) {
for (; stat != nullptr; stat = LIST_NEXT(stat, link)) {
struct lockstat *ls = &stat->s;
if (n < sizeof(*ls))
break;
......@@ -205,7 +205,7 @@ lockstat_read(struct inode *ip, char *dst, u32 off, u32 n)
if (cur < off) {
cache.off = 0;
cache.stat = (struct klockstat*) NULL;
cache.stat = (struct klockstat*) nullptr;
return 0;
}
......@@ -256,7 +256,7 @@ initlock(struct spinlock *lk, const char *name, int lockstat)
lk->cpu = 0;
#endif
#if LOCKSTAT
lk->stat = (struct klockstat*) NULL;
lk->stat = (struct klockstat*) nullptr;
if (lockstat)
lockstat_init(lk);
#endif
......
......@@ -449,7 +449,7 @@ allocsocket(struct file **rf, int *rfd)
int fd;
f = filealloc();
if (f == NULL)
if (f == nullptr)
return -1;
fd = fdalloc(f);
......
......@@ -144,7 +144,7 @@ vmap::vmap()
goto err;
}
if (kshared == NULL) {
if (kshared == nullptr) {
cprintf("vmap::vmap: kshared out of memory\n");
goto err;
}
......
......@@ -82,7 +82,7 @@ int
wq_push1(void (*fn)(struct work *w, void *a0), void *a0)
{
struct work *w = allocwork();
if (w == NULL)
if (w == nullptr)
return -1;
w->rip = (void*) fn;
w->arg0 = a0;
......@@ -97,7 +97,7 @@ int
wq_push2(void (*fn)(struct work*, void*, void*), void *a0, void *a1)
{
struct work *w = allocwork();
if (w == NULL)
if (w == nullptr)
return -1;
w->rip = (void*) fn;
w->arg0 = a0;
......@@ -177,7 +177,7 @@ wq_trywork(void)
pushcli();
w = __wq_pop(mycpu()->id);
if (w != NULL) {
if (w != nullptr) {
__wq_run(w);
popcli();
return 1;
......@@ -188,7 +188,7 @@ wq_trywork(void)
continue;
w = __wq_steal(i);
if (w != NULL) {
if (w != nullptr) {
__wq_run(w);
popcli();
return 1;
......@@ -330,9 +330,6 @@ benchwq(void)
cprintf("wq_push one: %lu\n", (e-s)/alloc_iters);
wq_dump();
} else {
while (running)
wq_trywork();
}
popcli();
}
......
#include "types.h"
#include <stddef.h>
#include <stdarg.h>
#include "fmt.hh"
#include "lib.h"
......@@ -168,7 +167,7 @@ vprintfmt(void (*putch)(int, void*), void *putdat,
// string
case 's':
if ((p = va_arg (ap, char *)) == NULL)
if ((p = va_arg (ap, char *)) == nullptr)
p = "(null)";
if (width > 0 && padc != '-')
for (width -= strlen (p); width > 0; width--)
......
......@@ -8,7 +8,7 @@ msgid_t
ipc_msg_alloc(void)
{
if (ipcctl->msghead - ipcctl->msgtail == IPC_NMSG)
return NULL_MSGID;
return nullptr_MSGID;
msgid_t i = ipcctl->msghead % IPC_NMSG;
ipcctl->msghead++;
......@@ -30,7 +30,7 @@ pageid_t
ipc_page_alloc(void)
{
if (ipcctl->pagehead - ipcctl->pagetail == IPC_NPAGE)
return NULL_PAGEID;
return nullptr_PAGEID;
pageid_t i = ipcctl->pagehead % IPC_NPAGE;
ipcctl->pagehead++;
......
......@@ -16,13 +16,13 @@ fasync(FILE *fp, size_t count, off_t off)
pageid_t pageid;
msgid = ipc_msg_alloc();
if (msgid == NULL_MSGID) {
if (msgid == nullptr_MSGID) {
fprintf(2, "fasync: ipc_msg_alloc failed\n");
return -1;
}
pageid = ipc_page_alloc();
if (pageid == NULL_PAGEID) {
if (pageid == nullptr_PAGEID) {
fprintf(2, "fasync: ipc_alloc_page failed\n");
return -1;
}
......
......@@ -56,7 +56,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
size = 0;
buf = (u8*) netalloc();
if (buf == NULL) {
if (buf == nullptr) {
cprintf("low_level_output: netalloc failed\n");
return ERR_MEM;
}
......@@ -65,7 +65,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
for(q = p; q != NULL; q = q->next) {
for(q = p; q != nullptr; q = q->next) {
/* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len
variable. */
......@@ -90,7 +90,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
* nullptr on memory error
*/
static struct pbuf *
low_level_input(struct netif *netif, void *buf, u16_t len)
......@@ -104,7 +104,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len)
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
if (p != nullptr) {
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
......@@ -113,7 +113,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len)
int copied = 0;
/* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */
for(q = p; q != NULL; q = q->next) {
for(q = p; q != nullptr; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable.
......@@ -161,7 +161,7 @@ if_input(struct netif *netif, void *buf, u16 len)
p = low_level_input(netif, buf, len);
netfree(buf);
/* no packet could be read, silently ignore this */
if (p == NULL) return;
if (p == nullptr) return;
/* points to packet payload, which starts with an Ethernet header */
ethhdr = (eth_hdr*) p->payload;
......@@ -198,7 +198,7 @@ if_input(struct netif *netif, void *buf, u16 len)
err_t
if_init(struct netif *netif)
{
netif->state = NULL;
netif->state = nullptr;
netif->output = etharp_output;
netif->linkoutput = low_level_output;
memmove(&netif->name[0], "en", 2);
......
......@@ -209,13 +209,13 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
struct proc *p;
lt = (struct lwip_thread*) kmalloc(sizeof(*lt));
if (lt == NULL)
if (lt == nullptr)
return 0;
lt->thread = thread;
lt->arg = arg;
p = threadalloc(lwip_thread, lt);
if (p == NULL)
if (p == nullptr)
panic("lwip: sys_thread_new");
safestrcpy(p->name, name, sizeof(p->name));
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论