This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 620a182f51065a50213627902d14a6c05ea87802 Author: Marco Casaroli <[email protected]> AuthorDate: Fri Jul 24 23:39:54 2026 +0200 examples/pffault: Add a test that touches a kernel address from user space. A small user program that reads or writes one address, by default 0x3fc98000, the base of the ESP32-S3 kernel DRAM region. A user process must not reach it, so the access must fault and only the process must die. "pffault w" makes the access a store, and a second argument names another address. With CONFIG_ESP32S3_PAGEFAULT and CONFIG_ESP32S3_PAGEFAULT_SELFTEST on the kernel side, "pffault r 0x80000000" exercises the recoverable-fault restart path, and "pffault r 0x0" the report path. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- examples/pffault/CMakeLists.txt | 33 +++++++++++++++++ examples/pffault/Kconfig | 28 ++++++++++++++ examples/pffault/Make.defs | 25 +++++++++++++ examples/pffault/Makefile | 32 ++++++++++++++++ examples/pffault/pffault_main.c | 82 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+) diff --git a/examples/pffault/CMakeLists.txt b/examples/pffault/CMakeLists.txt new file mode 100644 index 000000000..5352cab0d --- /dev/null +++ b/examples/pffault/CMakeLists.txt @@ -0,0 +1,33 @@ +# ############################################################################## +# apps/examples/pffault/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +if(CONFIG_EXAMPLES_PFFAULT) + nuttx_add_application( + NAME + ${CONFIG_EXAMPLES_PFFAULT_PROGNAME} + SRCS + pffault_main.c + STACKSIZE + ${CONFIG_EXAMPLES_PFFAULT_STACKSIZE} + PRIORITY + ${CONFIG_EXAMPLES_PFFAULT_PRIORITY}) +endif() diff --git a/examples/pffault/Kconfig b/examples/pffault/Kconfig new file mode 100644 index 000000000..92a7ad943 --- /dev/null +++ b/examples/pffault/Kconfig @@ -0,0 +1,28 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_PFFAULT + tristate "Page-fault / PMS isolation test" + default n + ---help--- + A user-space task that deliberately touches a kernel-space address to + exercise the ESP32-S3 PMS isolation boundary and the kernel's + recoverable-fault dispatcher. + +if EXAMPLES_PFFAULT + +config EXAMPLES_PFFAULT_PROGNAME + string "Program name" + default "pffault" + +config EXAMPLES_PFFAULT_PRIORITY + int "pffault task priority" + default 100 + +config EXAMPLES_PFFAULT_STACKSIZE + int "pffault stack size" + default DEFAULT_TASK_STACKSIZE + +endif diff --git a/examples/pffault/Make.defs b/examples/pffault/Make.defs new file mode 100644 index 000000000..85e12bb87 --- /dev/null +++ b/examples/pffault/Make.defs @@ -0,0 +1,25 @@ +############################################################################ +# apps/examples/pffault/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_EXAMPLES_PFFAULT),) +CONFIGURED_APPS += $(APPDIR)/examples/pffault +endif diff --git a/examples/pffault/Makefile b/examples/pffault/Makefile new file mode 100644 index 000000000..ab3cb25f4 --- /dev/null +++ b/examples/pffault/Makefile @@ -0,0 +1,32 @@ +############################################################################ +# apps/examples/pffault/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +PROGNAME = $(CONFIG_EXAMPLES_PFFAULT_PROGNAME) +PRIORITY = $(CONFIG_EXAMPLES_PFFAULT_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_PFFAULT_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_PFFAULT) + +MAINSRC = pffault_main.c + +include $(APPDIR)/Application.mk diff --git a/examples/pffault/pffault_main.c b/examples/pffault/pffault_main.c new file mode 100644 index 000000000..913c0b95e --- /dev/null +++ b/examples/pffault/pffault_main.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * apps/examples/pffault/pffault_main.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> +#include <stdint.h> +#include <stdbool.h> +#include <stdlib.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: main + * + * Description: + * Deliberately touch a kernel-space address from an unprivileged (WORLD1) + * user task to exercise the ESP32-S3 PMS isolation boundary. In a working + * protected build this raises a precise Load/StoreProhibited fault that + * the kernel's recoverable-fault dispatcher must handle (terminating just + * this task); the shell should survive. + * + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + /* Default target: the base of the kernel DRAM region, to which the user + * world has no PMS permission. A second argument "w" makes it a store. + */ + + volatile uint32_t *kaddr = (volatile uint32_t *)0x3fc98000; + bool store = (argc > 1 && argv[1][0] == 'w'); + + if (argc > 2) + { + kaddr = (volatile uint32_t *)strtoul(argv[2], NULL, 0); + } + + printf("pffault: user-space %s of kernel addr %p ...\n", + store ? "write" : "read", (void *)kaddr); + fflush(stdout); + + if (store) + { + *kaddr = 0xdeadbeef; /* Expect a precise StoreProhibited (WORLD1) */ + } + else + { + uint32_t v = *kaddr; /* Expect a precise LoadProhibited (WORLD1) */ + + printf("pffault: SURVIVED unexpectedly, read %08lx\n", + (unsigned long)v); + } + + printf("pffault: returned from the faulting access (unexpected)\n"); + return 0; +}
