mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 01:51:39 +00:00
posix-timers: Prevent UB from shifting negative signed value
Shifting a negative signed number is undefined behavior. Looking at the macros MAKE_PROCESS_CPUCLOCK and FD_TO_CLOCKID, it seems that the subexpression: (~(clockid_t) (pid) << 3) where clockid_t resolves to a signed int, which once negated, is undefined behavior to shift the value of if the results thus far are negative. It was further suggested to make these macros into inline functions. Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Dimitri Sivanich <sivanich@hpe.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-kselftest@vger.kernel.org Cc: Shuah Khan <shuah@kernel.org> Cc: Deepa Dinamani <deepa.kernel@gmail.com> Link: https://lkml.kernel.org/r/1514517100-18051-1-git-send-email-nick.desaulniers@gmail.com
This commit is contained in:
parent
00a5ae218d
commit
29f1b2b0fe
4 changed files with 23 additions and 12 deletions
|
@ -42,13 +42,26 @@ struct cpu_timer_list {
|
|||
#define CLOCKFD CPUCLOCK_MAX
|
||||
#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
|
||||
|
||||
#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
|
||||
((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
|
||||
#define MAKE_THREAD_CPUCLOCK(tid, clock) \
|
||||
MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
|
||||
static inline clockid_t make_process_cpuclock(const unsigned int pid,
|
||||
const clockid_t clock)
|
||||
{
|
||||
return ((~pid) << 3) | clock;
|
||||
}
|
||||
static inline clockid_t make_thread_cpuclock(const unsigned int tid,
|
||||
const clockid_t clock)
|
||||
{
|
||||
return make_process_cpuclock(tid, clock | CPUCLOCK_PERTHREAD_MASK);
|
||||
}
|
||||
|
||||
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
|
||||
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
|
||||
static inline clockid_t fd_to_clockid(const int fd)
|
||||
{
|
||||
return make_process_cpuclock((unsigned int) fd, CLOCKFD);
|
||||
}
|
||||
|
||||
static inline int clockid_to_fd(const clockid_t clk)
|
||||
{
|
||||
return ~(clk >> 3);
|
||||
}
|
||||
|
||||
#define REQUEUE_PENDING 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue