Removed legacy stdio in SBs.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15410 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
b84c1cf96a
commit
00684c677d
|
@ -72,7 +72,7 @@ static const sb_config_t sb_config1 = {
|
||||||
.writeable = true
|
.writeable = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.vfs_driver = (vfs_driver_c *)&root_overlay_driver
|
// .vfs_driver = (vfs_driver_c *)&root_overlay_driver
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sandbox 2 configuration.*/
|
/* Sandbox 2 configuration.*/
|
||||||
|
@ -89,7 +89,7 @@ static const sb_config_t sb_config2 = {
|
||||||
.writeable = true
|
.writeable = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.vfs_driver = (vfs_driver_c *)&root_overlay_driver
|
// .vfs_driver = (vfs_driver_c *)&root_overlay_driver
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sandbox objects.*/
|
/* Sandbox objects.*/
|
||||||
|
|
|
@ -225,28 +225,6 @@ typedef struct {
|
||||||
* @brief VFS driver associated to the sandbox as root.
|
* @brief VFS driver associated to the sandbox as root.
|
||||||
*/
|
*/
|
||||||
vfs_driver_c *vfs_driver;
|
vfs_driver_c *vfs_driver;
|
||||||
#else
|
|
||||||
/**
|
|
||||||
* @brief Sandbox STDIN stream.
|
|
||||||
* @note Set this to @p NULL if standard I/O is not needed.
|
|
||||||
* @note By design you can use HAL streams here, you need to use
|
|
||||||
* a cast however.
|
|
||||||
*/
|
|
||||||
SandboxStream *stdin_stream;
|
|
||||||
/**
|
|
||||||
* @brief Sandbox STDOUT stream.
|
|
||||||
* @note Set this to @p NULL if standard I/O is not needed.
|
|
||||||
* @note By design you can use HAL streams here, you need to use
|
|
||||||
* a cast however.
|
|
||||||
*/
|
|
||||||
SandboxStream *stdout_stream;
|
|
||||||
/**
|
|
||||||
* @brief Sandbox STDERR stream.
|
|
||||||
* @note Set this to @p NULL if standard I/O is not needed.
|
|
||||||
* @note By design you can use HAL streams here, you need to use
|
|
||||||
* a cast however.
|
|
||||||
*/
|
|
||||||
SandboxStream *stderr_stream;
|
|
||||||
#endif
|
#endif
|
||||||
} sb_config_t;
|
} sb_config_t;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,9 @@
|
||||||
* @name Standard API handlers
|
* @name Standard API handlers
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
||||||
#define SB_SVC0_HANDLER sb_api_stdio
|
#define SB_SVC0_HANDLER sb_api_stdio
|
||||||
|
#endif
|
||||||
#define SB_SVC1_HANDLER sb_api_exit
|
#define SB_SVC1_HANDLER sb_api_exit
|
||||||
#define SB_SVC2_HANDLER sb_api_get_systime
|
#define SB_SVC2_HANDLER sb_api_get_systime
|
||||||
#define SB_SVC3_HANDLER sb_api_get_frequency
|
#define SB_SVC3_HANDLER sb_api_get_frequency
|
||||||
|
@ -976,6 +978,7 @@ void __sb_abort(msg_t msg) {
|
||||||
chSysHalt("zombies");
|
chSysHalt("zombies");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
||||||
void sb_api_stdio(struct port_extctx *ectxp) {
|
void sb_api_stdio(struct port_extctx *ectxp) {
|
||||||
|
|
||||||
switch (ectxp->r0) {
|
switch (ectxp->r0) {
|
||||||
|
@ -1029,6 +1032,7 @@ void sb_api_stdio(struct port_extctx *ectxp) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* SB_CFG_ENABLE_VFS == TRUE */
|
||||||
|
|
||||||
void sb_api_exit(struct port_extctx *ectxp) {
|
void sb_api_exit(struct port_extctx *ectxp) {
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include "ch.h"
|
|
||||||
#include "sb.h"
|
#include "sb.h"
|
||||||
|
|
||||||
|
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module local definitions. */
|
/* Module local definitions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -50,7 +51,6 @@
|
||||||
/* Module local functions. */
|
/* Module local functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
|
||||||
static msg_t create_descriptor(sb_ioblock_t *iop,
|
static msg_t create_descriptor(sb_ioblock_t *iop,
|
||||||
vfs_node_c *np) {
|
vfs_node_c *np) {
|
||||||
unsigned fd;
|
unsigned fd;
|
||||||
|
@ -65,13 +65,11 @@ static msg_t create_descriptor(sb_ioblock_t *iop,
|
||||||
|
|
||||||
return CH_RET_EMFILE;
|
return CH_RET_EMFILE;
|
||||||
}
|
}
|
||||||
#endif /* SB_CFG_ENABLE_VFS == TRUE */
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module exported functions. */
|
/* Module exported functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
|
||||||
int sb_posix_open(const char *path, int flags) {
|
int sb_posix_open(const char *path, int flags) {
|
||||||
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
||||||
vfs_node_c *np = NULL;
|
vfs_node_c *np = NULL;
|
||||||
|
@ -322,87 +320,6 @@ int sb_posix_getcwd(char *buf, size_t size) {
|
||||||
return vfsDrvGetCurrentDirectory(sbp->config->vfs_driver, buf, size);
|
return vfsDrvGetCurrentDirectory(sbp->config->vfs_driver, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* Fallbacks for when there is no VFS.*/
|
|
||||||
uint32_t sb_posix_open(const char *pathname, uint32_t flags) {
|
|
||||||
|
|
||||||
(void)pathname;
|
|
||||||
(void)flags;
|
|
||||||
|
|
||||||
return SB_ERR_ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t sb_posix_close(uint32_t fd) {
|
|
||||||
|
|
||||||
if ((fd == 0U) || (fd == 1U) || (fd == 2U)) {
|
|
||||||
|
|
||||||
return SB_ERR_NOERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SB_ERR_EBADFD;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t sb_posix_read(uint32_t fd, uint8_t *buf, size_t count) {
|
|
||||||
sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
|
||||||
|
|
||||||
if (!sb_is_valid_write_range(sbcp, (void *)buf, count)) {
|
|
||||||
return SB_ERR_EFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd == 0U) {
|
|
||||||
SandboxStream *ssp = sbcp->config->stdin_stream;
|
|
||||||
|
|
||||||
if ((count == 0U) || (ssp == NULL)) {
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint32_t)ssp->vmt->read((void *)ssp, buf, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SB_ERR_EBADFD;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t sb_posix_write(uint32_t fd, const uint8_t *buf, size_t count) {
|
|
||||||
sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
|
||||||
|
|
||||||
if (!sb_is_valid_read_range(sbcp, (const void *)buf, count)) {
|
|
||||||
return SB_ERR_EFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd == 1U) {
|
|
||||||
SandboxStream *ssp = sbcp->config->stdout_stream;
|
|
||||||
|
|
||||||
if ((count == 0U) || (ssp == NULL)) {
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint32_t)ssp->vmt->write((void *)ssp, buf, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd == 2U) {
|
|
||||||
SandboxStream *ssp = sbcp->config->stderr_stream;
|
|
||||||
|
|
||||||
if ((count == 0U) || (ssp == NULL)) {
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint32_t)ssp->vmt->write((void *)ssp, buf, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SB_ERR_EBADFD;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t sb_posix_lseek(uint32_t fd, uint32_t offset, uint32_t whence) {
|
|
||||||
|
|
||||||
(void)offset;
|
|
||||||
(void)whence;
|
|
||||||
|
|
||||||
if ((fd == 0U) || (fd == 1U) || (fd == 2U)) {
|
|
||||||
|
|
||||||
return SB_ERR_ESPIPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SB_ERR_EBADFD;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
#define SBPOSIX_H
|
#define SBPOSIX_H
|
||||||
|
|
||||||
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
#if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module constants. */
|
/* Module constants. */
|
||||||
|
@ -93,6 +93,8 @@ static inline bool sb_is_existing_descriptor(sb_ioblock_t *iop, int fd) {
|
||||||
return (fd >= 0) && (fd < SB_CFG_FD_NUM) && (iop->vfs_nodes[fd] != NULL);
|
return (fd >= 0) && (fd < SB_CFG_FD_NUM) && (iop->vfs_nodes[fd] != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* SB_CFG_ENABLE_VFS == TRUE */
|
||||||
|
|
||||||
#endif /* SBPOSIX_H */
|
#endif /* SBPOSIX_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
Loading…
Reference in New Issue