From: OpenOCD-Gerrit <ope...@us...> - 2021-07-10 14:31:06
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 6f439e203289c517360fdc061ca9497fc4c530b8 (commit) from 4487270ea434782f25f790892c5f7d03b7cbe243 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6f439e203289c517360fdc061ca9497fc4c530b8 Author: Jan Matyas <ma...@co...> Date: Fri Jun 4 10:44:44 2021 +0200 target/semihosting: Fix of close(): Never close standard streams This change fixes behavior of the SEMIHOSTING_SYS_CLOSE operation. It ensures that OpenOCD's own stdin/stdout/stderr streams are never closed, not even if the target requests it via semihosting. Change-Id: Ia85af5963d1a3516284fd834f7197369a8fb268c Signed-off-by: Jan Matyas <ma...@co...> Reviewed-on: http://openocd.zylin.com/6291 Tested-by: jenkins Reviewed-by: Tim Newsome <ti...@si...> Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index bfb1ecaa7..ffed7350e 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -226,18 +226,28 @@ int semihosting_common(struct target *target) return retval; else { int fd = semihosting_get_field(target, 0, fields); - if (semihosting->is_fileio) { - if (fd == 0 || fd == 1 || fd == 2) { + /* Do not allow to close OpenOCD's own standard streams */ + if (fd == 0 || fd == 1 || fd == 2) { + LOG_DEBUG("ignoring semihosting attempt to close %s", + (fd == 0) ? "stdin" : + (fd == 1) ? "stdout" : "stderr"); + /* Just pretend success */ + if (semihosting->is_fileio) { semihosting->result = 0; - break; + } else { + semihosting->result = 0; + semihosting->sys_errno = 0; } + break; + } + /* Close the descriptor */ + if (semihosting->is_fileio) { semihosting->hit_fileio = true; fileio_info->identifier = "close"; fileio_info->param_1 = fd; } else { semihosting->result = close(fd); semihosting->sys_errno = errno; - LOG_DEBUG("close(%d)=%d", fd, (int)semihosting->result); } } ----------------------------------------------------------------------- Summary of changes: src/target/semihosting_common.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) hooks/post-receive -- Main OpenOCD repository |