[libc-commits] [libc] [libc] fortify jmp buffer for x86-64 (PR #112769)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Mon Dec 2 13:23:23 PST 2024
================
@@ -0,0 +1,34 @@
+//===-- Implementation header for jmpbuf checksum ---------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SETJMP_CHECKSUM_H
+#define LLVM_LIBC_SRC_SETJMP_CHECKSUM_H
+
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace jmpbuf {
+
+extern __UINTPTR_TYPE__ value_mask;
+extern __UINTPTR_TYPE__ checksum_cookie;
+
+// single register update derived from aHash
+// https://github.com/tkaitchuck/aHash/blob/master/src/fallback_hash.rs#L95
+//
+// checksum = folded_multiple(data ^ checksum, MULTIPLE)
+// folded_multiple(x, m) = HIGH(x * m) ^ LOW(x * m)
+
+// From Knuth's PRNG
+LIBC_INLINE constexpr __UINTPTR_TYPE__ MULTIPLE =
+ static_cast<__UINTPTR_TYPE__>(6364136223846793005ull);
----------------
nickdesaulniers wrote:
```suggestion
LIBC_INLINE constexpr auto MULTIPLE =
static_cast<__UINTPTR_TYPE__>(6364136223846793005ull);
```
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
https://github.com/llvm/llvm-project/pull/112769
More information about the libc-commits
mailing list