Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe38d28

Browse filesBrowse files
fix: naked_asm!
Signed-off-by: Anhad Singh <andypythonappdeveloper@gmail.com>
1 parent c877021 commit fe38d28
Copy full SHA for fe38d28

File tree

Expand file treeCollapse file tree

4 files changed

+19
-25
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+19
-25
lines changed

‎src/aero_kernel/src/arch/x86_64/mem.rs

Copy file name to clipboardExpand all lines: src/aero_kernel/src/arch/x86_64/mem.rs
+7-10Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18+
use core::arch::naked_asm;
19+
1820
fn should_store_by_byte() -> bool {
1921
let cpuid = raw_cpuid::CpuId::new();
2022
if let Some(features) = cpuid.get_extended_feature_info() {
@@ -32,7 +34,7 @@ unsafe extern "C" fn memcpy_movsq(dest: *mut u8, src: *const u8, len: usize) ->
3234
// %rdi = argument 1, `dest`
3335
// %rsi = argument 2, `src`
3436
// %rdx = argument 3, `len`
35-
asm!(
37+
naked_asm!(
3638
// Save the return value.
3739
"mov rax, rdi",
3840
// Copy in 8 byte chunks.
@@ -44,7 +46,6 @@ unsafe extern "C" fn memcpy_movsq(dest: *mut u8, src: *const u8, len: usize) ->
4446
"and rcx, 0x7",
4547
"rep movsb",
4648
"ret",
47-
options(noreturn)
4849
);
4950
}
5051

@@ -55,14 +56,13 @@ unsafe extern "C" fn memcpy_movsb(dest: *mut u8, src: *const u8, len: usize) ->
5556
// %rdi = argument 1, `dest`
5657
// %rsi = argument 2, `src`
5758
// %rdx = argument 3, `len`
58-
asm!(
59+
naked_asm!(
5960
// Save the return value.
6061
"mov rax, rdi",
6162
// Copy!
6263
"mov rcx, rdx",
6364
"rep movsb",
6465
"ret",
65-
options(noreturn)
6666
)
6767
}
6868

@@ -82,7 +82,7 @@ unsafe extern "C" fn memset_stosq(dest: *mut u8, byte: i32, len: usize) -> *mut
8282
// %rdi = argument 1, `dest`
8383
// %rsi = argument 2, `byte`
8484
// %rdx = argument 3, `len`
85-
asm!(
85+
naked_asm!(
8686
// Save the return value.
8787
"mov r11, rdi",
8888
// Create an 8-byte copy of the pattern.
@@ -101,7 +101,6 @@ unsafe extern "C" fn memset_stosq(dest: *mut u8, byte: i32, len: usize) -> *mut
101101
// Restore the return value.
102102
"mov rax, r11",
103103
"ret",
104-
options(noreturn)
105104
)
106105
}
107106

@@ -112,15 +111,14 @@ unsafe extern "C" fn memset_stosb(dest: *mut u8, byte: i32, len: usize) -> *mut
112111
// %rdi = argument 1, `dest`
113112
// %rsi = argument 2, `byte`
114113
// %rdx = argument 3, `len`
115-
asm!(
114+
naked_asm!(
116115
// Save the return value.
117116
"mov r11, rdi",
118117
"mov al, sil",
119118
"mov rcx, rdx",
120119
"rep stosb",
121120
"mov rax, r11",
122121
"ret",
123-
options(noreturn)
124122
)
125123
}
126124

@@ -141,7 +139,7 @@ unsafe extern "C" fn memmove_erms(dest: *mut u8, src: *const u8, len: usize) ->
141139
// %rdi = argument 1, `dest`
142140
// %rsi = argument 2, `src`
143141
// %rdx = argument 3, `len`
144-
asm!(
142+
naked_asm!(
145143
"mov rax, rdi",
146144
// Skip zero length.
147145
"test rdx, rdx",
@@ -167,7 +165,6 @@ unsafe extern "C" fn memmove_erms(dest: *mut u8, src: *const u8, len: usize) ->
167165
"rep movsb",
168166
"cld",
169167
"ret",
170-
options(noreturn)
171168
)
172169
}
173170

‎src/aero_kernel/src/arch/x86_64/syscall.rs

Copy file name to clipboardExpand all lines: src/aero_kernel/src/arch/x86_64/syscall.rs
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::utils::sync::IrqGuard;
99
use super::interrupts::InterruptErrorStack;
1010
use super::{asm_macros, io};
1111

12+
use core::arch::naked_asm;
1213
use core::mem::offset_of;
1314

1415
const ARCH_SET_GS: usize = 0x1001;
@@ -39,7 +40,7 @@ const ARCH_GET_GS: usize = 0x1004;
3940
/// The instruction also does not save anything on the stack and does *not* change the `RSP`.
4041
#[naked]
4142
unsafe extern "C" fn x86_64_syscall_handler() {
42-
asm!(
43+
naked_asm!(
4344
// make the GS base point to the kernel TLS
4445
"swapgs",
4546
// save the user stack pointer
@@ -89,7 +90,6 @@ unsafe extern "C" fn x86_64_syscall_handler() {
8990
tss_temp_ustack_off = const offset_of!(Tss, reserved2) + core::mem::size_of::<usize>(),
9091
tss_rsp0_off = const offset_of!(Tss, rsp) + core::mem::size_of::<usize>(),
9192
x86_64_do_syscall = sym x86_64_do_syscall,
92-
options(noreturn)
9393
)
9494
}
9595

@@ -107,7 +107,7 @@ unsafe extern "C" fn x86_64_syscall_handler() {
107107
/// The instruction expects the call number and arguments in the same registers as for SYSCALL.
108108
#[naked]
109109
unsafe extern "C" fn x86_64_sysenter_handler() {
110-
asm!(
110+
naked_asm!(
111111
"swapgs",
112112
// Build the interrupt frame expected by the kernel.
113113
"push {userland_ss}",
@@ -155,7 +155,6 @@ unsafe extern "C" fn x86_64_sysenter_handler() {
155155
userland_ss = const USER_SS.bits(),
156156
x86_64_check_sysenter = sym x86_64_check_sysenter,
157157
x86_64_do_syscall = sym x86_64_do_syscall,
158-
options(noreturn)
159158
)
160159
}
161160

‎src/aero_kernel/src/arch/x86_64/task.rs

Copy file name to clipboardExpand all lines: src/aero_kernel/src/arch/x86_64/task.rs
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use alloc::vec::Vec;
3737
use raw_cpuid::CpuId;
3838

3939
use core::alloc::Layout;
40+
use core::arch::naked_asm;
4041
use core::ptr::Unique;
4142

4243
use crate::arch::interrupts::InterruptErrorStack;
@@ -115,7 +116,8 @@ const USERLAND_STACK_BOTTOM: VirtAddr = USERLAND_STACK_TOP.const_sub_u64(USERLAN
115116

116117
#[naked]
117118
unsafe extern "C" fn jump_userland_exec(stack: VirtAddr, rip: VirtAddr, rflags: u64) {
118-
asm!(
119+
#[rustfmt::skip]
120+
naked_asm!(
119121
"push rdi", // stack
120122
"push rsi", // rip
121123
"push rdx", // rflags
@@ -124,14 +126,13 @@ unsafe extern "C" fn jump_userland_exec(stack: VirtAddr, rip: VirtAddr, rflags:
124126
"pop rcx",
125127
"pop rsp",
126128
"swapgs",
127-
"sysretq",
128-
options(noreturn)
129+
"sysretq"
129130
);
130131
}
131132

132133
#[naked]
133134
unsafe extern "C" fn task_spinup(prev: &mut Unique<Context>, next: &Context) {
134-
asm!(
135+
naked_asm!(
135136
// save callee-saved registers
136137
"push rbp",
137138
"push rbx",
@@ -158,34 +159,31 @@ unsafe extern "C" fn task_spinup(prev: &mut Unique<Context>, next: &Context) {
158159
"pop rbp",
159160
// resume the next thread
160161
"ret",
161-
options(noreturn)
162162
);
163163
}
164164

165165
#[naked]
166166
unsafe extern "C" fn iretq_init() {
167-
asm!(
167+
naked_asm!(
168168
"cli",
169169
// pop the error code
170170
"add rsp, 8",
171171
asm_macros::pop_preserved!(),
172172
asm_macros::pop_scratch!(),
173173
"iretq",
174-
options(noreturn)
175174
)
176175
}
177176

178177
#[naked]
179178
unsafe extern "C" fn fork_init() {
180-
asm!(
179+
naked_asm!(
181180
"cli",
182181
// pop the error code
183182
"add rsp, 8",
184183
asm_macros::pop_preserved!(),
185184
asm_macros::pop_scratch!(),
186185
"swapgs",
187186
"iretq",
188-
options(noreturn)
189187
)
190188
}
191189

‎src/aero_kernel/src/arch/x86_64/user_copy.rs

Copy file name to clipboardExpand all lines: src/aero_kernel/src/arch/x86_64/user_copy.rs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18+
use core::arch::naked_asm;
1819
use core::fmt::{Debug, Display};
1920
use core::mem::MaybeUninit;
2021
use core::ops::{Deref, DerefMut};
@@ -52,7 +53,7 @@ unsafe extern "C" fn copy_to_from_user(
5253
// %rsi = argument 2, `src`
5354
// %rdx = argument 3, `size`
5455
// %rcx = argument 4, `fault_resume` (copied to %r10)
55-
asm!(
56+
naked_asm!(
5657
// Copy `fault_resume` out of %rcx because it will be utilized by `rep movsb` latter.
5758
"mov r10, rcx",
5859
// Setup the page fault resume.
@@ -82,7 +83,6 @@ unsafe extern "C" fn copy_to_from_user(
8283
"1:",
8384
"xor eax, eax",
8485
"jmp 3b",
85-
options(noreturn)
8686
)
8787
}
8888

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.