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

Side by Side Diff: src/trusted/service_runtime/linux/x86/nacl_ldt.c

Issue 6937003: modified nacl_sync.h to have NACL_WUR for all functions that return a (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « src/trusted/service_runtime/fs/obj_proxy.c ('k') | src/trusted/service_runtime/nacl_globals.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can be
4 * be found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl local descriptor table manipulation support. 8 * NaCl local descriptor table manipulation support.
9 */ 9 */
10 10
11 #include <asm/ldt.h> 11 #include <asm/ldt.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 13
14 #include "native_client/src/shared/platform/nacl_sync.h" 14 #include "native_client/src/shared/platform/nacl_sync.h"
15 #include "native_client/src/shared/platform/nacl_sync_checked.h"
15 #include "native_client/src/trusted/service_runtime/arch/x86/nacl_ldt_x86.h" 16 #include "native_client/src/trusted/service_runtime/arch/x86/nacl_ldt_x86.h"
16 17
17 18
18 /* 19 /*
19 * struct LdtEntry is a structure that is laid out exactly as the segment 20 * struct LdtEntry is a structure that is laid out exactly as the segment
20 * descriptors described in the Intel reference manuals. This is needed 21 * descriptors described in the Intel reference manuals. This is needed
21 * because Mac and Windows use this representation in the methods used to 22 * because Mac and Windows use this representation in the methods used to
22 * set and get entries in the local descriptor table (LDT), but use different 23 * set and get entries in the local descriptor table (LDT), but use different
23 * names for the members. Linux uses a different representation to set, but 24 * names for the members. Linux uses a different representation to set, but
24 * also reads entries back in this format. It needs to be laid out packed, 25 * also reads entries back in this format. It needs to be laid out packed,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 */ 88 */
88 uint16_t NaClLdtAllocateSelector(int32_t entry_number, 89 uint16_t NaClLdtAllocateSelector(int32_t entry_number,
89 int size_is_in_pages, 90 int size_is_in_pages,
90 NaClLdtDescriptorType type, 91 NaClLdtDescriptorType type,
91 int read_exec_only, 92 int read_exec_only,
92 void* base_addr, 93 void* base_addr,
93 uint32_t size_minus_one) { 94 uint32_t size_minus_one) {
94 struct user_desc ud; 95 struct user_desc ud;
95 int retval; 96 int retval;
96 97
97 NaClMutexLock(&nacl_ldt_mutex); 98 NaClXMutexLock(&nacl_ldt_mutex);
98 99
99 if (-1 == entry_number) { 100 if (-1 == entry_number) {
100 /* -1 means caller did not specify -- allocate */ 101 /* -1 means caller did not specify -- allocate */
101 entry_number = NaClFindUnusedEntryNumber(); 102 entry_number = NaClFindUnusedEntryNumber();
102 103
103 if (-1 == entry_number) { 104 if (-1 == entry_number) {
104 /* 105 /*
105 * No free entries were available. 106 * No free entries were available.
106 */ 107 */
107 goto alloc_error; 108 goto alloc_error;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 * Install the LDT entry. 147 * Install the LDT entry.
147 */ 148 */
148 retval = modify_ldt(1, &ud, sizeof ud); 149 retval = modify_ldt(1, &ud, sizeof ud);
149 if (-1 == retval) { 150 if (-1 == retval) {
150 goto alloc_error; 151 goto alloc_error;
151 } 152 }
152 153
153 /* 154 /*
154 * Return an LDT selector with a requested privilege level of 3. 155 * Return an LDT selector with a requested privilege level of 3.
155 */ 156 */
156 NaClMutexUnlock(&nacl_ldt_mutex); 157 NaClXMutexUnlock(&nacl_ldt_mutex);
157 return (ud.entry_number << 3) | 0x7; 158 return (ud.entry_number << 3) | 0x7;
158 159
159 /* 160 /*
160 * All error returns go through this epilog. 161 * All error returns go through this epilog.
161 */ 162 */
162 alloc_error: 163 alloc_error:
163 NaClMutexUnlock(&nacl_ldt_mutex); 164 NaClXMutexUnlock(&nacl_ldt_mutex);
164 return 0; 165 return 0;
165 } 166 }
166 167
167 /* 168 /*
168 * Allocates a selector whose size is specified in pages. 169 * Allocates a selector whose size is specified in pages.
169 * Page granular protection requires that the start address be page-aligned. 170 * Page granular protection requires that the start address be page-aligned.
170 */ 171 */
171 uint16_t NaClLdtAllocatePageSelector(NaClLdtDescriptorType type, 172 uint16_t NaClLdtAllocatePageSelector(NaClLdtDescriptorType type,
172 int read_exec_only, 173 int read_exec_only,
173 void* base_addr, 174 void* base_addr,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 struct user_desc ud; 272 struct user_desc ud;
272 ud.entry_number = selector >> 3; 273 ud.entry_number = selector >> 3;
273 ud.seg_not_present = 1; 274 ud.seg_not_present = 1;
274 ud.base_addr = 0; 275 ud.base_addr = 0;
275 ud.limit = 0; 276 ud.limit = 0;
276 ud.limit_in_pages = 0; 277 ud.limit_in_pages = 0;
277 ud.read_exec_only = 0; 278 ud.read_exec_only = 0;
278 ud.seg_32bit = 0; 279 ud.seg_32bit = 0;
279 ud.useable = 0; 280 ud.useable = 0;
280 ud.contents = MODIFY_LDT_CONTENTS_DATA; 281 ud.contents = MODIFY_LDT_CONTENTS_DATA;
281 NaClMutexLock(&nacl_ldt_mutex); 282 NaClXMutexLock(&nacl_ldt_mutex);
282 modify_ldt(1, &ud, sizeof ud); 283 modify_ldt(1, &ud, sizeof ud);
283 NaClMutexUnlock(&nacl_ldt_mutex); 284 NaClXMutexUnlock(&nacl_ldt_mutex);
284 } 285 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/fs/obj_proxy.c ('k') | src/trusted/service_runtime/nacl_globals.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698