| OLD | NEW |
| 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 * Derived from Linux and Windows versions. | 8 * Derived from Linux and Windows versions. |
| 9 * TODO(jrg): locking is nooped. PrintSelector() #if 0'd. | 9 * TODO(jrg): locking is nooped. PrintSelector() #if 0'd. |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include <errno.h> | 12 #include <errno.h> |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 #include "native_client/src/include/portability.h" | 15 #include "native_client/src/include/portability.h" |
| 16 #include "native_client/src/shared/platform/nacl_sync.h" | 16 #include "native_client/src/shared/platform/nacl_sync.h" |
| 17 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 17 #include "native_client/src/trusted/service_runtime/arch/x86/nacl_ldt_x86.h" | 18 #include "native_client/src/trusted/service_runtime/arch/x86/nacl_ldt_x86.h" |
| 18 /* for LDT_ENTRIES */ | 19 /* for LDT_ENTRIES */ |
| 19 #include "native_client/src/trusted/service_runtime/arch/x86/sel_ldr_x86.h" | 20 #include "native_client/src/trusted/service_runtime/arch/x86/sel_ldr_x86.h" |
| 20 | 21 |
| 21 /* OSX specific */ | 22 /* OSX specific */ |
| 22 #include <architecture/i386/desc.h> /* ldt_desc, etc */ | 23 #include <architecture/i386/desc.h> /* ldt_desc, etc */ |
| 23 #include <architecture/i386/table.h> /* ldt_entry_t */ | 24 #include <architecture/i386/table.h> /* ldt_entry_t */ |
| 24 #include <architecture/i386/sel.h> /* sel_t */ | 25 #include <architecture/i386/sel.h> /* sel_t */ |
| 25 #include <i386/user_ldt.h> /* i386_set_ldt() */ | 26 #include <i386/user_ldt.h> /* i386_set_ldt() */ |
| 26 | 27 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 int size_is_in_pages, | 89 int size_is_in_pages, |
| 89 NaClLdtDescriptorType type, | 90 NaClLdtDescriptorType type, |
| 90 int read_exec_only, | 91 int read_exec_only, |
| 91 void* base_addr, | 92 void* base_addr, |
| 92 uint32_t size_minus_one) { | 93 uint32_t size_minus_one) { |
| 93 ldt_entry_t ldt; | 94 ldt_entry_t ldt; |
| 94 int sel_index = -1; | 95 int sel_index = -1; |
| 95 | 96 |
| 96 memset(&ldt, 0, sizeof(ldt)); | 97 memset(&ldt, 0, sizeof(ldt)); |
| 97 | 98 |
| 98 NaClMutexLock(&nacl_ldt_mutex); | 99 NaClXMutexLock(&nacl_ldt_mutex); |
| 99 | 100 |
| 100 switch (type) { | 101 switch (type) { |
| 101 case NACL_LDT_DESCRIPTOR_DATA: | 102 case NACL_LDT_DESCRIPTOR_DATA: |
| 102 ldt.data.type = (read_exec_only ? DESC_DATA_RONLY : DESC_DATA_WRITE); | 103 ldt.data.type = (read_exec_only ? DESC_DATA_RONLY : DESC_DATA_WRITE); |
| 103 break; | 104 break; |
| 104 case NACL_LDT_DESCRIPTOR_CODE: | 105 case NACL_LDT_DESCRIPTOR_CODE: |
| 105 ldt.code.type = (read_exec_only ? DESC_CODE_EXEC : DESC_CODE_READ); | 106 ldt.code.type = (read_exec_only ? DESC_CODE_EXEC : DESC_CODE_READ); |
| 106 break; | 107 break; |
| 107 default: | 108 default: |
| 108 goto alloc_error; | 109 goto alloc_error; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 149 } |
| 149 } else { | 150 } else { |
| 150 /* The caller specified an entry number - try only this one. */ | 151 /* The caller specified an entry number - try only this one. */ |
| 151 sel_index = i386_set_ldt(entry_number, &ldt, 1); | 152 sel_index = i386_set_ldt(entry_number, &ldt, 1); |
| 152 } | 153 } |
| 153 | 154 |
| 154 if (-1 == sel_index) { | 155 if (-1 == sel_index) { |
| 155 goto alloc_error; | 156 goto alloc_error; |
| 156 } | 157 } |
| 157 | 158 |
| 158 NaClMutexUnlock(&nacl_ldt_mutex); | 159 NaClXMutexUnlock(&nacl_ldt_mutex); |
| 159 | 160 |
| 160 return BuildSelector(sel_index); | 161 return BuildSelector(sel_index); |
| 161 | 162 |
| 162 /* | 163 /* |
| 163 * All error returns go through this epilog. | 164 * All error returns go through this epilog. |
| 164 */ | 165 */ |
| 165 alloc_error: | 166 alloc_error: |
| 166 NaClMutexUnlock(&nacl_ldt_mutex); | 167 NaClXMutexUnlock(&nacl_ldt_mutex); |
| 167 return 0; | 168 return 0; |
| 168 } | 169 } |
| 169 | 170 |
| 170 /* | 171 /* |
| 171 * Allocates a selector whose size is specified in pages. | 172 * Allocates a selector whose size is specified in pages. |
| 172 * Page granular protection requires that the start address be page-aligned. | 173 * Page granular protection requires that the start address be page-aligned. |
| 173 */ | 174 */ |
| 174 uint16_t NaClLdtAllocatePageSelector(NaClLdtDescriptorType type, | 175 uint16_t NaClLdtAllocatePageSelector(NaClLdtDescriptorType type, |
| 175 int read_exec_only, | 176 int read_exec_only, |
| 176 void* base_addr, | 177 void* base_addr, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 #else | 271 #else |
| 271 UNREFERENCED_PARAMETER(selector); | 272 UNREFERENCED_PARAMETER(selector); |
| 272 #endif | 273 #endif |
| 273 } | 274 } |
| 274 | 275 |
| 275 /* | 276 /* |
| 276 * Mark a selector as available for future reuse. | 277 * Mark a selector as available for future reuse. |
| 277 */ | 278 */ |
| 278 void NaClLdtDeleteSelector(uint16_t selector) { | 279 void NaClLdtDeleteSelector(uint16_t selector) { |
| 279 | 280 |
| 280 NaClMutexLock(&nacl_ldt_mutex); | 281 NaClXMutexLock(&nacl_ldt_mutex); |
| 281 if (-1 == i386_set_ldt(selector >> 3, NULL, 1)) { | 282 if (-1 == i386_set_ldt(selector >> 3, NULL, 1)) { |
| 282 perror("NaClLdtDeleteSelector: i386_set_ldt()"); | 283 perror("NaClLdtDeleteSelector: i386_set_ldt()"); |
| 283 } | 284 } |
| 284 NaClMutexUnlock(&nacl_ldt_mutex); | 285 NaClXMutexUnlock(&nacl_ldt_mutex); |
| 285 } | 286 } |
| OLD | NEW |