From 763f85c55fdb5a2c4f5bf98e4989a69d27da6e4f Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 20 Sep 2018 10:46:00 +0200 Subject: pipes do not work :( --- userspace/fd.c | 3 +-- userspace/newcalls.h | 15 +++++++++++++++ userspace/piper.c | 48 ++++++++++++++++++++---------------------------- userspace/snake2.c | 2 +- userspace/snake2.h | 10 ---------- 5 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 userspace/newcalls.h delete mode 100644 userspace/snake2.h (limited to 'userspace') diff --git a/userspace/fd.c b/userspace/fd.c index 09cb28e..80ffd20 100644 --- a/userspace/fd.c +++ b/userspace/fd.c @@ -3,7 +3,6 @@ int main() { - dup(stdout); +// dup(stdout); printf("dup\n"); - } diff --git a/userspace/newcalls.h b/userspace/newcalls.h new file mode 100644 index 0000000..9bc55a5 --- /dev/null +++ b/userspace/newcalls.h @@ -0,0 +1,15 @@ +////////////////////////////////////////////////// + +// this syscall will be moved to newlib later! +#define SYSCALL_CLONE 83 +#define SYSCALL_PIPE 84 + +int _clone(void) +{ + return syscall(SYSCALL_CLONE,0,0,0); +} +int _pipe(uint32_t fds[2]) +{ + return syscall(SYSCALL_PIPE,fds,0,0); +} +// diff --git a/userspace/piper.c b/userspace/piper.c index 73b9516..e433a5c 100644 --- a/userspace/piper.c +++ b/userspace/piper.c @@ -1,42 +1,34 @@ #include +#include "newcalls.h" int main() { - setvbuf(stdout,NULL,_IONBF,0); - /* - FILE *f=fopen("~testpipe","rw"); + int fds[2]; + _pipe(fds); + + printf("opened pipe / in fd=%d,out fd=%d\n",fds[0],fds[1]); int pid=_fork(); - if(pid==0) + if(pid) { - char buf[2]; - fread(buf,1,1,f); - printf("[%c]\n",buf[0]); - while(1); - } + while(1) // read forever from our pipe and echo to stdout + { + char buf[256]; + int len=fread(buf,1,255,fds[0]); + printf("%s",buf); + } - else - { - char buf[]="666"; - fwrite(buf,1,1,f); - printf("written\n"); - while(1); } - */ - int f=_open("~testpipe","RW"); - int pid=_fork(); - if(pid==0) - { - char buf[2]; - while(_read(f,buf,1))printf("%c",buf[0]); - } - else { - char buf[]="666 the number of the beast"; - _write(f,buf,27); - printf("written\n"); + + // write to our pipe + fwrite("Hello\n",1,6,fds[1]); + fwrite("Bello\n",1,6,fds[1]); + fwrite("Gello\n",1,6,fds[1]); + + // hang forever + while(1); } - } diff --git a/userspace/snake2.c b/userspace/snake2.c index 3b179ac..6fbd092 100644 --- a/userspace/snake2.c +++ b/userspace/snake2.c @@ -1,5 +1,5 @@ #include -#include "snake2.h" +#include "newcalls.h" static char lastc='d'; diff --git a/userspace/snake2.h b/userspace/snake2.h deleted file mode 100644 index d4c47a8..0000000 --- a/userspace/snake2.h +++ /dev/null @@ -1,10 +0,0 @@ -////////////////////////////////////////////////// - -// this syscall will be moved to newlib later! -#define SYSCALL_CLONE 83 - -int _clone(void) -{ - return syscall(SYSCALL_CLONE,0,0,0); -} -// -- cgit v1.2.3