2017-08-30 14:06:30 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2022-05-09 13:56:13 +02:00
|
|
|
#include <zephyr/arch/x86/ia32/asm.h>
|
|
|
|
|
#include <zephyr/arch/cpu.h>
|
2017-08-30 14:06:30 -07:00
|
|
|
#include <offsets_short.h>
|
2022-05-09 13:56:13 +02:00
|
|
|
#include <zephyr/syscall.h>
|
2023-11-13 15:12:45 -08:00
|
|
|
#include <zephyr/kernel/mm.h>
|
2020-12-14 17:18:12 -08:00
|
|
|
#include <x86_mmu.h>
|
2017-08-30 14:06:30 -07:00
|
|
|
|
|
|
|
|
/* Exports */
|
2019-03-14 09:20:46 -06:00
|
|
|
GTEXT(z_x86_syscall_entry_stub)
|
|
|
|
|
GTEXT(z_x86_userspace_enter)
|
2019-11-07 12:43:29 -08:00
|
|
|
GTEXT(arch_user_string_nlen)
|
2019-10-16 13:38:54 -07:00
|
|
|
GTEXT(z_x86_user_string_nlen_fault_start)
|
|
|
|
|
GTEXT(z_x86_user_string_nlen_fault_end)
|
|
|
|
|
GTEXT(z_x86_user_string_nlen_fixup)
|
2017-08-30 14:06:30 -07:00
|
|
|
|
|
|
|
|
/* Imports */
|
2018-08-24 10:35:10 +02:00
|
|
|
GDATA(_k_syscall_table)
|
2017-08-30 14:06:30 -07:00
|
|
|
|
2019-02-06 15:35:24 -08:00
|
|
|
#ifdef CONFIG_X86_KPTI
|
|
|
|
|
/* Switch from the shadow to the kernel page table, switch to the interrupted
|
|
|
|
|
* thread's kernel stack, and copy all context from the trampoline stack.
|
|
|
|
|
*
|
|
|
|
|
* Assumes all registers are callee-saved since this gets called from other
|
|
|
|
|
* ASM code. Assumes a particular stack layout which is correct for
|
|
|
|
|
* _exception_enter and _interrupt_enter when invoked with a call instruction:
|
|
|
|
|
*
|
|
|
|
|
* 28 SS
|
|
|
|
|
* 24 ES
|
|
|
|
|
* 20 EFLAGS
|
|
|
|
|
* 16 CS
|
|
|
|
|
* 12 EIP
|
|
|
|
|
* 8 isr_param or exc code
|
|
|
|
|
* 4 isr or exc handler
|
|
|
|
|
* 0 return address
|
|
|
|
|
*/
|
kernel: mmu: remove LINKER_USE_PINNED_SECTION and __pinned_* tagging
CONFIG_LINKER_USE_PINNED_SECTION is the second half of the selective
kernel-pinning model removed in issue #108773. With the kernel image
now always resident at boot (previous commit), the __pinned_*
attribute family is a no-op: every page they would have segregated is
already pinned by z_mem_manage_init()'s whole-image loop, so the
tagging contract neither adds safety nor remains maintainable.
Drop it.
Mechanical removals:
* All ~219 in-tree uses of __pinned_text, __pinned_rodata,
__pinned_data, __pinned_bss, __pinned_noinit, and __pinned_func
across arch/x86, drivers/interrupt_controller, drivers/timer,
arch/common, kernel, lib/libc, subsys/portability/posix, tests, and
the syscall code generator (scripts/build/gen_syscalls.py).
* The assembly aliases PINNED_TEXT/RODATA/DATA/BSS/NOINIT used in
arch/x86/core/ia32/*.S and drivers/interrupt_controller/
intc_loapic_spurious.S become plain TEXT/RODATA/DATA/BSS/NOINIT.
* K_KERNEL_PINNED_STACK_DEFINE, K_KERNEL_PINNED_STACK_ARRAY_DEFINE,
K_KERNEL_PINNED_STACK_ARRAY_DECLARE, K_THREAD_PINNED_STACK_DEFINE,
and K_THREAD_PINNED_STACK_ARRAY_DEFINE are removed. The few
in-tree callers (kernel/init.c, arch/arm/core/cortex_a_r/smp.c,
arch/arm64/core/fatal.c, arch/rx/core/prep_c.c,
arch/x86/core/prep_c.c, kernel/include/kernel_internal.h,
tests/bluetooth/hci_uart_async) move to the corresponding
non-pinned macros.
Machinery removals:
* Kconfig.zephyr drops CONFIG_LINKER_USE_PINNED_SECTION.
qemu_x86_tiny and qemu_x86_atom_virt drop their =y overrides.
* include/zephyr/linker/section_tags.h drops the __pinned_* macro
definitions (both arms). __isr collapses to an empty macro since
its only purpose was to alias __pinned_func.
* include/zephyr/linker/sections.h drops PINNED_TEXT_SECTION_NAME,
PINNED_BSS_SECTION_NAME, etc. and the bare PINNED_TEXT/RODATA/etc.
forwarders, plus the _APP_SMEM_PINNED_SECTION_NAME constant.
* include/zephyr/linker/linker-defs.h drops the lnkr_pinned_*
externs, the _app_smem_pinned_* externs, and the lnkr_is_pinned()
/ lnkr_is_region_pinned() inline helpers.
* include/zephyr/linker/utils.h drops the lnkr_pinned_rodata branch
in linker_is_in_rodata().
* include/zephyr/linker/app_smem_pinned{,_aligned,_unaligned}.ld
are deleted; cmake/linker/ld/target_configure.cmake stops
configuring them.
* boards/qemu/x86/qemu_x86_tiny.ld and
include/zephyr/arch/x86/ia32/linker.ld drop their pinned-section
blocks and the now-redundant #ifndef CONFIG_LINKER_USE_PINNED_SECTION
conditionals throughout the body. The
LIB_KERNEL_IN_SECT / LIB_ARCH_X86_IN_SECT / LIB_ZEPHYR_IN_SECT /
LIB_C_IN_SECT / LIB_DRIVERS_IN_SECT / LIB_SUBSYS_LOGGING_IN_SECT /
LIB_ZEPHYR_OBJECT_FILE_IN_SECT / ZEPHYR_KERNEL_FUNCS_IN_SECT macros
in qemu_x86_tiny.ld are deleted; they existed only to feed the
pinned text/rodata/data/bss/noinit sections.
* kernel/mmu.c drops the mark_linker_section_pinned(lnkr_pinned_start,
...) call. The mark_linker_section_pinned() helper survives but is
now gated only on CONFIG_LINKER_USE_BOOT_SECTION.
* arch/common/init.c and include/zephyr/arch/common/init.h drop
arch_bss_zero_pinned(); arch/x86/core/ia32/crt0.S drops the call
to it.
* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
thread's privileged stack on user-mode entry. With the kernel
image fully resident the stack is already mapped.
* arch/x86/gen_mmu.py drops map_region("lnkr_pinned") and the
set_region_perms() calls for lnkr_pinned_text / lnkr_pinned_rodata.
* CMakeLists.txt drops the LINKER_USE_PINNED_SECTION block that
generated APP_SMEM_PINNED_* variables and the
pinned_partitions target property feeding gen_app_partitions.py.
cmake/modules/extensions.cmake removes the PINNED_RODATA /
PINNED_RAM_SECTIONS / PINNED_DATA_SECTIONS zephyr_linker_sources()
location keywords and their snippet files.
scripts/build/gen_app_partitions.py drops --pinoutput /
--pinpartitions arguments and the pinned-output branch.
subsys/testsuite/coverage/CMakeLists.txt drops its
CONFIG_DEMAND_PAGING-conditional fork.
* scripts/build/gen_kobject_list.py drops the
app_smem_pinned_start / _end fallback for kobject placement
validation.
* tests/arch/x86/pagetables and tests/kernel/mem_protect/userspace
drop their lnkr_pinned_text / lnkr_pinned_rodata branches.
* include/zephyr/arch/x86/ia32/arch.h folds IRQSTUBS_TEXT_SECTION
to the unconditional ".text.irqstubs" form.
* tests/subsys/llext/src/syscalls_ext.c drops a stale comment about
syscalls landing in .pinned_text.
Targeted retentions:
* arch/x86/core/bootargs.c keeps multiboot_cmdline and efi_bootargs
in .noinit (was __pinned_noinit, which decayed to __noinit when
LINKER_USE_PINNED_SECTION was unset). The multiboot and zefi loader
paths write these buffers before Zephyr's BSS-zero step, so
zeroing them at boot loses the cmdline.
* arch/x86/core/ia32/fatal.c keeps _df_esf and _df_stack in .noinit.
They are scratch space written by the double-fault handler and have
no zero-init requirement; keeping them in .noinit also preserves
the historical post-noinit alignment that gen_mmu.py relies on
(z_mapped_size is computed before CMake-injected iterable sections
are appended to the linker script, so the post-noinit page padding
is what keeps those sections within the mapped region).
* include/zephyr/arch/x86/ia32/syscall.h and
include/zephyr/arch/x86/arch.h wrap the per-arch
arch_syscall_invoke* / arch_is_user_context / arch_k_cycle_get_*
implementations in @cond INTERNAL_HIDDEN. The public Doxygen
contract lives on the prototypes in
include/zephyr/arch/arch_interface.h; the per-arch implementations
are internal. Without this, removing the __pinned_func attribute
exposes the implementations to the doxygen-coverage delta check
as 10 newly-undocumented APIs.
Documentation updates are deferred to a separate commit.
Issue: #108773
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-15 16:33:20 -04:00
|
|
|
SECTION_FUNC(TEXT, z_x86_trampoline_to_kernel)
|
2019-02-06 15:35:24 -08:00
|
|
|
/* Check interrupted code segment to see if we came from ring 3
|
|
|
|
|
* and hence on the trampoline stack
|
|
|
|
|
*/
|
|
|
|
|
testb $3, 16(%esp) /* Offset of CS */
|
|
|
|
|
jz 1f
|
|
|
|
|
|
|
|
|
|
/* Stash these regs as we need to use them */
|
|
|
|
|
pushl %esi
|
|
|
|
|
pushl %edi
|
|
|
|
|
|
|
|
|
|
/* Switch to kernel page table */
|
2024-06-06 14:30:02 -07:00
|
|
|
movl $K_MEM_PHYS_ADDR(z_x86_kernel_ptables), %esi
|
2019-02-06 15:35:24 -08:00
|
|
|
movl %esi, %cr3
|
|
|
|
|
|
|
|
|
|
/* Save old trampoline stack pointer in %edi */
|
|
|
|
|
movl %esp, %edi
|
|
|
|
|
|
2019-11-19 15:08:49 -08:00
|
|
|
/* Switch to privilege mode stack */
|
2019-02-06 15:35:24 -08:00
|
|
|
movl $_kernel, %esi
|
|
|
|
|
movl _kernel_offset_to_current(%esi), %esi
|
2019-11-19 15:08:49 -08:00
|
|
|
movl _thread_offset_to_psp(%esi), %esp
|
2019-02-06 15:35:24 -08:00
|
|
|
|
|
|
|
|
/* Transplant stack context and restore ESI/EDI. Taking care to zero
|
|
|
|
|
* or put uninteresting values where we stashed ESI/EDI since the
|
|
|
|
|
* trampoline page is insecure and there might a context switch
|
|
|
|
|
* on the way out instead of returning to the original thread
|
|
|
|
|
* immediately.
|
|
|
|
|
*/
|
|
|
|
|
pushl 36(%edi) /* SS */
|
|
|
|
|
pushl 32(%edi) /* ESP */
|
|
|
|
|
pushl 28(%edi) /* EFLAGS */
|
|
|
|
|
pushl 24(%edi) /* CS */
|
|
|
|
|
pushl 20(%edi) /* EIP */
|
|
|
|
|
pushl 16(%edi) /* error code or isr parameter */
|
|
|
|
|
pushl 12(%edi) /* exception/irq handler */
|
|
|
|
|
pushl 8(%edi) /* return address */
|
|
|
|
|
movl 4(%edi), %esi /* restore ESI */
|
|
|
|
|
movl $0, 4(%edi) /* Zero old esi storage area */
|
|
|
|
|
xchgl %edi, (%edi) /* Exchange old edi to restore it and put
|
|
|
|
|
old sp in the storage area */
|
|
|
|
|
|
|
|
|
|
/* Trampoline stack should have nothing sensitive in it at this point */
|
|
|
|
|
1:
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
/* Copy interrupt return stack context to the trampoline stack, switch back
|
|
|
|
|
* to the user page table, and only then 'iret'. We jump to this instead
|
|
|
|
|
* of calling 'iret' if KPTI is turned on.
|
|
|
|
|
*
|
|
|
|
|
* Stack layout is expected to be as follows:
|
|
|
|
|
*
|
|
|
|
|
* 16 SS
|
|
|
|
|
* 12 ESP
|
|
|
|
|
* 8 EFLAGS
|
|
|
|
|
* 4 CS
|
|
|
|
|
* 0 EIP
|
|
|
|
|
*
|
|
|
|
|
* This function is conditionally macroed to KPTI_IRET/KPTI_IRET_USER
|
|
|
|
|
*/
|
kernel: mmu: remove LINKER_USE_PINNED_SECTION and __pinned_* tagging
CONFIG_LINKER_USE_PINNED_SECTION is the second half of the selective
kernel-pinning model removed in issue #108773. With the kernel image
now always resident at boot (previous commit), the __pinned_*
attribute family is a no-op: every page they would have segregated is
already pinned by z_mem_manage_init()'s whole-image loop, so the
tagging contract neither adds safety nor remains maintainable.
Drop it.
Mechanical removals:
* All ~219 in-tree uses of __pinned_text, __pinned_rodata,
__pinned_data, __pinned_bss, __pinned_noinit, and __pinned_func
across arch/x86, drivers/interrupt_controller, drivers/timer,
arch/common, kernel, lib/libc, subsys/portability/posix, tests, and
the syscall code generator (scripts/build/gen_syscalls.py).
* The assembly aliases PINNED_TEXT/RODATA/DATA/BSS/NOINIT used in
arch/x86/core/ia32/*.S and drivers/interrupt_controller/
intc_loapic_spurious.S become plain TEXT/RODATA/DATA/BSS/NOINIT.
* K_KERNEL_PINNED_STACK_DEFINE, K_KERNEL_PINNED_STACK_ARRAY_DEFINE,
K_KERNEL_PINNED_STACK_ARRAY_DECLARE, K_THREAD_PINNED_STACK_DEFINE,
and K_THREAD_PINNED_STACK_ARRAY_DEFINE are removed. The few
in-tree callers (kernel/init.c, arch/arm/core/cortex_a_r/smp.c,
arch/arm64/core/fatal.c, arch/rx/core/prep_c.c,
arch/x86/core/prep_c.c, kernel/include/kernel_internal.h,
tests/bluetooth/hci_uart_async) move to the corresponding
non-pinned macros.
Machinery removals:
* Kconfig.zephyr drops CONFIG_LINKER_USE_PINNED_SECTION.
qemu_x86_tiny and qemu_x86_atom_virt drop their =y overrides.
* include/zephyr/linker/section_tags.h drops the __pinned_* macro
definitions (both arms). __isr collapses to an empty macro since
its only purpose was to alias __pinned_func.
* include/zephyr/linker/sections.h drops PINNED_TEXT_SECTION_NAME,
PINNED_BSS_SECTION_NAME, etc. and the bare PINNED_TEXT/RODATA/etc.
forwarders, plus the _APP_SMEM_PINNED_SECTION_NAME constant.
* include/zephyr/linker/linker-defs.h drops the lnkr_pinned_*
externs, the _app_smem_pinned_* externs, and the lnkr_is_pinned()
/ lnkr_is_region_pinned() inline helpers.
* include/zephyr/linker/utils.h drops the lnkr_pinned_rodata branch
in linker_is_in_rodata().
* include/zephyr/linker/app_smem_pinned{,_aligned,_unaligned}.ld
are deleted; cmake/linker/ld/target_configure.cmake stops
configuring them.
* boards/qemu/x86/qemu_x86_tiny.ld and
include/zephyr/arch/x86/ia32/linker.ld drop their pinned-section
blocks and the now-redundant #ifndef CONFIG_LINKER_USE_PINNED_SECTION
conditionals throughout the body. The
LIB_KERNEL_IN_SECT / LIB_ARCH_X86_IN_SECT / LIB_ZEPHYR_IN_SECT /
LIB_C_IN_SECT / LIB_DRIVERS_IN_SECT / LIB_SUBSYS_LOGGING_IN_SECT /
LIB_ZEPHYR_OBJECT_FILE_IN_SECT / ZEPHYR_KERNEL_FUNCS_IN_SECT macros
in qemu_x86_tiny.ld are deleted; they existed only to feed the
pinned text/rodata/data/bss/noinit sections.
* kernel/mmu.c drops the mark_linker_section_pinned(lnkr_pinned_start,
...) call. The mark_linker_section_pinned() helper survives but is
now gated only on CONFIG_LINKER_USE_BOOT_SECTION.
* arch/common/init.c and include/zephyr/arch/common/init.h drop
arch_bss_zero_pinned(); arch/x86/core/ia32/crt0.S drops the call
to it.
* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
thread's privileged stack on user-mode entry. With the kernel
image fully resident the stack is already mapped.
* arch/x86/gen_mmu.py drops map_region("lnkr_pinned") and the
set_region_perms() calls for lnkr_pinned_text / lnkr_pinned_rodata.
* CMakeLists.txt drops the LINKER_USE_PINNED_SECTION block that
generated APP_SMEM_PINNED_* variables and the
pinned_partitions target property feeding gen_app_partitions.py.
cmake/modules/extensions.cmake removes the PINNED_RODATA /
PINNED_RAM_SECTIONS / PINNED_DATA_SECTIONS zephyr_linker_sources()
location keywords and their snippet files.
scripts/build/gen_app_partitions.py drops --pinoutput /
--pinpartitions arguments and the pinned-output branch.
subsys/testsuite/coverage/CMakeLists.txt drops its
CONFIG_DEMAND_PAGING-conditional fork.
* scripts/build/gen_kobject_list.py drops the
app_smem_pinned_start / _end fallback for kobject placement
validation.
* tests/arch/x86/pagetables and tests/kernel/mem_protect/userspace
drop their lnkr_pinned_text / lnkr_pinned_rodata branches.
* include/zephyr/arch/x86/ia32/arch.h folds IRQSTUBS_TEXT_SECTION
to the unconditional ".text.irqstubs" form.
* tests/subsys/llext/src/syscalls_ext.c drops a stale comment about
syscalls landing in .pinned_text.
Targeted retentions:
* arch/x86/core/bootargs.c keeps multiboot_cmdline and efi_bootargs
in .noinit (was __pinned_noinit, which decayed to __noinit when
LINKER_USE_PINNED_SECTION was unset). The multiboot and zefi loader
paths write these buffers before Zephyr's BSS-zero step, so
zeroing them at boot loses the cmdline.
* arch/x86/core/ia32/fatal.c keeps _df_esf and _df_stack in .noinit.
They are scratch space written by the double-fault handler and have
no zero-init requirement; keeping them in .noinit also preserves
the historical post-noinit alignment that gen_mmu.py relies on
(z_mapped_size is computed before CMake-injected iterable sections
are appended to the linker script, so the post-noinit page padding
is what keeps those sections within the mapped region).
* include/zephyr/arch/x86/ia32/syscall.h and
include/zephyr/arch/x86/arch.h wrap the per-arch
arch_syscall_invoke* / arch_is_user_context / arch_k_cycle_get_*
implementations in @cond INTERNAL_HIDDEN. The public Doxygen
contract lives on the prototypes in
include/zephyr/arch/arch_interface.h; the per-arch implementations
are internal. Without this, removing the __pinned_func attribute
exposes the implementations to the doxygen-coverage delta check
as 10 newly-undocumented APIs.
Documentation updates are deferred to a separate commit.
Issue: #108773
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-15 16:33:20 -04:00
|
|
|
SECTION_FUNC(TEXT, z_x86_trampoline_to_user)
|
2019-02-06 15:35:24 -08:00
|
|
|
/* Check interrupted code segment to see if we came from ring 3
|
|
|
|
|
* and hence on the trampoline stack
|
|
|
|
|
*/
|
|
|
|
|
testb $3, 4(%esp) /* Offset of CS */
|
|
|
|
|
jz 1f
|
|
|
|
|
|
|
|
|
|
/* Otherwise, fall through ... */
|
|
|
|
|
|
kernel: mmu: remove LINKER_USE_PINNED_SECTION and __pinned_* tagging
CONFIG_LINKER_USE_PINNED_SECTION is the second half of the selective
kernel-pinning model removed in issue #108773. With the kernel image
now always resident at boot (previous commit), the __pinned_*
attribute family is a no-op: every page they would have segregated is
already pinned by z_mem_manage_init()'s whole-image loop, so the
tagging contract neither adds safety nor remains maintainable.
Drop it.
Mechanical removals:
* All ~219 in-tree uses of __pinned_text, __pinned_rodata,
__pinned_data, __pinned_bss, __pinned_noinit, and __pinned_func
across arch/x86, drivers/interrupt_controller, drivers/timer,
arch/common, kernel, lib/libc, subsys/portability/posix, tests, and
the syscall code generator (scripts/build/gen_syscalls.py).
* The assembly aliases PINNED_TEXT/RODATA/DATA/BSS/NOINIT used in
arch/x86/core/ia32/*.S and drivers/interrupt_controller/
intc_loapic_spurious.S become plain TEXT/RODATA/DATA/BSS/NOINIT.
* K_KERNEL_PINNED_STACK_DEFINE, K_KERNEL_PINNED_STACK_ARRAY_DEFINE,
K_KERNEL_PINNED_STACK_ARRAY_DECLARE, K_THREAD_PINNED_STACK_DEFINE,
and K_THREAD_PINNED_STACK_ARRAY_DEFINE are removed. The few
in-tree callers (kernel/init.c, arch/arm/core/cortex_a_r/smp.c,
arch/arm64/core/fatal.c, arch/rx/core/prep_c.c,
arch/x86/core/prep_c.c, kernel/include/kernel_internal.h,
tests/bluetooth/hci_uart_async) move to the corresponding
non-pinned macros.
Machinery removals:
* Kconfig.zephyr drops CONFIG_LINKER_USE_PINNED_SECTION.
qemu_x86_tiny and qemu_x86_atom_virt drop their =y overrides.
* include/zephyr/linker/section_tags.h drops the __pinned_* macro
definitions (both arms). __isr collapses to an empty macro since
its only purpose was to alias __pinned_func.
* include/zephyr/linker/sections.h drops PINNED_TEXT_SECTION_NAME,
PINNED_BSS_SECTION_NAME, etc. and the bare PINNED_TEXT/RODATA/etc.
forwarders, plus the _APP_SMEM_PINNED_SECTION_NAME constant.
* include/zephyr/linker/linker-defs.h drops the lnkr_pinned_*
externs, the _app_smem_pinned_* externs, and the lnkr_is_pinned()
/ lnkr_is_region_pinned() inline helpers.
* include/zephyr/linker/utils.h drops the lnkr_pinned_rodata branch
in linker_is_in_rodata().
* include/zephyr/linker/app_smem_pinned{,_aligned,_unaligned}.ld
are deleted; cmake/linker/ld/target_configure.cmake stops
configuring them.
* boards/qemu/x86/qemu_x86_tiny.ld and
include/zephyr/arch/x86/ia32/linker.ld drop their pinned-section
blocks and the now-redundant #ifndef CONFIG_LINKER_USE_PINNED_SECTION
conditionals throughout the body. The
LIB_KERNEL_IN_SECT / LIB_ARCH_X86_IN_SECT / LIB_ZEPHYR_IN_SECT /
LIB_C_IN_SECT / LIB_DRIVERS_IN_SECT / LIB_SUBSYS_LOGGING_IN_SECT /
LIB_ZEPHYR_OBJECT_FILE_IN_SECT / ZEPHYR_KERNEL_FUNCS_IN_SECT macros
in qemu_x86_tiny.ld are deleted; they existed only to feed the
pinned text/rodata/data/bss/noinit sections.
* kernel/mmu.c drops the mark_linker_section_pinned(lnkr_pinned_start,
...) call. The mark_linker_section_pinned() helper survives but is
now gated only on CONFIG_LINKER_USE_BOOT_SECTION.
* arch/common/init.c and include/zephyr/arch/common/init.h drop
arch_bss_zero_pinned(); arch/x86/core/ia32/crt0.S drops the call
to it.
* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
thread's privileged stack on user-mode entry. With the kernel
image fully resident the stack is already mapped.
* arch/x86/gen_mmu.py drops map_region("lnkr_pinned") and the
set_region_perms() calls for lnkr_pinned_text / lnkr_pinned_rodata.
* CMakeLists.txt drops the LINKER_USE_PINNED_SECTION block that
generated APP_SMEM_PINNED_* variables and the
pinned_partitions target property feeding gen_app_partitions.py.
cmake/modules/extensions.cmake removes the PINNED_RODATA /
PINNED_RAM_SECTIONS / PINNED_DATA_SECTIONS zephyr_linker_sources()
location keywords and their snippet files.
scripts/build/gen_app_partitions.py drops --pinoutput /
--pinpartitions arguments and the pinned-output branch.
subsys/testsuite/coverage/CMakeLists.txt drops its
CONFIG_DEMAND_PAGING-conditional fork.
* scripts/build/gen_kobject_list.py drops the
app_smem_pinned_start / _end fallback for kobject placement
validation.
* tests/arch/x86/pagetables and tests/kernel/mem_protect/userspace
drop their lnkr_pinned_text / lnkr_pinned_rodata branches.
* include/zephyr/arch/x86/ia32/arch.h folds IRQSTUBS_TEXT_SECTION
to the unconditional ".text.irqstubs" form.
* tests/subsys/llext/src/syscalls_ext.c drops a stale comment about
syscalls landing in .pinned_text.
Targeted retentions:
* arch/x86/core/bootargs.c keeps multiboot_cmdline and efi_bootargs
in .noinit (was __pinned_noinit, which decayed to __noinit when
LINKER_USE_PINNED_SECTION was unset). The multiboot and zefi loader
paths write these buffers before Zephyr's BSS-zero step, so
zeroing them at boot loses the cmdline.
* arch/x86/core/ia32/fatal.c keeps _df_esf and _df_stack in .noinit.
They are scratch space written by the double-fault handler and have
no zero-init requirement; keeping them in .noinit also preserves
the historical post-noinit alignment that gen_mmu.py relies on
(z_mapped_size is computed before CMake-injected iterable sections
are appended to the linker script, so the post-noinit page padding
is what keeps those sections within the mapped region).
* include/zephyr/arch/x86/ia32/syscall.h and
include/zephyr/arch/x86/arch.h wrap the per-arch
arch_syscall_invoke* / arch_is_user_context / arch_k_cycle_get_*
implementations in @cond INTERNAL_HIDDEN. The public Doxygen
contract lives on the prototypes in
include/zephyr/arch/arch_interface.h; the per-arch implementations
are internal. Without this, removing the __pinned_func attribute
exposes the implementations to the doxygen-coverage delta check
as 10 newly-undocumented APIs.
Documentation updates are deferred to a separate commit.
Issue: #108773
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-15 16:33:20 -04:00
|
|
|
SECTION_FUNC(TEXT, z_x86_trampoline_to_user_always)
|
2019-02-06 15:35:24 -08:00
|
|
|
/* Stash EDI, need a free register */
|
|
|
|
|
pushl %edi
|
|
|
|
|
|
2020-04-30 16:46:29 -07:00
|
|
|
/* Store old stack pointer and switch to trampoline stack.
|
|
|
|
|
* Lock IRQs before changing stack pointer to the trampoline stack,
|
|
|
|
|
* we don't want any interrupts also using the trampoline stack
|
|
|
|
|
* during this time.
|
2019-02-06 15:35:24 -08:00
|
|
|
*/
|
2020-04-30 16:46:29 -07:00
|
|
|
movl %esp, %edi
|
2019-02-06 15:35:24 -08:00
|
|
|
cli
|
2020-04-30 16:46:29 -07:00
|
|
|
movl $z_trampoline_stack_end, %esp
|
2019-02-06 15:35:24 -08:00
|
|
|
|
|
|
|
|
/* Copy context */
|
|
|
|
|
pushl 20(%edi) /* SS */
|
|
|
|
|
pushl 16(%edi) /* ESP */
|
|
|
|
|
pushl 12(%edi) /* EFLAGS */
|
|
|
|
|
pushl 8(%edi) /* CS */
|
|
|
|
|
pushl 4(%edi) /* EIP */
|
|
|
|
|
xchgl %edi, (%edi) /* Exchange old edi to restore it and put
|
|
|
|
|
trampoline stack address in its old storage
|
|
|
|
|
area */
|
2019-11-19 15:08:49 -08:00
|
|
|
/* Switch to user page table */
|
2019-02-06 15:35:24 -08:00
|
|
|
pushl %eax
|
2019-07-29 18:22:30 -07:00
|
|
|
movl $_kernel, %eax
|
|
|
|
|
movl _kernel_offset_to_current(%eax), %eax
|
2019-11-19 15:08:49 -08:00
|
|
|
movl _thread_offset_to_ptables(%eax), %eax
|
2019-02-06 15:35:24 -08:00
|
|
|
movl %eax, %cr3
|
|
|
|
|
popl %eax
|
|
|
|
|
movl $0, -4(%esp) /* Delete stashed EAX data */
|
|
|
|
|
|
|
|
|
|
/* Trampoline stack should have nothing sensitive in it at this point */
|
|
|
|
|
1:
|
|
|
|
|
iret
|
|
|
|
|
#endif /* CONFIG_X86_KPTI */
|
|
|
|
|
|
2017-08-30 14:06:30 -07:00
|
|
|
/* Landing site for syscall SW IRQ. Marshal arguments and call C function for
|
2019-02-06 15:35:24 -08:00
|
|
|
* further processing. We're on the kernel stack for the invoking thread,
|
|
|
|
|
* unless KPTI is enabled, in which case we're on the trampoline stack and
|
|
|
|
|
* need to get off it before enabling interrupts.
|
2017-08-30 14:06:30 -07:00
|
|
|
*/
|
2019-03-14 09:20:46 -06:00
|
|
|
SECTION_FUNC(TEXT, z_x86_syscall_entry_stub)
|
2019-02-06 15:35:24 -08:00
|
|
|
#ifdef CONFIG_X86_KPTI
|
|
|
|
|
/* Stash these regs as we need to use them */
|
|
|
|
|
pushl %esi
|
|
|
|
|
pushl %edi
|
|
|
|
|
|
|
|
|
|
/* Switch to kernel page table */
|
2024-06-06 14:30:02 -07:00
|
|
|
movl $K_MEM_PHYS_ADDR(z_x86_kernel_ptables), %esi
|
2019-02-06 15:35:24 -08:00
|
|
|
movl %esi, %cr3
|
|
|
|
|
|
|
|
|
|
/* Save old trampoline stack pointer in %edi */
|
|
|
|
|
movl %esp, %edi
|
|
|
|
|
|
2019-11-19 15:08:49 -08:00
|
|
|
/* Switch to privilege elevation stack */
|
2019-02-06 15:35:24 -08:00
|
|
|
movl $_kernel, %esi
|
|
|
|
|
movl _kernel_offset_to_current(%esi), %esi
|
2019-11-19 15:08:49 -08:00
|
|
|
movl _thread_offset_to_psp(%esi), %esp
|
2019-02-06 15:35:24 -08:00
|
|
|
|
|
|
|
|
/* Transplant context according to layout above. Variant of logic
|
|
|
|
|
* in x86_trampoline_to_kernel */
|
|
|
|
|
pushl 24(%edi) /* SS */
|
|
|
|
|
pushl 20(%edi) /* ESP */
|
|
|
|
|
pushl 16(%edi) /* EFLAGS */
|
|
|
|
|
pushl 12(%edi) /* CS */
|
|
|
|
|
pushl 8(%edi) /* EIP */
|
|
|
|
|
movl 4(%edi), %esi /* restore ESI */
|
|
|
|
|
movl $0, 4(%edi) /* Zero old esi storage area */
|
|
|
|
|
xchgl %edi, (%edi) /* Exchange old edi to restore it and put
|
|
|
|
|
old sp in the storage area */
|
|
|
|
|
|
|
|
|
|
/* Trampoline stack should have nothing sensitive in it at this point */
|
|
|
|
|
#endif /* CONFIG_X86_KPTI */
|
|
|
|
|
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
sti /* re-enable interrupts */
|
|
|
|
|
cld /* clear direction flag, restored on 'iret' */
|
|
|
|
|
|
|
|
|
|
/* call_id is in ESI. bounds-check it, must be less than
|
|
|
|
|
* K_SYSCALL_LIMIT
|
|
|
|
|
*/
|
2018-08-10 15:43:31 +02:00
|
|
|
cmp $K_SYSCALL_LIMIT, %esi
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
jae _bad_syscall
|
|
|
|
|
|
|
|
|
|
_id_ok:
|
2019-06-29 20:52:44 -07:00
|
|
|
#ifdef CONFIG_X86_BOUNDS_CHECK_BYPASS_MITIGATION
|
2019-03-07 16:07:48 -08:00
|
|
|
/* Prevent speculation with bogus system call IDs */
|
|
|
|
|
lfence
|
|
|
|
|
#endif
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
/* Marshal arguments per calling convention to match what is expected
|
|
|
|
|
* for _k_syscall_handler_t functions
|
|
|
|
|
*/
|
|
|
|
|
push %esp /* ssf */
|
2017-09-19 09:59:42 -07:00
|
|
|
push %ebp /* arg6 */
|
2017-08-30 14:06:30 -07:00
|
|
|
push %edi /* arg5 */
|
|
|
|
|
push %ebx /* arg4 */
|
|
|
|
|
push %ecx /* arg3 */
|
|
|
|
|
push %edx /* arg2 */
|
|
|
|
|
push %eax /* arg1 */
|
|
|
|
|
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
/* from the call ID in ESI, load EBX with the actual function pointer
|
|
|
|
|
* to call by looking it up in the system call dispatch table
|
|
|
|
|
*/
|
|
|
|
|
xor %edi, %edi
|
|
|
|
|
mov _k_syscall_table(%edi, %esi, 4), %ebx
|
|
|
|
|
|
|
|
|
|
/* Run the handler, which is some entry in _k_syscall_table */
|
2019-12-18 15:11:59 -08:00
|
|
|
call *%ebx
|
2017-08-30 14:06:30 -07:00
|
|
|
|
|
|
|
|
/* EAX now contains return value. Pop or xor everything else to prevent
|
|
|
|
|
* information leak from kernel mode.
|
|
|
|
|
*/
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
pop %edx /* old arg1 value, discard it */
|
2017-08-30 14:06:30 -07:00
|
|
|
pop %edx
|
|
|
|
|
pop %ecx
|
|
|
|
|
pop %ebx
|
|
|
|
|
pop %edi
|
2017-09-19 09:59:42 -07:00
|
|
|
/* Discard ssf and arg6 */
|
|
|
|
|
add $8, %esp
|
2019-02-06 15:35:24 -08:00
|
|
|
KPTI_IRET_USER
|
2017-08-30 14:06:30 -07:00
|
|
|
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
_bad_syscall:
|
|
|
|
|
/* ESI had a bogus syscall value in it, replace with the bad syscall
|
|
|
|
|
* handler's ID, and put the bad ID as its first argument. This
|
|
|
|
|
* clobbers ESI but the bad syscall handler never returns
|
|
|
|
|
* anyway, it's going to generate a kernel oops
|
|
|
|
|
*/
|
|
|
|
|
mov %esi, %eax
|
2018-08-10 15:43:31 +02:00
|
|
|
mov $K_SYSCALL_BAD, %esi
|
userspace: flesh out internal syscall interface
* Instead of a common system call entry function, we instead create a
table mapping system call ids to handler skeleton functions which are
invoked directly by the architecture code which receives the system
call.
* system call handler prototype specified. All but the most trivial
system calls will implement one of these. They validate all the
arguments, including verifying kernel/device object pointers, ensuring
that the calling thread has appropriate access to any memory buffers
passed in, and performing other parameter checks that the base system
call implementation does not check, or only checks with __ASSERT().
It's only possible to install a system call implementation directly
inside this table if the implementation has a return value and requires
no validation of any of its arguments.
A sample handler implementation for k_mutex_unlock() might look like:
u32_t _syscall_k_mutex_unlock(u32_t mutex_arg, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, void *ssf)
{
struct k_mutex *mutex = (struct k_mutex *)mutex_arg;
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(mutex, K_OBJ_MUTEX, 0, ssf);
_SYSCALL_VERIFY(mutex->lock_count > 0, ssf);
_SYSCALL_VERIFY(mutex->owner == _current, ssf);
k_mutex_unlock(mutex);
return 0;
}
* the x86 port modified to work with the system call table instead of
calling a common handler function. fixed an issue where registers being
changed could confuse the compiler has been fixed; all registers, even
ones used for parameters, must be preserved across the system call.
* a new arch API for producing a kernel oops when validating system call
arguments added. The debug information reported will be from the system
call site and not inside the handler function.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-13 18:04:21 -07:00
|
|
|
jmp _id_ok
|
|
|
|
|
|
2017-08-30 14:06:30 -07:00
|
|
|
|
2018-06-22 14:29:57 -07:00
|
|
|
/*
|
2019-11-07 12:43:29 -08:00
|
|
|
* size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err_arg)
|
2018-06-22 14:29:57 -07:00
|
|
|
*/
|
2019-11-07 12:43:29 -08:00
|
|
|
SECTION_FUNC(TEXT, arch_user_string_nlen)
|
2018-06-22 14:29:57 -07:00
|
|
|
push %ebp
|
|
|
|
|
mov %esp, %ebp
|
|
|
|
|
|
|
|
|
|
/* error value, set to -1 initially. This location is -4(%ebp) */
|
|
|
|
|
push $-1
|
|
|
|
|
|
|
|
|
|
/* Do the strlen operation, based on disassembly of minimal libc */
|
|
|
|
|
xor %eax, %eax /* EAX = 0, length count */
|
|
|
|
|
mov 0x8(%ebp), %edx /* EDX base of string */
|
|
|
|
|
|
|
|
|
|
/* This code might page fault */
|
|
|
|
|
strlen_loop:
|
2026-07-16 23:17:07 +08:00
|
|
|
cmp 0xc(%ebp), %eax /* Max length reached? */
|
|
|
|
|
je strlen_done
|
2019-10-16 13:38:54 -07:00
|
|
|
z_x86_user_string_nlen_fault_start:
|
2018-06-22 14:29:57 -07:00
|
|
|
cmpb $0x0, (%edx, %eax, 1) /* *(EDX + EAX) == 0? Could fault. */
|
|
|
|
|
|
2019-10-16 13:38:54 -07:00
|
|
|
z_x86_user_string_nlen_fault_end:
|
2018-06-22 14:29:57 -07:00
|
|
|
je strlen_done
|
|
|
|
|
inc %eax /* EAX++ and loop again */
|
|
|
|
|
jmp strlen_loop
|
|
|
|
|
|
|
|
|
|
strlen_done:
|
|
|
|
|
/* Set error value to 0 since we succeeded */
|
|
|
|
|
movl $0, -4(%ebp)
|
|
|
|
|
|
2019-10-16 13:38:54 -07:00
|
|
|
z_x86_user_string_nlen_fixup:
|
2018-06-22 14:29:57 -07:00
|
|
|
/* Write error value to err pointer parameter */
|
|
|
|
|
movl 0x10(%ebp), %ecx
|
|
|
|
|
pop %edx
|
|
|
|
|
movl %edx, (%ecx)
|
|
|
|
|
|
|
|
|
|
pop %ebp
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
2019-03-14 09:20:46 -06:00
|
|
|
/* FUNC_NORETURN void z_x86_userspace_enter(k_thread_entry_t user_entry,
|
2017-08-30 14:06:30 -07:00
|
|
|
* void *p1, void *p2, void *p3,
|
2020-05-27 11:26:57 -05:00
|
|
|
* uint32_t stack_end,
|
|
|
|
|
* uint32_t stack_start)
|
2017-08-30 14:06:30 -07:00
|
|
|
*
|
|
|
|
|
* A one-way trip to userspace.
|
|
|
|
|
*/
|
2019-03-14 09:20:46 -06:00
|
|
|
SECTION_FUNC(TEXT, z_x86_userspace_enter)
|
2017-08-30 14:06:30 -07:00
|
|
|
pop %esi /* Discard return address on stack */
|
|
|
|
|
|
|
|
|
|
/* Fetch parameters on the stack */
|
|
|
|
|
pop %eax /* user_entry */
|
|
|
|
|
pop %edx /* p1 */
|
|
|
|
|
pop %ecx /* p2 */
|
|
|
|
|
pop %esi /* p3 */
|
|
|
|
|
pop %ebx /* stack_end (high address) */
|
|
|
|
|
pop %edi /* stack_start (low address) */
|
|
|
|
|
|
|
|
|
|
/* Move to the kernel stack for this thread, so we can erase the
|
|
|
|
|
* user stack. The kernel stack is the page immediately before
|
|
|
|
|
* the user stack.
|
|
|
|
|
*
|
|
|
|
|
* For security reasons, we must erase the entire user stack.
|
|
|
|
|
* We don't know what previous contexts it was used and do not
|
|
|
|
|
* want to leak any information.
|
|
|
|
|
*/
|
|
|
|
|
mov %edi, %esp
|
|
|
|
|
|
2020-10-20 13:28:50 -07:00
|
|
|
/* Erase and enable US bit in page tables for the stack buffer */
|
2017-08-30 14:06:30 -07:00
|
|
|
push %ecx
|
|
|
|
|
push %eax
|
2020-10-20 13:28:50 -07:00
|
|
|
push %edx
|
|
|
|
|
call z_x86_current_stack_perms
|
|
|
|
|
pop %edx
|
2017-08-30 14:06:30 -07:00
|
|
|
pop %eax
|
|
|
|
|
pop %ecx
|
|
|
|
|
|
2020-10-20 13:28:50 -07:00
|
|
|
/* Set stack pointer to the base of the freshly-erased user stack.
|
|
|
|
|
* Now that this is set we won't need EBX any more.
|
2017-08-30 14:06:30 -07:00
|
|
|
*/
|
|
|
|
|
mov %ebx, %esp
|
|
|
|
|
|
|
|
|
|
/* Set segment registers (except CS and SS which are done in
|
|
|
|
|
* a special way by 'iret' below)
|
|
|
|
|
*/
|
|
|
|
|
mov $USER_DATA_SEG, %bx
|
|
|
|
|
mov %bx, %ds
|
|
|
|
|
mov %bx, %es
|
|
|
|
|
|
2019-03-08 14:19:05 -07:00
|
|
|
/* Push arguments to z_thread_entry() */
|
2017-08-30 14:06:30 -07:00
|
|
|
push %esi /* p3 */
|
|
|
|
|
push %ecx /* p2 */
|
|
|
|
|
push %edx /* p1 */
|
|
|
|
|
push %eax /* user_entry */
|
|
|
|
|
/* NULL return address */
|
|
|
|
|
push $0
|
|
|
|
|
|
|
|
|
|
/* Save stack pointer at this position, this is where it will be
|
2019-03-08 14:19:05 -07:00
|
|
|
* when we land in z_thread_entry()
|
2017-08-30 14:06:30 -07:00
|
|
|
*/
|
|
|
|
|
mov %esp, %edi
|
|
|
|
|
|
|
|
|
|
/* Inter-privilege 'iret' pops all of these. Need to fake an interrupt
|
|
|
|
|
* return to enter user mode as far calls cannot change privilege
|
|
|
|
|
* level
|
|
|
|
|
*/
|
|
|
|
|
push $USER_DATA_SEG /* SS */
|
|
|
|
|
push %edi /* ESP */
|
|
|
|
|
pushfl /* EFLAGS */
|
|
|
|
|
push $USER_CODE_SEG /* CS */
|
2019-03-08 14:19:05 -07:00
|
|
|
push $z_thread_entry /* EIP */
|
2017-08-30 14:06:30 -07:00
|
|
|
|
2019-03-08 14:19:05 -07:00
|
|
|
/* We will land in z_thread_entry() in user mode after this */
|
2019-02-06 15:35:24 -08:00
|
|
|
KPTI_IRET_USER
|