#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only # # Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org> # # Abtract class for generating kernel runtime verification monitors from specification file
# if the current kernel is from a distro this may not be a full kernel tree # verify that one of the files we are going to modify is available if os.path.exists(os.path.join(kernel_path, "rv_trace.h")):
self.rv_dir = kernel_path return
raise FileNotFoundError("Could not find the rv directory, do you have the kernel source installed?")
def _read_file(self, path): try:
fd = open(path, 'r') except OSError: raise Exception("Cannot open the file: %s" % path)
content = fd.read()
fd.close() return content
def _read_template_file(self, file): try:
path = os.path.join(self.abs_template_dir, file) return self._read_file(path) except Exception: # Specific template file not found. Try the generic template file in the template/ # directory, which is one level up
path = os.path.join(self.abs_template_dir, "..", file) return self._read_file(path)
def fill_parent(self): return"&rv_%s" % self.parent if self.parent else"NULL"
def fill_include_parent(self): if self.parent: return"#include \n" % (self.parent, self.parent) return""
def fill_tracepoint_tooltip(self):
monitor_class_type = self.fill_monitor_class_type() if self.auto_patch:
self._patch_file("rv_trace.h", "// Add new monitors based on CONFIG_%s here" % monitor_class_type, "#include " % (self.name, self.name)) return" - Patching %s/rv_trace.h, double check the result" % self.rv_dir
return""" - Edit %s/rv_trace.h:
Add this line where other tracepoints are included and %s is defined: #include <monitors/%s/%s_trace.h> """ % (self.rv_dir, monitor_class_type, self.name, self.name)
def _kconfig_marker(self, container=None) -> str: return"# Add new %smonitors here" % (container + " " if container else"")
def fill_kconfig_tooltip(self): if self.auto_patch: # monitors with a container should stay together in the Kconfig
self._patch_file("Kconfig",
self._kconfig_marker(self.parent), "source \"kernel/trace/rv/monitors/%s/Kconfig\"" % (self.name)) return" - Patching %s/Kconfig, double check the result" % self.rv_dir
return""" - Edit %s/Kconfig:
Add this line where other monitors are included:
source \"kernel/trace/rv/monitors/%s/Kconfig\" """ % (self.rv_dir, self.name)
def fill_makefile_tooltip(self):
name = self.name
name_up = name.upper() if self.auto_patch:
self._patch_file("Makefile", "# Add new monitors here", "obj-$(CONFIG_RV_MON_%s) += monitors/%s/%s.o" % (name_up, name, name)) return" - Patching %s/Makefile, double check the result" % self.rv_dir
return""" - Edit %s/Makefile:
Add this line where other monitors are included:
obj-$(CONFIG_RV_MON_%s) += monitors/%s/%s.o """ % (self.rv_dir, name_up, name, name)
def fill_monitor_tooltip(self): if self.auto_patch: return" - Monitor created in %s/monitors/%s" % (self.rv_dir, self. name) return" - Move %s/ to the kernel's monitor directory (%s/monitors)" % (self.name, self.rv_dir)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.