mirror of
https://github.com/gnif/vendor-reset
synced 2025-02-17 12:37:18 +00:00
[core] split hook code out of module.c
This commit is contained in:
parent
dd8eadc6e7
commit
b62fdae038
@ -3,6 +3,6 @@ vendor-reset-y += \
|
|||||||
src/vendor-reset-dev.o \
|
src/vendor-reset-dev.o \
|
||||||
src/ioctl.o \
|
src/ioctl.o \
|
||||||
src/ftrace.o \
|
src/ftrace.o \
|
||||||
src/hooks.o
|
src/hook.o
|
||||||
|
|
||||||
ccflags-y += -I$(src)/src
|
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
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include "hook.h"
|
||||||
#include <linux/pci.h>
|
|
||||||
#include "vendor-reset-dev.h"
|
|
||||||
#include "ftrace.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 (*orig_pci_dev_specific_reset)(struct pci_dev *dev, int probe);
|
||||||
|
|
||||||
static int hooked_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[] = {
|
struct ftrace_hook fh_hooks[] = {
|
||||||
HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset),
|
HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset),
|
||||||
{0},
|
{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
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __VENDOR_RESET_HOOKS_H__
|
#ifndef __VENDOR_RESET_HOOK_H__
|
||||||
#define __VENDOR_RESET_HOOKS_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
|
|
21
src/module.c
21
src/module.c
@ -20,13 +20,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
|
||||||
#include "ioctl.h"
|
#include "ioctl.h"
|
||||||
#include "ftrace.h"
|
|
||||||
#include "hooks.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)
|
static int __init vendor_reset_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -35,14 +30,9 @@ static int __init vendor_reset_init(void)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (install_hook)
|
ret = vendor_reset_hook_init();
|
||||||
{
|
if (ret)
|
||||||
ret = fh_install_hooks(fh_hooks);
|
goto err;
|
||||||
if (ret)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
vr_info("hooks installed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -53,15 +43,12 @@ err:
|
|||||||
|
|
||||||
static void __exit vendor_reset_exit(void)
|
static void __exit vendor_reset_exit(void)
|
||||||
{
|
{
|
||||||
if (install_hook)
|
vendor_reset_hook_exit();
|
||||||
fh_remove_hooks(fh_hooks);
|
|
||||||
|
|
||||||
vendor_reset_ioctl_exit();
|
vendor_reset_ioctl_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(vendor_reset_init);
|
module_init(vendor_reset_init);
|
||||||
module_exit(vendor_reset_exit);
|
module_exit(vendor_reset_exit);
|
||||||
module_param(install_hook, bool, 0);
|
|
||||||
|
|
||||||
MODULE_LICENSE("GPL v2");
|
MODULE_LICENSE("GPL v2");
|
||||||
MODULE_AUTHOR("Geoffrey McRae <geoff@hostfission.com>");
|
MODULE_AUTHOR("Geoffrey McRae <geoff@hostfission.com>");
|
||||||
|
Loading…
Reference in New Issue
Block a user