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 <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/6291 Tested-by: jenkins Reviewed-by: Tim Newsome <tim@sifive.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
4487270ea4
commit
6f439e2032
|
@ -226,18 +226,28 @@ int semihosting_common(struct target *target)
|
||||||
return retval;
|
return retval;
|
||||||
else {
|
else {
|
||||||
int fd = semihosting_get_field(target, 0, fields);
|
int fd = semihosting_get_field(target, 0, fields);
|
||||||
if (semihosting->is_fileio) {
|
/* Do not allow to close OpenOCD's own standard streams */
|
||||||
if (fd == 0 || fd == 1 || fd == 2) {
|
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;
|
semihosting->result = 0;
|
||||||
|
} else {
|
||||||
|
semihosting->result = 0;
|
||||||
|
semihosting->sys_errno = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* Close the descriptor */
|
||||||
|
if (semihosting->is_fileio) {
|
||||||
semihosting->hit_fileio = true;
|
semihosting->hit_fileio = true;
|
||||||
fileio_info->identifier = "close";
|
fileio_info->identifier = "close";
|
||||||
fileio_info->param_1 = fd;
|
fileio_info->param_1 = fd;
|
||||||
} else {
|
} else {
|
||||||
semihosting->result = close(fd);
|
semihosting->result = close(fd);
|
||||||
semihosting->sys_errno = errno;
|
semihosting->sys_errno = errno;
|
||||||
|
|
||||||
LOG_DEBUG("close(%d)=%d", fd, (int)semihosting->result);
|
LOG_DEBUG("close(%d)=%d", fd, (int)semihosting->result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue