Commit | Line | Data |
---|---|---|
b76e5200 MD |
1 | #ifndef _UAPI_LINUX_RSEQ_H |
2 | #define _UAPI_LINUX_RSEQ_H | |
3 | ||
4 | /* | |
5 | * linux/rseq.h | |
6 | * | |
7 | * Restartable sequences system call API | |
8 | * | |
9 | * Copyright (c) 2015-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
30 | #ifdef __KERNEL__ | |
31 | # include <linux/types.h> | |
32 | #else /* #ifdef __KERNEL__ */ | |
33 | # include <stdint.h> | |
34 | #endif /* #else #ifdef __KERNEL__ */ | |
35 | ||
36 | #include <asm/byteorder.h> | |
37 | ||
38 | #ifdef __LP64__ | |
39 | # define RSEQ_FIELD_u32_u64(field) uint64_t field | |
40 | #elif defined(__BYTE_ORDER) ? \ | |
41 | __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN) | |
42 | # define RSEQ_FIELD_u32_u64(field) uint32_t _padding ## field, field | |
43 | #else | |
44 | # define RSEQ_FIELD_u32_u64(field) uint32_t field, _padding ## field | |
45 | #endif | |
46 | ||
47 | enum rseq_flags { | |
48 | RSEQ_FORCE_UNREGISTER = (1 << 0), | |
49 | }; | |
50 | ||
51 | /* | |
52 | * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always | |
53 | * contained within a single cache-line. It is usually declared as | |
54 | * link-time constant data. | |
55 | */ | |
56 | struct rseq_cs { | |
57 | RSEQ_FIELD_u32_u64(start_ip); | |
58 | RSEQ_FIELD_u32_u64(post_commit_ip); | |
59 | RSEQ_FIELD_u32_u64(abort_ip); | |
60 | } __attribute__((aligned(4 * sizeof(uint64_t)))); | |
61 | ||
62 | union rseq_cpu_event { | |
63 | struct { | |
64 | /* | |
65 | * Restartable sequences cpu_id field. | |
66 | * Updated by the kernel, and read by user-space with | |
67 | * single-copy atomicity semantics. Aligned on 32-bit. | |
68 | * Negative values are reserved for user-space. | |
69 | */ | |
70 | int32_t cpu_id; | |
71 | /* | |
72 | * Restartable sequences event_counter field. | |
73 | * Updated by the kernel, and read by user-space with | |
74 | * single-copy atomicity semantics. Aligned on 32-bit. | |
75 | */ | |
76 | uint32_t event_counter; | |
77 | } e; | |
78 | /* | |
79 | * On architectures with 64-bit aligned reads, both cpu_id and | |
80 | * event_counter can be read with single-copy atomicity | |
81 | * semantics. | |
82 | */ | |
83 | uint64_t v; | |
84 | }; | |
85 | ||
86 | /* | |
87 | * struct rseq is aligned on 2 * 8 bytes to ensure it is always | |
88 | * contained within a single cache-line. | |
89 | */ | |
90 | struct rseq { | |
91 | union rseq_cpu_event u; | |
92 | /* | |
93 | * Restartable sequences rseq_cs field. | |
94 | * Contains NULL when no critical section is active for the | |
95 | * current thread, or holds a pointer to the currently active | |
96 | * struct rseq_cs. | |
97 | * Updated by user-space at the beginning and end of assembly | |
98 | * instruction sequence block, and by the kernel when it | |
99 | * restarts an assembly instruction sequence block. Read by the | |
100 | * kernel with single-copy atomicity semantics. Aligned on | |
101 | * 64-bit. | |
102 | */ | |
103 | RSEQ_FIELD_u32_u64(rseq_cs); | |
104 | } __attribute__((aligned(2 * sizeof(uint64_t)))); | |
105 | ||
106 | #endif /* _UAPI_LINUX_RSEQ_H */ |