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

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