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

c++ userspace, half-way

上级 e899cb3b
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
}
char buf[512];
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
#include "fcntl.h"
}
enum { nthread = 2 };
enum { nloop = 100 };
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
}
int
main(int argc, char *argv[])
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
}
#define NITERS 16
......@@ -18,7 +20,7 @@ execbench(void)
exit();
}
if (pid == 0) {
char *av[] = { "forkexecbench", "x", 0 };
const char *av[] = { "forkexecbench", "x", 0 };
exec("forkexecbench", av);
printf(1, "exec failed\n");
exit();
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
}
#define NCHILD 2
#define NDEPTH 7
......@@ -28,7 +30,7 @@ forktree(int depth)
depth++;
char depthbuf[16];
snprintf(depthbuf, sizeof(depthbuf), "%d", depth);
char *av[] = { "forkexectree", depthbuf };
const char *av[] = { "forkexectree", depthbuf };
exec("forkexectree", av);
}
}
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
}
#define NCHILD 2
#define NDEPTH 5
......
extern "C" {
#include "types.h"
#include "user.h"
}
int
main(int argc, char *argv[])
......
extern "C" {
#include "types.h"
#include "user.h"
#include "lib.h"
#include "unet.h"
#include "fcntl.h"
#include "stat.h"
}
#define VERSION "0.1"
#define HTTP_VERSION "1.0"
......@@ -19,7 +21,7 @@ static int xwrite(int fd, const void *buf, u64 n)
printf(1, "xwrite: failed %d\n", r);
return -1;
}
buf += r;
buf = (char *) buf + r;
n -= r;
}
......@@ -208,7 +210,7 @@ parse(const char *b, char **rurl)
b++;
len = b - url;
r = malloc(len+1);
r = (char *) malloc(len+1);
if (r == NULL)
return -1;
memmove(r, url, len);
......
// init: The initial user-level program
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "lib.h"
}
static char *sh_argv[] = { "sh", 0 };
static char *app_argv[][MAXARG] = {
static const char *sh_argv[] = { "sh", 0 };
static const char *app_argv[][MAXARG] = {
#ifdef LWIP
{ "telnetd", 0 },
{ "httpd", 0 },
......@@ -15,7 +17,7 @@ static char *app_argv[][MAXARG] = {
};
static int
startone(char **argv)
startone(const char **argv)
{
int pid;
......@@ -52,7 +54,7 @@ main(void)
if (mknod("/dev/lockstat", 4, 1) < 0)
printf(2, "init: mknod lockstat failed\n");
for (int i = 0; i < NELEM(app_argv); i++)
for (u32 i = 0; i < NELEM(app_argv); i++)
startone(app_argv[i]);
for(;;){
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
}
int
main(int argc, char **argv)
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "amd64.h"
#include "lockstat.h"
}
static void
xwrite(int fd, char c)
......@@ -50,7 +52,7 @@ stats(void)
}
int
main(int ac, char *av[])
main(int ac, const char *av[])
{
int fd = open("/dev/lockstat", O_RDWR);
if (fd < 0)
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
}
static struct uspinlock l;
static volatile int tcount;
......@@ -57,7 +59,7 @@ main(int ac, char **av)
sbrk(8192);
void *tstack = sbrk(0);
// printf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, thr, (void *)(u64)i);
int tid = forkt(tstack, (void*) thr, (void *)(u64)i);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid);
}
......
......@@ -13,7 +13,8 @@ UPROGS += \
$(O)/_telnetd \
$(O)/_httpd
CFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
CFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
CXXFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
LWIP_CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -I$(QEMUSRC) \
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
}
int
main(int argc, char *argv[])
......
// Shell.
extern "C" {
#include "types.h"
#include "user.h"
#include "fcntl.h"
}
// Parsed command representation
#define EXEC 1
......@@ -19,7 +21,7 @@ struct cmd {
struct execcmd {
int type;
char *argv[MAXARGS];
const char *argv[MAXARGS];
char *eargv[MAXARGS];
};
......@@ -50,7 +52,7 @@ struct backcmd {
};
int fork1(void); // Fork but panics on failure.
void panic(char*);
void panic(const char*);
struct cmd *parsecmd(char*);
// Execute cmd. Never returns.
......@@ -173,7 +175,7 @@ main(void)
}
void
panic(char *s)
panic(const char *s)
{
printf(2, "%s\n", s);
exit();
......@@ -198,7 +200,7 @@ execcmd(void)
{
struct execcmd *cmd;
cmd = malloc(sizeof(*cmd));
cmd = (struct execcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = EXEC;
return (struct cmd*)cmd;
......@@ -209,7 +211,7 @@ redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd)
{
struct redircmd *cmd;
cmd = malloc(sizeof(*cmd));
cmd = (struct redircmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = REDIR;
cmd->cmd = subcmd;
......@@ -225,7 +227,7 @@ pipecmd(struct cmd *left, struct cmd *right)
{
struct pipecmd *cmd;
cmd = malloc(sizeof(*cmd));
cmd = (struct pipecmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = PIPE;
cmd->left = left;
......@@ -238,7 +240,7 @@ listcmd(struct cmd *left, struct cmd *right)
{
struct listcmd *cmd;
cmd = malloc(sizeof(*cmd));
cmd = (struct listcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = LIST;
cmd->left = left;
......@@ -251,7 +253,7 @@ backcmd(struct cmd *subcmd)
{
struct backcmd *cmd;
cmd = malloc(sizeof(*cmd));
cmd = (struct backcmd *) malloc(sizeof(*cmd));
memset(cmd, 0, sizeof(*cmd));
cmd->type = BACK;
cmd->cmd = subcmd;
......@@ -309,7 +311,7 @@ gettoken(char **ps, char *es, char **q, char **eq)
}
int
peek(char **ps, char *es, char *toks)
peek(char **ps, char *es, const char *toks)
{
char *s;
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "amd64.h"
}
int
main(int ac, char *av[])
......
extern "C" {
#include "types.h"
#include "user.h"
#include "unet.h"
}
int
main(void)
......@@ -46,7 +48,7 @@ main(void)
continue;
}
if (pid == 0) {
static char *argv[] = { "sh", 0 };
static const char *argv[] = { "sh", 0 };
close(0);
close(1);
close(2);
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
}
static struct uspinlock l;
static volatile int tcount;
......@@ -28,7 +30,7 @@ main(void)
for(int i = 0; i < nthread; i++) {
sbrk(8192);
void *tstack = sbrk(0);
int tid = forkt(tstack, thr, (void*)(u64)(0xc0ffee00|i));
int tid = forkt(tstack, (void*) thr, (void*)(u64)(0xc0ffee00|i));
printf(1, "thrtest[%d]: child %d\n", getpid(), tid);
}
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "amd64.h"
}
int
main(int ac, char *av[])
main(int ac, const char *av[])
{
u64 t0 = rdtsc();
......
......@@ -9,14 +9,14 @@ int write(int, const void*, int);
int read(int, void*, int);
int close(int);
int kill(int);
int exec(char*, char**);
int exec(const char*, const char**);
int open(const char*, int);
int mknod(char*, short, short);
int unlink(char*);
int mknod(const char*, short, short);
int unlink(const char*);
int fstat(int fd, struct stat*);
int link(char*, char*);
int mkdir(char*);
int chdir(char*);
int link(const char*, const char*);
int mkdir(const char*);
int chdir(const char*);
int dup(int);
int getpid(void);
char* sbrk(int);
......
extern "C" {
#include "types.h"
#include "stat.h"
#include "user.h"
......@@ -5,10 +6,11 @@
#include "fcntl.h"
#include "syscall.h"
#include "traps.h"
}
char buf[2048];
char name[3];
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
int stdout = 1;
// simple file system tests
......@@ -85,7 +87,7 @@ writetest(void)
void
writetest1(void)
{
int i, fd, n;
int fd, n;
printf(stdout, "big files test\n");
......@@ -95,7 +97,7 @@ writetest1(void)
exit();
}
for(i = 0; i < MAXFILE; i++){
for(u32 i = 0; i < MAXFILE; i++){
((int*)buf)[0] = i;
if(write(fd, buf, 512) != 512){
printf(stdout, "error: write big file failed\n", i);
......@@ -113,7 +115,7 @@ writetest1(void)
n = 0;
for(;;){
i = read(fd, buf, 512);
u32 i = read(fd, buf, 512);
if(i == 0){
if(n == MAXFILE - 1){
printf(stdout, "read only %d blocks from big", n);
......@@ -331,7 +333,7 @@ mem(void)
if((pid = fork(0)) == 0){
m1 = 0;
while((m2 = malloc(10001)) != 0){
*(char**)m2 = m1;
*(char**)m2 = (char*) m1;
m1 = m2;
}
while(m1){
......@@ -410,7 +412,7 @@ void
twofiles(void)
{
int fd, pid, i, j, n, total;
char *fname;
const char *fname;
printf(1, "twofiles test\n");
......@@ -1450,7 +1452,7 @@ bigargtest(void)
pid = fork(0);
if(pid == 0){
char *args[32+1];
const char *args[32+1];
int i;
for(i = 0; i < 32; i++)
args[i] = "bigargs test: failed\n ";
......@@ -1467,7 +1469,7 @@ bigargtest(void)
}
void
uox(char *name, char *data)
uox(char *name, const char *data)
{
int fd = open(name, O_CREATE|O_RDWR);
if(fd < 0){
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论