qinwei2004 commented on code in PR #6478: URL: https://github.com/apache/incubator-nuttx/pull/6478#discussion_r920722016
########## arch/arm64/src/common/arm64_mmu.c: ########## @@ -0,0 +1,619 @@ +/*************************************************************************** + * arch/arm64/src/common/arm64_mmu.c + * + * 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 <stdint.h> +#include <debug.h> +#include <assert.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> +#include <arch/chip/chip.h> + +#include "arm64_arch.h" +#include "arm64_internal.h" +#include "arm64_fatal.h" +#include "arm64_mmu.h" + +/*************************************************************************** + * Pre-processor Definitions + ***************************************************************************/ + +/* MMU debug option + * #define CONFIG_MMU_ASSERT 1 + * #define CONFIG_MMU_DEBUG 1 + * #define CONFIG_MMU_DUMP_PTE 1 + */ + +#ifdef CONFIG_MMU_DEBUG + +#define L0_SPACE "" +#define L1_SPACE " " +#define L2_SPACE " " +#define L3_SPACE " " +#define XLAT_TABLE_LEVEL_SPACE(level) \ + (((level) == 0) ? L0_SPACE : \ + ((level) == 1) ? L1_SPACE : \ + ((level) == 2) ? L2_SPACE : L3_SPACE) +#endif + +#ifdef CONFIG_MMU_ASSERT +#define __MMU_ASSERT(__cond, fmt, ...) \ + do { \ + if (!(__cond)){ \ + trace_printf(fmt, ## __VA_ARGS__); \ + PANIC(); \ + } \ Review Comment: The current macro is dangerous because (ptr) - sizeof(type) if using ptr size type for calculation. So if ptr is uint8_t * then it will jump back by sizeof(type) bytes, but if it is uint64_t * than by sizeof(type) * 8 bytes --- I try to following container_of defined in NuttX, please check but actually if we want to get a completely safety version, we maybe need to follow container_of in Linux kernel -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org