-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrmm_kcalloc.cocci
72 lines (62 loc) · 1.68 KB
/
drmm_kcalloc.cocci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: GPL-2.0-only
/// Detect allocation that create arrays of structs using functions like alloc_large_system_hash
/// and mark the types with stores to __uncontained_array easily parsable
/// by llvm
///
// Confidence: Moderate
// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
// Copyright: (C) 2012 Gilles Muller, INRIA/LIP6.
// URL: http://coccinelle.lip6.fr/
// Comments:
// Options: --no-includes --include-headers
virtual context
virtual org
virtual report
virtual patch
@array_type@
type t;
expression c, xxx, xxx1;
fresh identifier i = "__uncontained_tmp";
position p1;
@@
c = drmm_kcalloc(xxx, xxx1, <+... sizeof(t) ...+>, ...)@p1;
++ {
++ t i;
++ __uncontained_array = (unsigned long)&i;
++ }
@array_var@
expression E, c, xxx, xxx1;
fresh identifier i = "__uncontained_tmp";
position p1;
@@
c = drmm_kcalloc(xxx, xxx1, <+... sizeof E ...+>, ...)@p1;
++ {
++ typeof (E) i;
++ __uncontained_array = (unsigned long)&i;
++ }
@add_glob_declaration depends on array_type || array_var@
@@
#include <...>
+
+ #ifndef _UNCONTAINED_ARRAY_H
+ #define _UNCONTAINED_ARRAY_H
+ static volatile unsigned long __uncontained_array;
+ #endif /*_UNCONTAINED_ARRAY_H*/
@add_glob_declaration2 depends on (array_type || array_var) && !add_glob_declaration@
@@
#include "..."
+
+ #ifndef _UNCONTAINED_ARRAY_H
+ #define _UNCONTAINED_ARRAY_H
+ static volatile unsigned long __uncontained_array;
+ #endif /*_UNCONTAINED_ARRAY_H*/
@script:python depends on report@
p1 << array_type.p1;
@@
msg = "Detected custom type allocation"
coccilib.report.print_report(p1[0], msg)
@script:python depends on report@
p1 << array_var.p1;
@@
msg = "Detected custom type allocation"
coccilib.report.print_report(p1[0], msg)