From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web09.31215.1658770443514738408 for ; Mon, 25 Jul 2022 10:34:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Pm/n/Dlp; spf=pass (domain: gmail.com, ip: 209.85.214.169, mailfrom: ayushdevel1325@gmail.com) Received: by mail-pl1-f169.google.com with SMTP id g17so11067382plh.2 for ; Mon, 25 Jul 2022 10:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to:cc:from :subject:content-transfer-encoding; bh=hLeXT4VMny2lad/gkTqaQG/jWXoPLQAPkDHW/uHjHFE=; b=Pm/n/DlpQEzN8pElGA2XS+Tenc2TR0O8NePNUnyDWzz1TEidbtpXSefF7DYGeCIWSl cxtVLgcOoDwMWTr3IPCCu4h6FBIONp1ln7zJdqpIE4qPNKUy+7rZKquJDYfZAYX0m19v Rl4diuCusqLMRQExXEp2mKlrcpo29pudeWGVouP5ETNsOWt6IaeYTU5+ytWNr8Y+vPo3 D4F2cv58xA47/9rUDDec89/HRsx+qK3bxs38mu8W//2YdYiXiDpXwuWkQ9oWaGroeRmF tx84zzmqG+jrP8Dy4ekxfIbhHcjp9Sm7zC70GgQgK84bVFtNzAYP8Sw29quTx5Q6qXJb EtvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject:content-transfer-encoding; bh=hLeXT4VMny2lad/gkTqaQG/jWXoPLQAPkDHW/uHjHFE=; b=zXh9Jdx7wlGjS15IsgPPZ8Goo2O4gWRqNsWfzXa54Hgs7C+j6fYUJ/krsWIFk9n3xw fbAGMHoGvpFb5K1Gf3dcAJTSIBZLSanm8Qxkzjum9iO8xKclzN6GWH0xWca3bPs5rlR/ FCr5Ybz6aQUkuL0C9KeAYlhNPSmXMpv5AvjMs0UO3MfWqPXM4D2/4MHkddARebzjNqSs G2LkbYh56TZ5iqe48ptitbIvibN80VHnSOrPIvPzZjn9osiXhyjUsWxILUogIv2AQwal ahhLL/wQpACfpf2bgQvEreUeE6ubxMn8uHuyOL7fcclnA4azd4jNEcolDtyKUbxPe4Wh 5kPA== X-Gm-Message-State: AJIora8ufsA78oqQWpekOi7FcJAO8tLcnrYcb4g7VZrEwMqmcEMKKwSm bGE6OQMnFp88TR2Ro8nEIHiHNqCDpVk= X-Google-Smtp-Source: AGRyM1s586Y7bhfH+XBvxGzOOZijKEhR0KPdvP750maIBKiVuG1OWZGSWg1KEwYortChHw/uCzBfuQ== X-Received: by 2002:a17:90a:cb88:b0:1f2:166c:fd3f with SMTP id a8-20020a17090acb8800b001f2166cfd3fmr15078092pju.133.1658770442521; Mon, 25 Jul 2022 10:34:02 -0700 (PDT) Return-Path: Received: from ?IPV6:2401:4900:1f3f:cdbd:2337:e3f:3e2d:534? ([2401:4900:1f3f:cdbd:2337:e3f:3e2d:534]) by smtp.gmail.com with ESMTPSA id o9-20020a62cd09000000b0052abfc4b4a4sm10162694pfg.12.2022.07.25.10.33.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jul 2022 10:34:01 -0700 (PDT) Message-ID: <15b0ac38-4b55-4b19-3f76-506c5b858949@gmail.com> Date: Mon, 25 Jul 2022 23:03:57 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: "devel@edk2.groups.io" Cc: "Kinney, Michael D" , "mikuback@linux.microsoft.com" , "Gaibusab, Jabeena B" , "Yao, Jiewen" From: "Ayush Singh" Subject: Casting i128 into f64 in UEFI Rust pagefaults Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello everyone.While running Rust tests in UEFI environment, I have come across a numeric test that causes a pagefault. A simple reproducible example for this is given below: ```rust fn main() {     use std::hint::black_box as b;     let z: i128 = b(1);     assert!((-z as f64) < 0.0); } ``` The exception output is as follows: ``` !!!! X64 Exception Type - 0E(#PF - Page-Fault)  CPU Apic ID - 00000000 !!!! ExceptionData - 0000000000000000  I:0 R:0 U:0 W:0 P:0 PK:0 SS:0 SGX:0 RIP  - 000000000603DB60, CS  - 0000000000000038, RFLAGS - 0000000000000246 RAX  - 0000000000000000, RCX - FFFFFFFFFFFFFFFF, RDX - FFFFFFFFFFFFFFFF RBX  - 0000000000000000, RSP - 0000000007EDF1D0, RBP - 0000000007EDF4C0 RSI  - 0000000007EDF360, RDI - 0000000007EDF3C0 R8   - 0000000000000000, R9  - 0000000000000038, R10 - 0000000000000000 R11  - 0000000000000000, R12 - 00000000060C6018, R13 - 0000000007EDF520 R14  - 0000000007EDF6A8, R15 - 0000000005FA9490 DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030 GS   - 0000000000000030, SS  - 0000000000000030 CR0  - 0000000080010033, CR2 - FFFFFFFFFFFFFFFF, CR3 - 0000000007C01000 CR4  - 0000000000000668, CR8 - 0000000000000000 DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 GDTR - 00000000079DE000 0000000000000047, LDTR - 0000000000000000 IDTR - 0000000007418018 0000000000000FFF,   TR - 0000000000000000 FXSAVE_STATE - 0000000007EDEE30 !!!! Find image based on IP(0x603DB60) /var/home/ayush/Documents/Programming/Rust/uefi/hello_world_std/target/x86_64-unknown-uefi/debug/deps/hello_world_std-338028f9369e2d42.pdb (ImageBase=000000000603C000, EntryPoint=000000000603D8C0) !!!! ``` From my testing, the exception only occurs when a few conditions are met. 1. The binary is compiled in Debug mode. No error in Release mode. 2. `i128` is in a black_box [1]. Does not occur if `black_box` is not present. 3. It has to be `i128`. `i64` or something else work fine. 4. The cast has to be done on `-z`. Doing the same with `+z` is fine. I have also been discussing this in the Rust zulipchat [2], so feel free to chime in there. Additionally, here are links for more information about this program: 1. Assembly: https://rust-lang.zulipchat.com/user_uploads/4715/od51Y9Dkfjahcg9HHcOud8Fm/hello_world_std-338028f9369e2d42.s 2. EFI Binary: https://rust-lang.zulipchat.com/user_uploads/4715/CknqtXLR8SaJZmyOnXctQkpL/hello_world_std.efi 3. PDB file: https://rust-lang.zulipchat.com/user_uploads/4715/zV4i6DsjgQXotp_gS1naEsU0/hello_world_std-338028f9369e2d42.pdb Yours Sincerely, Ayush Singh [1]: https://doc.rust-lang.org/std/hint/fn.black_box.html [2]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Casting.20i128.20to.20f64.20in.20black_box.20causes.20exception.20in.20UEFI