changeset 173:7c200a8328fa

fix user malloc and spinlock redefinition
author kono
date Fri, 17 Jan 2020 14:30:07 +0900
parents 5fa74a8989b0
children 8c12438a9827
files src/file.cbc src/gearsTools/lib/Gears/Context/Template/XV6.pm src/interface/file.dg src/pipe.cbc src/spinlock.h
diffstat 5 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/file.cbc	Fri Jan 17 13:14:19 2020 +0900
+++ b/src/file.cbc	Fri Jan 17 14:30:07 2020 +0900
@@ -11,7 +11,9 @@
 #include "proc.h"
 
 #define __ncode __code
-#
+
+// data_gear "file.dg"
+
 struct devsw devsw[NDEV];
 struct cbc_devsw cbc_devsw[NDEV];
 
--- a/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Fri Jan 17 13:14:19 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Fri Jan 17 14:30:07 2020 +0900
@@ -35,6 +35,7 @@
 #define calloc(a,b)  kmalloc((a)*(b))
 #define free(a)  kfree(a)
 #else
+extern void* malloc(unsigned int sz);
 #define calloc(a,b)  malloc((a)*(b))
 #define free(a)  free(a)
 #endif
@@ -109,9 +110,6 @@
 
 #define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name)
 
-#ifndef CBC_XV6_CONTEXT
-#define CBC_XV6_CONTEXT TRUE
-
 #include "c/enumCode.h"
 
 #include "types.h"
@@ -158,6 +156,7 @@
     enum Code before;
 };
 
+#include "spinlock.h"
 typedef int Int;
 #ifndef USE_CUDAWorker
 typedef unsigned long long CUdeviceptr;
@@ -172,6 +171,8 @@
 print $out "union Data {\n";
 print $out $dgs;
 print $out  <<'EOF';
+
+#ifndef CbC_XV6_CONTEXT
     struct Context Context;
 }; // union Data end       this is necessary for context generator
 typedef union Data Data;
@@ -190,6 +191,7 @@
 
 #include "c/extern.h"
 
+#define CbC_XV6_CONTEXT 1
 extern __code start_code(struct Context* cbc_context);
 extern __code exit_code(struct Context* cbc_context);
 extern __code meta(struct Context* cbc_context, enum Code next);
--- a/src/interface/file.dg	Fri Jan 17 13:14:19 2020 +0900
+++ b/src/interface/file.dg	Fri Jan 17 14:30:07 2020 +0900
@@ -1,11 +1,14 @@
 typedef struct file <Impl> {
     union Data* file;
+    enum { FD_NONE, FD_PIPE, FD_INODE } type; //TODO: after remoe
     int          ref;   // reference count
     char         readable;
     char         writable;
     unsigned int off;
     struct stat* st;
     char* addr;
+    struct pipe *pipe; //TODO : remove
+    struct inode *ip; //TODO : remove
     int n;
     int fd;
     __code stat(Impl* file, struct stat* st, __code next(...));
--- a/src/pipe.cbc	Fri Jan 17 13:14:19 2020 +0900
+++ b/src/pipe.cbc	Fri Jan 17 14:30:07 2020 +0900
@@ -10,7 +10,8 @@
 #define PIPESIZE 512
 
 #define __ncode __code
-#
+// data_gear "pipe.h"
+
 /*
 struct pipe {
     struct spinlock lock;
--- a/src/spinlock.h	Fri Jan 17 13:14:19 2020 +0900
+++ b/src/spinlock.h	Fri Jan 17 14:30:07 2020 +0900
@@ -1,4 +1,5 @@
 // Mutual exclusion lock.
+#ifndef SPINLOCK_H
 struct spinlock {
     uint        locked;     // Is the lock held?
 
@@ -8,4 +9,5 @@
     uint        pcs[10];    // The call stack (an array of program counters)
     // that locked the lock.
 };
-
+#endif // SPINLOCK_H
+#define SPINLOCK_H