Debian Codegraph @

random/jitterentropy-timer.h

raw
1 /*
2 * Copyright (C) 2021, Stephan Mueller <[email protected]>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20 #ifndef JITTERENTROPY_TIMER_H
21 #define JITTERENTROPY_TIMER_H
22
23 #include "jitterentropy.h"
24
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29
30 #ifdef JENT_CONF_ENABLE_INTERNAL_TIMER
31
32 void jent_notime_block_switch(void);
33 int jent_notime_settick(struct rand_data *ec);
34 void jent_notime_unsettick(struct rand_data *ec);
35 void jent_get_nstime_internal(struct rand_data *ec, uint64_t *out);
36 int jent_notime_enable(struct rand_data *ec, unsigned int flags);
37 void jent_notime_disable(struct rand_data *ec);
38 int jent_notime_switch(struct jent_notime_thread *new_thread);
39 void jent_notime_force(void);
40 int jent_notime_forced(void);
41
42 #else /* JENT_CONF_ENABLE_INTERNAL_TIMER */
43
44 static inline void jent_notime_block_switch(void) { }
45
46 static inline int jent_notime_settick(struct rand_data *ec)
47 {
48 (void)ec;
49 return 0;
50 }
51
52 static inline void jent_notime_unsettick(struct rand_data *ec) { (void)ec; }
53
54 static inline void jent_get_nstime_internal(struct rand_data *ec, uint64_t *out)
55 {
56 (void)ec;
57 jent_get_nstime(out);
58 }
59
60 static inline int jent_notime_enable(struct rand_data *ec, unsigned int flags)
61 {
62 (void)ec;
63
64 /* If we force the timer-less noise source, we return an error */
65 if (flags & JENT_FORCE_INTERNAL_TIMER)
66 return EHEALTH;
67
68 return 0;
69 }
70
71 static inline void jent_notime_disable(struct rand_data *ec)
72 {
73 (void)ec;
74 }
75
76 static inline int jent_notime_switch(struct jent_notime_thread *new_thread)
77 {
78 (void)new_thread;
79 return -EOPNOTSUPP;
80 }
81
82 static inline void jent_notime_force(void) { }
83
84 static inline int jent_notime_forced(void) { return 0; }
85
86 #endif /* JENT_CONF_ENABLE_INTERNAL_TIMER */
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif /* JITTERENTROPY-TIMER_H */