Skip to content

MemsetMemcpyNullref test fails on mono #98628

Open

Description

@EgorBo

The test I am adding in #98623 fails on mono (at least on mono windows x64 Release @ Windows.10.Amd64.Open - logs. probably will fail on other pipelines as well).

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

public unsafe class MemsetMemcpyNullref
{
    [Fact]
    public static void MemsetMemcpyThrowNullRefonNull()
    {
        Assert.Throws<NullReferenceException>(() => MemoryInit(null));
        Assert.Throws<NullReferenceException>(() => MemoryCopy(null, null));
        Assert.Throws<NullReferenceException>(() =>
            {
                // Check when only src is null
                HugeStruct hs = default;
                MemoryCopy(&hs, null);
            });
        Assert.Throws<NullReferenceException>(() =>
            {
                // Check when only dst is null
                HugeStruct hs = default;
                MemoryCopy(null, &hs);
            });

        // Check various lengths
        uint[] lengths = [1, 10, 100, 1000, 10000, 100000, 1000000];
        foreach (uint length in lengths)
        {
            Assert.Throws<NullReferenceException>(() => MemoryInitByref(ref Unsafe.NullRef<byte>(), length));
            Assert.Throws<NullReferenceException>(() => MemoryCopyByref(ref Unsafe.NullRef<byte>(), ref Unsafe.NullRef<byte>(), length));
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void MemoryCopy(HugeStruct* dst, HugeStruct* src) => 
        *dst = *src;

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void MemoryCopyByref(ref byte dst, ref byte src, uint len) => 
        Unsafe.CopyBlockUnaligned(ref dst, ref src, len);

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void MemoryInit(HugeStruct* dst) => 
        *dst = default;

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void MemoryInitByref(ref byte dst, uint len) => 
        Unsafe.InitBlockUnaligned(ref dst, 42, len);

    private struct HugeStruct
    {
        public fixed byte Data[20_000];
    }
}

Activity

  1. ghost added
    untriaged
    on Feb 18, 2024
  2. ghost added
    needs-area-label
    on Feb 18, 2024
  3. added
    disabled-test
    and removed
    needs-area-label
    on Feb 18, 2024
  4. lambdageek commented on Feb 20, 2024

    @lambdageek
    Member
  5. vargaz commented on Feb 21, 2024

    @vargaz
    Contributor

    This happens because it eventually calls Buffer:Memmove, which doesn't throw for null/null because of these lines:

                if (((nuint)(nint)Unsafe.ByteOffset(ref src, ref dest) < len) || ((nuint)(nint)Unsafe.ByteOffset(ref dest, ref src) < len))
                {
                    goto BuffersOverlap;
                }
    
            BuffersOverlap:
                // If the buffers overlap perfectly, there's no point to copying the data.
                if (Unsafe.AreSame(ref dest, ref src))
                {
                    return;
                }
    
  6. removed
    untriaged
    on Feb 23, 2024
  7. added this to the Future milestone on Jun 21, 2024
  8. steveisok commented on Jun 21, 2024

    @steveisok
    Member

    Actually, given it's windows x64 mono, we probably won't fix this.

  9. lambdageek commented on Jun 21, 2024

    @lambdageek
    Member

    This is a disabled test issue, and it's marked for all platforms. So we should update issues.targets before closing; also we should validate what happens on non-Windows platforms

    <ExcludeList Include="$(XunitTestBinBase)/JIT/opt/Structs/MemsetMemcpyNullref/*">
    <Issue>https://github.com/dotnet/runtime/issues/98628</Issue>
    </ExcludeList>

  10. matouskozak commented on Apr 22, 2025

    @matouskozak
    Member

    The test is crashing on apple mobile as well (see https://dev.azure.com/dnceng-public/public/_build/results?buildId=1022038)

    04:33:45] dbug: 2025-04-22 04:33:45.856615-0400 JIT.opt[31537:721847] 04:33:45.856 Running test: JIT/opt/Structs/MemsetMemcpyNullref/MemsetMemcpyNullref.dll
    [04:33:45] dbug: 
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Native Crash Reporting
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Got a SIGSEGV while executing native code. This usually indicates
    [04:33:45] dbug: a fatal error in the mono runtime or one of the native libraries
    [04:33:45] dbug: used by your application.
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: 
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Native stacktrace:
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: 0x10292aaf4 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_dump_native_crash_info
    [04:33:45] dbug: 0x1028d6e60 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_handle_native_crash
    [04:33:45] dbug: 0x102843b70 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_sigsegv_signal_handler_debug
    [04:33:45] dbug: 0x102d677e0 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
    [04:33:45] dbug: 0x102938c9c - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_interp_exec_method
    [04:33:45] dbug: 0x10292c040 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : interp_runtime_invoke
    [04:33:45] dbug: 0x102846df4 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_jit_runtime_invoke
    [04:33:45] dbug: 0x1027dbee4 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_runtime_invoke_checked
    [04:33:45] dbug: 0x1027e30f0 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_runtime_exec_main_checked
    [04:33:45] dbug: 0x102899fe8 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_jit_exec
    [04:33:45] dbug: 0x1029ddc64 - /Users/helix-runner/Library/Developer/CoreSimulator/Devices/F0181BD0-1FFB-4066-9C00-23083DF5431F/data/Containers/Bundle/Application/C36CB03A-21F7-4B75-8055-3A1866897685/JIT.opt.app/JIT.opt : mono_ios_runtime_init
    [04:33:45] dbug: 0x18016a4f4 - /Library/Developer/CoreSimulator/Volumes/iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib : _dispatch_call_block_and_release
    [04:33:45] dbug: 0x18016bd3c - /Library/Developer/CoreSimulator/Volumes/iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib : _dispatch_client_callout
    [04:33:45] dbug: 0x18016f288 - /Library/Developer/CoreSimulator/Volumes/iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib : _dispatch_queue_override_invoke
    [04:33:45] dbug: 0x18017e30c - /Library/Developer/CoreSimulator/Volumes/iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib : _dispatch_root_queue_drain
    [04:33:45] dbug: 0x18017ed58 - /Library/Developer/CoreSimulator/Volumes/iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib : _dispatch_worker_thread2
    [04:33:45] dbug: 0x102d877d8 - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread
    [04:33:45] dbug: 0x102d865d4 - /usr/lib/system/libsystem_pthread.dylib : start_wqthread
    [04:33:45] dbug: 
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: External Debugger Dump:
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: 
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Basic Fault Address Reporting
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Memory around native instruction pointer (0x102d670e0):0x102d670d0  61 04 01 a8 61 04 02 a8 61 04 03 a8 c0 03 5f d6  a...a...a....._.
    [04:33:45] dbug: 0x102d670e0  01 04 00 a9 01 04 01 a9 01 04 02 a9 01 04 03 a9  ................
    [04:33:45] dbug: 0x102d670f0  03 00 01 91 63 e4 7a 92 42 00 00 8b 64 00 01 91  ....c.z.B...d...
    [04:33:45] dbug: 0x102d67100  42 00 04 eb 09 01 00 54 61 04 00 a9 61 04 01 a9  B......Ta...a...
    [04:33:45] dbug: 
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: Managed Stacktrace:
    [04:33:45] dbug: =================================================================
    [04:33:45] dbug: =================================================================
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Codegen-JIT-monodisabled-test

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions