arch/sim: add host_errno_get/set for sim to backup/restore in "irq"

Avoid the errno changed after interrupt in sim and make return value
mistake when according to errno.
Move host_errno_convert from macro to sim_errno.c.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
buxiasen
2025-07-29 15:42:05 +08:00
committed by Xiang Xiao
parent cd2bf49474
commit 100c9dd20b
5 changed files with 101 additions and 7 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ ifeq ($(CONFIG_FS_LARGEFILE),y)
endif
HOSTSRCS = sim_hostirq.c sim_hostmemory.c sim_hostmisc.c sim_hosttime.c sim_hostuart.c
HOSTSRCS += sim_hostfs.c
HOSTSRCS += sim_hostfs.c sim_errno.c
hostfs.h: $(TOPDIR)/include/nuttx/fs/hostfs.h
@echo "CP: $<"
+2
View File
@@ -284,6 +284,8 @@ endif()
list(APPEND HOSTSRCS sim_hostfs.c)
list(APPEND HOST_DEFINITIONS CONFIG_NAME_MAX=${CONFIG_NAME_MAX})
list(APPEND HOSTSRCS sim_errno.c)
configure_file(${NUTTX_DIR}/include/nuttx/fs/hostfs.h
${CMAKE_CURRENT_BINARY_DIR}/hostfs.h COPYONLY)
configure_file(${CMAKE_BINARY_DIR}/include/nuttx/config.h
+46
View File
@@ -0,0 +1,46 @@
/****************************************************************************
* arch/sim/src/sim/posix/sim_errno.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 <errno.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int host_errno_convert(int errcode)
{
return errcode;
}
int host_errno_get(void)
{
return errno;
}
void host_errno_set(int errcode)
{
errno = errcode;
}
+6 -6
View File
@@ -107,12 +107,6 @@
#define sim_savestate(regs) sim_copyfullstate(regs, up_current_regs())
#define sim_restorestate(regs) up_set_current_regs(regs)
/* Provide a common interface, which should have different conversions
* on different platforms.
*/
#define host_errno_convert(errcode) (errcode)
#define sim_saveusercontext(saveregs, ret) \
do \
{ \
@@ -215,6 +209,12 @@ void sim_copyfullstate(xcpt_reg_t *dest, xcpt_reg_t *src);
void *sim_doirq(int irq, void *regs);
void sim_unlock(void);
/* sim_errno.c */
int host_errno_convert(int errcode);
int host_errno_get(void);
void host_errno_set(int errcode);
/* sim_hostmisc.c ***********************************************************/
void host_abort(int status);
+46
View File
@@ -0,0 +1,46 @@
/****************************************************************************
* arch/sim/src/sim/win/sim_errno.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 <errno.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int host_errno_convert(int errcode)
{
return errcode;
}
int host_errno_get(void)
{
return errno;
}
void host_errno_set(int errcode)
{
errno = errcode;
}