summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
Diffstat (limited to 'user')
-rw-r--r--user/monitor_user.c44
-rw-r--r--user/monitor_user.h20
2 files changed, 64 insertions, 0 deletions
diff --git a/user/monitor_user.c b/user/monitor_user.c
new file mode 100644
index 0000000..91da839
--- /dev/null
+++ b/user/monitor_user.c
@@ -0,0 +1,44 @@
+#include "monitor_user.h"
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#define DEVICE "/dev/variable_monitor"
+int file_desc = -1;
+
+/// @brief start watch
+/// @param w_arg
+/// @return 0 means success, other means fail
+int start_watch(watch_arg w_arg) {
+ if (file_desc < 0) {
+ file_desc = open(DEVICE, 0);
+ }
+ if (file_desc < 0) {
+ printf("Can't open device file: %s\n", DEVICE);
+ return -1;
+ }
+
+ if (ioctl(file_desc, 1, &w_arg) < 0) {
+ printf("ioctl failed\n");
+ close(file_desc);
+ return -1;
+ }
+ return 0;
+}
+
+/// @brief cancel watch
+/// @return 0 means success, other means fail
+int cancel_watch() {
+ if (file_desc < 0) {
+ file_desc = open(DEVICE, 0);
+ }
+ if (file_desc < 0) {
+ printf("Device not open: %s,%d \n", DEVICE, file_desc);
+ return file_desc;
+ }
+
+ close(file_desc);
+ file_desc = -1;
+ return 0;
+}
diff --git a/user/monitor_user.h b/user/monitor_user.h
new file mode 100644
index 0000000..f4d9df1
--- /dev/null
+++ b/user/monitor_user.h
@@ -0,0 +1,20 @@
+// monitor_interface.h
+#include <sys/types.h>
+
+#define MAX_NAME_LEN (15) // max name length
+typedef struct {
+ pid_t task_id; // current process id
+ char name[MAX_NAME_LEN + 1]; // name
+ void *ptr; // virtual address
+ int length_byte; // byte
+ long long threshold; // threshold value
+ unsigned char unsigned_flag; // unsigned flag (true: unsigned, false: signed)
+ unsigned char greater_flag; // reverse flag (true: >, false: <)
+ unsigned long time_ns; // timer interval (ns)
+} watch_arg;
+
+// start watch
+int start_watch(watch_arg w_arg);
+
+// cancel watch
+int cancel_watch(void); \ No newline at end of file