[core] split hook code out of module.c

pull/1/head
Geoffrey McRae 4 years ago
parent dd8eadc6e7
commit b62fdae038

@ -3,6 +3,6 @@ vendor-reset-y += \
src/vendor-reset-dev.o \
src/ioctl.o \
src/ftrace.o \
src/hooks.o
src/hook.o
ccflags-y += -I$(src)/src

@ -17,12 +17,19 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/kernel.h>
#include <linux/pci.h>
#include "vendor-reset-dev.h"
#include "hook.h"
#include "ftrace.h"
#include "hooks.h"
#include "vendor-reset-dev.h"
#include <linux/module.h>
#define vr_info(fmt, args...) pr_info("vendor-reset-hook: " fmt, ##args)
#define vr_warn(fmt, args...) pr_warn("vendor-reset-hook: " fmt, ##args)
static bool install_hook = true;
module_param(install_hook, bool, 0);
static bool hook_installed = false;
static int (*orig_pci_dev_specific_reset)(struct pci_dev *dev, int probe);
static int hooked_pci_dev_specific_reset(struct pci_dev *dev, int probe)
@ -42,6 +49,34 @@ static int hooked_pci_dev_specific_reset(struct pci_dev *dev, int probe)
}
struct ftrace_hook fh_hooks[] = {
HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset),
{0},
HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset),
{0},
};
long vendor_reset_hook_init(void)
{
int ret = 0;
if (install_hook)
{
ret = fh_install_hooks(fh_hooks);
if (ret)
vr_warn("install failed");
else
{
vr_info("installed");
hook_installed = true;
}
}
return ret;
}
void vendor_reset_hook_exit(void)
{
if (hook_installed)
{
fh_remove_hooks(fh_hooks);
hook_installed = false;
}
}

@ -17,11 +17,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __VENDOR_RESET_HOOKS_H__
#define __VENDOR_RESET_HOOKS_H__
#ifndef __VENDOR_RESET_HOOK_H__
#define __VENDOR_RESET_HOOK_H__
#include <linux/types.h>
long vendor_reset_hook_init(void);
void vendor_reset_hook_exit(void);
extern struct ftrace_hook fh_hooks[];
#endif
#endif

@ -20,13 +20,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <linux/module.h>
#include "ioctl.h"
#include "ftrace.h"
#include "hooks.h"
#define vr_info(fmt, args...) pr_info("vendor-reset: " fmt, ##args)
static bool install_hook = true;
static int __init vendor_reset_init(void)
{
int ret;
@ -35,14 +30,9 @@ static int __init vendor_reset_init(void)
if (ret)
return ret;
if (install_hook)
{
ret = fh_install_hooks(fh_hooks);
if (ret)
goto err;
vr_info("hooks installed\n");
}
ret = vendor_reset_hook_init();
if (ret)
goto err;
return 0;
@ -53,15 +43,12 @@ err:
static void __exit vendor_reset_exit(void)
{
if (install_hook)
fh_remove_hooks(fh_hooks);
vendor_reset_hook_exit();
vendor_reset_ioctl_exit();
}
module_init(vendor_reset_init);
module_exit(vendor_reset_exit);
module_param(install_hook, bool, 0);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Geoffrey McRae <geoff@hostfission.com>");

Loading…
Cancel
Save