• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision12992 (tree)
Zeit2019-09-15 16:24:28
Autorgdisirio

Log Message

Sandbox-side file API.

Ändern Zusammenfassung

Diff

--- trunk/os/sb/common/sberr.h (revision 12991)
+++ trunk/os/sb/common/sberr.h (revision 12992)
@@ -46,9 +46,20 @@
4646 #define SB_ERR_ENOSYS ((uint32_t)(-88))
4747
4848 #define SB_ERR_ERRORMASK 0xFFFFFF00U
49-#define SB_ERR_ISERROR(x) (((x) & SB_ERR_ERRORMASK) == SB_ERR_ERRORMASK)
49+#define SB_ERR_ISERROR(x) (((uint32_t)(x) & SB_ERR_ERRORMASK) == SB_ERR_ERRORMASK)
5050 /** @} */
5151
52+/**
53+ * @name Posix-like function codes
54+ * @{
55+ */
56+#define SB_POSIX_OPEN 1
57+#define SB_POSIX_CLOSE 2
58+#define SB_POSIX_READ 3
59+#define SB_POSIX_WRITE 4
60+#define SB_POSIX_LSEEK 5
61+/** @} */
62+
5263 /*===========================================================================*/
5364 /* Module pre-compile time settings. */
5465 /*===========================================================================*/
--- trunk/os/sb/host/sbposix.h (revision 12991)
+++ trunk/os/sb/host/sbposix.h (revision 12992)
@@ -32,17 +32,6 @@
3232 /* Module constants. */
3333 /*===========================================================================*/
3434
35-/**
36- * @name Posix-like function codes
37- * @{
38- */
39-#define SB_POSIX_OPEN 1
40-#define SB_POSIX_CLOSE 2
41-#define SB_POSIX_READ 3
42-#define SB_POSIX_WRITE 4
43-#define SB_POSIX_LSEEK 5
44-/** @} */
45-
4635 /*===========================================================================*/
4736 /* Module pre-compile time settings. */
4837 /*===========================================================================*/
--- trunk/os/sb/user/sbuser.c (revision 12991)
+++ trunk/os/sb/user/sbuser.c (revision 12992)
@@ -27,6 +27,7 @@
2727
2828 #include <stdint.h>
2929 #include <stdbool.h>
30+#include <stddef.h>
3031
3132 #include "sbuser.h"
3233
@@ -67,7 +68,7 @@
6768 */
6869 void sbApiInit(void) {
6970
70- sb.frequency = sbGetFrequency();
71+ sb.frequency = (time_conv_t)sbGetFrequency();
7172 }
7273
7374 /** @} */
--- trunk/os/sb/user/sbuser.h (revision 12991)
+++ trunk/os/sb/user/sbuser.h (revision 12992)
@@ -187,6 +187,80 @@
187187 /*===========================================================================*/
188188
189189 /**
190+ * @brief Posix-style file open.
191+ *
192+ * @param[in] pathname file to be opened
193+ * @param[in] flags open mode
194+ * @return The file descriptor or an error.
195+ */
196+static inline uint32_t sbFileOpen(const char *pathname,
197+ uint32_t flags) {
198+
199+ __syscall3r(0, SB_POSIX_OPEN, pathname, flags);
200+ return r0;
201+}
202+
203+/**
204+ * @brief Posix-style file close.
205+ *
206+ * @param[in] fd file descriptor
207+ * @return Operation result.
208+ */
209+static inline uint32_t sbFileClose(uint32_t fd) {
210+
211+ __syscall2r(0, SB_POSIX_CLOSE, fd);
212+ return r0;
213+}
214+
215+/**
216+ * @brief Posix-style file read.
217+ *
218+ * @param[in] fd file descriptor
219+ * @param[out] buf buffer pointer
220+ * @param[in] count number of bytes
221+ * @return The number of bytes really transferred or an error.
222+ */
223+static inline size_t sbFileRead(uint32_t fd,
224+ uint8_t *buf,
225+ size_t count) {
226+
227+ __syscall4r(0, SB_POSIX_READ, fd, buf, count);
228+ return (size_t)r0;
229+}
230+
231+/**
232+ * @brief Posix-style file write.
233+ *
234+ * @param[in] fd file descriptor
235+ * @param[in] buf buffer pointer
236+ * @param[in] count number of bytes
237+ * @return The number of bytes really transferred or an error.
238+ */
239+static inline size_t sbFileWrite(uint32_t fd,
240+ const uint8_t *buf,
241+ size_t count) {
242+
243+ __syscall4r(0, SB_POSIX_WRITE, fd, buf, count);
244+ return (size_t)r0;
245+}
246+
247+/**
248+ * @brief Posix-style file seek.
249+ *
250+ * @param[in] fd file descriptor
251+ * @param[in] offset file offset
252+ * @param[in] whence operation mode
253+ * @return Operation result.
254+ */
255+static inline uint32_t sbFileSeek(uint32_t fd,
256+ uint32_t offset,
257+ uint32_t whence) {
258+
259+ __syscall4r(0, SB_POSIX_LSEEK, fd, offset, whence);
260+ return (size_t)r0;
261+}
262+
263+/**
190264 * @brief Terminates the sandbox.
191265 *
192266 * @param[in] msg The exit message.
Show on old repository browser