Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/hotspot/share/cds/archiveHeapLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "memory/iterator.inline.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "sanitizers/ub.hpp"
#include "utilities/bitMap.inline.hpp"
#include "utilities/copy.hpp"

Expand Down Expand Up @@ -61,9 +62,7 @@ ptrdiff_t ArchiveHeapLoader::_mapped_heap_delta = 0;

// Every mapped region is offset by _mapped_heap_delta from its requested address.
// See FileMapInfo::heap_region_requested_address().
#if defined(__clang__) || defined(__GNUC__)
__attribute__((no_sanitize("undefined")))
#endif
ATTRIBUTE_NO_UBSAN
void ArchiveHeapLoader::init_mapped_heap_info(address mapped_heap_bottom, ptrdiff_t delta, int dumptime_oop_shift) {
assert(!_mapped_heap_relocation_initialized, "only once");
if (!UseCompressedOops) {
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/prims/unsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "runtime/threadSMR.hpp"
#include "runtime/vmOperations.hpp"
#include "runtime/vm_version.hpp"
#include "sanitizers/ub.hpp"
#include "services/threadService.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
Expand Down Expand Up @@ -244,9 +245,7 @@ class MemoryAccess : StackObj {

// we use this method at some places for writing to 0 e.g. to cause a crash;
// ubsan does not know that this is the desired behavior
#if defined(__clang__) || defined(__GNUC__)
__attribute__((no_sanitize("undefined")))
#endif
ATTRIBUTE_NO_UBSAN
void put(T x) {
GuardUnsafeAccess guard(_thread);
*addr() = normalize_for_write(x);
Expand Down
43 changes: 43 additions & 0 deletions src/hotspot/share/sanitizers/ub.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#ifndef SHARE_SANITIZERS_UB_HPP
#define SHARE_SANITIZERS_UB_HPP

// ATTRIBUTE_NO_UBSAN
//
// Function attribute which informs the compiler to disable UBSan checks in the
// following function or method.
// Useful if the function or method is known to do something special or even 'dangerous', for
// example causing desired signals/crashes.
#if defined(__clang__) || defined(__GNUC__)
#define ATTRIBUTE_NO_UBSAN __attribute__((no_sanitize("undefined")))
#endif

#ifndef ATTRIBUTE_NO_UBSAN
#define ATTRIBUTE_NO_UBSAN
#endif

#endif // SHARE_SANITIZERS_UB_HPP
5 changes: 2 additions & 3 deletions src/hotspot/share/utilities/vmError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "runtime/vmOperations.hpp"
#include "runtime/vmThread.hpp"
#include "runtime/vm_version.hpp"
#include "sanitizers/ub.hpp"
#include "utilities/debug.hpp"
#include "utilities/decoder.hpp"
#include "utilities/defaultStream.hpp"
Expand Down Expand Up @@ -2086,9 +2087,7 @@ typedef void (*voidfun_t)();
// compared to one generated with raise (asynchronous vs synchronous). See JDK-8065895.
volatile int sigfpe_int = 0;

#if defined(__clang__) || defined(__GNUC__)
__attribute__((no_sanitize("undefined")))
#endif
ATTRIBUTE_NO_UBSAN
static void ALWAYSINLINE crash_with_sigfpe() {

// generate a native synchronous SIGFPE where possible;
Expand Down