Directly define __usercopy_{start,end} in the usercopy functions
As opposed to requiring a linker script
This commit is contained in:
@@ -25,9 +25,6 @@ SECTIONS {
|
||||
.text : AT(ADDR(.text) - KERNEL_OFFSET) {
|
||||
__text_start = .;
|
||||
*(.text*)
|
||||
__usercopy_start = .;
|
||||
*(.usercopy-fns)
|
||||
__usercopy_end = .;
|
||||
. = ALIGN(4096);
|
||||
__text_end = .;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,6 @@ SECTIONS {
|
||||
.text ALIGN(4K) : AT(ADDR(.text) - KERNEL_OFFSET) {
|
||||
__text_start = .;
|
||||
*(.text*)
|
||||
__usercopy_start = .;
|
||||
*(.usercopy-fns)
|
||||
__usercopy_end = .;
|
||||
}
|
||||
|
||||
.rodata ALIGN(4K) : AT(ADDR(.rodata) - KERNEL_OFFSET) {
|
||||
|
||||
@@ -27,9 +27,6 @@ SECTIONS {
|
||||
*(.early_init.text*)
|
||||
. = ALIGN(4096);
|
||||
*(.text*)
|
||||
__usercopy_start = .;
|
||||
*(.usercopy-fns)
|
||||
__usercopy_end = .;
|
||||
. = ALIGN(4096);
|
||||
__text_end = .;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,6 @@ SECTIONS {
|
||||
.text ALIGN(4K) : AT(ADDR(.text) - KERNEL_OFFSET) {
|
||||
__text_start = .;
|
||||
*(.text*)
|
||||
__usercopy_start = .;
|
||||
*(.usercopy-fns)
|
||||
__usercopy_end = .;
|
||||
}
|
||||
|
||||
.rodata ALIGN(4K) : AT(ADDR(.rodata) - KERNEL_OFFSET) {
|
||||
|
||||
@@ -37,11 +37,12 @@ pub use ::rmm::AArch64Arch as CurrentRmmArch;
|
||||
pub use arch_copy_to_user as arch_copy_from_user;
|
||||
|
||||
#[unsafe(naked)]
|
||||
#[unsafe(link_section = ".usercopy-fns")]
|
||||
pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -> u8 {
|
||||
// x0, x1, x2
|
||||
core::arch::naked_asm!(
|
||||
"
|
||||
.global __usercopy_start
|
||||
__usercopy_start:
|
||||
mov x4, x0
|
||||
mov x0, 0
|
||||
2:
|
||||
@@ -58,6 +59,8 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -
|
||||
b 2b
|
||||
3:
|
||||
ret
|
||||
.global __usercopy_end
|
||||
__usercopy_end:
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@ use core::arch::naked_asm;
|
||||
|
||||
pub use arch_copy_to_user as arch_copy_from_user;
|
||||
|
||||
#[unsafe(link_section = ".usercopy-fns")]
|
||||
#[unsafe(naked)]
|
||||
pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -> u8 {
|
||||
naked_asm!(
|
||||
"
|
||||
.global __usercopy_start
|
||||
__usercopy_start:
|
||||
addi sp, sp, -16
|
||||
sd fp, 0(sp)
|
||||
sd ra, 8(sp)
|
||||
@@ -55,6 +56,8 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -
|
||||
bne a2, x0, 4b
|
||||
5: mv a0, x0
|
||||
ret
|
||||
.global __usercopy_end
|
||||
__usercopy_end:
|
||||
"
|
||||
)
|
||||
}
|
||||
|
||||
+4
-1
@@ -17,10 +17,11 @@ pub mod flags {
|
||||
}
|
||||
|
||||
#[unsafe(naked)]
|
||||
#[unsafe(link_section = ".usercopy-fns")]
|
||||
pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -> u8 {
|
||||
core::arch::naked_asm!(
|
||||
"
|
||||
.global __usercopy_start
|
||||
__usercopy_start:
|
||||
push edi
|
||||
push esi
|
||||
|
||||
@@ -34,6 +35,8 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -
|
||||
|
||||
xor eax, eax
|
||||
ret
|
||||
.global __usercopy_end
|
||||
__usercopy_end:
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
+23
-18
@@ -24,27 +24,32 @@ pub mod flags {
|
||||
// TODO: Maybe support rewriting relocations (using LD's --emit-relocs) when working with entire
|
||||
// functions?
|
||||
#[unsafe(naked)]
|
||||
#[unsafe(link_section = ".usercopy-fns")]
|
||||
pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -> u8 {
|
||||
// TODO: spectre_v1
|
||||
|
||||
core::arch::naked_asm!(alternative!(
|
||||
feature: "smap",
|
||||
then: ["
|
||||
xor eax, eax
|
||||
mov rcx, rdx
|
||||
stac
|
||||
rep movsb
|
||||
clac
|
||||
ret
|
||||
"],
|
||||
default: ["
|
||||
xor eax, eax
|
||||
mov rcx, rdx
|
||||
rep movsb
|
||||
ret
|
||||
"]
|
||||
));
|
||||
core::arch::naked_asm!(
|
||||
".global __usercopy_start
|
||||
__usercopy_start:",
|
||||
alternative!(
|
||||
feature: "smap",
|
||||
then: ["
|
||||
xor eax, eax
|
||||
mov rcx, rdx
|
||||
stac
|
||||
rep movsb
|
||||
clac
|
||||
ret
|
||||
"],
|
||||
default: ["
|
||||
xor eax, eax
|
||||
mov rcx, rdx
|
||||
rep movsb
|
||||
ret
|
||||
"]
|
||||
),
|
||||
".global __usercopy_end
|
||||
__usercopy_end:"
|
||||
);
|
||||
}
|
||||
pub use arch_copy_to_user as arch_copy_from_user;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user