1 | // RUN: %check_clang_tidy %s android-cloexec-memfd-create %t |
2 | |
3 | #define MFD_ALLOW_SEALING 1 |
4 | #define __O_CLOEXEC 3 |
5 | #define MFD_CLOEXEC __O_CLOEXEC |
6 | #define TEMP_FAILURE_RETRY(exp) \ |
7 | ({ \ |
8 | int _rc; \ |
9 | do { \ |
10 | _rc = (exp); \ |
11 | } while (_rc == -1); \ |
12 | }) |
13 | #define NULL 0 |
14 | |
15 | extern "C" int memfd_create(const char *name, unsigned int flags); |
16 | |
17 | void a() { |
18 | memfd_create(NULL, MFD_ALLOW_SEALING); |
19 | // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: 'memfd_create' should use MFD_CLOEXEC where possible [android-cloexec-memfd-create] |
20 | // CHECK-FIXES: memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC) |
21 | TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING)); |
22 | // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: 'memfd_create' |
23 | // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC)) |
24 | } |
25 | |
26 | void f() { |
27 | memfd_create(NULL, flags: 3); |
28 | // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'memfd_create' |
29 | // CHECK-FIXES: memfd_create(NULL, 3 | MFD_CLOEXEC) |
30 | TEMP_FAILURE_RETRY(memfd_create(NULL, 3)); |
31 | // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: 'memfd_create' |
32 | // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, 3 | MFD_CLOEXEC)) |
33 | |
34 | int flag = 3; |
35 | memfd_create(NULL, flags: flag); |
36 | TEMP_FAILURE_RETRY(memfd_create(NULL, flag)); |
37 | } |
38 | |
39 | namespace i { |
40 | int memfd_create(const char *name, unsigned int flags); |
41 | |
42 | void d() { |
43 | memfd_create(NULL, MFD_ALLOW_SEALING); |
44 | TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING)); |
45 | } |
46 | |
47 | } // namespace i |
48 | |
49 | void e() { |
50 | memfd_create(NULL, MFD_CLOEXEC); |
51 | TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_CLOEXEC)); |
52 | memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC); |
53 | TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC)); |
54 | } |
55 | |
56 | class G { |
57 | public: |
58 | int memfd_create(const char *name, unsigned int flags); |
59 | void d() { |
60 | memfd_create(NULL, MFD_ALLOW_SEALING); |
61 | TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING)); |
62 | } |
63 | }; |
64 | |