syscall: add config option to check syscall source
This commit is contained in:
parent
930cbc26e1
commit
7ef26f26e9
4 changed files with 24 additions and 0 deletions
|
@ -9,6 +9,13 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_CHECK_SYSCALL_SOURCE
|
||||||
|
/* syscall.S */
|
||||||
|
extern uintptr_t __syscall_entry_point;
|
||||||
|
#endif
|
||||||
|
|
||||||
void arch_enter(void *sp)
|
void arch_enter(void *sp)
|
||||||
{
|
{
|
||||||
struct reg_snapshot *regs = sp;
|
struct reg_snapshot *regs = sp;
|
||||||
|
@ -17,6 +24,18 @@ void arch_enter(void *sp)
|
||||||
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
|
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
|
||||||
int sc_ret;
|
int sc_ret;
|
||||||
|
|
||||||
|
# ifdef CONFIG_CHECK_SYSCALL_SOURCE
|
||||||
|
/*
|
||||||
|
* We need to ignore the program counter's LSB because the CPU uses
|
||||||
|
* that as a flag for whether it's operating in ARM or Thumb mode
|
||||||
|
* (1 for Thumb); the instructions are always 2-byte aligned.
|
||||||
|
*/
|
||||||
|
if ((regs->hw.pc & 0xfffffffe) != __syscall_entry_point) {
|
||||||
|
arch_syscall_set_rval(regs, -EACCES);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
if (sc_num > NSYSCALLS) {
|
if (sc_num > NSYSCALLS) {
|
||||||
arch_syscall_set_rval(regs, -ENOSYS);
|
arch_syscall_set_rval(regs, -ENOSYS);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -32,6 +32,8 @@ func_begin syscall
|
||||||
ldr r4, [sp, #16] /* arg5 */
|
ldr r4, [sp, #16] /* arg5 */
|
||||||
ldr r5, [sp, #20] /* arg6 */
|
ldr r5, [sp, #20] /* arg6 */
|
||||||
|
|
||||||
|
.global __syscall_entry_point
|
||||||
|
__syscall_entry_point:
|
||||||
svc #0
|
svc #0
|
||||||
|
|
||||||
pop {r4-r5,r7}
|
pop {r4-r5,r7}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define ARDIX_VERSION_STR "@ardix_VERSION@@ardix_VERSION_SUFFIX@"
|
#define ARDIX_VERSION_STR "@ardix_VERSION@@ardix_VERSION_SUFFIX@"
|
||||||
|
|
||||||
#cmakedefine DEBUG
|
#cmakedefine DEBUG
|
||||||
|
#cmakedefine CONFIG_CHECK_SYSCALL_SOURCE
|
||||||
|
|
||||||
#define ARCH "@ARCH@"
|
#define ARCH "@ARCH@"
|
||||||
#define ARCH_@ARCH_UPPERCASE@
|
#define ARCH_@ARCH_UPPERCASE@
|
||||||
|
|
|
@ -25,6 +25,8 @@ set(CONFIG_SERIAL_BUFSZ 256 CACHE STRING "Default serial buffer size in bytes")
|
||||||
|
|
||||||
set(CONFIG_PRINTF_BUFSZ 64 CACHE STRING "Default buffer size for printf() and friends")
|
set(CONFIG_PRINTF_BUFSZ 64 CACHE STRING "Default buffer size for printf() and friends")
|
||||||
|
|
||||||
|
option(CONFIG_CHECK_SYSCALL_SOURCE "Prohibit inline syscalls" OFF)
|
||||||
|
|
||||||
# This file is part of Ardix.
|
# This file is part of Ardix.
|
||||||
# Copyright (c) 2021 Felix Kopp <owo@fef.moe>.
|
# Copyright (c) 2021 Felix Kopp <owo@fef.moe>.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue