summaryrefslogtreecommitdiffstats
path: root/lib/libjove/syscall/path-fromobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libjove/syscall/path-fromobj.c')
-rw-r--r--lib/libjove/syscall/path-fromobj.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libjove/syscall/path-fromobj.c b/lib/libjove/syscall/path-fromobj.c
new file mode 100644
index 0000000..1c0c5d9
--- /dev/null
+++ b/lib/libjove/syscall/path-fromobj.c
@@ -0,0 +1,33 @@
+#include <path-fromobj.h>
+
+int
+path_fromobj_s(KernelObjectTyped *obj, uint8_t *buffer, int size)
+{
+ size_t depth = 0, odepth = 0;
+ for(KernelObjectTyped *o = obj->parent; o; o = o->parent, depth++);
+
+ odepth = depth;
+ if(depth > size) depth = size;
+
+ for(int i = 0; i < depth; i++) {
+ buffer[depth - i - 1] = obj->membi;
+ obj = obj->parent;
+ }
+ return odepth;
+}
+
+int
+path_tobuf(KernelObjectTyped *obj, uint8_t *buffer, size_t at, size_t bufferw)
+{
+ if(at + sizeof(size_t) > bufferw) return -1;
+
+ size_t *buffer_pathW = (size_t*)(&buffer[at]);
+ uint8_t *buffer_path = (uint8_t*)(&buffer_pathW[1]);
+
+ size_t maxDepth = bufferw - (buffer_path - buffer);
+ size_t objDepth = path_fromobj_s(obj, buffer_path, bufferw - (size_t)(buffer_path - buffer));
+ if(objDepth > maxDepth) return -1;
+
+ *buffer_pathW = objDepth;
+ return (int)(buffer_path - buffer) + objDepth;
+}