1 /*
2 * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
3 *
4 */
5
6 #include "config.h"
7 #include <xen/lib.h>
8 #include <xen/types.h>
9 #include <xen/version.h>
10 #include <xen/livepatch.h>
11 #include <xen/livepatch_payload.h>
12
13 #include <public/sysctl.h>
14
15 static const char hello_world_patch_this_fnc[] = "xen_extra_version";
16 extern const char *xen_hello_world(void);
17 static unsigned int cnt;
18
apply_hook(void)19 static void apply_hook(void)
20 {
21 printk(KERN_DEBUG "Hook executing.\n");
22 }
23
revert_hook(void)24 static void revert_hook(void)
25 {
26 printk(KERN_DEBUG "Hook unloaded.\n");
27 }
28
hi_func(void)29 static void hi_func(void)
30 {
31 printk(KERN_DEBUG "%s: Hi! (called %u times)\n", __func__, ++cnt);
32 };
33
check_fnc(void)34 static void check_fnc(void)
35 {
36 printk(KERN_DEBUG "%s: Hi func called %u times\n", __func__, cnt);
37 BUG_ON(cnt == 0 || cnt > 2);
38 }
39
40 LIVEPATCH_LOAD_HOOK(apply_hook);
41 LIVEPATCH_UNLOAD_HOOK(revert_hook);
42
43 /* Imbalance here. Two load and three unload. */
44
45 LIVEPATCH_LOAD_HOOK(hi_func);
46 LIVEPATCH_UNLOAD_HOOK(hi_func);
47
48 LIVEPATCH_UNLOAD_HOOK(check_fnc);
49
50 struct livepatch_func __section(".livepatch.funcs") livepatch_xen_hello_world = {
51 .version = LIVEPATCH_PAYLOAD_VERSION,
52 .name = hello_world_patch_this_fnc,
53 .new_addr = xen_hello_world,
54 .old_addr = xen_extra_version,
55 .new_size = NEW_CODE_SZ,
56 .old_size = OLD_CODE_SZ,
57 };
58
59 /*
60 * Local variables:
61 * mode: C
62 * c-file-style: "BSD"
63 * c-basic-offset: 4
64 * tab-width: 4
65 * indent-tabs-mode: nil
66 * End:
67 */
68