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.
1
10
2
11
use std:: arch:: asm;
3
12
4
13
fn main ( ) {
5
14
let t = 100 ;
6
15
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.
8
17
// let t_ptr = 99999999999999 as *const usize;
9
18
let x = dereference ( t_ptr) ;
10
19
11
20
println ! ( "{}" , x) ;
12
21
}
13
22
23
+ #[ cfg( target_arch = "x86-64" ) ]
14
24
fn dereference ( ptr : * const usize ) -> usize {
15
25
let mut res: usize ;
16
- unsafe {
26
+ unsafe {
17
27
asm ! ( "mov {0}, [{1}]" , out( reg) res, in( reg) ptr)
18
28
} ;
19
29
res
20
30
}
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