1 /* 2 * Copyright 2010-2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "Config.h" 18 19 #include "ScriptCached.h" 20 21 #include "DebugHelper.h" 22 23 #include <stdlib.h> 24 25 namespace bcc { 26 27 ScriptCached::~ScriptCached() { 28 // Deallocate string pool, exported var list, exported func list 29 if (mpStringPoolRaw) { free(mpStringPoolRaw); } 30 if (mpExportVars) { free(mpExportVars); } 31 if (mpExportFuncs) { free(mpExportFuncs); } 32 if (mpExportForEach) { free(mpExportForEach); } 33 if (mpObjectSlotList) { free(mpObjectSlotList); } 34 } 35 36 void ScriptCached::getExportVarList(size_t varListSize, void **varList) { 37 if (varList) { 38 size_t varCount = getExportVarCount(); 39 40 if (varCount > varListSize) { 41 varCount = varListSize; 42 } 43 44 memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount); 45 } 46 } 47 48 49 void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) { 50 if (funcList) { 51 size_t funcCount = getExportFuncCount(); 52 53 if (funcCount > funcListSize) { 54 funcCount = funcListSize; 55 } 56 57 memcpy(funcList, mpExportFuncs->cached_addr_list, 58 sizeof(void *) * funcCount); 59 } 60 } 61 62 63 void ScriptCached::getExportForEachList(size_t forEachListSize, 64 void **forEachList) { 65 if (forEachList) { 66 size_t forEachCount = getExportForEachCount(); 67 68 if (forEachCount > forEachListSize) { 69 forEachCount = forEachListSize; 70 } 71 72 memcpy(forEachList, mpExportForEach->cached_addr_list, 73 sizeof(void *) * forEachCount); 74 } 75 } 76 77 78 void ScriptCached::getPragmaList(size_t pragmaListSize, 79 char const **keyList, 80 char const **valueList) { 81 size_t pragmaCount = getPragmaCount(); 82 83 if (pragmaCount > pragmaListSize) { 84 pragmaCount = pragmaListSize; 85 } 86 87 if (keyList) { 88 for (size_t i = 0; i < pragmaCount; ++i) { 89 *keyList++ = mPragmas[i].first; 90 } 91 } 92 93 if (valueList) { 94 for (size_t i = 0; i < pragmaCount; ++i) { 95 *valueList++ = mPragmas[i].second; 96 } 97 } 98 } 99 100 101 void ScriptCached::getObjectSlotList(size_t objectSlotListSize, 102 uint32_t *objectSlotList) { 103 if (objectSlotList) { 104 size_t objectSlotCount = getObjectSlotCount(); 105 106 if (objectSlotCount > objectSlotListSize) { 107 objectSlotCount = objectSlotListSize; 108 } 109 110 memcpy(objectSlotList, mpObjectSlotList->object_slot_list, 111 sizeof(uint32_t) * objectSlotCount); 112 } 113 } 114 115 116 void *ScriptCached::lookup(const char *name) { 117 return rsloaderGetSymbolAddress(mRSExecutable, name); 118 } 119 120 void ScriptCached::getFuncInfoList(size_t funcInfoListSize, 121 FuncInfo *funcInfoList) { 122 if (funcInfoList) { 123 size_t funcCount = getFuncCount(); 124 125 if (funcCount > funcInfoListSize) { 126 funcCount = funcInfoListSize; 127 } 128 129 FuncInfo *info = funcInfoList; 130 for (FuncTable::const_iterator 131 I = mFunctions.begin(), E = mFunctions.end(); 132 I != E && funcCount > 0; ++I, ++info, --funcCount) { 133 info->name = I->first.c_str(); 134 info->addr = I->second.first; 135 info->size = I->second.second; 136 } 137 } 138 } 139 140 141 } // namespace bcc 142