| OLD | NEW |
| 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 <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "native_client/src/include/concurrency_ops.h" | 9 #include "native_client/src/include/concurrency_ops.h" |
| 10 #include "native_client/src/include/nacl_platform.h" | 10 #include "native_client/src/include/nacl_platform.h" |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 shm_map_size = shm_map_offset_end - shm_map_offset; | 617 shm_map_size = shm_map_offset_end - shm_map_offset; |
| 618 if (shm_map_size > NACL_MAP_PAGESIZE) { | 618 if (shm_map_size > NACL_MAP_PAGESIZE) { |
| 619 /* call with size==offset==0 to clear cache */ | 619 /* call with size==offset==0 to clear cache */ |
| 620 CachedMapWritableText(nap, 0, 0); | 620 CachedMapWritableText(nap, 0, 0); |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 | 623 |
| 624 int32_t NaClTextDyncodeCreate(struct NaClApp *nap, | 624 int32_t NaClTextDyncodeCreate(struct NaClApp *nap, |
| 625 uint32_t dest, | 625 uint32_t dest, |
| 626 void *code_copy, | 626 void *code_copy, |
| 627 uint32_t size) { | 627 uint32_t size, |
| 628 const struct NaClValidationMetadata *metadata) { |
| 628 uintptr_t dest_addr; | 629 uintptr_t dest_addr; |
| 629 uint8_t *mapped_addr; | 630 uint8_t *mapped_addr; |
| 630 int32_t retval = -NACL_ABI_EINVAL; | 631 int32_t retval = -NACL_ABI_EINVAL; |
| 631 int validator_result; | 632 int validator_result; |
| 632 struct NaClPerfCounter time_dyncode_create; | 633 struct NaClPerfCounter time_dyncode_create; |
| 633 NaClPerfCounterCtor(&time_dyncode_create, "NaClTextDyncodeCreate"); | 634 NaClPerfCounterCtor(&time_dyncode_create, "NaClTextDyncodeCreate"); |
| 634 | 635 |
| 635 if (NULL == nap->text_shm) { | 636 if (NULL == nap->text_shm) { |
| 636 NaClLog(1, "NaClTextDyncodeCreate: Dynamic loading not enabled\n"); | 637 NaClLog(1, "NaClTextDyncodeCreate: Dynamic loading not enabled\n"); |
| 637 return -NACL_ABI_EINVAL; | 638 return -NACL_ABI_EINVAL; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 664 } | 665 } |
| 665 | 666 |
| 666 NaClXMutexLock(&nap->dynamic_load_mutex); | 667 NaClXMutexLock(&nap->dynamic_load_mutex); |
| 667 | 668 |
| 668 /* | 669 /* |
| 669 * Validate the code before trying to create the region. This avoids the need | 670 * Validate the code before trying to create the region. This avoids the need |
| 670 * to delete the region if validation fails. | 671 * to delete the region if validation fails. |
| 671 * See: http://code.google.com/p/nativeclient/issues/detail?id=2566 | 672 * See: http://code.google.com/p/nativeclient/issues/detail?id=2566 |
| 672 */ | 673 */ |
| 673 if (!nap->skip_validator) { | 674 if (!nap->skip_validator) { |
| 674 validator_result = NaClValidateCode(nap, dest, code_copy, size); | 675 validator_result = NaClValidateCode(nap, dest, code_copy, size, metadata); |
| 675 } else { | 676 } else { |
| 676 NaClLog(LOG_ERROR, "VALIDATION SKIPPED.\n"); | 677 NaClLog(LOG_ERROR, "VALIDATION SKIPPED.\n"); |
| 677 validator_result = LOAD_OK; | 678 validator_result = LOAD_OK; |
| 678 } | 679 } |
| 679 | 680 |
| 680 NaClPerfCounterMark(&time_dyncode_create, | 681 NaClPerfCounterMark(&time_dyncode_create, |
| 681 NACL_PERF_IMPORTANT_PREFIX "DynRegionValidate"); | 682 NACL_PERF_IMPORTANT_PREFIX "DynRegionValidate"); |
| 682 NaClPerfCounterIntervalLast(&time_dyncode_create); | 683 NaClPerfCounterIntervalLast(&time_dyncode_create); |
| 683 | 684 |
| 684 if (validator_result != LOAD_OK | 685 if (validator_result != LOAD_OK |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 /* | 745 /* |
| 745 * Make a private copy of the code, so that we can validate it | 746 * Make a private copy of the code, so that we can validate it |
| 746 * without a TOCTTOU race condition. | 747 * without a TOCTTOU race condition. |
| 747 */ | 748 */ |
| 748 code_copy = malloc(size); | 749 code_copy = malloc(size); |
| 749 if (NULL == code_copy) { | 750 if (NULL == code_copy) { |
| 750 return -NACL_ABI_ENOMEM; | 751 return -NACL_ABI_ENOMEM; |
| 751 } | 752 } |
| 752 memcpy(code_copy, (uint8_t*) src_addr, size); | 753 memcpy(code_copy, (uint8_t*) src_addr, size); |
| 753 | 754 |
| 754 retval = NaClTextDyncodeCreate(nap, dest, code_copy, size); | 755 /* Unknown data source, no metadata. */ |
| 756 retval = NaClTextDyncodeCreate(nap, dest, code_copy, size, NULL); |
| 755 | 757 |
| 756 free(code_copy); | 758 free(code_copy); |
| 757 return retval; | 759 return retval; |
| 758 } | 760 } |
| 759 | 761 |
| 760 int32_t NaClSysDyncodeModify(struct NaClAppThread *natp, | 762 int32_t NaClSysDyncodeModify(struct NaClAppThread *natp, |
| 761 uint32_t dest, | 763 uint32_t dest, |
| 762 uint32_t src, | 764 uint32_t src, |
| 763 uint32_t size) { | 765 uint32_t size) { |
| 764 struct NaClApp *nap = natp->nap; | 766 struct NaClApp *nap = natp->nap; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 /* | 975 /* |
| 974 * Still waiting for some threads to report in... | 976 * Still waiting for some threads to report in... |
| 975 */ | 977 */ |
| 976 retval = -NACL_ABI_EAGAIN; | 978 retval = -NACL_ABI_EAGAIN; |
| 977 } | 979 } |
| 978 | 980 |
| 979 cleanup_unlock: | 981 cleanup_unlock: |
| 980 NaClXMutexUnlock(&nap->dynamic_load_mutex); | 982 NaClXMutexUnlock(&nap->dynamic_load_mutex); |
| 981 return retval; | 983 return retval; |
| 982 } | 984 } |
| OLD | NEW |