Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: src/include/minsfi_ptr.h

Issue 546883003: MinSFI: Passing arguments to the entry function (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #ifndef NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PTR_H_
8 #define NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PTR_H_
9
10 #include <assert.h>
11
12 #include "native_client/src/include/minsfi_priv.h"
13
14 /*
15 * This defines what ToMinsfiPtr should do if the given native pointer
16 * is not within the bounds of the allocated memory region. We abort in
17 * production code and return a magic constant when invoked inside tests.
18 */
19 #ifndef MINSFI_PTR_CONVERSION_TEST
20 #define ToMinsfiPtr_AbortAction abort();
21 #else // MINSFI_PTR_CONVERSION_TEST
22 #define ToMinsfiPtr_AbortAction return 0xCAFEBABE;
23 #endif // MINSFI_PTR_CONVERSION_TEST
24
25 /*
26 * Convert an untrusted pointer into a native pointer. Because this is just
27 * some integer provided by the untrusted code, we must sandbox it the same
28 * way the SandboxMemoryAccesses compiler pass does.
29 */
30 static inline char *FromMinsfiPtr(sfiptr_t sfiptr, const MinsfiSandbox *sb) {
31 uint32_t masked_sfiptr = sfiptr & sb->ptr_mask;
32 return sb->mem_base + masked_sfiptr;
33 }
34
35 /*
36 * Convert a native pointer into an untrusted pointer. This means simply
37 * subtracting the memory base from the address.
38 */
39 static inline sfiptr_t ToMinsfiPtr(char *ptr, const MinsfiSandbox *sb) {
jvoung (off chromium) 2014/09/10 17:04:29 you could probably make this a const char *ptr
dbrazdil 2014/09/10 18:49:47 Done.
40 uintptr_t ptr_int = (uintptr_t) ptr;
41 uintptr_t base_int = (uintptr_t) sb->mem_base;
42 sfiptr_t sb_ptr = ptr_int - base_int;
43
44 /* Check that the pointer is in the bounds of the allocated memory region. */
45 if ((base_int > ptr_int) || ((sb_ptr & (~sb->ptr_mask)) != 0)) {
46 ToMinsfiPtr_AbortAction
47 }
48
49 return sb_ptr;
50 }
51
52 #endif // NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698