From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from rn-mailsvcp-ppex-lapp44.apple.com (rn-mailsvcp-ppex-lapp44.apple.com [17.179.253.48]) by mx.groups.io with SMTP id smtpd.web11.121.1658775316195338314 for ; Mon, 25 Jul 2022 11:55:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=S5r0LsNg; spf=pass (domain: apple.com, ip: 17.179.253.48, mailfrom: afish@apple.com) Received: from pps.filterd (rn-mailsvcp-ppex-lapp44.rno.apple.com [127.0.0.1]) by rn-mailsvcp-ppex-lapp44.rno.apple.com (8.16.1.2/8.16.1.2) with SMTP id 26PIjLMU030450; Mon, 25 Jul 2022 11:55:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=SDswEb2LUzWIi4+Uk2BDhakeGjT0qpyviJV3fY0VLwg=; b=S5r0LsNgFui771c0eR9N5BU70/IuKf5gMFJ0cvmKTDU27NM15RQYvAEyi8UED82yhXSd qmcWTEO7WwEw1ZpIRtF/SKNuFYbn+5tRtLCs2OcnpEMMthsfG3hR7H/uglROMOAkehuK aJ5K1J/fXZyHQCiPAu4AnHT7WbzEFItnKIGMwjm3Qjqu+H4vm8JZ/LWLPKjZVtiLKPZG +crkEa/aCNu7yK9qe7+GN+g9qqieUzGakz7VUIN830uYUaQzu+KjDSZvxirb6nrzlhUD IPiNvE8OAHklmir/WWUaDayahCuxrp3zTCxRDeR9mV7lt5/zeNVa5f6FB9IlHB7I3URx Xg== Received: from rn-mailsvcp-mta-lapp01.rno.apple.com (rn-mailsvcp-mta-lapp01.rno.apple.com [10.225.203.149]) by rn-mailsvcp-ppex-lapp44.rno.apple.com with ESMTP id 3hgcg8n7bg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 25 Jul 2022 11:55:15 -0700 Received: from rn-mailsvcp-mmp-lapp02.rno.apple.com (rn-mailsvcp-mmp-lapp02.rno.apple.com [17.179.253.15]) by rn-mailsvcp-mta-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPS id <0RFL011OVB80FE00@rn-mailsvcp-mta-lapp01.rno.apple.com>; Mon, 25 Jul 2022 11:55:12 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp02.rno.apple.com by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) id <0RFL00N00B7Y6F00@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Mon, 25 Jul 2022 11:55:12 -0700 (PDT) X-Va-A: X-Va-T-CD: f900b3001c7ef03eb53e4f1f41858654 X-Va-E-CD: fa9e1aa2e33b303a80c7290ebbbc84ef X-Va-R-CD: b22de2176895e5e0422f5f3b61053f8b X-Va-CD: 0 X-Va-ID: 16346173-4a32-440b-a07c-b6a92bd90587 X-V-A: X-V-T-CD: f900b3001c7ef03eb53e4f1f41858654 X-V-E-CD: fa9e1aa2e33b303a80c7290ebbbc84ef X-V-R-CD: b22de2176895e5e0422f5f3b61053f8b X-V-CD: 0 X-V-ID: 40321c05-bc19-416b-a912-300012c9b569 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-07-25_12:2022-07-25,2022-07-25 signatures=0 Received: from smtpclient.apple (unknown [17.235.32.128]) by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPSA id <0RFL00SHEB7R3000@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Mon, 25 Jul 2022 11:55:04 -0700 (PDT) From: "Andrew Fish" Message-id: <57E4EE5B-4A4C-4592-A811-14DB025C58E1@apple.com> MIME-version: 1.0 (Mac OS X Mail 16.0 \(3729.0.22.1.1\)) Subject: Re: [edk2-devel] Casting i128 into f64 in UEFI Rust pagefaults Date: Mon, 25 Jul 2022 11:54:53 -0700 In-reply-to: <116DE63D-B96C-4D2F-9CF6-299F053329D7@apple.com> Cc: ayushdevel1325@gmail.com, Mike Kinney , "mikuback@linux.microsoft.com" , "Gaibusab, Jabeena B" , "Yao, Jiewen" To: edk2-devel-groups-io , Andrew Fish References: <15b0ac38-4b55-4b19-3f76-506c5b858949@gmail.com> <170523E2507C1293.4676@groups.io> <116DE63D-B96C-4D2F-9CF6-299F053329D7@apple.com> X-Mailer: Apple Mail (2.3729.0.22.1.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-07-25_12:2022-07-25,2022-07-25 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_80C29AFD-DA37-4588-A48B-88C06F030B17" --Apple-Mail=_80C29AFD-DA37-4588-A48B-88C06F030B17 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I guess I could at least dump to the end (req)=E2=80=A6. Going backwards is= a bit painful in x86.=20 (lldb) dis -s 0x0000000140001B60 -b -c 30 hello_world_std.efi[0x140001b60]: 48 8b 09 movq (%r= cx), %rcx hello_world_std.efi[0x140001b63]: 48 01 c1 addq %ra= x, %rcx hello_world_std.efi[0x140001b66]: 4c 89 c2 movq %r8= , %rdx hello_world_std.efi[0x140001b69]: 48 11 c2 adcq %ra= x, %rdx hello_world_std.efi[0x140001b6c]: 48 31 c1 xorq %ra= x, %rcx hello_world_std.efi[0x140001b6f]: 48 31 c2 xorq %ra= x, %rdx hello_world_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 00 80 movabsq $-= 0x8000000000000000, %rsi ; imm =3D 0x8000000000000000=20 hello_world_std.efi[0x140001b7c]: 4c 21 c6 andq %r8= , %rsi hello_world_std.efi[0x140001b7f]: e8 5c 55 00 00 callq 0x1= 400070e0 hello_world_std.efi[0x140001b84]: 48 09 f0 orq %rs= i, %rax hello_world_std.efi[0x140001b87]: 48 83 c4 20 addq $0x= 20, %rsp hello_world_std.efi[0x140001b8b]: 5e popq %rs= i hello_world_std.efi[0x140001b8c]: c3 retq =20 hello_world_std.efi[0x140001b8d]: cc int3 =20 hello_world_std.efi[0x140001b8e]: cc int3 =20 hello_world_std.efi[0x140001b8f]: cc int3 =20 hello_world_std.efi[0x140001b90]: e9 db 55 00 00 jmp 0x1= 40007170 hello_world_std.efi[0x140001b95]: cc int3 =20 =E2=80=A6 Then we can guess based on how functions get aligned to find the start=E2= =80=A6. hello_world_std.efi[0x140001b50]: 56 push= q %rsi hello_world_std.efi[0x140001b51]: 48 83 ec 20 subq= $0x20, %rsp hello_world_std.efi[0x140001b55]: 4c 8b 41 08 movq= 0x8(%rcx), %r8 hello_world_std.efi[0x140001b59]: 4c 89 c0 movq= %r8, %rax hello_world_std.efi[0x140001b5c]: 48 c1 f8 3f sarq= $0x3f, %rax hello_world_std.efi[0x140001b60]: 48 8b 09 movq= (%rcx), %rcx hello_world_std.efi[0x140001b63]: 48 01 c1 addq= %rax, %rcx hello_world_std.efi[0x140001b66]: 4c 89 c2 movq= %r8, %rdx hello_world_std.efi[0x140001b69]: 48 11 c2 adcq= %rax, %rdx hello_world_std.efi[0x140001b6c]: 48 31 c1 xorq= %rax, %rcx hello_world_std.efi[0x140001b6f]: 48 31 c2 xorq= %rax, %rdx hello_world_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 00 80 mova= bsq $-0x8000000000000000, %rsi ; imm =3D 0x8000000000000000=20 hello_world_std.efi[0x140001b7c]: 4c 21 c6 andq= %r8, %rsi hello_world_std.efi[0x140001b7f]: e8 5c 55 00 00 call= q 0x1400070e0 hello_world_std.efi[0x140001b84]: 48 09 f0 orq = %rsi, %rax hello_world_std.efi[0x140001b87]: 48 83 c4 20 addq= $0x20, %rsp hello_world_std.efi[0x140001b8b]: 5e popq= %rsi hello_world_std.efi[0x140001b8c]: c3 retq= =20 So the faulting function is getting passed a bad pointer as its 1st arg.=20 Thanks, Andrew Fish > On Jul 25, 2022, at 11:45 AM, Andrew Fish wrote: >=20 > Ops=E2=80=A6 Looks like your PE/COFF is linked at 0x0000000140000000, so = 0x140001b60 is the interesting bit. >=20 > (lldb) dis -s 0x0000000140001B60 -b > hello_world_std.efi[0x140001b60]: 48 8b 09 movq (= %rcx), %rcx > hello_world_std.efi[0x140001b63]: 48 01 c1 addq %= rax, %rcx > hello_world_std.efi[0x140001b66]: 4c 89 c2 movq %= r8, %rdx > hello_world_std.efi[0x140001b69]: 48 11 c2 adcq %= rax, %rdx > hello_world_std.efi[0x140001b6c]: 48 31 c1 xorq %= rax, %rcx > hello_world_std.efi[0x140001b6f]: 48 31 c2 xorq %= rax, %rdx > hello_world_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 00 80 movabsq = $-0x8000000000000000, %rsi ; imm =3D 0x8000000000000000=20 > hello_world_std.efi[0x140001b7c]: 4c 21 c6 andq %= r8, %rsi >=20 > RCX - FFFFFFFFFFFFFFFF >=20 > So yea that looks like the fault.=20 >=20 > I don=E2=80=99t see that pattern in your .s file=E2=80=A6.=20 >=20 > Can you figure out what function is @ 0x140001b60 in the PE/COFF image. D= o you have a map file from the linker? >=20 > Thanks, >=20 > Andrew Fish >=20 > PS Again sorry I don=E2=80=99t have anything installed to crack PDB files= .=20 >=20 > Thanks, >=20 > Andrew Fish >=20 >> On Jul 25, 2022, at 10:51 AM, Andrew Fish via groups.io wrote: >>=20 >> Ayush, >>=20 >> CR2 is the fault address so 0xFFFFFFFFFFFFFFFF. Given for EFI Virt =3D= =3D Physical the fault address looks like a bad pointer.=20 >>=20 >> Sorry I=E2=80=99ve not used VC++ in a long time so I don=E2=80=99t know = how to debug with VC++, but If I was using clang/lldb I=E2=80=99d look at t= he source and assembly for the fault address.=20 >>=20 >> The image base is: 0x000000000603C000 >> The fault PC/RIP is: 000000000603DB60 >>=20 >> So the faulting code is at 0x1B60 in the image. Given the images are lin= ked at zero you should be able to load the build product into the debugger = and look at what code is at offset 0x1B60. The same should work for any too= ls that dump the binary.=20 >>=20 >> Thanks, >>=20 >> Andrew Fish >>=20 >>> On Jul 25, 2022, at 10:33 AM, Ayush Singh wr= ote: >>>=20 >>> Hello everyone.While running Rust tests in UEFI environment, I have com= e across a numeric test that causes a pagefault. A simple reproducible exam= ple for this is given below: >>>=20 >>> ```rust >>>=20 >>> fn main() { >>> use std::hint::black_box as b; >>>=20 >>> let z: i128 =3D b(1); >>> assert!((-z as f64) < 0.0); >>> } >>>=20 >>> ``` >>>=20 >>>=20 >>> The exception output is as follows: >>>=20 >>> ``` >>>=20 >>> !!!! 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 - 0000000000000= 246 >>> 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/Progra= mming/Rust/uefi/hello_world_std/target/x86_64-unknown-uefi/debug/deps/hello= _world_std-338028f9369e2d42.pdb (ImageBase=3D000000000603C000, EntryPoint= =3D000000000603D8C0) !!!! >>>=20 >>> ``` >>>=20 >>>=20 >>> From my testing, the exception only occurs when a few conditions are me= t. >>>=20 >>> 1. The binary is compiled in Debug mode. No error in Release mode. >>>=20 >>> 2. `i128` is in a black_box [1]. Does not occur if `black_box` is not p= resent. >>>=20 >>> 3. It has to be `i128`. `i64` or something else work fine. >>>=20 >>> 4. The cast has to be done on `-z`. Doing the same with `+z` is fine. >>>=20 >>>=20 >>> I have also been discussing this in the Rust zulipchat [2], so feel fre= e to chime in there. >>>=20 >>>=20 >>> Additionally, here are links for more information about this program: >>>=20 >>> 1. Assembly: https://rust-lang.zulipchat.com/user_uploads/4715/od51Y9Dk= fjahcg9HHcOud8Fm/hello_world_std-338028f9369e2d42.s >>>=20 >>> 2. EFI Binary: https://rust-lang.zulipchat.com/user_uploads/4715/CknqtX= LR8SaJZmyOnXctQkpL/hello_world_std.efi >>>=20 >>> 3. PDB file: https://rust-lang.zulipchat.com/user_uploads/4715/zV4i6Dsj= gQXotp_gS1naEsU0/hello_world_std-338028f9369e2d42.pdb >>>=20 >>>=20 >>> Yours Sincerely, >>>=20 >>> Ayush Singh >>>=20 >>>=20 >>> [1]: https://doc.rust-lang.org/std/hint/fn.black_box.html >>>=20 >>> [2]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2= Fhelp/topic/Casting.20i128.20to.20f64.20in.20black_box.20causes.20exception= .20in.20UEFI >>>=20 >>>=20 >>>=20 >>=20 >>=20 >=20 --Apple-Mail=_80C29AFD-DA37-4588-A48B-88C06F030B17 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 I guess I could at least dump to = the end (req)=E2=80=A6. Going backwards is a bit painful in x86. 
=

(lldb) dis -s 0x0000000140001B60 -b = -c 30

hello_world_std.efi[0x140001b60]: 48 8b 09     &n= bsp;                 movq   (%= rcx), %rcx

hello_world_std.efi[0x140001b63]: 48 01 c1     &n= bsp;                 addq   %r= ax, %rcx

hello_world_std.efi[0x140001b66]: 4c 89 c2     &n= bsp;                 movq   %r= 8, %rdx

hello_world_std.efi[0x140001b69]: 48 11 c2     &n= bsp;                 adcq   %r= ax, %rdx

hello_world_std.efi[0x140001b6c]: 48 31 c1     &n= bsp;                 xorq   %r= ax, %rcx

hello_world_std.efi[0x140001b6f]: 48 31 c2     &n= bsp;                 xorq   %r= ax, %rdx

hello_world_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 0= 0 80  movabsq $-0x8000000000000000, %rsi ; imm =3D 0x8000000000000000&= nbsp;

hello_world_std.efi[0x140001b7c]: 4c 21 c6     &n= bsp;                 andq   %r= 8, %rsi

hello_world_std.efi[0x140001b7f]: e8 5c 55 00 00   &nb= sp;             callq  0x1400070e0

hello_world_std.efi[0x140001b84]: 48 09 f0     &n= bsp;                 orq  &nbs= p; %rsi, %rax

hello_world_std.efi[0x140001b87]: 48 83 c4 20    =                 addq   $0x20, = %rsp

hello_world_std.efi[0x140001b8b]: 5e       &= nbsp;                    = popq   %rsi

hello_world_std.efi[0x140001b8c]: c3       &= nbsp;                    = retq   

hello_world_std.efi[0x140001b8d]: cc       &= nbsp;                    = int3   

hello_world_std.efi[0x140001b8e]: cc       &= nbsp;                    = int3   

hello_world_std.efi[0x140001b8f]: cc       &= nbsp;                    = int3   

hello_world_std.efi[0x140001b90]: e9 db 55 00 00   &nb= sp;             jmp    0x140007170<= /span>

hello_world_std.efi[0x140001b95]: cc       &= nbsp;                    = int3   

=E2=80=A6

Then we can guess based on how functi= ons get aligned to find the start=E2=80=A6.

hello_= world_std.efi[0x140001b50]: 56             &n= bsp;                     = pushq  %rsi

hello_world_std.efi[0x140001b51]: 48 83 ec 20    =                      = ; subq   $0x20, %rsp

hello_world_std.efi[0x140001b55]: 4c 8b 41 08    =                      = ; movq   0x8(%rcx), %r8

hello_world_std.efi[0x140001b59]: 4c 89 c0     &n= bsp;                     =   movq   %r8, %rax

hello_world_std.efi[0x140001b5c]: 48 c1 f8 3f    =                      = ; sarq   $0x3f, %rax

hello_world_std.efi[0x140001b60]: 48 8b 09     &n= bsp;                     =   movq   (%rcx), %rcx

hello_world_std.efi[0x140001b63]: 48 01 c1     &n= bsp;                     =   addq   %rax, %rcx

hello_world_std.efi[0x140001b66]: 4c 89 c2     &n= bsp;                     =   movq   %r8, %rdx

hello_world_std.efi[0x140001b69]: 48 11 c2     &n= bsp;                     =   adcq   %rax, %rdx

hello_world_std.efi[0x140001b6c]: 48 31 c1     &n= bsp;                     =   xorq   %rax, %rcx

hello_world_std.efi[0x140001b6f]: 48 31 c2     &n= bsp;                     =   xorq   %rax, %rdx

hello_world_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 0= 0 80        movabsq $-0x8000000000000000, %rsi ; imm = =3D 0x8000000000000000 

hello_world_std.efi[0x140001b7c]: 4c 21 c6     &n= bsp;                     =   andq   %r8, %rsi

hello_world_std.efi[0x140001b7f]: e8 5c 55 00 00   &nb= sp;                   callq&nb= sp; 0x1400070e0

hello_world_std.efi[0x140001b84]: 48 09 f0     &n= bsp;                     =   orq    %rsi, %rax

hello_world_std.efi[0x140001b87]: 48 83 c4 20    =                      = ; addq   $0x20, %rsp

hello_world_std.efi[0x140001b8b]: 5e       &= nbsp;                    =       popq   %rsi

hello_world_std.efi[0x140001b8c]: c3       &= nbsp;                    =       retq   


= So the faulting= function is getting passed a bad pointer as its 1st arg. 

Th= anks,

Andrew Fish

<= div>On Jul 25, 2022, at 11:45 AM, Andrew Fish <afish@apple.com> wrote= :

O= ps=E2=80=A6 Looks like your PE/COFF is linked at 0x0000000140000000, s= o 0x140001b60 is the interesting bit.

(lldb) dis -s 0x0000000140001B60 -b
hello_world_std.efi[0x140001b60]: 48 8b 09         =               movq   (%rcx), %rcx
hello_world_std.efi[0x140001b63]: 48 01 c1 &nb= sp;                     a= ddq   %rax, %rcx
hello_world_std.efi[0x1= 40001b66]: 4c 89 c2                =       movq   %r8, %rdx
h= ello_world_std.efi[0x140001b69]: 48 11 c2          = ;             adcq   %rax, %rdx
hello_world_std.efi[0x140001b6c]: 48 31 c1   &nb= sp;                   xorq &nb= sp; %rax, %rcx
hello_world_std.efi[0x140001b6= f]: 48 31 c2                  =     xorq   %rax, %rdx
hello_w= orld_std.efi[0x140001b72]: 48 be 00 00 00 00 00 00 00 80  movabsq $-0x= 8000000000000000, %rsi ; imm =3D 0x8000000000000000 
hello_world_std.efi[0x140001b7c]: 4c 21 c6      = ;                 andq   %r8, = %rsi

 RCX - FFFFFFFFFFFFFFFF

So yea that looks like = the fault. 

I don=E2=80=99t see that pattern in your .s file= =E2=80=A6. 

Can you figure out what function is @ 0x140001b60 in the PE= /COFF image. Do you have a map file from the linker?

Thanks,
Andrew Fish

PS Again sorry I don=E2=80=99t have anything insta= lled to crack PDB files. 

Thanks,

Andrew Fish=

On Jul 25, 2022, at 10:51 AM,= Andrew Fish via groups.io <afish=3Dapple.com@groups.io> wrote:
=
Ayush,=

CR2 is the fa= ult address so 0xFFFFFFFFFFFFFFFF. Given for EFI Virt =3D=3D Physical the f= ault address looks like a bad pointer. 

Sorry I=E2=80=99ve not used VC++ in a = long time so I don=E2=80=99t know how to debug with VC++, but If I was usin= g clang/lldb I=E2=80=99d look at the source and assembly for the fault addr= ess. 

The image base is: 0x000000000603C000
The= fault PC/RIP is: 000000000603DB60

So the faulting code is at 0x1B60 in the image. = Given the images are linked at zero you should be able to load the build pr= oduct into the debugger and look at what code is at offset 0x1B60. The same= should work for any tools that dump the binary. 

Thanks,

Andrew Fish

On Jul 25, 2022, at 10:33 AM, Ayush Singh <ay= ushdevel1325@gmail.com> wrote:


```rust

fn main() {
    use std::hint::black_box as b;=

    let z: i128 = =3D b(1);
    assert!((-z as f64) &l= t; 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  - 000000000= 603DB60, CS  - 0000000000000038, RFLAGS - 0000000000000246
RAX  - 0000000000000000, RCX - FFFFFFFFFFFFFFFF, RDX - FF= FFFFFFFFFFFFFF
RBX  - 0000000000000000, RSP - = 0000000007EDF1D0, RBP - 0000000007EDF4C0
RSI  = - 0000000007EDF360, RDI - 0000000007EDF3C0

<= span style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size:= 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; let= ter-spacing: normal; text-align: start; text-indent: 0px; text-transform: n= one; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px= ; text-decoration: none; float: none; display: inline !important;">R8 =   - 0000000000000000, R9  - 0000000000000038, R10 - 0000000000000= 000

R11  - 0000000000000000, R12 - 00000000060= C6018, R13 - 0000000007EDF520
R14  - 000000000= 7EDF6A8, R15 - 0000000005FA9490
DS   - 0= 000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
GS   - 0000000000000030, SS  - 000000= 0000000030
CR0  - 0000000080010033, CR2 - FFFF= FFFFFFFFFFFF, CR3 - 0000000007C01000
CR4  - 00= 00000000000668, CR8 - 0000000000000000
DR0  - = 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000

DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0= 000000000000400
GDTR - 00000000079DE000 00000000000= 00047, LDTR - 0000000000000000
IDTR - 00000000074= 18018 0000000000000FFF,   TR - 0000000000000000
FXSAVE_STATE - 0000000007EDEE30
!!!! Find = image based on IP(0x603DB60) /var/home/ayush/Documents/Programming/Rust/uef= i/hello_world_std/target/x86_64-unknown-uefi/debug/deps/hello_world_std-338= 028f9369e2d42.pdb (ImageBase=3D000000000603C000, EntryPoint=3D000000000603D= 8C0) !!!!

```


From my testi= ng, 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 pres= ent.

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 f= ree to chime in there.


Additionally, here are links for more information abo= ut this program:

1. Assemb= ly: https://rust-lang.zulipchat.com/user_uploads/4715/od51Y9Dkfjahcg9HHcOud= 8Fm/hello_world_std-338028f9369e2d42.s

2. EFI Binary: = https://rust-lang.zulipchat.com/user_uploads/4715/CknqtXLR8SaJZmy= OnXctQkpL/hello_world_std.efi

3. PDB file: https://rust-lang.zulipchat.com/user_uploads/4715/zV4i6Dsjg= QXotp_gS1naEsU0/hello_world_std-338028f9369e2d42.pdb


Yours Sincerely,
Ayush Singh


[1]: h= ttps://doc.rust-lang.org/std/hint/fn.black_box.html

[2]: 
htt= ps://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/= Casting.20i128.20to.20f64.20in.20black_box.20causes.20exception.20in.20UEFI=






--Apple-Mail=_80C29AFD-DA37-4588-A48B-88C06F030B17--