bool test_valid() { for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) { nsDependentCString str8(ValidStrings[i].m8); nsDependentString str16(ValidStrings[i].m16); if (!NS_ConvertUTF16toUTF8(str16).Equals(str8)) return false; if (!NS_ConvertUTF8toUTF16(str8).Equals(str16)) return false; nsCString tmp8("string "); AppendUTF16toUTF8(str16, tmp8); if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8)) return false; nsString tmp16(NS_LITERAL_STRING("string ")); AppendUTF8toUTF16(str8, tmp16); if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16)) return false; if (CompareUTF8toUTF16(str8, str16) != 0) return false; } return true; }
uint32_t do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, uid_t uid, pid_t spid) { struct svcinfo *si; if (!svc_can_find(s, len, spid)) { ALOGE("find_service('%s') uid=%d - PERMISSION DENIED\n", str8(s, len), uid); return 0; } si = find_svc(s, len); //ALOGI("check_service('%s') handle = %x\n", str8(s, len), si ? si->handle : 0); if (si && si->handle) { if (!si->allow_isolated) { // If this service doesn't allow access from isolated processes, // then check the uid to see if it is isolated. uid_t appid = uid % AID_USER; if (appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END) { return 0; } } return si->handle; } else { return 0; } }
PRBool test_basic() { for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) { nsDependentString str16(ValidStrings[i].m16); nsDependentCString str8(ValidStrings[i].m8); nsCOMPtr<nsIAtom> atom = do_GetAtom(str16); if (!atom->Equals(str16) || !atom->EqualsUTF8(str8)) return PR_FALSE; nsString tmp16; nsCString tmp8; atom->ToString(tmp16); atom->ToUTF8String(tmp8); if (!str16.Equals(tmp16) || !str8.Equals(tmp8)) return PR_FALSE; if (!nsDependentString(atom->GetUTF16String()).Equals(str16)) return PR_FALSE; if (!nsAtomString(atom).Equals(str16) || !nsDependentAtomString(atom).Equals(str16) || !nsAtomCString(atom).Equals(str8)) return PR_FALSE; } return PR_TRUE; }
PRBool test_valid() { for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) { nsDependentCString str8(ValidStrings[i].m8); nsDependentString str16(ValidStrings[i].m16); if (!NS_ConvertUTF16toUTF8(str16).Equals(str8)) return PR_FALSE; if (!NS_ConvertUTF8toUTF16(str8).Equals(str16)) return PR_FALSE; nsCString tmp8("string "); AppendUTF16toUTF8(str16, tmp8); if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8)) return PR_FALSE; nsString tmp16(NS_LITERAL_STRING("string ")); AppendUTF8toUTF16(str8, tmp16); if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16)) return PR_FALSE; if (CompareUTF8toUTF16(str8, str16) != 0) return PR_FALSE; } return PR_TRUE; }
int do_add_service(struct binder_state *bs, uint16_t *s, unsigned len, void *ptr, unsigned uid, int allow_isolated) { struct svcinfo *si; //ALOGI("add_service('%s',%p,%s) uid=%d\n", str8(s), ptr, // allow_isolated ? "allow_isolated" : "!allow_isolated", uid); if (!ptr || (len == 0) || (len > 127)) return -1; if (!svc_can_register(uid, s)) { ALOGE("add_service('%s',%p) uid=%d - PERMISSION DENIED\n", str8(s), ptr, uid); return -1; } si = find_svc(s, len); if (si) { if (si->ptr) { ALOGE("add_service('%s',%p) uid=%d - ALREADY REGISTERED, OVERRIDE\n", str8(s), ptr, uid); svcinfo_death(bs, si); } si->ptr = ptr; } else { si = malloc(sizeof(*si) + (len + 1) * sizeof(uint16_t)); if (!si) { ALOGE("add_service('%s',%p) uid=%d - OUT OF MEMORY\n", str8(s), ptr, uid); return -1; } si->ptr = ptr; si->len = len; memcpy(si->name, s, (len + 1) * sizeof(uint16_t)); si->name[len] = '\0'; si->death.func = svcinfo_death; si->death.ptr = si; si->allow_isolated = allow_isolated; si->next = svclist; svclist = si; } binder_acquire(bs, ptr); binder_link_to_death(bs, ptr, &si->death); return 0; }
// 默认的死亡通知函数,即释放service对应的binder_ref void svcinfo_death(struct binder_state *bs, void *ptr) { struct svcinfo *si = ptr; ALOGI("service '%s' died\n", str8(si->name)); if (si->ptr) { binder_release(bs, si->ptr); si->ptr = 0; } }
void svcinfo_death(struct binder_state *bs, void *ptr) { struct svcinfo *si = (struct svcinfo* ) ptr; ALOGI("service '%s' died\n", str8(si->name, si->len)); if (si->handle) { binder_release(bs, si->handle); si->handle = 0; } }
ECode RILParcel::ReadString( /* [out] */ String* result) { VALIDATE_NOT_NULL(result); *result = String(NULL); size_t len; const char16_t* str = parcel->readString16Inplace(&len); if (str) { android::String8 str8(str, len); *result = String(str8.string()); } return NOERROR; }
TEST(UTF, Invalid8) { for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) { nsDependentString str16(Invalid8Strings[i].m16); nsDependentCString str8(Invalid8Strings[i].m8); EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16)); nsString tmp16(NS_LITERAL_STRING("string ")); AppendUTF8toUTF16(str8, tmp16); EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16)); EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0); } }
TEST(UTF, Malformed8) { // Don't run this test in debug builds as that intentionally asserts. #ifndef DEBUG for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) { nsDependentCString str8(Malformed8Strings[i]); EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).IsEmpty()); nsString tmp16(NS_LITERAL_STRING("string")); AppendUTF8toUTF16(str8, tmp16); EXPECT_TRUE(tmp16.EqualsLiteral("string")); EXPECT_NE(CompareUTF8toUTF16(str8, EmptyString()), 0); } #endif }
android::status_t NativeCursorWindow::createFromParcel(IParcel* parcel, NativeCursorWindow** outCursorWindow) { android::Parcel* p; parcel->GetDataPayload((Handle32*)&p); android::String8 str8(p->readString8()); String name(str8.string()); android::status_t result; int ashmemFd = p->readFileDescriptor(); if (ashmemFd == int(android::BAD_TYPE)) { result = android::BAD_TYPE; } else { ssize_t size = ashmem_get_size_region(ashmemFd); if (size < 0) { result = android::UNKNOWN_ERROR; } else { int dupAshmemFd = ::dup(ashmemFd); if (dupAshmemFd < 0) { result = -errno; } else { void* data = ::mmap(NULL, size, PROT_READ, MAP_SHARED, dupAshmemFd, 0); if (data == MAP_FAILED) { result = -errno; } else { NativeCursorWindow* window = new NativeCursorWindow(name, dupAshmemFd, data, size, true /*readOnly*/); LOG_WINDOW("Created NativeCursorWindow from parcel: freeOffset=%d, " "numRows=%d, numColumns=%d, mSize=%d, mData=%p", window->mHeader->freeOffset, window->mHeader->numRows, window->mHeader->numColumns, window->mSize, window->mData); *outCursorWindow = window; return android::OK; } ::close(dupAshmemFd); } } } *outCursorWindow = NULL; return result; }
int checklibUtils(){ char bigbuf[BIGBUF_SZ]; char strObj[0x1000]; void *handle = dlopen( "libutils.so", RTLD_NOW ); memset(strObj, 0, sizeof(strObj) ); /* This corresponds to: 'android::String8::String8(char const*, unsigned int)' */ void * ( *str8)(void * obj, char const * string, int len) = NULL; str8 = dlsym(handle, "_ZN7android7String8C2EPKcj"); memset(bigbuf, 0xf0, BIGBUF_SZ); str8(strObj, (const char *)bigbuf, -1); char **ppstr = (char **)strObj; if ((*ppstr)[0] == 0xf0) { printf("Is Vulnerable\n"); exit(1); }else{ printf("Is not vulnerable\n"); exit(0); } }
bool test_malformed8() { // Don't run this test in debug builds as that intentionally asserts. #ifndef DEBUG for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) { nsDependentCString str8(Malformed8Strings[i]); if (!NS_ConvertUTF8toUTF16(str8).IsEmpty()) return false; nsString tmp16(NS_LITERAL_STRING("string")); AppendUTF8toUTF16(str8, tmp16); if (!tmp16.Equals(NS_LITERAL_STRING("string"))) return false; if (CompareUTF8toUTF16(str8, EmptyString()) == 0) return false; } #endif return true; }
int svcmgr_handler(struct binder_state *bs, struct binder_transaction_data *txn, struct binder_io *msg, struct binder_io *reply) { struct svcinfo *si; uint16_t *s; size_t len; uint32_t handle; uint32_t strict_policy; int allow_isolated; //ALOGI("target=%p code=%d pid=%d uid=%d\n", // (void*) txn->target.ptr, txn->code, txn->sender_pid, txn->sender_euid); if (txn->target.ptr != BINDER_SERVICE_MANAGER) return -1; if (txn->code == PING_TRANSACTION) return 0; // Equivalent to Parcel::enforceInterface(), reading the RPC // header with the strict mode policy mask and the interface name. // Note that we ignore the strict_policy and don't propagate it // further (since we do no outbound RPCs anyway). strict_policy = bio_get_uint32(msg); s = bio_get_string16(msg, &len); if (s == NULL) { return -1; } if ((len != (sizeof(svcmgr_id) / 2)) || memcmp(svcmgr_id, s, sizeof(svcmgr_id))) { fprintf(stderr,"invalid id %s\n", str8(s, len)); return -1; } if (sehandle && selinux_status_updated() > 0) { struct selabel_handle *tmp_sehandle = selinux_android_service_context_handle(); if (tmp_sehandle) { selabel_close(sehandle); sehandle = tmp_sehandle; } } switch(txn->code) { case SVC_MGR_GET_SERVICE: case SVC_MGR_CHECK_SERVICE: s = bio_get_string16(msg, &len); if (s == NULL) { return -1; } handle = do_find_service(bs, s, len, txn->sender_euid, txn->sender_pid); if (!handle) break; bio_put_ref(reply, handle); return 0; case SVC_MGR_ADD_SERVICE: s = bio_get_string16(msg, &len); if (s == NULL) { return -1; } handle = bio_get_ref(msg); allow_isolated = bio_get_uint32(msg) ? 1 : 0; if (do_add_service(bs, s, len, handle, txn->sender_euid, allow_isolated, txn->sender_pid)) return -1; break; case SVC_MGR_LIST_SERVICES: { uint32_t n = bio_get_uint32(msg); if (!svc_can_list(txn->sender_pid, txn->sender_euid)) { ALOGE("list_service() uid=%d - PERMISSION DENIED\n", txn->sender_euid); return -1; } si = svclist; while ((n-- > 0) && si) si = si->next; if (si) { bio_put_string16(reply, si->name); return 0; } return -1; } default: ALOGE("unknown code %d\n", txn->code); return -1; } bio_put_uint32(reply, 0); return 0; }
int svcmgr_handler(struct binder_state *bs, struct binder_transaction_data *txn, struct binder_io *msg, struct binder_io *reply) { struct svcinfo *si; uint16_t *s; size_t len; uint32_t handle; uint32_t strict_policy; int allow_isolated; //ALOGI("target=%x code=%d pid=%d uid=%d\n", // txn->target.handle, txn->code, txn->sender_pid, txn->sender_euid); if (txn->target.handle != svcmgr_handle) return -1; if (txn->code == PING_TRANSACTION) return 0; // Equivalent to Parcel::enforceInterface(), reading the RPC // header with the strict mode policy mask and the interface name. // Note that we ignore the strict_policy and don't propagate it // further (since we do no outbound RPCs anyway). strict_policy = bio_get_uint32(msg); s = bio_get_string16(msg, &len); if ((len != (sizeof(svcmgr_id) / 2)) || memcmp(svcmgr_id, s, sizeof(svcmgr_id))) { fprintf(stderr,"invalid id %s\n", str8(s)); return -1; } switch(txn->code) { case SVC_MGR_GET_SERVICE: case SVC_MGR_CHECK_SERVICE: s = bio_get_string16(msg, &len); handle = do_find_service(bs, s, len, txn->sender_euid); if (!handle) break; bio_put_ref(reply, handle); return 0; case SVC_MGR_ADD_SERVICE: s = bio_get_string16(msg, &len); handle = bio_get_ref(msg); allow_isolated = bio_get_uint32(msg) ? 1 : 0; if (do_add_service(bs, s, len, handle, txn->sender_euid, allow_isolated)) return -1; break; case SVC_MGR_LIST_SERVICES: { uint32_t n = bio_get_uint32(msg); si = svclist; while ((n-- > 0) && si) si = si->next; if (si) { bio_put_string16(reply, si->name); return 0; } return -1; } default: ALOGE("unknown code %d\n", txn->code); return -1; } bio_put_uint32(reply, 0); return 0; }
static int svc_can_find(const uint16_t *name, size_t name_len, pid_t spid, uid_t uid) { const char *perm = "find"; return check_mac_perms_from_lookup(spid, uid, perm, str8(name, name_len)) ? 1 : 0; }
void HttpMsgBuf::writeString(const wchar_t* str){ W2UTF8 str8(str); writeInt(str8.size()); write(str8.data(), str8.size()); }
int main() { try { TestSection("StdTerms"); TestSubsection("TermGarbage"); { MyTestTerm *term1 = new MyTestTerm(10); MyTestTerm2 *term2 = new MyTestTerm2(20); SReference ref1(term1); SReference ref2(term2); SReference ref3(new MyTestTerm(30)); SReference ref4(new MyTestTerm2(40)); TEST("constructed", constructed, 4); TEST("noone-destructed", destructed, 0); ref4 = new MyTestTerm(300); TEST("assign_ptr", destructed, 1); ref4 = ref1; TEST("assign_ref", destructed, 2); ref3 = 0; TEST("assign_null", destructed, 3); } TEST("correctness", constructed, destructed); { constructed = destructed = 0; SReference ref1(new MyTestTerm(200)); SReference ref2(new MyTestTerm(300)); TESTB("before_assigning_refs",constructed == 2 && destructed == 0); ref1 = ref2; TEST("after_assigning_refs", destructed, 1); } TestSubsection("TermType"); { SReference ref5(new MyTestTerm(50)); TESTB("type-of", ref5->TermType() == MyTestTerm::TypeId); TESTB("not-type-of", ref5->TermType() != MyTestTerm2::TypeId); TESTB("subtype", ref5->TermType().IsSubtypeOf(SExpression::TypeId)); TESTB("not-subtype", !(ref5->TermType().IsSubtypeOf(MyTestTerm2::TypeId))); SReference ref6(new MyTestTerm22(60)); TESTB("subtype2_", ref6->TermType() == MyTestTerm22::TypeId); TESTB("22subE", MyTestTerm22::TypeId.IsSubtypeOf(SExpression::TypeId)); TESTB("22sub2", MyTestTerm22::TypeId.IsSubtypeOf(MyTestTerm2::TypeId)); TESTB("2subE", MyTestTerm2::TypeId.IsSubtypeOf(SExpression::TypeId)); TESTB("subtype2", ref6->TermType().IsSubtypeOf(SExpression::TypeId)); TESTB("subtype22", ref6->TermType().IsSubtypeOf(MyTestTerm2::TypeId)); TESTB("subtype22_self", ref6->TermType().IsSubtypeOf(MyTestTerm22::TypeId)); SReference ref7(new MyTestTerm2(70)); TESTB("not-subtype22", !(ref7->TermType().IsSubtypeOf(MyTestTerm22::TypeId))); } TestSubsection("TermCasts"); { SReference ref(new MyTestTerm(50)); SReference ref2(new MyTestTerm2(70)); TESTB("cast_to_lterm", ref.DynamicCastGetPtr<SExpression>() == ref.GetPtr()); TESTB("cast_to_lterm2", ref.DynamicCastGetPtr<SExpression>() == ref.GetPtr()); TESTB("cast_to_itself", ref.DynamicCastGetPtr<MyTestTerm>() == ref.GetPtr()); TESTB("failed_cast", ref.DynamicCastGetPtr<MyTestTerm2>()==0); } TestSubsection("SExpressionCasts"); { SReference ref(new MyTestTerm(50)); SReference ref2(new MyTestTerm2(70)); TESTB("cast_to_lterm", ref.DynamicCastGetPtr<SExpression>() == ref.GetPtr()); TESTB("cast_to_lterm2", ref.DynamicCastGetPtr<SExpression>() == ref.GetPtr()); TESTB("cast_to_itself", ref.DynamicCastGetPtr<MyTestTerm>() == ref.GetPtr()); TESTB("failed_cast", ref.DynamicCastGetPtr<MyTestTerm2>()==0); } TestSubsection("BasicTerms"); { SReference intref(25); TESTC("integer_term", intref->TermType(), SExpressionInt::TypeId); TEST("integer_value", intref.GetInt(), 25); SReference floatref(25.0); TESTC("float_term", floatref->TermType(), SExpressionFloat::TypeId); TESTC("float_value", floatref.GetFloat(), (intelib_float_t)25.0); SReference strref("A_STRING"); TESTC("pchar_term", strref->TermType(), SExpressionString::TypeId); TESTC("pchar_value", strcmp((const char*)strref.GetString(), "A_STRING"), 0); SReference charref('a'); TESTC("char_term", charref->TermType(), SExpressionChar::TypeId); TEST("char_value", charref.GetSingleChar(), 'a'); } TestSubsection("SExpressionString"); { SReference strref1(new SExpressionString("A", "B")); TEST("concatenation_1_1", strref1.GetString(), "AB"); SReference strref2(new SExpressionString("AA", "BB")); TEST("concatenation_2_2", strref2.GetString(), "AABB"); SReference strref3(new SExpressionString("AAA", "BBB")); TEST("concatenation_3_3", strref3.GetString(), "AAABBB"); SReference strref4(new SExpressionString("AAAA", "BBBB")); TEST("concatenation_4_4", strref4.GetString(), "AAAABBBB"); SReference strref5(new SExpressionString("AAAAA", "BBBBB")); TEST("concatenation_5_5", strref5.GetString(), "AAAAABBBBB"); SReference strref6(new SExpressionString("A")); TEST("construction1", strref6.GetString(), "A"); SReference strref7(new SExpressionString("AA")); TEST("construction2", strref7.GetString(), "AA"); SReference strref8(new SExpressionString("AAA")); TEST("construction3", strref8.GetString(), "AAA"); SReference strref9(new SExpressionString("AAAA")); TEST("construction4", strref9.GetString(), "AAAA"); } TestSubsection("SString"); { SString str1; TESTC("default_is_empty", str1.c_str()[0], '\0'); SString str2(""); TESTC("empty_strings", str1, str2); TESTC("empty_is_empty", str2.c_str()[0], '\0'); SString str3("AAA"); SString str4("BBB"); SString str5 = str3 + str4; TEST("string_addition", str5.c_str(), "AAABBB"); SString str6("CCC"); str6 += "DDD"; TEST("string_increment_by_pchar", str6.c_str(), "CCCDDD"); SString str7("EEE"); SString str8("FFF"); str7 += str8; TEST("string_increment_by_string", str7.c_str(), "EEEFFF"); SString str10("Final countdown"); SString str11("Final"); str11 += " countdown"; TESTB("string_equals_itself", str10 == str10); TESTB("string_doesnt_differ_from_itself", !(str10 != str10)); TESTB("two_equal_strings", str10 == str11); TESTB("equal_strings_dont_differ", !(str10 != str11)); SString str12("Another string"); TESTB("two_non_equal_strings", str11 != str12); TESTB("nonequals_non_equal", !(str11 == str12)); SString str13; SString str14(""); TESTB("empty_strings_equal", str13 == str14); TESTB("empty_strings_dont_differ", !(str13 != str14)); SReference strref("my_string"); SString str15(strref); TEST("string_from_lreference", str15.c_str(), "my_string"); { int flag = 0; try { SReference ref(25); SString str(ref); } catch(IntelibX_not_a_string lx) { flag = 0x56; } TESTB("string_from_int_fails", flag == 0x56); } } TestSubsection("TextRepresentation"); { SReference intref(100); TEST("integer_text_rep", intref->TextRepresentation().c_str(), "100"); char buf[100]; intelib_float_t fl; fl = 100.1; SReference fltref(fl); snprintf(buf, sizeof(buf), INTELIB_FLOAT_FORMAT, fl); TEST("float_text_rep", fltref->TextRepresentation().c_str(), buf); fl = 100.0; SReference fltref2(fl); snprintf(buf, sizeof(buf), INTELIB_FLOAT_FORMAT, fl); TEST("float2_text_rep", fltref2->TextRepresentation().c_str(), buf); SReference strref("mystring"); TEST("string_text_rep", strref->TextRepresentation().c_str(), "\"mystring\""); SReference unbound; SReference unbound2; SReference unblist(unbound, unbound2); TEST("unbound_text_representation", unblist->TextRepresentation().c_str(), "(#<UNBOUND> . #<UNBOUND>)"); } TestSubsection("DottedPairs"); { SReference pairref(25, 36); TEST("pair_25_36", pairref->TextRepresentation().c_str(), "(25 . 36)"); SReference dotlistref(25, SReference(36, 49)); TEST("dotlist_25_36_49", dotlistref->TextRepresentation().c_str(), "(25 36 . 49)"); SReference empty_list_ref(*PTheEmptyList); TEST("empty_list_ref", empty_list_ref->TextRepresentation().c_str(), (*PTheEmptyList)->TextRepresentation().c_str()); TESTB("empty_list_equal_empty", empty_list_ref.GetPtr() == PTheEmptyList->GetPtr()); TESTB("dot_list_notequal_empty", dotlistref.GetPtr() != PTheEmptyList->GetPtr()); SReference list25ref(25, *PTheEmptyList); TEST("list_1_elem", list25ref->TextRepresentation().c_str(), "(25)"); SReference list_16_25_ref(16, list25ref); TEST("cons_with_list", list_16_25_ref->TextRepresentation().c_str(), "(16 25)"); SReference list_of_lists_ref(list25ref, SReference(list25ref, *PTheEmptyList)); TEST("list_of_lists", list_of_lists_ref->TextRepresentation().c_str(), "((25) (25))"); } TestSubsection("SExpressionLabel"); { SExpressionLabel *lab1 = new SExpressionLabel("lab1"); SReference labref(lab1); TEST("label", labref->TextRepresentation().c_str(), "lab1"); TESTB("label_equality", labref == SReference(lab1)); SReference labref2(lab1); TESTB("label_equality2", labref== labref2); SReference ref3(25); TESTB("label_non_eq", labref != ref3); #if 0 // no support for booleans in sexpression core TEST("boolean_true", LTheLispBooleanTrue.TextRepresentation().c_str(), #if CLSTYLE_BOOLEANS == 0 "#T" #else "T" #endif ); #endif } TestSubsection("SListConstructor"); { SListConstructor L; SReference list_int((L|25)); TEST("list_of_1_int", list_int->TextRepresentation().c_str(), "(25)"); SReference list_str((L|"abcd")); TEST("list_of_1_str", list_str->TextRepresentation().c_str(), "(\"abcd\")"); intelib_float_t fl = 1.1; SReference list_float((L|fl)); char buf[128]; snprintf(buf, sizeof(buf), "(" INTELIB_FLOAT_FORMAT ")", fl); TEST("list_of_1_float", list_float->TextRepresentation().c_str(), buf); } TestSubsection("ListConstructionAlgebra"); { SListConstructor L; SReference listref((L|25, 36, 49, "abcd", "efgh")); TEST("plain_list", listref->TextRepresentation().c_str(), "(25 36 49 \"abcd\" \"efgh\")"); SReference listref2((L|(L|25), 36, (L|(L|(L|49))))); TEST("list_with_lists", listref2->TextRepresentation().c_str(), "((25) 36 (((49))))"); SReference listref3((L|(L|(L|(L|(L)))))); TEST("empty_buried_list", listref3->TextRepresentation().c_str(), (SString("((((")+ (*PTheEmptyList)-> TextRepresentation().c_str()+ SString("))))")).c_str()); SReference dotpairref((L|25 || 36)); TEST("dotted_pair", dotpairref->TextRepresentation().c_str(), "(25 . 36)"); SReference dotlistref((L|9, 16, 25)||36); TEST("dotted_list", dotlistref->TextRepresentation().c_str(), "(9 16 25 . 36)"); SReference dotpairref2((L|25)^36); TEST("dotted_pair", dotpairref2->TextRepresentation().c_str(), "((25) . 36)"); SReference dotlistref2((L|9, 16, 25)^36); TEST("dotted_list", dotlistref2->TextRepresentation().c_str(), "((9 16 25) . 36)"); SReference just_a_cons(SReference("abc")^SReference(225)); TEST("cons_with_^", just_a_cons->TextRepresentation().c_str(), "(\"abc\" . 225)"); SReference empty(L); empty,25; TEST("comma_on_empty_list", empty->TextRepresentation().c_str(), "(25)"); } TestSubsection("IsEql"); { SReference five(5); TESTB("is_eql_numbers", five.IsEql(5)); TESTB("isnt_eql_numbers", !five.IsEql(3)); TESTB("isnt_eql_num_to_string", !five.IsEql("abc")); SReference abc("abc"); TESTB("is_eql_strings", abc.IsEql("abc")); TESTB("isnt_eql_strings", !abc.IsEql("def")); TESTB("isnt_eql_string_to_num", !abc.IsEql(5)); } TestSubsection("UnboundByDefault"); { SReference unbound; TESTB("sreference_unbound", !unbound.GetPtr()); GenericSReference<MyTestTerm22, IntelibX_wrong_expression_type> p; TESTB("gensref_unbound", !p.GetPtr()); } #if 0 // no support for booleans TestSubsection("Booleans"); { SReference true_ref(LTheLispBooleanTrue); TESTB("boolean_true", true_ref->IsTrue()); SReference false_ref(LTheLispBooleanFalse); TESTB("boolean_false", !(false_ref->IsTrue())); SReference some_ref(25); TESTB("boolean_some", some_ref->IsTrue()); } #endif TestSubsection("Epilogue"); TEST("final-cleanup", destructed, constructed); TestScore(); } catch(...) { printf("Something strange caught\n"); } return 0; }
/* * 处理驱动传递上来的数据 * xn为原始数据, * msg为格式化为binder_io之后的数据, * reply用来保存处理结果 */ int svcmgr_handler(struct binder_state *bs, struct binder_txn *txn, struct binder_io *msg, struct binder_io *reply) { struct svcinfo *si; uint16_t *s; unsigned len; void *ptr; uint32_t strict_policy; int allow_isolated; // ALOGI("target=%p code=%d pid=%d uid=%d\n", // txn->target, txn->code, txn->sender_pid, txn->sender_euid); if (txn->target != svcmgr_handle) return -1; // Equivalent to Parcel::enforceInterface(), reading the RPC // header with the strict mode policy mask and the interface name. // Note that we ignore the strict_policy and don't propagate it // further (since we do no outbound RPCs anyway). strict_policy = bio_get_uint32(msg); s = bio_get_string16(msg, &len); if ((len != (sizeof(svcmgr_id) / 2)) || memcmp(svcmgr_id, s, sizeof(svcmgr_id))) { fprintf(stderr,"invalid id %s\n", str8(s)); return -1; } switch(txn->code) { case SVC_MGR_GET_SERVICE: case SVC_MGR_CHECK_SERVICE: // get service: 返回service对应的weak ref s = bio_get_string16(msg, &len); ptr = do_find_service(bs, s, len, txn->sender_euid); if (!ptr) break; bio_put_ref(reply, ptr); return 0; case SVC_MGR_ADD_SERVICE: // add service: 为service创建对应的svcinfo对象 s = bio_get_string16(msg, &len); ptr = bio_get_ref(msg); allow_isolated = bio_get_uint32(msg) ? 1 : 0; if (do_add_service(bs, s, len, ptr, txn->sender_euid, allow_isolated)) return -1; break; case SVC_MGR_LIST_SERVICES: { // list service: 返回当前注册过的service's name列表 unsigned n = bio_get_uint32(msg); si = svclist; while ((n-- > 0) && si) si = si->next; if (si) { bio_put_string16(reply, si->name); return 0; } return -1; } default: ALOGE("unknown code %d\n", txn->code); return -1; } bio_put_uint32(reply, 0); return 0; }
str8 Variable_null::string() const { return str8(); }
int svcmgr_handler(struct binder_state *bs, struct binder_txn *txn, struct binder_io *msg, struct binder_io *reply) { struct svcinfo *si; uint16_t *s; unsigned len; void *ptr; // LOGI("target=%p code=%d pid=%d uid=%d\n", // txn->target, txn->code, txn->sender_pid, txn->sender_euid); if (txn->target != svcmgr_handle) return -1; s = bio_get_string16(msg, &len); if ((len != (sizeof(svcmgr_id) / 2)) || memcmp(svcmgr_id, s, sizeof(svcmgr_id))) { fprintf(stderr,"invalid id %s\n", str8(s)); return -1; } switch(txn->code) { case SVC_MGR_GET_SERVICE: case SVC_MGR_CHECK_SERVICE: s = bio_get_string16(msg, &len); ptr = do_find_service(bs, s, len); if (!ptr) break; bio_put_ref(reply, ptr); return 0; case SVC_MGR_ADD_SERVICE: s = bio_get_string16(msg, &len); ptr = bio_get_ref(msg); if (do_add_service(bs, s, len, ptr, txn->sender_euid)) return -1; break; case SVC_MGR_LIST_SERVICES: { unsigned n = bio_get_uint32(msg); si = svclist; while ((n-- > 0) && si) si = si->next; if (si) { bio_put_string16(reply, si->name); return 0; } return -1; } default: LOGE("unknown code %d\n", txn->code); return -1; } bio_put_uint32(reply, 0); return 0; }