File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
ch01/a-assembly-dereference/src Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 1+ //! # FIXES:
2+ //! The number is identical to the number in the GitHub issue tracker
3+ //!
4+ //! ## FIX ISSUE #11:
5+ //! See:https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/11
6+ //! The book didn't make it clear that this example will only work on `x86-64` architecture,
7+ //! so users on newer M-series macs (which uses the ARM64 instruciton set), will get a
8+ //! compilation error. This is solved by conditionally compiling a version that works
9+ //! with the ARM64 instruction set.
110
211use std:: arch:: asm;
312
413fn main ( ) {
514 let t = 100 ;
615 let t_ptr: * const usize = & t; // if you comment out this...
7- // ...and uncomment the line below. The program will fail.
16+ // ...and uncomment the line below. The program will fail.
817 // let t_ptr = 99999999999999 as *const usize;
918 let x = dereference ( t_ptr) ;
1019
1120 println ! ( "{}" , x) ;
1221}
1322
23+ #[ cfg( target_arch = "x86-64" ) ]
1424fn dereference ( ptr : * const usize ) -> usize {
1525 let mut res: usize ;
16- unsafe {
26+ unsafe {
1727 asm ! ( "mov {0}, [{1}]" , out( reg) res, in( reg) ptr)
1828 } ;
1929 res
2030}
31+
32+ // FIX #11
33+ #[ cfg( target_arch = "aarch64" ) ]
34+ fn dereference ( ptr : * const usize ) -> usize {
35+ let mut res: usize ;
36+ unsafe {
37+ asm ! ( "ldr {0}, [{1}]" , out( reg) res, in( reg) ptr)
38+ } ;
39+ res
40+ }
41+
42+
You can’t perform that action at this time.
0 commit comments