File tree 4 files changed +40
-18
lines changed
4 files changed +40
-18
lines changed Original file line number Diff line number Diff line change
1
+ /// FIX #31:
2
+ /// Inline assembly blocks inside naked functions now need to use
3
+ /// the `naked_asm` macro instead of the good old `asm` macro.
4
+ /// The `noreturn` option is implicitly set by the `naked_asm`
5
+ /// macro so there is no need to set that.
6
+ ///
7
+ /// See: https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/31
8
+ /// for more information.
1
9
#![ feature( naked_functions) ]
2
- use std:: arch:: asm;
10
+ use std:: arch:: { asm, naked_asm } ;
3
11
4
12
const DEFAULT_STACK_SIZE : usize = 1024 * 1024 * 2 ;
5
13
const MAX_THREADS : usize = 4 ;
@@ -141,7 +149,7 @@ fn guard() {
141
149
142
150
#[ naked]
143
151
unsafe extern "C" fn skip ( ) {
144
- asm ! ( "ret" , options ( noreturn ) )
152
+ naked_asm ! ( "ret" )
145
153
}
146
154
147
155
pub fn yield_thread ( ) {
@@ -155,7 +163,7 @@ pub fn yield_thread() {
155
163
#[ no_mangle]
156
164
#[ cfg_attr( target_os = "macos" , export_name = "\x01 switch" ) ] // see: How-to-MacOS-M.md for explanation
157
165
unsafe extern "C" fn switch ( ) {
158
- asm ! (
166
+ naked_asm ! (
159
167
"mov [rdi + 0x00], rsp" ,
160
168
"mov [rdi + 0x08], r15" ,
161
169
"mov [rdi + 0x10], r14" ,
@@ -170,8 +178,7 @@ unsafe extern "C" fn switch() {
170
178
"mov r12, [rsi + 0x20]" ,
171
179
"mov rbx, [rsi + 0x28]" ,
172
180
"mov rbp, [rsi + 0x30]" ,
173
- "ret" ,
174
- options( noreturn)
181
+ "ret"
175
182
) ;
176
183
}
177
184
Original file line number Diff line number Diff line change
1
+ /// FIX #31:
2
+ /// Inline assembly blocks inside naked functions now need to use
3
+ /// the `naked_asm` macro instead of the good old `asm` macro.
4
+ /// The `noreturn` option is implicitly set by the `naked_asm`
5
+ /// macro so there is no need to set that.
6
+ ///
7
+ /// See: https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/31
8
+ /// for more information.
1
9
#![ feature( naked_functions) ]
2
- use std:: { arch:: asm, ptr } ;
10
+ use std:: { arch:: { asm, naked_asm } } ;
3
11
4
12
const DEFAULT_STACK_SIZE : usize = 1024 * 1024 * 2 ;
5
13
const MAX_THREADS : usize = 4 ;
@@ -152,8 +160,8 @@ fn call(thread: u64) {
152
160
}
153
161
154
162
#[ naked]
155
- unsafe fn skip ( ) {
156
- asm ! ( "ret" , options ( noreturn ) )
163
+ unsafe extern "C" fn skip ( ) {
164
+ naked_asm ! ( "ret" )
157
165
}
158
166
159
167
// this function is changed
@@ -175,8 +183,8 @@ pub fn yield_thread() {
175
183
#[ naked]
176
184
#[ no_mangle]
177
185
#[ cfg_attr( target_os = "macos" , export_name = "\x01 switch" ) ]
178
- unsafe fn switch ( ) {
179
- asm ! (
186
+ unsafe extern "C" fn switch ( ) {
187
+ naked_asm ! (
180
188
"mov 0x00[rdi], rsp" ,
181
189
"mov 0x08[rdi], r15" ,
182
190
"mov 0x10[rdi], r14" ,
@@ -192,8 +200,7 @@ unsafe fn switch() {
192
200
"mov rbx, 0x28[rsi]" ,
193
201
"mov rbp, 0x30[rsi]" ,
194
202
"mov rdi, 0x38[rsi]" ,
195
- "ret" ,
196
- options( noreturn)
203
+ "ret"
197
204
) ;
198
205
}
199
206
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ Last we need to change our `switch()`function and update our assembly. After all
248
248
#[naked]
249
249
#[no_mangle]
250
250
unsafe extern " C" fn switch () {
251
- asm ! (
251
+ naked_asm ! (
252
252
" movaps [rcx + 0x00], xmm6" ,
253
253
" movaps [rcx + 0x10], xmm7" ,
254
254
" movaps [rcx + 0x20], xmm8" ,
@@ -295,7 +295,7 @@ unsafe extern "C" fn switch() {
295
295
" mov gs:0x08, rax" ,
296
296
" mov rax, [rdx + 0xf0]" ,
297
297
" mov gs:0x10, rax" ,
298
- " ret" , options ( noreturn )
298
+ " ret"
299
299
);
300
300
}
301
301
```
Original file line number Diff line number Diff line change
1
+ /// FIX #31:
2
+ /// Inline assembly blocks inside naked functions now need to use
3
+ /// the `naked_asm` macro instead of the good old `asm` macro.
4
+ /// The `noreturn` option is implicitly set by the `naked_asm`
5
+ /// macro so there is no need to set that.
6
+ ///
7
+ /// See: https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/31
8
+ /// for more information.
1
9
#![ feature( naked_functions) ]
2
- use std:: arch:: asm;
10
+ use std:: arch:: { asm, naked_asm } ;
3
11
4
12
const DEFAULT_STACK_SIZE : usize = 1024 * 1024 * 2 ;
5
13
const MAX_THREADS : usize = 4 ;
@@ -145,7 +153,7 @@ impl Runtime {
145
153
146
154
#[ naked]
147
155
unsafe extern "C" fn skip ( ) {
148
- asm ! ( "ret" , options ( noreturn ) )
156
+ naked_asm ! ( "ret" )
149
157
}
150
158
151
159
@@ -168,7 +176,7 @@ pub fn yield_thread() {
168
176
#[ no_mangle]
169
177
#[ cfg_attr( target_os = "macos" , export_name = "\x01 switch" ) ]
170
178
unsafe extern "C" fn switch ( ) {
171
- asm ! (
179
+ naked_asm ! (
172
180
"mov [rdi + 0x00], rsp" ,
173
181
"mov [rdi + 0x08], r15" ,
174
182
"mov [rdi + 0x10], r14" ,
@@ -183,7 +191,7 @@ unsafe extern "C" fn switch() {
183
191
"mov r12, [rsi + 0x20]" ,
184
192
"mov rbx, [rsi + 0x28]" ,
185
193
"mov rbp, [rsi + 0x30]" ,
186
- "ret" , options ( noreturn )
194
+ "ret"
187
195
) ;
188
196
}
189
197
You can’t perform that action at this time.
0 commit comments