diff options
Diffstat (limited to 'samples/livepatch/livepatch-shadow-fix1.c')
-rw-r--r-- | samples/livepatch/livepatch-shadow-fix1.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c index 830c55514f9f..04151c7f2631 100644 --- a/samples/livepatch/livepatch-shadow-fix1.c +++ b/samples/livepatch/livepatch-shadow-fix1.c | |||
@@ -56,6 +56,21 @@ struct dummy { | |||
56 | unsigned long jiffies_expire; | 56 | unsigned long jiffies_expire; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | /* | ||
60 | * The constructor makes more sense together with klp_shadow_get_or_alloc(). | ||
61 | * In this example, it would be safe to assign the pointer also to the shadow | ||
62 | * variable returned by klp_shadow_alloc(). But we wanted to show the more | ||
63 | * complicated use of the API. | ||
64 | */ | ||
65 | static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data) | ||
66 | { | ||
67 | void **shadow_leak = shadow_data; | ||
68 | void *leak = ctor_data; | ||
69 | |||
70 | *shadow_leak = leak; | ||
71 | return 0; | ||
72 | } | ||
73 | |||
59 | struct dummy *livepatch_fix1_dummy_alloc(void) | 74 | struct dummy *livepatch_fix1_dummy_alloc(void) |
60 | { | 75 | { |
61 | struct dummy *d; | 76 | struct dummy *d; |
@@ -74,7 +89,8 @@ struct dummy *livepatch_fix1_dummy_alloc(void) | |||
74 | * pointer to handle resource release. | 89 | * pointer to handle resource release. |
75 | */ | 90 | */ |
76 | leak = kzalloc(sizeof(int), GFP_KERNEL); | 91 | leak = kzalloc(sizeof(int), GFP_KERNEL); |
77 | klp_shadow_alloc(d, SV_LEAK, &leak, sizeof(leak), GFP_KERNEL); | 92 | klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL, |
93 | shadow_leak_ctor, leak); | ||
78 | 94 | ||
79 | pr_info("%s: dummy @ %p, expires @ %lx\n", | 95 | pr_info("%s: dummy @ %p, expires @ %lx\n", |
80 | __func__, d, d->jiffies_expire); | 96 | __func__, d, d->jiffies_expire); |