Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
---
 Makefile                     |  1 +
 core/osv_c_wrappers.cc       | 33 +++++++++++++++++++++++++++++++++
 include/osv/osv_c_wrappers.h | 27 +++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 core/osv_c_wrappers.cc
 create mode 100644 include/osv/osv_c_wrappers.h

diff --git a/Makefile b/Makefile
index 7e15d0e..95da609 100644
--- a/Makefile
+++ b/Makefile
@@ -908,6 +908,7 @@ objects += core/net_trace.o
 objects += core/app.o
 objects += core/libaio.o
 objects += core/osv_execve.o
+objects += core/osv_c_wrappers.o
 
 #include $(src)/libc/build.mk:
 libc =
diff --git a/core/osv_c_wrappers.cc b/core/osv_c_wrappers.cc
new file mode 100644
index 0000000..abd5fe3
--- /dev/null
+++ b/core/osv_c_wrappers.cc
@@ -0,0 +1,33 @@
+
+#include <osv/debug.hh>
+#include <osv/sched.hh>
+#include <osv/app.hh>
+
+using namespace osv;
+using namespace sched;
+
+extern "C" {
+
+int osv_get_all_app_threads(pid_t tid, pid_t** tid_arr, size_t *len) {
+    thread* app_thread = tid==0? thread::current(): thread::find_by_id(tid);
+    if (app_thread == nullptr) {
+        return ESRCH;
+    }
+    std::vector<thread*> app_threads;
+    with_all_app_threads([&](thread& th2) {
+        app_threads.push_back(&th2);
+    }, *app_thread);
+
+    *tid_arr = (pid_t*)malloc(app_threads.size()*sizeof(pid_t));
+    if (*tid_arr == nullptr) {
+        *len = 0;
+        return ENOMEM;
+    }
+    *len = 0;
+    for (auto th : app_threads) {
+        (*tid_arr)[(*len)++] = th->id();
+    }
+    return 0;
+}
+
+}
diff --git a/include/osv/osv_c_wrappers.h b/include/osv/osv_c_wrappers.h
new file mode 100644
index 0000000..acef016
--- /dev/null
+++ b/include/osv/osv_c_wrappers.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 XLAB, d.o.o.
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#ifndef INCLUDED_OSV_C_WRAPPERS_H
+#define INCLUDED_OSV_C_WRAPPERS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+Save in *tid_arr array TIDs of all threads from app which "owns" input 
tid/thread.
+*tid_arr is allocated with malloc, *len holds lenght.
+Caller is responsible to free tid_arr.
+Returns 0 on success, error code on error.
+*/
+int osv_get_all_app_threads(pid_t tid, pid_t** tid_arr, size_t* max_len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_OSV_C_WRAPPERS_H */
-- 
2.5.0

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to