changeset 3951:a4161bb5ee6e

libgfx: added vm address translation function
author Alexandre Becoulet <alexandre.becoulet@free.fr>
date Wed, 06 Jun 2018 21:29:54 +0200
parents 1fededc14646
children 01577c807d28
files libgfx/bytecode.c
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgfx/bytecode.c	Wed Jun 06 21:29:06 2018 +0200
+++ b/libgfx/bytecode.c	Wed Jun 06 21:29:54 2018 +0200
@@ -24,6 +24,17 @@
   gfx_tilemap_init(&ctx->tilemap, &ctx->s[0], 1, 1, 0);
 }
 
+static inline void *
+gfx_translate_addr(struct bc_context_s *vm, bc_reg_t addr,
+                   size_t size, bool_t writable)
+{
+#ifdef CONFIG_MUTEK_BYTECODE_SANDBOX
+  if (vm->sandbox)
+    return bc_translate_addr(vm, addr, size, writable);
+#endif
+  return (void*)p;
+}
+
 error_t gfx_bc_run(struct bc_context_s *vm,
 		   struct gfx_bc_context_s *ctx,
 		   uint16_t op)
@@ -49,7 +60,8 @@
 	  gfx_surface_bytes(&s, w, h, fmt))
 	return -ERANGE;
 
-      void *data = bc_translate_addr(vm, p, s, 0);
+      void *data = gfx_translate_addr(vm, p, s, 0);
+
       if (!data || gfx_surface_init(ctx->s + n, data,
 				    s, w, h, fmt))
 	return -ERANGE;
@@ -206,7 +218,7 @@
       gfx_pos_t y = gfx_vector_yint(s);
 
       bc_reg_t p = bc_get_reg(vm, op & 15);
-      const uint8_t *str = bc_translate_addr(vm, p, len, 0);
+      const uint8_t *str = gfx_translate_addr(vm, p, len, 0);
 
       enum gfx_direction_e dir = (op >> 8) & 3;
       if (str != NULL)