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

Side by Side Diff: src/trusted/debug_stub/posix/platform_impl.cc

Issue 10896004: Don't modify memory access right when changing data in debug stub. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 CHECK(close(pipe_fds[0]) == 0); 61 CHECK(close(pipe_fds[0]) == 0);
62 CHECK(close(pipe_fds[1]) == 0); 62 CHECK(close(pipe_fds[1]) == 0);
63 return success; 63 return success;
64 } 64 }
65 65
66 bool IPlatform::GetMemory(uint64_t virt, uint32_t len, void *dst) { 66 bool IPlatform::GetMemory(uint64_t virt, uint32_t len, void *dst) {
67 return SafeMemoryCopy(dst, reinterpret_cast<void*>(virt), len); 67 return SafeMemoryCopy(dst, reinterpret_cast<void*>(virt), len);
68 } 68 }
69 69
70 bool IPlatform::SetMemory(uint64_t virt, uint32_t len, void *src) { 70 bool IPlatform::SetMemory(struct NaClApp* nap, uint64_t virt, uint32_t len,
Mark Seaborn 2012/08/29 17:29:43 Use the " *" spacing style
halyavin 2012/08/30 09:46:28 Done.
71 void *src) {
71 uintptr_t page_mask = NACL_PAGESIZE - 1; 72 uintptr_t page_mask = NACL_PAGESIZE - 1;
72 uintptr_t page = virt & ~page_mask; 73 uintptr_t page = virt & ~page_mask;
73 uintptr_t mapping_size = ((virt + len + page_mask) & ~page_mask) - page; 74 uintptr_t mapping_size = ((virt + len + page_mask) & ~page_mask) - page;
74 if (mprotect(reinterpret_cast<void*>(page), mapping_size, 75 bool is_code = virt + len <= nap->mem_start + nap->dynamic_text_end;
75 PROT_READ | PROT_WRITE) != 0) { 76 if (is_code && mprotect(reinterpret_cast<void*>(page), mapping_size,
Mark Seaborn 2012/08/29 17:29:43 Nit: I would suggest this is clearer as a nested '
halyavin 2012/08/30 09:46:28 Done.
77 PROT_READ | PROT_WRITE) != 0) {
Mark Seaborn 2012/08/29 17:29:43 Should we change this to read+write+exec so as not
halyavin 2012/08/30 09:46:28 Yes, we are not going to support non-stop mode any
76 return false; 78 return false;
77 } 79 }
78 bool succeeded = SafeMemoryCopy(reinterpret_cast<void*>(virt), src, len); 80 bool succeeded = SafeMemoryCopy(reinterpret_cast<void*>(virt), src, len);
79 // TODO(mseaborn): We assume here that SetMemory() is being used to 81 // TODO(mseaborn): We use mprotect only to modify code area, so
Mark Seaborn 2012/08/29 17:29:43 You have left a 'TODO' here but the comment does n
halyavin 2012/08/30 09:46:28 Changed wording a bit to clarify why zero page is
80 // set or remove a breakpoint in the code area, so that PROT_READ | 82 // PROT_READ | PROT_EXEC are the correct flags to restore the mapping to.
81 // PROT_EXEC are the correct flags to restore the mapping to.
82 // The earlier mprotect() does not tell us what the original flags
83 // were. To find this out we could either:
84 // * read /proc/self/maps (not available inside outer sandbox); or
85 // * use service_runtime's own mapping tables.
86 // Alternatively, we could modify code the same way nacl_text.c does. 83 // Alternatively, we could modify code the same way nacl_text.c does.
87 if (mprotect(reinterpret_cast<void*>(page), mapping_size, 84 if (is_code && mprotect(reinterpret_cast<void*>(page), mapping_size,
88 PROT_READ | PROT_EXEC) != 0) { 85 PROT_READ | PROT_EXEC) != 0) {
89 return false; 86 return false;
90 } 87 }
91 // Flush the instruction cache in case we just modified code to add 88 // Flush the instruction cache in case we just modified code to add
92 // or remove a breakpoint, otherwise breakpoints will not behave 89 // or remove a breakpoint, otherwise breakpoints will not behave
93 // reliably on ARM. 90 // reliably on ARM.
94 NaClFlushCacheForDoublyMappedCode((uint8_t *) virt, (uint8_t *) virt, len); 91 NaClFlushCacheForDoublyMappedCode((uint8_t *) virt, (uint8_t *) virt, len);
95 return succeeded; 92 return succeeded;
96 } 93 }
97 94
98 } // End of port namespace 95 } // End of port namespace
99 96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698