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G91ciByb3V0aW5lcyB0byBxdWV1ZSBwYWNrZXRzIGhlcmUuIFdlIGVtcHR5IHRoZQorICoJcXVldWUgaW4gdGhlIGxvY2FsIHNvZnRuZXQgaGFuZGxlci4KKyAqLworREVGSU5FX1BFUl9DUFUoc3RydWN0IHNvZnRuZXRfZGF0YSwgc29mdG5ldF9kYXRhKSA9IHsgMCwgfTsKKworI2lmZGVmIENPTkZJR19TWVNGUworZXh0ZXJuIGludCBuZXRkZXZfc3lzZnNfaW5pdCh2b2lkKTsKK2V4dGVybiBpbnQgbmV0ZGV2X3JlZ2lzdGVyX3N5c2ZzKHN0cnVjdCBuZXRfZGV2aWNlICopOworZXh0ZXJuIHZvaWQgbmV0ZGV2X3VucmVnaXN0ZXJfc3lzZnMoc3RydWN0IG5ldF9kZXZpY2UgKik7CisjZWxzZQorI2RlZmluZSBuZXRkZXZfc3lzZnNfaW5pdCgpCSAJKDApCisjZGVmaW5lIG5ldGRldl9yZWdpc3Rlcl9zeXNmcyhkZXYpCSgwKQorI2RlZmluZQluZXRkZXZfdW5yZWdpc3Rlcl9zeXNmcyhkZXYpCWRvIHsgfSB3aGlsZSgwKQorI2VuZGlmCisKKworLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKworCQlQcm90b2NvbCBtYW5hZ2VtZW50IGFuZCByZWdpc3RyYXRpb24gcm91dGluZXMKKworKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KKworLyoKKyAqCUZvciBlZmZpY2llbmN5CisgKi8KKworaW50IG5ldGRldl9uaXQ7CisKKy8qCisgKglBZGQgYSBwcm90b2NvbCBJRCB0byB0aGUgbGlzdC4gTm93IHRoYXQgdGhlIGlucHV0IGhhbmRsZXIgaXMKKyAqCXNtYXJ0ZXIgd2UgY2FuIGRpc3BlbnNlIHdpdG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9uCisgKgorICoJUmVtb3ZlIGEgcHJvdG9jb2wgaGFuZGxlciB0aGF0IHdhcyBwcmV2aW91c2x5IGFkZGVkIHRvIHRoZSBrZXJuZWwKKyAqCXByb3RvY29sIGhhbmRsZXJzIGJ5IGRldl9hZGRfcGFjaygpLiBUaGUgcGFzc2VkICZwYWNrZXRfdHlwZSBpcyByZW1vdmVkCisgKglmcm9tIHRoZSBrZXJuZWwgbGlzdHMgYW5kIGNhbiBiZSBmcmVlZCBvciByZXVzZWQgb25jZSB0aGlzIGZ1bmN0aW9uCisgKglyZXR1cm5zLgorICoKKyAqCVRoaXMgY2FsbCBzbGVlcHMgdG8gZ3VhcmFudGVlIHRoYXQgbm8gQ1BVIGlzIGxvb2tpbmcgYXQgdGhlIHBhY2tldAorICoJdHlwZSBhZnRlciByZXR1cm4uCisgKi8KK3ZvaWQgZGV2X3JlbW92ZV9wYWNrKHN0cnVjdCBwYWNrZXRfdHlwZSAqcHQpCit7CisJX19kZXZfcmVtb3ZlX3BhY2socHQpOworCQorCXN5bmNocm9uaXplX25ldCgpOworfQorCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCisKKwkJICAgICAgRGV2aWNlIEJvb3QtdGltZSBTZXR0aW5ncyBSb3V0aW5lcworCisqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworCisvKiBCb290IHRpbWUgY29uZmlndXJhdGlvbiB0YWJsZSAqLworc3RhdGljIHN0cnVjdCBuZXRkZXZfYm9vdF9zZXR1cCBkZXZfYm9vdF9zZXR1cFtORVRERVZfQk9PVF9TRVRVUF9NQVhdOworCisvKioKKyAqCW5ldGRldl9ib290X3NldHVwX2FkZAktIGFkZCBuZXcgc2V0dXAgZW50cnkKKyAqCUBuYW1lOiBuYW1lIG9mIHRoZSBkZXZpY2UKKyAqCU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MF0gPiAwKQorCQltYXAuaXJxID0gaW50c1sxXTsKKwlpZiAoaW50c1swXSA+IDEpCisJCW1hcC5iYXNlX2FkZHIgPSBpbnRzWzJdOworCWlmIChpbnRzWzBdID4gMikKKwkJbWFwLm1lbV9zdGFydCA9IGludHNbM107CisJaWYgKGludHNbMF0gPiAzKQorCQltYXAubWVtX2VuZCA9IGludHNbNF07CisKKwkvKiBBZGQgbmV3IGVudHJ5IHRvIHRoZSBsaXN0ICovCisJcmV0dXJuIG5ldGRldl9ib290X3NldHVwX2FkZChzdHIsICZtYXApOworfQorCitfX3NldHVwKCJuZXRkZXY9IiwgbmV0ZGV2X2Jvb3Rfc2V0dXApOworCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgorCisJCQkgICAgRGV2aWNlIEludGVyZmFjZSBTdWJyb3V0aW5lcworCisqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworCisvKioKKyAqCV9fZGV2X2dldF9ieV9uYW1lCS0gZmluZCBhIGRldmljZSBieSBpdHMgbmFtZQorICoJQG5hbWU6IG5hbWUgdG8gZmluZAorICoKKyAqCUZpbmQgYW4gaW50ZXJmYWNlIGJ5IG5hbWUuIE11c3QgYmUgY2FsbGVkIHVuZGVyIFJUTkwgc2VtYXBob3JlCisgKglvciBAZGV2X2Jhc2VfbG9jay4gSWYgdGhlIG5hbWUgaXMgZm91bmQgYSBwb2ludGVyIHRvIHRoZSBkZXZpY2UKKyAqCWlzIHJldHVybmVkLiBJZiB0aGUgbmFtZSBpcyBub3QgZm91bmQgdGhlbiAlTlVMTCBpcyByZXR1cm5lZC4gVGhlCisgKglyZWZlcmVuY2UgY291bnRlcnMgYXJlIG5vdCBpbmNyZW1lbnRlZCBzbyB0aGUgY2FsbGVyIG11c3QgYmUKKyAqCWNhcmVmdWwg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sKKwlsb2NhbF9iaF9lbmFibGUoKTsKKworb3V0X2tmcmVlX3NrYjoKKwlrZnJlZV9za2Ioc2tiKTsKKwlyZXR1cm4gcmM7CitvdXQ6CisJbG9jYWxfYmhfZW5hYmxlKCk7CisJcmV0dXJuIHJjOworfQorCisKKy8qPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KKwkJCVJlY2VpdmVyIHJvdXRpbmVzCisgID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki8KKworaW50IG5ldGRldl9tYXhfYmFja2xvZyA9IDMwMDsKK2ludCB3ZWlnaHRfcCA9IDY0OyAgICAgICAgICAgIC8qIG9sZCBiYWNrbG9nIHdlaWdodCAqLworLyogVGhlc2UgbnVtYmVycyBhcmUgc2VsZWN0ZWQgYmFzZWQgb24gaW50dWl0aW9uIGFuZCBzb21lCisgKiBleHBlcmltZW50YXRpb20sIGlmIHlvdSBoYXZlIG1vcmUgc2NpZW50aWZpYyB3YXkgb2YgZG9pbmcgdGhpcworICogcGxlYXNlIGdvIGFoZWFkIGFuZCBmaXggdGhpbmdzLgorICovCitpbnQgbm9fY29uZ190aHJlc2ggPSAxMDsKK2ludCBub19jb25nID0gMjA7CitpbnQgbG9fY29uZyA9IDEwMDsKK2ludCBtb2RfY29uZyA9IDI5MDsKKworREVGSU5FX1BFUl9DUFUoc3RydWN0IG5ldGlmX3J4X3N0YXRzLCBuZXRkZXZfcnhfc3RhdCkgPSB7IDAsIH07CisKKworc3RhdGljIHZvaWQgZ2V0X3NhbXBsZV9zdGF0cyhpbnQgY3B1KQoreworI2lmZGVmIFJBTkRfTElFCisJdW5zaWduZWQgbG9uZyByZDsKKwlpbnQgcnE7CisjZW5kaWYKKwlzdHJ1Y3Qgc29mdG5ldF9kYXRhICpzZCA9ICZwZXJfY3B1KHNvZnRuZXRfZGF0YSw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B1LCAwKTsKK30KKworc3RhdGljIHUzMiBmbG93X2hhc2hfY29kZShzdHJ1Y3QgZmxvd2kgKmtleSwgaW50IGNwdSkKK3sKKwl1MzIgKmsgPSAodTMyICopIGtleTsKKworCXJldHVybiAoamhhc2gyKGssIChzaXplb2YoKmtleSkgLyBzaXplb2YodTMyKSksIGZsb3dfaGFzaF9ybmQoY3B1KSkgJgorCQkoZmxvd19oYXNoX3NpemUgLSAxKSk7Cit9CisKKyNpZiAoQklUU19QRVJfTE9ORyA9PSA2NCkKK3R5cGVkZWYgdTY0IGZsb3dfY29tcGFyZV90OworI2Vsc2UKK3R5cGVkZWYgdTMyIGZsb3dfY29tcGFyZV90OworI2VuZGlmCisKK2V4dGVybiB2b2lkIGZsb3dpX2lzX21pc3NpemVkKHZvaWQpOworCisvKiBJIGhlYXIgd2hhdCB5b3UncmUgc2F5aW5nLCB1c2UgbWVtY21wLiAgQnV0IG1lbWNtcCBjYW5ub3QgbWFrZQorICogaW1wb3J0YW50IGFzc3VtcHRpb25zIHRoYXQgd2UgY2FuIGhlcmUsIHN1Y2ggYXMgYWxpZ25tZW50IGFuZAorICogY29uc3RhbnQgc2l6ZS4KKyAqLworc3RhdGljIGludCBmbG93X2tleV9jb21wYXJlKHN0cnVjdCBmbG93aSAqa2V5MSwgc3RydWN0IGZsb3dpICprZXkyKQoreworCWZsb3dfY29tcGFyZV90ICprMSwgKmsxX2xpbSwgKmsyOworCWNvbnN0IGludCBuX2VsZW0gPSBzaXplb2Yoc3RydWN0IGZsb3dpKSAvIHNpemVvZihmbG93X2NvbXBhcmVfdCk7CisKKwlpZiAoc2l6ZW9mKHN0cnVjdCBmbG93aSkgJSBzaXplb2YoZmxvd19jb21wYXJlX3QpKQorCQlmbG93aV9pc19taXNzaXplZCgpOworCisJazEgPSAoZmxvd19jb21wYXJlX3QgKikga2V5MTsKKwlrMV9saW0gPSBrMSArIG5fZWxlbTsKKworCWsyID0gKGZsb3dfY29tcGFyZV90ICopIGtleTI7CisK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IHdpbGwgYmUgcmUtc2VudCAqLworCisgICAgICAgIC8qIHJ1bnRpbWUgY291bnRlcnMgcmVsYXRpbmcgdG8gY2xvbmVfc2tiICovCisgICAgICAgIF9fdTY0IG5leHRfdHhfdXM7ICAgICAgICAgIC8qIHRpbWVzdGFtcCBvZiB3aGVuIHRvIHR4IG5leHQgKi8KKyAgICAgICAgX191MzIgbmV4dF90eF9uczsKKyAgICAgICAgCisgICAgICAgIF9fdTY0IGFsbG9jYXRlZF9za2JzOworICAgICAgICBfX3UzMiBjbG9uZV9jb3VudDsKKwlpbnQgbGFzdF9vazsgICAgICAgICAgIC8qIFdhcyBsYXN0IHNrYiBzZW50PyAKKwkgICAgICAgICAgICAgICAgICAgICAgICAqIE9yIGEgZmFpbGVkIHRyYW5zbWl0IG9mIHNvbWUgc29ydD8gIFRoaXMgd2lsbCBrZWVwCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogc2VxdWVuY2UgbnVtYmVycyBpbiBvcmRlciwgZm9yIGV4YW1wbGUuCisJCQkJKi8KKyAgICAgICAgX191NjQgc3RhcnRlZF9hdDsgLyogbWljcm8tc2Vjb25kcyAqLworICAgICAgICBfX3U2NCBzdG9wcGVkX2F0OyAvKiBtaWNyby1zZWNvbmRzICovCisgICAgICAgIF9fdTY0IGlkbGVfYWNjOyAvKiBtaWNyby1zZWNvbmRzICovCisgICAgICAgIF9fdTMyIHNlcV9udW07CisgICAgICAgIAorICAgICAgICBpbnQgY2xvbmVfc2tiOyAvKiBVc2UgbXVsdGlwbGUgU0tCcyBkdXJpbmcgcGFja2V0IGdlbi4gIElmIHRoaXMgbnVtYmVyCisgICAgICAgICAgICAgICAgICAgICAgICAgICogaXMgZ3JlYXRlciB0aGFuIDEsIHRoZW4gdGhhdCBtYW55IGNvcHBpZXMgb2YgdGhlIHNhbWUKKyAgICAgICAgICAgICAgICAgICAgICAgICAgKiBwYWNrZXQgd2lsbCBiZSBzZW50IGJlZm9yZSBhIG5ldyBwYWNrZXQgaXMgYWxsb2NhdGVkLgorICAgICAgICAgICAgICAgICAgICAgICAgICAqIEZvciBpbnN0YW5jZSwgaWYgeW91IHdhbnQgdG8gc2VuZCAxMDI0IGlkZW50aWNhbCBwYWNrZXRzCisgICAgICAgICAgICAgICAgICAgICAgICAgICogYmVmb3JlIGNyZWF0aW5nIGEgbmV3IHBhY2tldCwgc2V0IGNsb25lX3NrYiB0byAxMDI0LgorICAgICAgICAgICAgICAgICAgICAgICAgICAqLworICAgICAgICAKKyAgICAgICAgY2hhciBkc3RfbWluW0lQX05BTUVfU1pdOyAvKiBJUCwgaWUgMS4yLjMuNCAqLworICAgICAgICBjaGFyIGRzdF9tYXhbSVBfTkFNRV9TWl07IC8qIElQLCBpZSAxLjIuMy40ICovCisgICAgICAgIGNoYXIgc3JjX21pbltJUF9OQU1FX1NaXTsgLyogSVAsIGllIDEuMi4zLjQgKi8KKyAgICAgICAgY2hhciBzcmNfbWF4W0lQX05BTUVfU1pdOyAvKiBJUCwgaWUgMS4yLjMuNCAqLworCisJc3RydWN0IGluNl9hZGRyICBpbjZfc2FkZHI7CisJc3RydWN0IGluNl9hZGRyICBpbjZfZGFkZHI7CisJc3RydWN0IGluNl9hZGRyICBjdXJfaW42X2RhZGRyOworCXN0cnVjdCBpbjZfYWRkciAgY3VyX2luNl9zYWRkcjsKKwkvKiBGb3IgcmFuZ2VzICovCisJc3RydWN0IGluNl9hZGRyICBtaW5faW42X2RhZGRyOworCXN0cnVjdCBpbjZfYWRkciAgbWF4X2luNl9kYWRkcjsKKwlzdHJ1Y3QgaW42X2FkZHIgIG1pbl9pbjZfc2FkZHI7CisJc3RydWN0IGluNl9hZGRyICBtYXhfaW42X3NhZGRyOworCisgICAgICAgIC8qIElmIHdlJ3JlIGRvaW5nIHJhbmdlcywgcmFuZG9tIG9yIGluY3JlbWVudGFsLCB0aGVuIHRoaXMKKyAgICAgICAgICogZGVmaW5lcyB0aGUgbWluL21heCBmb3IgdGhvc2UgcmFuZ2VzLgorICAg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kcjsKKyAgICAgICAgX191MTYgY3VyX3VkcF9kc3Q7CisgICAgICAgIF9fdTE2IGN1cl91ZHBfc3JjOworICAgICAgICBfX3UzMiBjdXJfcGt0X3NpemU7CisgICAgICAgIAorICAgICAgICBfX3U4IGhoWzE0XTsKKyAgICAgICAgLyogPSB7IAorICAgICAgICAgICAweDAwLCAweDgwLCAweEM4LCAweDc5LCAweEIzLCAweENCLCAKKyAgICAgICAgICAgCisgICAgICAgICAgIFdlIGZpbGwgaW4gU1JDIGFkZHJlc3MgbGF0ZXIKKyAgICAgICAgICAgMHgwMCwgMHgwMCwgMHgwMCwgMHgwMCwgMHgwMCwgMHgwMCwKKyAgICAgICAgICAgMHgwOCwgMHgwMAorICAgICAgICAgICB9OworICAgICAgICAqLworICAgICAgICBfX3UxNiBwYWQ7IC8qIHBhZCBvdXQgdGhlIGhoIHN0cnVjdCB0byBhbiBldmVuIDE2IGJ5dGVzICovCisKKyAgICAgICAgc3RydWN0IHNrX2J1ZmYqIHNrYjsgLyogc2tiIHdlIGFyZSB0byB0cmFuc21pdCBuZXh0LCBtYWlubHkgdXNlZCBmb3Igd2hlbiB3ZQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKiBhcmUgdHJhbnNtaXR0aW5nIHRoZSBzYW1lIG9uZSBtdWx0aXBsZSB0aW1lcworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KKyAgICAgICAgc3RydWN0IG5ldF9kZXZpY2UqIG9kZXY7IC8qIFRoZSBvdXQtZ29pbmcgZGV2aWNlLiAgTm90ZSB0aGF0IHRoZSBkZXZpY2Ugc2hvdWxkCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKiBoYXZlIGl0J3MgcGdfaW5mbyBwb2ludGVyIHBvaW50aW5nIGJhY2sgdG8gdGhpcworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogZGV2aWNlLiAgVGhpcyB3aWxsIGJlIHNldCB3aGVuIHRoZSB1c2VyIHNwZWNpZmllcworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogdGhlIG91dC1nb2luZyBkZXZpY2UgbmFtZSAobm90IHdoZW4gdGhlIGluamVjdCBpcworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogc3RhcnRlZCBhcyBpdCB1c2VkIHRvIGRvLikKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLworCXN0cnVjdCBmbG93X3N0YXRlICpmbG93czsKKwl1bnNpZ25lZCBjZmxvd3M7ICAgICAgICAgLyogQ29uY3VycmVudCBmbG93cyAoY29uZmlnKSAqLworCXVuc2lnbmVkIGxmbG93OyAgICAgICAgICAvKiBGbG93IGxlbmd0aCAgKGNvbmZpZykgKi8KKwl1bnNpZ25lZCBuZmxvd3M7ICAgICAgICAgLyogYWNjdW11bGF0ZWQgZmxvd3MgKHN0YXRzKSAqLworfTsKKworc3RydWN0IHBrdGdlbl9oZHIgeworICAgICAgICBfX3UzMiBwZ2hfbWFnaWM7CisgICAgICAgIF9fdTMyIHNlcV9udW07CisJX191MzIgdHZfc2VjOworCV9fdTMyIHR2X3VzZWM7Cit9OworCitzdHJ1Y3QgcGt0Z2VuX3RocmVhZCB7CisgICAgICAgIHNwaW5sb2NrX3QgaWZfbG9jazsKKyAgICAgICAgc3RydWN0IHBrdGdlbl9kZXYgKmlmX2xpc3Q7ICAgICAgICAgICAvKiBBbGwgZGV2aWNlIGhlcmUgKi8KKyAgICAgICAgc3RydWN0IHBrdGdlbl90aHJlYWQqIG5leHQ7CisgICAgICAgIGNoYXIgbmFtZVszMl07CisgICAgICAgIGNoYXIgZm5hbWVbMTI4XTsgLyogbmFtZSBvZiBwcm9jIGZpbGUgKi8KKyAgICAgICAgc3RydWN0IHByb2NfZGlyX2VudHJ5ICpwcm9jX2VudDsKKyAgICAgICAgY2hhciByZXN1bHRbNTEyXTsKKyAgICAgICAgdTMyIG1heF9iZWZvcmVfc29mdGlycTsgLyogV2UnbGwgY2FsbCBkb19zb2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sKKyAgICAgICAgdTY0IHJlcyA9IDAsIGQgPSAxOworCisgICAgICAgIGlmIChiID4gMCkgeworICAgICAgICAgICAgICAgIHdoaWxlIChiIDwgYSkgeworICAgICAgICAgICAgICAgICAgICAgICAgYiA8PD0gMTsKKyAgICAgICAgICAgICAgICAgICAgICAgIGQgPDw9IDE7CisgICAgICAgICAgICAgICAgfQorICAgICAgICB9CisgICAgICAgIAorICAgICAgICBkbyB7CisgICAgICAgICAgICAgICAgaWYgKCBhID49IGIgKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBhIC09IGI7CisgICAgICAgICAgICAgICAgICAgICAgICByZXMgKz0gZDsKKyAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICAgYiA+Pj0gMTsKKyAgICAgICAgICAgICAgICBkID4+PSAxOworICAgICAgICB9CisgICAgICAgIHdoaWxlIChkKTsKKworICAgICAgICBpZiAoUEdfRElWID09IHR5cGUpIHsKKyAgICAgICAgICAgICAgICByZXR1cm4gKCgoeCBeIHkpICYgKDFsbDw8NjMpKSA9PSAwKSA/IHJlcyA6IC0oczY0KXJlczsKKyAgICAgICAgfQorICAgICAgICBlbHNlIHsKKyAgICAgICAgICAgICAgICByZXR1cm4gKCh4ICYgKDFsbDw8NjMpKSA9PSAwKSA/IGEgOiAtKHM2NClhOworICAgICAgICB9Cit9CisKKy8qIEVuZCBvZiBoYWNrcyB0byBkZWFsIHdpdGggNjQtYml0IG1hdGggb24geDg2ICovCisKKy8qKiBDb252ZXJ0IHRvIG1pbGlzZWNvbmRzICovCitzdGF0aWMgaW5saW5lIF9fdTY0IHR2X3RvX21zKGNvbnN0IHN0cnVjdCB0aW1ldmFsKiB0dikgCit7CisgICAgICAgIF9fdTY0IG1zID0gdHYtPnR2X3VzZWMgLyAxMDAwOworICAgICAgICBtcyArPSAoX191NjQpdHYtPnR2X3NlYyAqIChfX3U2NCkxMDAwOworICAgICAgICByZXR1cm4gbXM7Cit9CisKKworLyoqIENvbnZlcnQgdG8gbWljcm8tc2Vjb25kcyAqLworc3RhdGljIGlubGluZSBfX3U2NCB0dl90b191cyhjb25zdCBzdHJ1Y3QgdGltZXZhbCogdHYpIAoreworICAgICAgICBfX3U2NCB1cyA9IHR2LT50dl91c2VjOworICAgICAgICB1cyArPSAoX191NjQpdHYtPnR2X3NlYyAqIChfX3U2NCkxMDAwMDAwOworICAgICAgICByZXR1cm4gdXM7Cit9CisKK3N0YXRpYyBpbmxpbmUgX191NjQgcGdfZGl2KF9fdTY0IG4sIF9fdTMyIGJhc2UpIHsKKyAgICAgICAgX191NjQgdG1wID0gbjsKKyAgICAgICAgZG9fZGl2KHRtcCwgYmFzZSk7CisgICAgICAgIC8qIHByaW50aygicGt0Z2VuOiBwZ19kaXYsIG46ICVsbHUgIGJhc2U6ICVkICBydjogJWxsdVxuIiwKKyAgICAgICAgICAgICAgICAgIG4sIGJhc2UsIHRtcCk7ICovCisgICAgICAgIHJldHVybiB0bXA7Cit9CisKK3N0YXRpYyBpbmxpbmUgX191NjQgcGdfZGl2NjQoX191NjQgbiwgX191NjQgYmFzZSkgCit7CisgICAgICAgIF9fdTY0IHRtcCA9IG47CisvKgorICogSG93IGRvIHdlIGtub3cgaWYgdGhlIGFyY2hpdGVjdHJ1cmUgd2UgYXJlIHJ1bm5pbmcgb24KKyAqIHN1cHBvcnRzIGRpdmlzaW9uIHdpdGggNjQgYml0IGJhc2U/CisgKiAKKyAqLworI2lmIGRlZmluZWQoX19zcGFyY192OV9fKSB8fCBkZWZpbmVkKF9fcG93ZXJwYzY0X18pIHx8IGRlZmluZWQoX19hbHBoYV9fKSB8fCBkZWZpbmVkKF9feDg2XzY0X18pIHx8IGRlZmluZWQoX19pYTY0X18pIAorCisJCWRvX2Rpdih0bXAsIGJhc2UpOworI2Vsc2UKKwkJdG1wID0gZGl2cmVtZGkzKG4sIGJhc2UsIFBHX0RJVik7CisjZW5kaWYKKyAgICAgICAgcmV0dXJuIHRtcDsKK30KKworc3RhdGljIGlubGluZSB1MzIgcGt0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2VuOiBVbmtub3duIGNvbW1hbmQ6ICVzXG4iLCBkYXRhKTsKKworCWVyciA9IGNvdW50OworCisgb3V0X2ZyZWU6CisJdmZyZWUgKGRhdGEpOworIG91dDoKKyAgICAgICAgcmV0dXJuIGVycjsKK30KKworc3RhdGljIGludCBwcm9jX2lmX3JlYWQoY2hhciAqYnVmICwgY2hhciAqKnN0YXJ0LCBvZmZfdCBvZmZzZXQsCisgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgbGVuLCBpbnQgKmVvZiwgdm9pZCAqZGF0YSkKK3sKKwljaGFyICpwOworCWludCBpOworICAgICAgICBzdHJ1Y3QgcGt0Z2VuX2RldiAqcGt0X2RldiA9IChzdHJ1Y3QgcGt0Z2VuX2RldiopKGRhdGEpOworICAgICAgICBfX3U2NCBzYTsKKyAgICAgICAgX191NjQgc3RvcHBlZDsKKyAgICAgICAgX191NjQgbm93ID0gZ2V0Q3VyVXMoKTsKKyAgICAgICAgCisJcCA9IGJ1ZjsKKwlwICs9IHNwcmludGYocCwgIlBhcmFtczogY291bnQgJWxsdSAgbWluX3BrdF9zaXplOiAldSAgbWF4X3BrdF9zaXplOiAldVxuIiwKKwkJICAgICAodW5zaWduZWQgbG9uZyBsb25nKSBwa3RfZGV2LT5jb3VudCwKKwkJICAgICBwa3RfZGV2LT5taW5fcGt0X3NpemUsIHBrdF9kZXYtPm1heF9wa3Rfc2l6ZSk7CisKKwlwICs9IHNwcmludGYocCwgIiAgICAgZnJhZ3M6ICVkICBkZWxheTogJXUgIGNsb25lX3NrYjogJWQgIGlmbmFtZTogJXNcbiIsCisgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5uZnJhZ3MsIDEwMDAqcGt0X2Rldi0+ZGVsYXlfdXMrcGt0X2Rldi0+ZGVsYXlfbnMsIHBrdF9kZXYtPmNsb25lX3NrYiwgcGt0X2Rldi0+aWZuYW1lKTsKKworCXAgKz0gc3ByaW50ZihwLCAiICAgICBmbG93czogJXUgZmxvd2xlbjog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0gMCkgJiYgCisJICAgIChwa3RfZGV2LT5zcmNfbWFjWzFdID09IDApICYmIAorCSAgICAocGt0X2Rldi0+c3JjX21hY1syXSA9PSAwKSAmJiAKKwkgICAgKHBrdF9kZXYtPnNyY19tYWNbM10gPT0gMCkgJiYgCisJICAgIChwa3RfZGV2LT5zcmNfbWFjWzRdID09IDApICYmIAorCSAgICAocGt0X2Rldi0+c3JjX21hY1s1XSA9PSAwKSkgCisKKwkJZm9yIChpID0gMDsgaSA8IDY7IGkrKykgCisJCQlwICs9IHNwcmludGYocCwgIiUwMlglcyIsIHBrdF9kZXYtPm9kZXYtPmRldl9hZGRyW2ldLCBpID09IDUgPyAiICAiIDogIjoiKTsKKworCWVsc2UgCisJCWZvciAoaSA9IDA7IGkgPCA2OyBpKyspIAorCQkJcCArPSBzcHJpbnRmKHAsICIlMDJYJXMiLCBwa3RfZGV2LT5zcmNfbWFjW2ldLCBpID09IDUgPyAiICAiIDogIjoiKTsKKworICAgICAgICBwICs9IHNwcmludGYocCwgImRzdF9tYWM6ICIpOworCWZvciAoaSA9IDA7IGkgPCA2OyBpKyspIAorCQlwICs9IHNwcmludGYocCwgIiUwMlglcyIsIHBrdF9kZXYtPmRzdF9tYWNbaV0sIGkgPT0gNSA/ICJcbiIgOiAiOiIpOworCisgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiICAgICB1ZHBfc3JjX21pbjogJWQgIHVkcF9zcmNfbWF4OiAlZCAgdWRwX2RzdF9taW46ICVkICB1ZHBfZHN0X21heDogJWRcbiIsCisgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfc3JjX21pbiwgcGt0X2Rldi0+dWRwX3NyY19tYXgsIHBrdF9kZXYtPnVkcF9kc3RfbWluLAorICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+dWRwX2RzdF9tYXgpOworCisgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiICAgICBzcmNfbWFjX2NvdW50OiAlZCAgZHN0X21hY19jb3VudDogJWQgXG4gICAgIEZsYWdzOiAiLAorICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+c3JjX21hY19jb3VudCwgcGt0X2Rldi0+ZHN0X21hY19jb3VudCk7CisKKworICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiAgRl9JUFY2KSAKKyAgICAgICAgICAgICAgICBwICs9IHNwcmludGYocCwgIklQVjYgICIpOworCisgICAgICAgIGlmIChwa3RfZGV2LT5mbGFncyAmICBGX0lQU1JDX1JORCkgCisgICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJJUFNSQ19STkQgICIpOworCisgICAgICAgIGlmIChwa3RfZGV2LT5mbGFncyAmIEZfSVBEU1RfUk5EKSAKKyAgICAgICAgICAgICAgICBwICs9IHNwcmludGYocCwgIklQRFNUX1JORCAgIik7CisgICAgICAgIAorICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1RYU0laRV9STkQpIAorICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiVFhTSVpFX1JORCAgIik7CisgICAgICAgIAorICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1VEUFNSQ19STkQpIAorICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiVURQU1JDX1JORCAgIik7CisgICAgICAgIAorICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1VEUERTVF9STkQpIAorICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiVURQRFNUX1JORCAgIik7CisgICAgICAgIAorICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX01BQ1NSQ19STkQpIAorICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiTUFDU1JDX1JORCAgIik7CisgICAgICAgIAorICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX01BQ0RTVF9STkQpIAorICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiTUF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gICAgICAgICAgICAgIGNoYXIgYzsKKyAgICAgICAgICAgICAgICBpZiAoZ2V0X3VzZXIoYywgJnVzZXJfYnVmZmVyW2ldKSkKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUZBVUxUOworICAgICAgICAgICAgICAgIHN3aXRjaCAoYykgeworCQljYXNlICdcIic6CisJCWNhc2UgJ1xuJzoKKwkJY2FzZSAnXHInOgorCQljYXNlICdcdCc6CisJCWNhc2UgJyAnOgorCQljYXNlICc9JzoKKwkJCWJyZWFrOworCQlkZWZhdWx0OgorCQkJZ290byBkb25lOworCQl9OworCX0KK2RvbmU6CisJcmV0dXJuIGk7Cit9CisKK3N0YXRpYyB1bnNpZ25lZCBsb25nIG51bV9hcmcoY29uc3QgY2hhciBfX3VzZXIgKnVzZXJfYnVmZmVyLCB1bnNpZ25lZCBsb25nIG1heGxlbiwgCisJCQkgICAgIHVuc2lnbmVkIGxvbmcgKm51bSkKK3sKKwlpbnQgaSA9IDA7CisJKm51bSA9IDA7CisgIAorCWZvcig7IGkgPCBtYXhsZW47IGkrKykgeworICAgICAgICAgICAgICAgIGNoYXIgYzsKKyAgICAgICAgICAgICAgICBpZiAoZ2V0X3VzZXIoYywgJnVzZXJfYnVmZmVyW2ldKSkKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUZBVUxUOworICAgICAgICAgICAgICAgIGlmICgoYyA+PSAnMCcpICYmIChjIDw9ICc5JykpIHsKKwkJCSpudW0gKj0gMTA7CisJCQkqbnVtICs9IGMgLScwJzsKKwkJfSBlbHNlCisJCQlicmVhazsKKwl9CisJcmV0dXJuIGk7Cit9CisKK3N0YXRpYyBpbnQgc3Rybl9sZW4oY29uc3QgY2hhciBfX3VzZXIgKnVzZXJfYnVmZmVyLCB1bnNpZ25lZCBpbnQgbWF4bGVuKQoreworCWludCBpID0gMDsKKworCWZvcig7IGkgPCBtYXhsZW47IGkrKykgeworICAgICAgICAgICAgICAgIGNoYXIgYzsKKyAgICAgICAgICAgICAgICBpZiAoZ2V0X3VzZXIoYywgJnVzZXJfYnVmZmVyW2ldKSkKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUZBVUxUOworICAgICAgICAgICAgICAgIHN3aXRjaCAoYykgeworCQljYXNlICdcIic6CisJCWNhc2UgJ1xuJzoKKwkJY2FzZSAnXHInOgorCQljYXNlICdcdCc6CisJCWNhc2UgJyAnOgorCQkJZ290byBkb25lX3N0cjsKKwkJCWJyZWFrOworCQlkZWZhdWx0OgorCQkJYnJlYWs7CisJCX07CisJfQorZG9uZV9zdHI6CisKKwlyZXR1cm4gaTsKK30KKworc3RhdGljIGludCBwcm9jX2lmX3dyaXRlKHN0cnVjdCBmaWxlICpmaWxlLCBjb25zdCBjaGFyIF9fdXNlciAqdXNlcl9idWZmZXIsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgdW5zaWduZWQgbG9uZyBjb3VudCwgdm9pZCAqZGF0YSkKK3sKKwlpbnQgaSA9IDAsIG1heCwgbGVuOworCWNoYXIgbmFtZVsxNl0sIHZhbHN0clszMl07CisJdW5zaWduZWQgbG9uZyB2YWx1ZSA9IDA7CisgICAgICAgIHN0cnVjdCBwa3RnZW5fZGV2ICpwa3RfZGV2ID0gKHN0cnVjdCBwa3RnZW5fZGV2KikoZGF0YSk7CisgICAgICAgIGNoYXIqIHBnX3Jlc3VsdCA9IE5VTEw7CisgICAgICAgIGludCB0bXAgPSAwOworCWNoYXIgYnVmWzEyOF07CisgICAgICAgIAorICAgICAgICBwZ19yZXN1bHQgPSAmKHBrdF9kZXYtPnJlc3VsdFswXSk7CisgICAgICAgIAorCWlmIChjb3VudCA8IDEpIHsKKwkJcHJpbnRrKCJwa3RnZW46IHdyb25nIGNvbW1hbmQgZm9ybWF0XG4iKTsKKwkJcmV0dXJuIC1FSU5WQUw7CisJfQorICAKKwltYXggPSBjb3VudCAtIGk7CisJdG1wID0gY291bnRfdHJhaWxfY2hhcnMoJnVzZXJfYnVmZmVyW2ldLCBtYXgpOworICAgICAgICBpZiAodG1wIDwgMCkgeyAKKwkJcHJpbnRrKCJwa3RnZW46IGlsbGVnYWwgZm9ybWF0XG4iKTsKKwkJcmV0dXJuIHRtcDsgCisJfQorICAgICAgICBpICs9IHRtcDsKKyAgICAgICAgCisJLyogUmVhZCB2YXJpYWJsZSBuYW1lICovCisKKwlsZW4gPSBzdHJuX2xlbigmdXNlcl9idWZmZXJbaV0sIHNpemVvZihuYW1lKSAtIDEpOworICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CisJbWVtc2V0KG5hbWUsIDAsIHNpemVvZihuYW1lKSk7CisJaWYgKGNvcHlfZnJvbV91c2VyKG5hbWUsICZ1c2VyX2J1ZmZlcltpXSwgbGVuKSApCisJCXJldHVybiAtRUZBVUxUOworCWkgKz0gbGVuOworICAKKwltYXggPSBjb3VudCAtaTsKKwlsZW4gPSBjb3VudF90cmFpbF9jaGFycygmdXNlcl9idWZmZXJbaV0sIG1heCk7CisgICAgICAgIGlmIChsZW4gPCAwKSAKKyAgICAgICAgICAgICAgICByZXR1cm4gbGVuOworICAgICAgICAKKwlpICs9IGxlbjsKKworCWlmIChkZWJ1ZykgeworICAgICAgICAgICAgICAgIGNoYXIgdGJbY291bnQgKyAxXTsKKyAgICAgICAgICAgICAgICBpZiAoY29weV9mcm9tX3VzZXIodGIsIHVzZXJfYnVmZmVyLCBjb3VudCkpCisJCQlyZXR1cm4gLUVGQVVMVDsKKyAgICAgICAgICAgICAgICB0Yltjb3VudF0gPSAwOworCQlwcmludGsoInBrdGdlbjogJXMsJWx1ICBidWZmZXIgLTolczotXG4iLCBuYW1lLCBjb3VudCwgdGIpOworICAgICAgICB9CisKKwlpZiAoIXN0cmNtcChuYW1lLCAibWluX3BrdF9zaXplIikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHV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AgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfc3JjX21pbiA9IHZhbHVlOworICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX3VkcF9zcmMgPSB2YWx1ZTsKKyAgICAgICAgICAgICAgICB9ICAgICAgIAorCQlzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiB1ZHBfc3JjX21pbj0ldSIsIHBrdF9kZXYtPnVkcF9zcmNfbWluKTsKKwkJcmV0dXJuIGNvdW50OworCX0KKyAJaWYgKCFzdHJjbXAobmFtZSwgInVkcF9kc3RfbWluIikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisgICAgICAgICAgICAgICAgaWYgKHZhbHVlICE9IHBrdF9kZXYtPnVkcF9kc3RfbWluKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfZHN0X21pbiA9IHZhbHVlOworICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX3VkcF9kc3QgPSB2YWx1ZTsKKyAgICAgICAgICAgICAgICB9CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IHVkcF9kc3RfbWluPSV1IiwgcGt0X2Rldi0+dWRwX2RzdF9taW4pOworCQlyZXR1cm4gY291bnQ7CisJfQorIAlpZiAoIXN0cmNtcChuYW1lLCAidWRwX3NyY19tYXgiKSkgeworCQlsZW4gPSBudW1fYXJnKCZ1c2VyX2J1ZmZlcltpXSwgMTAsICZ2YWx1ZSk7CisgICAgICAgICAgICAgICAgaWYgKGxlbiA8IDApIHsgcmV0dXJuIGxlbjsgfQorCQlpICs9IGxlbjsKKyAgICAgICAgICAgICAgICBpZiAodmFsdWUgIT0gcGt0X2Rldi0+dWRwX3NyY19tYXgpIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPnVkcF9zcmNfbWF4ID0gdmFsdWU7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdXJfdWRwX3NyYyA9IHZhbHVlOworICAgICAgICAgICAgICAgIH0KKwkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogdWRwX3NyY19tYXg9JXUiLCBwa3RfZGV2LT51ZHBfc3JjX21heCk7CisJCXJldHVybiBjb3VudDsKKwl9CisgCWlmICghc3RyY21wKG5hbWUsICJ1ZHBfZHN0X21heCIpKSB7CisJCWxlbiA9IG51bV9hcmcoJnVzZXJfYnVmZmVyW2ldLCAxMCwgJnZhbHVlKTsKKyAgICAgICAgICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CisJCWkgKz0gbGVuOworICAgICAgICAgICAgICAgIGlmICh2YWx1ZSAhPSBwa3RfZGV2LT51ZHBfZHN0X21heCkgeworICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+dWRwX2RzdF9tYXggPSB2YWx1ZTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmN1cl91ZHBfZHN0ID0gdmFsdWU7CisgICAgICAgICAgICAgICAgfQorCQlzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiB1ZHBfZHN0X21heD0ldSIsIHBrdF9kZXYtPnVkcF9kc3RfbWF4KTsKKwkJcmV0dXJuIGNvdW50OworCX0KKwlpZiAoIXN0cmNtcChuYW1lLCAiY2xvbmVfc2tiIikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y2xvbmVfc2tiID0gdmFsdWU7CisJCisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGNsb25lX3NrYj0lZCIsIHBrdF9kZXYtPmNsb25lX3NrYik7CisJCXJldHVybiBjb3VudDsKKwl9CisJaWYgKCFzdHJjbXAobmFtZSwgImNvdW50IikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisJCXBrdF9kZXYtPmNvdW50ID0gdmFsdWU7CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGNvdW50PSVsbHUiLAorCQkJKHVuc2lnbmVkIGxvbmcgbG9uZykgcGt0X2Rldi0+Y291bnQpOworCQlyZXR1cm4gY291bnQ7CisJfQorCWlmICghc3RyY21wKG5hbWUsICJzcmNfbWFjX2NvdW50IikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisJCWlmIChwa3RfZGV2LT5zcmNfbWFjX2NvdW50ICE9IHZhbHVlKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5zcmNfbWFjX2NvdW50ID0gdmFsdWU7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdXJfc3JjX21hY19vZmZzZXQgPSAwOworICAgICAgICAgICAgICAgIH0KKwkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogc3JjX21hY19jb3VudD0lZCIsIHBrdF9kZXYtPnNyY19tYWNfY291bnQpOworCQlyZXR1cm4gY291bnQ7CisJfQorCWlmICghc3RyY21wKG5hbWUsICJkc3RfbWFjX2NvdW50IikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisJCWlmIChwa3RfZGV2LT5kc3RfbWFjX2NvdW50ICE9IHZhbHVlKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5kc3RfbWFjX2NvdW50ID0gdmFsdWU7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdXJfZHN0X21hY19vZmZzZXQgPSAwOworICAgICAgICAgICAgICAgIH0KKwkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogZHN0X21hY19jb3VudD0lZCIsIHBrdF9kZXYtPmRzdF9tYWNfY291bnQpOworCQlyZXR1cm4gY291bnQ7CisJfQorCWlmICghc3RyY21wKG5hbWUsICJmbGFnIikpIHsKKyAgICAgICAgICAgICAgICBjaGFyIGZbMzJdOworICAgICAgICAgICAgICAgIG1lbXNldChmLCAwLCAzMik7CisJCWxlbiA9IHN0cm5fbGVuKCZ1c2VyX2J1ZmZlcltpXSwgc2l6ZW9mKGYpIC0gMSk7CisgICAgICAgICAgICAgICAgaWYgKGxlbiA8IDApIHsgcmV0dXJuIGxlbjsgfQorCQlpZiAoY29weV9mcm9tX3VzZXIoZiwgJnVzZXJfYnVmZmVyW2ldLCBsZW4pKQorCQkJcmV0dXJuIC1FRkFVTFQ7CisJCWkgKz0gbGVuOworICAgICAgICAgICAgICAgIGlmIChzdHJjbXAoZiwgIklQU1JDX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgfD0gRl9JUFNSQ19STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhSVBTUkNfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9JUFNSQ19STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJUWFNJWkVfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX1RYU0laRV9STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhVFhTSVpFX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgJj0gfkZfVFhTSVpFX1JORDsKKyAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIklQRFNUX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgfD0gRl9JUERTVF9STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhSVBEU1RfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9JUERTVF9STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJVRFBTUkNfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX1VEUFNSQ19STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhVURQU1JDX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgJj0gfkZfVURQU1JDX1JORDsKKyAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIlVEUERTVF9STkQiKSA9PSAwKSAKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzIHw9IEZfVURQRFNUX1JORDsKKyAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIiFVRFBEU1RfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9VRFBEU1RfUk5EOworICAgICAgICAgICAgICAgIAorICAgICAgICAgICAgICAgIGVsc2UgaWYgKHN0cmNtcChmLCAiTUFDU1JDX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgfD0gRl9NQUNTUkNfUk5EOworICAgICAgICAgICAgICAgIAorICAgICAgICAgICAgICAgIGVsc2UgaWYgKHN0cmNtcChmLCAiIU1BQ1NSQ19STkQiKSA9PSAwKSAKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzICY9IH5GX01BQ1NSQ19STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJNQUNEU1RfUk5EIikgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX01BQ0RTVF9STkQ7CisgICAgICAgICAgICAgICAgCisgICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhTUFDRFNUX1JORCIpID09IDApIAorICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgJj0gfkZfTUFDRFNUX1JORDsKKyAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAgICBlbHNlIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIHNwcmludGYocGdfcmVzdWx0LCAiRmxhZyAtOiVzOi0gdW5rbm93blxuQXZhaWxhYmxlIGZsYWdzLCAocHJlcGVuZCAhIHRvIHVuLXNldCBmbGFnKTpcbiVzIiwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZiwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIklQU1JDX1JORCwgSVBEU1RfUk5ELCBUWFNJWkVfUk5ELCBVRFBTUkNfUk5ELCBVRFBEU1RfUk5ELCBNQUNTUkNfUk5ELCBNQUNEU1RfUk5EXG4iKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjb3VudDsKKyAgICAgICAgICAgICAgICB9CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGZsYWdzPTB4JXgiLCBwa3RfZGV2LT5mbGFncyk7CisJCXJldHVybiBjb3VudDsKKwl9CisJaWYgKCFzdHJjbXAobmFtZSwgImRzdF9taW4iKSB8fCAhc3RyY21wKG5hbWUsICJkc3QiKSkgeworCQlsZW4gPSBzdHJuX2xlbigmdXNlcl9idWZmZXJbaV0sIHNpemVvZihwa3RfZGV2LT5kc3RfbWluKSAtIDEpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKworICAgICAgICAgICAgICAgIGlmIChjb3B5X2Zyb21fdXNlcihidWYsICZ1c2VyX2J1ZmZlcltpXSwgbGVuKSkKKwkJCXJldHVybiAtRUZBVUxUOworICAgICAgICAgICAgICAgIGJ1ZltsZW5dID0gMDsKKyAgICAgICAgICAgICAgICBpZiAoc3RyY21wKGJ1ZiwgcGt0X2Rldi0+ZHN0X21pbikgIT0gMCkgeworICAgICAgICAgICAgICAgICAgICAgICAgbWVtc2V0KHBrdF9kZXYtPmRzdF9taW4sIDAsIHNpemVvZihwa3RfZGV2LT5kc3RfbWluKSk7CisgICAgICAgICAgICAgICAgICAgICAgICBzdHJuY3B5KHBrdF9kZXYtPmRzdF9taW4sIGJ1ZiwgbGVuKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmRhZGRyX21pbiA9IGluX2F0b24ocGt0X2Rldi0+ZHN0X21pbik7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdXJfZGFkZHIgPSBwa3RfZGV2LT5kYWRkcl9taW47CisgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgIGlmKGRlYnVnKQorICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRrKCJwa3RnZW46IGRzdF9taW4gc2V0IHRvOiAlc1xuIiwgcGt0X2Rldi0+ZHN0X21pbik7CisgICAgICAgICAgICAgICAgaSArPSBsZW47CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGRzdF9taW49JXMiLCBwa3RfZGV2LT5kc3RfbWluKTsKKwkJcmV0dXJuIGNvdW50OworCX0KKwlpZiAoIXN0cmNtcChuYW1lLCAiZHN0X21heCIpKSB7CisJCWxlbiA9IHN0cm5fbGVuKCZ1c2VyX2J1ZmZlcltpXSwgc2l6ZW9mKHBrdF9kZXYtPmRzdF9tYXgpIC0gMSk7CisgICAgICAgICAgICAgICAgaWYgKGxlbiA8IDApIHsgcmV0dXJuIGxlbjsgfQorCisgICAgICAgICAgICAgICAgaWYgKGNvcHlfZnJvbV91c2VyKGJ1ZiwgJnVzZXJfYnVmZmVyW2ldLCBsZW4pKQorCQkJcmV0dXJuIC1FRkFVTFQ7CisKKyAgICAgICAgICAgICAgICBidWZbbGVuXSA9IDA7CisgICAgICAgICAgICAgICAgaWYgKHN0cmNtcChidWYsIHBrdF9kZXYtPmRzdF9tYXgpICE9IDApIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIG1lbXNldChwa3RfZGV2LT5kc3RfbWF4LCAwLCBzaXplb2YocGt0X2Rldi0+ZHN0X21heCkpOworICAgICAgICAgICAgICAgICAgICAgICAgc3RybmNweShwa3RfZGV2LT5kc3RfbWF4LCBidWYsIGxlbik7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5kYWRkcl9tYXggPSBpbl9hdG9uKHBrdF9kZXYtPmRzdF9tYXgpOworICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX2RhZGRyID0gcGt0X2Rldi0+ZGFkZHJfbWF4OworICAgICAgICAgICAgICAgIH0KKwkJaWYoZGVidWcpCisJCQlwcmludGsoInBrdGdlbjogZHN0X21heCBzZXQgdG86ICVzXG4iLCBwa3RfZGV2LT5k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lpZiAoIXN0cmNtcChuYW1lLCAic3JjX21pbiIpKSB7CisJCWxlbiA9IHN0cm5fbGVuKCZ1c2VyX2J1ZmZlcltpXSwgc2l6ZW9mKHBrdF9kZXYtPnNyY19taW4pIC0gMSk7CisgICAgICAgICAgICAgICAgaWYgKGxlbiA8IDApIHsgcmV0dXJuIGxlbjsgfQorICAgICAgICAgICAgICAgIGlmIChjb3B5X2Zyb21fdXNlcihidWYsICZ1c2VyX2J1ZmZlcltpXSwgbGVuKSkKKwkJCXJldHVybiAtRUZBVUxUOworICAgICAgICAgICAgICAgIGJ1ZltsZW5dID0gMDsKKyAgICAgICAgICAgICAgICBpZiAoc3RyY21wKGJ1ZiwgcGt0X2Rldi0+c3JjX21pbikgIT0gMCkgeworICAgICAgICAgICAgICAgICAgICAgICAgbWVtc2V0KHBrdF9kZXYtPnNyY19taW4sIDAsIHNpemVvZihwa3RfZGV2LT5zcmNfbWluKSk7CisgICAgICAgICAgICAgICAgICAgICAgICBzdHJuY3B5KHBrdF9kZXYtPnNyY19taW4sIGJ1ZiwgbGVuKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPnNhZGRyX21pbiA9IGluX2F0b24ocGt0X2Rldi0+c3JjX21pbik7CisgICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdXJfc2FkZHIgPSBwa3RfZGV2LT5zYWRkcl9taW47CisgICAgICAgICAgICAgICAgfQorCQlpZihkZWJ1ZykKKwkJCXByaW50aygicGt0Z2VuOiBzcmNfbWluIHNldCB0bzogJXNcbiIsIHBrdF9kZXYtPnNyY19taW4pOworCQlpICs9IGxlbjsKKwkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogc3JjX21pbj0lcyIsIHBrdF9kZXYtPnNyY19taW4pOworCQlyZXR1cm4gY291bnQ7CisJfQorCWlmICghc3RyY21wKG5hbWUsICJzcmNfbWF4IikpIHsKKwkJbGVuID0gc3Rybl9sZW4oJnVzZXJfYnVmZmVyW2ldLCBzaXplb2YocGt0X2Rldi0+c3JjX21heCkgLSAxKTsKKyAgICAgICAgICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CisgICAgICAgICAgICAgICAgaWYgKGNvcHlfZnJvbV91c2VyKGJ1ZiwgJnVzZXJfYnVmZmVyW2ldLCBsZW4pKQorCQkJcmV0dXJuIC1FRkFVTFQ7CisgICAgICAgICAgICAgICAgYnVmW2xlbl0gPSAwOworICAgICAgICAgICAgICAgIGlmIChzdHJjbXAoYnVmLCBwa3RfZGV2LT5zcmNfbWF4KSAhPSAwKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBtZW1zZXQocGt0X2Rldi0+c3JjX21heCwgMCwgc2l6ZW9mKHBrdF9kZXYtPnNyY19tYXgpKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHN0cm5jcHkocGt0X2Rldi0+c3JjX21heCwgYnVmLCBsZW4pOworICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+c2FkZHJfbWF4ID0gaW5fYXRvbihwa3RfZGV2LT5zcmNfbWF4KTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmN1cl9zYWRkciA9IHBrdF9kZXYtPnNhZGRyX21heDsKKyAgICAgICAgICAgICAgICB9CisJCWlmKGRlYnVnKQorCQkJcHJpbnRrKCJwa3RnZW46IHNyY19tYXggc2V0IHRvOiAlc1xuIiwgcGt0X2Rldi0+c3JjX21heCk7CisJCWkgKz0gbGVuOworCQlzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiBzcmNfbWF4PSVzIiwgcGt0X2Rldi0+c3JjX21heCk7CisJCXJldHVybiBjb3VudDsKKwl9CisJaWYgKCFzdHJjbXAobmFtZSwgImRzdF9tYWMiKSkgeworCQljaGFyICp2ID0gdmFsc3RyOworICAgICAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgb2xkX2RtYWNbNl07CisJCXVuc2lnbmVkIGNoYXIgKm0gPSBwa3RfZGV2LT5k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Y2xlYXJfY291bnRlcnMiKSkgeworICAgICAgICAgICAgICAgIHBrdGdlbl9jbGVhcl9jb3VudGVycyhwa3RfZGV2KTsKKyAgICAgICAgICAgICAgICBzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiBDbGVhcmluZyBjb3VudGVycy5cbiIpOworICAgICAgICAgICAgICAgIHJldHVybiBjb3VudDsKKyAgICAgICAgfQorCisJaWYgKCFzdHJjbXAobmFtZSwgImZsb3dzIikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisJCWlmICh2YWx1ZSA+IE1BWF9DRkxPV1MpCisJCQl2YWx1ZSA9IE1BWF9DRkxPV1M7CisKKwkJcGt0X2Rldi0+Y2Zsb3dzID0gdmFsdWU7CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGZsb3dzPSV1IiwgcGt0X2Rldi0+Y2Zsb3dzKTsKKwkJcmV0dXJuIGNvdW50OworCX0KKworCWlmICghc3RyY21wKG5hbWUsICJmbG93bGVuIikpIHsKKwkJbGVuID0gbnVtX2FyZygmdXNlcl9idWZmZXJbaV0sIDEwLCAmdmFsdWUpOworICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KKwkJaSArPSBsZW47CisJCXBrdF9kZXYtPmxmbG93ID0gdmFsdWU7CisJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGZsb3dsZW49JXUiLCBwa3RfZGV2LT5sZmxvdyk7CisJCXJldHVybiBjb3VudDsKKwl9CisgICAgICAgIAorCXNwcmludGYocGt0X2Rldi0+cmVzdWx0LCAiTm8gc3VjaCBwYXJhbWV0ZXIgXCIlc1wiIiwgbmFtZSk7CisJcmV0dXJuIC1FSU5WQUw7Cit9CisKK3N0YXRpYyBpbnQgcHJvY190aHJlYWRfcmVhZChjaGFyICpidWYgLCBjaGFyICoqc3RhcnQsIG9mZl90IG9mZnNldCwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgbGVuLCBpbnQgKmVvZiwgdm9pZCAqZGF0YSkKK3sKKwljaGFyICpwOworICAgICAgICBzdHJ1Y3QgcGt0Z2VuX3RocmVhZCAqdCA9IChzdHJ1Y3QgcGt0Z2VuX3RocmVhZCopKGRhdGEpOworICAgICAgICBzdHJ1Y3QgcGt0Z2VuX2RldiAqcGt0X2RldiA9IE5VTEw7CisKKworICAgICAgICBpZiAoIXQpIHsKKyAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogRVJST1I6IGNvdWxkIG5vdCBmaW5kIHRocmVhZCBpbiBwcm9jX3RocmVhZF9yZWFkXG4iKTsKKyAgICAgICAgICAgICAgICByZXR1cm4gLUVJTlZBTDsKKyAgICAgICAgfQorCisJcCA9IGJ1ZjsKKwlwICs9IHNwcmludGYocCwgIk5hbWU6ICVzICBtYXhfYmVmb3JlX3NvZnRpcnE6ICVkXG4iLAorICAgICAgICAgICAgICAgICAgICAgdC0+bmFtZSwgdC0+bWF4X2JlZm9yZV9zb2Z0aXJxKTsKKworICAgICAgICBwICs9IHNwcmludGYocCwgIlJ1bm5pbmc6ICIpOworICAgICAgICAKKyAgICAgICAgaWZfbG9jayh0KTsKKyAgICAgICAgZm9yKHBrdF9kZXYgPSB0LT5pZl9saXN0O3BrdF9kZXY7IHBrdF9kZXYgPSBwa3RfZGV2LT5uZXh0KSAKKwkJaWYocGt0X2Rldi0+cnVubmluZykKKwkJCXAgKz0gc3ByaW50ZihwLCAiJXMgIiwgcGt0X2Rldi0+aWZuYW1lKTsKKyAgICAgICAgCisgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiXG5TdG9wcGVkOiAiKTsKKworICAgICAgICBmb3IocGt0X2RldiA9IHQtPmlmX2xpc3Q7cGt0X2RldjsgcGt0X2RldiA9IHBrdF9kZXYtPm5leHQpIAorCQlpZighcGt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VMVDsKKwkJaSArPSBsZW47CisJCXRocmVhZF9sb2NrKCk7CisgICAgICAgICAgICAgICAgcGt0Z2VuX2FkZF9kZXZpY2UodCwgZik7CisJCXRocmVhZF91bmxvY2soKTsKKyAgICAgICAgICAgICAgICByZXQgPSBjb3VudDsKKyAgICAgICAgICAgICAgICBzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiBhZGRfZGV2aWNlPSVzIiwgZik7CisJCWdvdG8gb3V0OworCX0KKworICAgICAgICBpZiAoIXN0cmNtcChuYW1lLCAicmVtX2RldmljZV9hbGwiKSkgeworCQl0aHJlYWRfbG9jaygpOworCQl0LT5jb250cm9sIHw9IFRfUkVNREVWOworCQl0aHJlYWRfdW5sb2NrKCk7CisJCWN1cnJlbnQtPnN0YXRlID0gVEFTS19JTlRFUlJVUFRJQkxFOworCQlzY2hlZHVsZV90aW1lb3V0KEhaLzgpOyAgLyogUHJvcGFnYXRlIHRocmVhZC0+Y29udHJvbCAgKi8KKwkJcmV0ID0gY291bnQ7CisgICAgICAgICAgICAgICAgc3ByaW50ZihwZ19yZXN1bHQsICJPSzogcmVtX2RldmljZV9hbGwiKTsKKwkJZ290byBvdXQ7CisJfQorCisgICAgICAgIGlmICghc3RyY21wKG5hbWUsICJtYXhfYmVmb3JlX3NvZnRpcnEiKSkgeworICAgICAgICAgICAgICAgIGxlbiA9IG51bV9hcmcoJnVzZXJfYnVmZmVyW2ldLCAxMCwgJnZhbHVlKTsKKwkJdGhyZWFkX2xvY2soKTsKKyAgICAgICAgICAgICAgICB0LT5tYXhfYmVmb3JlX3NvZnRpcnEgPSB2YWx1ZTsKKwkJdGhyZWFkX3VubG9jaygpOworICAgICAgICAgICAgICAgIHJldCA9IGNvdW50OworICAgICAgICAgICAgICAgIHNwcmludGYocGdfcmVzdWx0LCAiT0s6IG1heF9iZWZvcmVfc29mdGlycT0lbHUiLCB2YWx1ZSk7CisJCWdvdG8gb3V0OworCX0KKworCXJldCA9IC1FSU5WQUw7Cisgb3V0OgorCisJcmV0dXJuIHJldDsKK30KKworc3RhdGljIGludCBjcmVhdGVfcHJvY19kaXIodm9pZCkKK3sKKyAgICAgICAgaW50ICAgICBsZW47CisgICAgICAgIC8qICBkb2VzIHByb2NfZGlyIGFscmVhZHkgZXhpc3RzICovCisgICAgICAgIGxlbiA9IHN0cmxlbihQR19QUk9DX0RJUik7CisKKyAgICAgICAgZm9yIChwZ19wcm9jX2RpciA9IHByb2NfbmV0LT5zdWJkaXI7IHBnX3Byb2NfZGlyOyBwZ19wcm9jX2Rpcj1wZ19wcm9jX2Rpci0+bmV4dCkgeworICAgICAgICAgICAgICAgIGlmICgocGdfcHJvY19kaXItPm5hbWVsZW4gPT0gbGVuKSAmJgorCQkgICAgKCEgbWVtY21wKHBnX3Byb2NfZGlyLT5uYW1lLCBQR19QUk9DX0RJUiwgbGVuKSkpIAorICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIH0KKyAgICAgICAgCisgICAgICAgIGlmICghcGdfcHJvY19kaXIpIAorICAgICAgICAgICAgICAgIHBnX3Byb2NfZGlyID0gY3JlYXRlX3Byb2NfZW50cnkoUEdfUFJPQ19ESVIsIFNfSUZESVIsIHByb2NfbmV0KTsKKyAgICAgICAgCisgICAgICAgIGlmICghcGdfcHJvY19kaXIpIAorICAgICAgICAgICAgICAgIHJldHVybiAtRU5PREVWOworICAgICAgICAKKyAgICAgICAgcmV0dXJuIDA7Cit9CisKK3N0YXRpYyBpbnQgcmVtb3ZlX3Byb2NfZGlyKHZvaWQpCit7CisgICAgICAgIHJlbW92ZV9wcm9jX2VudHJ5KFBHX1BST0NfRElSLCBwcm9jX25ldCk7CisgICAgICAgIHJldHVybiAwOworfQorCisvKiBUaGluayBmaW5kIG9yIHJlbW92ZSBmb3IgTk4gKi8KK3N0YXRpYyBzdHJ1Y3QgcGt0Z2VuX2RldiAqX19wa3RnZW5fTk5fdGhyZWFkcyhjb25zdCBjaGFyKiBpZm5hbWUsIGludCByZW1vdmUpI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AorICovCitzdGF0aWMgdm9pZCBtb2RfY3VyX2hlYWRlcnMoc3RydWN0IHBrdGdlbl9kZXYgKnBrdF9kZXYpIHsgICAgICAgIAorICAgICAgICBfX3UzMiBpbW47CisgICAgICAgIF9fdTMyIGlteDsKKwlpbnQgIGZsb3cgPSAwOworCisJaWYocGt0X2Rldi0+Y2Zsb3dzKSAgeworCQlmbG93ID0gcGt0Z2VuX3JhbmRvbSgpICUgcGt0X2Rldi0+Y2Zsb3dzOworCQkKKwkJaWYgKHBrdF9kZXYtPmZsb3dzW2Zsb3ddLmNvdW50ID4gcGt0X2Rldi0+bGZsb3cpCisJCQlwa3RfZGV2LT5mbG93c1tmbG93XS5jb3VudCA9IDA7CisJfQkJCQkJCQorCisKKwkvKiAgRGVhbCB3aXRoIHNvdXJjZSBNQUMgKi8KKyAgICAgICAgaWYgKHBrdF9kZXYtPnNyY19tYWNfY291bnQgPiAxKSB7CisgICAgICAgICAgICAgICAgX191MzIgbWM7CisgICAgICAgICAgICAgICAgX191MzIgdG1wOworCisgICAgICAgICAgICAgICAgaWYgKHBrdF9kZXYtPmZsYWdzICYgRl9NQUNTUkNfUk5EKSAKKyAgICAgICAgICAgICAgICAgICAgICAgIG1jID0gcGt0Z2VuX3JhbmRvbSgpICUgKHBrdF9kZXYtPnNyY19tYWNfY291bnQpOworICAgICAgICAgICAgICAgIGVsc2UgeworICAgICAgICAgICAgICAgICAgICAgICAgbWMgPSBwa3RfZGV2LT5jdXJfc3JjX21hY19vZmZzZXQrKzsKKyAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwa3RfZGV2LT5jdXJfc3JjX21hY19vZmZzZXQgPiBwa3RfZGV2LT5zcmNfbWFjX2NvdW50KSAKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX3NyY19tYWNfb2Zmc2V0ID0gMDsKKyAgICAgICAgICAgICAgICB9CisKKyAgICAgICAgICAgICAgICB0bXAgPSBwa3RfZGV2LT5zcmNfbWFjWzVdICsgKG1jICYgMHhGRik7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbMTFdID0gdG1wOworICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5zcmNfbWFjWzRdICsgKChtYyA+PiA4KSAmIDB4RkYpICsgKHRtcCA+PiA4KSk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbMTBdID0gdG1wOworICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5zcmNfbWFjWzNdICsgKChtYyA+PiAxNikgJiAweEZGKSArICh0bXAgPj4gOCkpOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzldID0gdG1wOworICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5zcmNfbWFjWzJdICsgKChtYyA+PiAyNCkgJiAweEZGKSArICh0bXAgPj4gOCkpOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzhdID0gdG1wOworICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5zcmNfbWFjWzFdICsgKHRtcCA+PiA4KSk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbN10gPSB0bXA7ICAgICAgICAKKyAgICAgICAgfQorCisgICAgICAgIC8qICBEZWFsIHdpdGggRGVzdGluYXRpb24gTUFDICovCisgICAgICAgIGlmIChwa3RfZGV2LT5kc3RfbWFjX2NvdW50ID4gMSkgeworICAgICAgICAgICAgICAgIF9fdTMyIG1jOworICAgICAgICAgICAgICAgIF9fdTMyIHRtcDsKKworICAgICAgICAgICAgICAgIGlmIChwa3RfZGV2LT5mbGFncyAmIEZfTUFDRFNUX1JORCkgCisgICAgICAgICAgICAgICAgICAgICAgICBtYyA9IHBrdGdlbl9yYW5kb20oKSAlIChwa3RfZGV2LT5kc3RfbWFjX2NvdW50KTsKKworICAgICAgICAgICAgICAgIGVsc2UgeworICAgICAgICAgICAgICAgICAgICAgICAgbWMgPSBwa3RfZGV2LT5jdXJfZHN0X21hY19vZmZzZXQrKzsKKyAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwa3RfZGV2LT5jdXJfZHN0X21hY19vZmZzZXQgPiBwa3RfZGV2LT5kc3RfbWFjX2NvdW50KSB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmN1cl9kc3RfbWFjX29mZnNldCA9IDA7CisgICAgICAgICAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICAgfQorCisgICAgICAgICAgICAgICAgdG1wID0gcGt0X2Rldi0+ZHN0X21hY1s1XSArIChtYyAmIDB4RkYpOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzVdID0gdG1wOworICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5kc3RfbWFjWzRdICsgKChtYyA+PiA4KSAmIDB4RkYpICsgKHRtcCA+PiA4KSk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbNF0gPSB0bXA7CisgICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPmRzdF9tYWNbM10gKyAoKG1jID4+IDE2KSAmIDB4RkYpICsgKHRtcCA+PiA4KSk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbM10gPSB0bXA7CisgICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPmRzdF9tYWNbMl0gKyAoKG1jID4+IDI0KSAmIDB4RkYpICsgKHRtcCA+PiA4KSk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbMl0gPSB0bXA7CisgICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPmRzdF9tYWNbMV0gKyAodG1wID4+IDgpKTsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT5oaFsxXSA9IHRtcDsgICAgICAgIAorICAgICAgICB9CisKKyAgICAgICAgaWYgKHBrdF9kZXYtPnVkcF9zcmNfbWluIDwgcGt0X2Rldi0+dWRwX3NyY19tYXgpIHsKKyAgICAgICAgICAgICAgICBpZiAocGt0X2Rldi0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worCQl0ID0gdC0+bmV4dDsKKwl9CisgICAgICAgdGhyZWFkX3VubG9jaygpOworfQorCitzdGF0aWMgaW50IHRocmVhZF9pc19ydW5uaW5nKHN0cnVjdCBwa3RnZW5fdGhyZWFkICp0ICkKK3sKKyAgICAgICAgc3RydWN0IHBrdGdlbl9kZXYgKm5leHQ7CisgICAgICAgIGludCByZXMgPSAwOworCisgICAgICAgIGZvcihuZXh0PXQtPmlmX2xpc3Q7IG5leHQ7IG5leHQ9bmV4dC0+bmV4dCkgeyAKKwkJaWYobmV4dC0+cnVubmluZykgeworCQkJcmVzID0gMTsKKwkJCWJyZWFrOworCQl9CisgICAgICAgIH0KKyAgICAgICAgcmV0dXJuIHJlczsKK30KKworc3RhdGljIGludCBwa3RnZW5fd2FpdF90aHJlYWRfcnVuKHN0cnVjdCBwa3RnZW5fdGhyZWFkICp0ICkKK3sKKyAgICAgICAgaWZfbG9jayh0KTsKKworICAgICAgICB3aGlsZSh0aHJlYWRfaXNfcnVubmluZyh0KSkgeworCisgICAgICAgICAgICAgICAgaWZfdW5sb2NrKHQpOworCisJCW1zbGVlcF9pbnRlcnJ1cHRpYmxlKDEwMCk7IAorCisgICAgICAgICAgICAgICAgaWYgKHNpZ25hbF9wZW5kaW5nKGN1cnJlbnQpKSAKKyAgICAgICAgICAgICAgICAgICAgICAgIGdvdG8gc2lnbmFsOworICAgICAgICAgICAgICAgIGlmX2xvY2sodCk7CisgICAgICAgIH0KKyAgICAgICAgaWZfdW5sb2NrKHQpOworICAgICAgICByZXR1cm4gMTsKKyBzaWduYWw6CisgICAgICAgIHJldHVybiAwOworfQorCitzdGF0aWMgaW50IHBrdGdlbl93YWl0X2FsbF90aHJlYWRzX3J1bih2b2lkKQoreworCXN0cnVjdCBwa3RnZW5fdGhyZWFkICp0ID0gcGt0Z2VuX3RocmVhZHM7CisJaW50IHNpZyA9IDE7CisJCisJd2hpbGUgKHQpIHsKKwkJc2lnID0gcGt0Z2VuX3dhaXRfdGhyZWFkX3J1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dF9kZXYtPnN0YXJ0ZWRfYXQ7CisKKyAgICAgICBpZGxlID0gcGt0X2Rldi0+aWRsZV9hY2M7CisKKyAgICAgICBwICs9IHNwcmludGYocCwgIk9LOiAlbGx1KGMlbGx1K2QlbGx1KSB1c2VjLCAlbGx1ICglZGJ5dGUsJWRmcmFncylcbiIsCisgICAgICAgICAgICAgICAgICAgICh1bnNpZ25lZCBsb25nIGxvbmcpIHRvdGFsX3VzLCAKKwkJICAgICh1bnNpZ25lZCBsb25nIGxvbmcpKHRvdGFsX3VzIC0gaWRsZSksIAorCQkgICAgKHVuc2lnbmVkIGxvbmcgbG9uZykgaWRsZSwKKyAgICAgICAgICAgICAgICAgICAgKHVuc2lnbmVkIGxvbmcgbG9uZykgcGt0X2Rldi0+c29mYXIsIAorCQkgICAgcGt0X2Rldi0+Y3VyX3BrdF9zaXplLCBucl9mcmFncyk7CisKKyAgICAgICBwcHMgPSBwa3RfZGV2LT5zb2ZhciAqIFVTRUNfUEVSX1NFQzsKKworICAgICAgIHdoaWxlICgodG90YWxfdXMgPj4gMzIpICE9IDApIHsKKyAgICAgICAgICAgICAgIHBwcyA+Pj0gMTsKKyAgICAgICAgICAgICAgIHRvdGFsX3VzID4+PSAxOworICAgICAgIH0KKworICAgICAgIGRvX2RpdihwcHMsIHRvdGFsX3VzKTsKKyAgICAgICAKKyAgICAgICBicHMgPSBwcHMgKiA4ICogcGt0X2Rldi0+Y3VyX3BrdF9zaXplOworCisgICAgICAgbWJwcyA9IGJwczsKKyAgICAgICBkb19kaXYobWJwcywgMTAwMDAwMCk7CisgICAgICAgcCArPSBzcHJpbnRmKHAsICIgICVsbHVwcHMgJWxsdU1iL3NlYyAoJWxsdWJwcykgZXJyb3JzOiAlbGx1IiwKKyAgICAgICAgICAgICAgICAgICAgKHVuc2lnbmVkIGxvbmcgbG9uZykgcHBzLCAKKwkJICAgICh1bnNpZ25lZCBsb25nIGxvbmcpIG1icHMsIAorCQkgICAgKHVuc2lnbmVkIGxvbmcg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AgICAgICAgICAgICAgICAgICAgc2lnbWFzayhTSUdLSUxMKSB8IAorICAgICAgICAgICAgICAgICAgICAgIHNpZ21hc2soU0lHU1RPUCl8IAorICAgICAgICAgICAgICAgICAgICAgIHNpZ21hc2soU0lHVEVSTSkpOworCisgICAgICAgIHJlY2FsY19zaWdwZW5kaW5nKCk7CisgICAgICAgIHNwaW5fdW5sb2NrX2lycSgmY3VycmVudC0+c2lnaGFuZC0+c2lnbG9jayk7CisKKwkvKiBNaWdyYXRlIHRvIHRoZSByaWdodCBDUFUgKi8KKwlzZXRfY3B1c19hbGxvd2VkKGN1cnJlbnQsIGNwdW1hc2tfb2ZfY3B1KGNwdSkpOworICAgICAgICBpZiAoc21wX3Byb2Nlc3Nvcl9pZCgpICE9IGNwdSkKKyAgICAgICAgICAgICAgICBCVUcoKTsKKworCWluaXRfd2FpdHF1ZXVlX2hlYWQoJnQtPnF1ZXVlKTsKKworCXQtPmNvbnRyb2wgJj0gfihUX1RFUk1JTkFURSk7CisJdC0+Y29udHJvbCAmPSB+KFRfUlVOKTsKKwl0LT5jb250cm9sICY9IH4oVF9TVE9QKTsKKwl0LT5jb250cm9sICY9IH4oVF9SRU1ERVYpOworCisgICAgICAgIHQtPnBpZCA9IGN1cnJlbnQtPnBpZDsgICAgICAgIAorCisgICAgICAgIFBHX0RFQlVHKHByaW50aygicGt0Z2VuOiBzdGFydGluZyBwa3RnZW4vJWQ6ICBwaWQ9JWRcbiIsIGNwdSwgY3VycmVudC0+cGlkKSk7CisKKwltYXhfYmVmb3JlX3NvZnRpcnEgPSB0LT5tYXhfYmVmb3JlX3NvZnRpcnE7CisgICAgICAgIAorICAgICAgICBfX3NldF9jdXJyZW50X3N0YXRlKFRBU0tfSU5URVJSVVBUSUJMRSk7CisgICAgICAgIG1iKCk7CisKKyAgICAgICAgd2hpbGUgKDEpIHsKKwkJCisJCV9fc2V0X2N1cnJlbnRfc3RhdGUoVEFTS19SVU5OSU5HKTsKKworCQkvKgorCQkgKiBHZ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gaWZfbG9jayh0KTsKKworICAgICAgICBmb3IocGt0X2Rldj10LT5pZl9saXN0OyBwa3RfZGV2OyBwa3RfZGV2ID0gcGt0X2Rldi0+bmV4dCApIHsKKyAgICAgICAgICAgICAgICBpZiAoc3RyY21wKHBrdF9kZXYtPmlmbmFtZSwgaWZuYW1lKSA9PSAwKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICB9CisgICAgICAgIH0KKworICAgICAgICBpZl91bmxvY2sodCk7CisJUEdfREVCVUcocHJpbnRrKCJwa3RnZW46IGZpbmRfZGV2KCVzKSByZXR1cm5pbmcgJXBcbiIsIGlmbmFtZSxwa3RfZGV2KSk7CisgICAgICAgIHJldHVybiBwa3RfZGV2OworfQorCisvKiAKKyAqIEFkZHMgYSBkZXYgYXQgZnJvbnQgb2YgaWZfbGlzdC4gCisgKi8KKworc3RhdGljIGludCBhZGRfZGV2X3RvX3RocmVhZChzdHJ1Y3QgcGt0Z2VuX3RocmVhZCAqdCwgc3RydWN0IHBrdGdlbl9kZXYgKnBrdF9kZXYpIAoreworCWludCBydiA9IDA7CisJCisgICAgICAgIGlmX2xvY2sodCk7CisKKyAgICAgICAgaWYgKHBrdF9kZXYtPnBnX3RocmVhZCkgeworICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogIGFscmVhZHkgYXNzaWduZWQgdG8gYSB0aHJlYWQuXG4iKTsKKyAgICAgICAgICAgICAgICBydiA9IC1FQlVTWTsKKyAgICAgICAgICAgICAgICBnb3RvIG91dDsKKyAgICAgICAgfQorCXBrdF9kZXYtPm5leHQgPXQtPmlmX2xpc3Q7IHQtPmlmX2xpc3Q9cGt0X2RldjsKKyAgICAgICAgcGt0X2Rldi0+cGdfdGhyZWFkID0gdDsKKwlwa3RfZGV2LT5ydW5uaW5nID0gMDsKKworIG91dDoKKyAgICAgICAgaWZfdW5sb2NrKHQpOyAgICAgICAgCisgICAgICAgIHJldHVybiBydjsKK30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ID0gMDsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT5jbG9uZV9za2IgPSBwZ19jbG9uZV9za2JfZDsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT5kZWxheV91cyA9IHBnX2RlbGF5X2QgLyAxMDAwOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPmRlbGF5X25zID0gcGdfZGVsYXlfZCAlIDEwMDA7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y291bnQgPSBwZ19jb3VudF9kOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPnNvZmFyID0gMDsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfc3JjX21pbiA9IDk7IC8qIHNpbmsgcG9ydCAqLworICAgICAgICAgICAgICAgIHBrdF9kZXYtPnVkcF9zcmNfbWF4ID0gOTsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfZHN0X21pbiA9IDk7CisgICAgICAgICAgICAgICAgcGt0X2Rldi0+dWRwX2RzdF9tYXggPSA5OworCisgICAgICAgICAgICAgICAgc3RybmNweShwa3RfZGV2LT5pZm5hbWUsIGlmbmFtZSwgMzEpOworICAgICAgICAgICAgICAgIHNwcmludGYocGt0X2Rldi0+Zm5hbWUsICJuZXQvJXMvJXMiLCBQR19QUk9DX0RJUiwgaWZuYW1lKTsKKworICAgICAgICAgICAgICAgIGlmICghIHBrdGdlbl9zZXR1cF9kZXYocGt0X2RldikpIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogcGt0Z2VuX3NldHVwX2RldiBmYWlsZWQuXG4iKTsKKwkJCWlmIChwa3RfZGV2LT5mbG93cykKKwkJCQl2ZnJlZShwa3RfZGV2LT5mbG93cyk7CisgICAgICAgICAgICAgICAgICAgICAgICBrZnJlZShwa3RfZGV2KTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRU5PREVWOworICAgICAgICAgICAgICAgIH0KKworICAgICAgICAgICAgICAgIHBrdF9kZXYtPnByb2NfZW50ID0gY3JlYXRlX3Byb2NfZW50cnkocGt0X2Rldi0+Zm5hbWUsIDA2MDAsIE5VTEwpOworICAgICAgICAgICAgICAgIGlmICghcGt0X2Rldi0+cHJvY19lbnQpIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBjYW5ub3QgY3JlYXRlICVzIHByb2NmcyBlbnRyeS5cbiIsIHBrdF9kZXYtPmZuYW1lKTsKKwkJCWlmIChwa3RfZGV2LT5mbG93cykKKwkJCQl2ZnJlZShwa3RfZGV2LT5mbG93cyk7CisgICAgICAgICAgICAgICAgICAgICAgICBrZnJlZShwa3RfZGV2KTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUlOVkFMOworICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICBwa3RfZGV2LT5wcm9jX2VudC0+cmVhZF9wcm9jID0gcHJvY19pZl9yZWFkOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPnByb2NfZW50LT53cml0ZV9wcm9jID0gcHJvY19pZl93cml0ZTsKKyAgICAgICAgICAgICAgICBwa3RfZGV2LT5wcm9jX2VudC0+ZGF0YSA9ICh2b2lkKikocGt0X2Rldik7CisJCXBrdF9kZXYtPnByb2NfZW50LT5vd25lciA9IFRISVNfTU9EVUxFOworCisgICAgICAgICAgICAgICAgcmV0dXJuIGFkZF9kZXZfdG9fdGhyZWFkKHQsIHBrdF9kZXYpOworICAgICAgICB9CisgICAgICAgIGVsc2UgeworICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogaW50ZXJmYWNlIGFscmVhZHkgdXNlZC5cbiIpOworICAgICAgICAgICAgICAgIHJldHVybiAtRUJVU1k7CisgICAgICAgIH0KK30KKworc3RhdGljIHN0cnVjdCBwa3RnZW5fdGhyZWFkICpwa3RnZW5fZmluZF90aHJlYWQoY29uc3QgY2hhciogbmFtZSkgCit7CisgICAgICAgIHN0cnVjdCBwa3RnZW5fdGhyZWFkICp0ID0gTlVMTDsKKworICAgICAgIHRocmVhZF9sb2NrKCk7CisKKyAgICAgICAgdCA9IHBrdGdlbl90aHJlYWRzOworICAgICAgICB3aGlsZSAodCkgeworICAgICAgICAgICAgICAgIGlmIChzdHJjbXAodC0+bmFtZSwgbmFtZSkgPT0gMCkgCisgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKworICAgICAgICAgICAgICAgIHQgPSB0LT5uZXh0OworICAgICAgICB9CisgICAgICAgIHRocmVhZF91bmxvY2soKTsKKyAgICAgICAgcmV0dXJuIHQ7Cit9CisKK3N0YXRpYyBpbnQgcGt0Z2VuX2NyZWF0ZV90aHJlYWQoY29uc3QgY2hhciogbmFtZSwgaW50IGNwdSkgCit7CisgICAgICAgIHN0cnVjdCBwa3RnZW5fdGhyZWFkICp0ID0gTlVMTDsKKworICAgICAgICBpZiAoc3RybGVuKG5hbWUpID4gMzEpIHsKKyAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogRVJST1I6ICBUaHJlYWQgbmFtZSBjYW5ub3QgYmUgbW9yZSB0aGFuIDMxIGNoYXJhY3RlcnMuXG4iKTsKKyAgICAgICAgICAgICAgICByZXR1cm4gLUVJTlZBTDsKKyAgICAgICAgfQorICAgICAgICAKKyAgICAgICAgaWYgKHBrdGdlbl9maW5kX3RocmVhZChuYW1lKSkgeworICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogdGhyZWFkOiAlcyBhbHJlYWR5IGV4aXN0c1xuIiwgbmFtZSk7CisgICAgICAgICAgICAgICAgcmV0dXJuIC1FSU5WQUw7CisgICAgICAgIH0KKworICAgICAgICB0ID0gKHN0cnVjdCBwa3RnZW5fdGhyZWFkKikoa21hbGxvYyhzaXplb2Yoc3RydWN0IHBrdGdlbl90aHJlYWQpLCBHRlBfS0VSTkVMKSk7CisgICAgICAgIGlmICghdCkgeworICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogb3V0IG9mIG1lbW9yeSwgY2FuJ3QgY3JlYXRlIG5ldyB0aHJlYWQuXG4iKTsKKyAgICAgICAgICAgICAgICByZXR1cm4gLUVOT01FTTsKKyAgICAgICAgfQorCisgICAgICAgIG1lbXNldCh0LCAwLCBzaXplb2Yoc3RydWN0IHBrdGdlbl90aHJlYWQpKTsKKyAgICAgICAgc3RyY3B5KHQtPm5hbWUsIG5hbWUpOworICAgICAgICBzcGluX2xvY2tfaW5pdCgmdC0+aWZfbG9jayk7CisJdC0+Y3B1ID0gY3B1OworICAgICAgICAKKyAgICAgICAgc3ByaW50Zih0LT5mbmFtZSwgIm5ldC8lcy8lcyIsIFBHX1BST0NfRElSLCB0LT5uYW1lKTsKKyAgICAgICAgdC0+cHJvY19lbnQgPSBjcmVhdGVfcHJvY19lbnRyeSh0LT5mbmFtZSwgMDYwMCwgTlVMTCk7CisgICAgICAgIGlmICghdC0+cHJvY19lbnQpIHsKKyAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogY2Fubm90IGNyZWF0ZSAlcyBwcm9jZnMgZW50cnkuXG4iLCB0LT5mbmFtZSk7CisgICAgICAgICAgICAgICAga2ZyZWUodCk7CisgICAgICAgICAgICAgICAgcmV0dXJuIC1FSU5WQUw7CisgICAgICAgIH0KKyAgICAgICAgdC0+cHJvY19lbnQtPnJlYWRfcHJvYyA9IHByb2NfdGhyZWFkX3JlYWQ7CisgICAgICAgIHQtPnByb2NfZW50LT53cml0ZV9wcm9jID0gcHJvY190aHJlYWRfd3JpdGU7CisgICAgICAgIHQtPnByb2NfZW50LT5kYXRhID0gKHZvaWQqKSh0KTsKKyAgICAgICAgdC0+cHJvY19lbnQtPm93bmVyID0gVEhJU19NT0RVTEU7CisKKyAgICAgICAgdC0+bmV4dCA9IHBrdGdlbl90aHJlYWRzOworICAgICAgICBwa3RnZW5fdGhyZWFkcyA9IHQ7CisKKwlpZiAoa2VybmVsX3RocmVhZCgodm9pZCAqKSBwa3RnZW5fdGhyZWFkX3d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nZW5fc3RvcF9kZXZpY2UocGt0X2Rldik7CisgICAgICAgIH0KKyAgICAgICAgCisgICAgICAgIC8qIERpcy1hc3NvY2lhdGUgZnJvbSB0aGUgaW50ZXJmYWNlICovCisKKwlpZiAocGt0X2Rldi0+b2RldikgeworCQlkZXZfcHV0KHBrdF9kZXYtPm9kZXYpOworICAgICAgICAgICAgICAgIHBrdF9kZXYtPm9kZXYgPSBOVUxMOworICAgICAgICB9CisgICAgICAgIAorCS8qIEFuZCB1cGRhdGUgdGhlIHRocmVhZCBpZl9saXN0ICovCisKKwlfcmVtX2Rldl9mcm9tX2lmX2xpc3QodCwgcGt0X2Rldik7CisKKyAgICAgICAgLyogQ2xlYW4gdXAgcHJvYyBmaWxlIHN5c3RlbSAqLworCisgICAgICAgIGlmIChzdHJsZW4ocGt0X2Rldi0+Zm5hbWUpKSAKKyAgICAgICAgICAgICAgICByZW1vdmVfcHJvY19lbnRyeShwa3RfZGV2LT5mbmFtZSwgTlVMTCk7CisKKwlpZiAocGt0X2Rldi0+Zmxvd3MpCisJCXZmcmVlKHBrdF9kZXYtPmZsb3dzKTsKKwlrZnJlZShwa3RfZGV2KTsKKyAgICAgICAgcmV0dXJuIDA7Cit9CisKK3N0YXRpYyBpbnQgX19pbml0IHBnX2luaXQodm9pZCkgCit7CisJaW50IGNwdTsKKwlwcmludGsodmVyc2lvbik7CisKKyAgICAgICAgbW9kdWxlX2ZuYW1lWzBdID0gMDsKKworCWNyZWF0ZV9wcm9jX2RpcigpOworCisgICAgICAgIHNwcmludGYobW9kdWxlX2ZuYW1lLCAibmV0LyVzL3BnY3RybCIsIFBHX1BST0NfRElSKTsKKyAgICAgICAgbW9kdWxlX3Byb2NfZW50ID0gY3JlYXRlX3Byb2NfZW50cnkobW9kdWxlX2ZuYW1lLCAwNjAwLCBOVUxMKTsKKyAgICAgICAgaWYgKCFtb2R1bGVfcHJvY19lbnQpIHsKKyAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogRVJST1I6IG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c2stPnNrX3R5cGU7CQkgIAkJCisJCQlicmVhazsKKworCQljYXNlIFNPX0VSUk9SOgorCQkJdi52YWwgPSAtc29ja19lcnJvcihzayk7CisJCQlpZih2LnZhbD09MCkKKwkJCQl2LnZhbCA9IHhjaGcoJnNrLT5za19lcnJfc29mdCwgMCk7CisJCQlicmVhazsKKworCQljYXNlIFNPX09PQklOTElORToKKwkJCXYudmFsID0gISFzb2NrX2ZsYWcoc2ssIFNPQ0tfVVJHSU5MSU5FKTsKKwkJCWJyZWFrOworCQorCQljYXNlIFNPX05PX0NIRUNLOgorCQkJdi52YWwgPSBzay0+c2tfbm9fY2hlY2s7CisJCQlicmVhazsKKworCQljYXNlIFNPX1BSSU9SSVRZOgorCQkJdi52YWwgPSBzay0+c2tfcHJpb3JpdHk7CisJCQlicmVhazsKKwkJCisJCWNhc2UgU09fTElOR0VSOgkKKwkJCWx2CQk9IHNpemVvZih2LmxpbmcpOworCQkJdi5saW5nLmxfb25vZmYJPSAhIXNvY2tfZmxhZyhzaywgU09DS19MSU5HRVIpOworIAkJCXYubGluZy5sX2xpbmdlcgk9IHNrLT5za19saW5nZXJ0aW1lIC8gSFo7CisJCQlicmVhazsKKwkJCQkJCisJCWNhc2UgU09fQlNEQ09NUEFUOgorCQkJc29ja193YXJuX29ic29sZXRlX2JzZGlzbSgiZ2V0c29ja29wdCIpOworCQkJYnJlYWs7CisKKwkJY2FzZSBTT19USU1FU1RBTVA6CisJCQl2LnZhbCA9IHNvY2tfZmxhZyhzaywgU09DS19SQ1ZUU1RBTVApOworCQkJYnJlYWs7CisKKwkJY2FzZSBTT19SQ1ZUSU1FTzoKKwkJCWx2PXNpemVvZihzdHJ1Y3QgdGltZXZhbCk7CisJCQlpZiAoc2stPnNrX3JjdnRpbWVvID09IE1BWF9TQ0hFRFVMRV9USU1FT1VUKSB7CisJCQkJdi50bS50dl9zZWMgPSAwOworCQkJCXYudG0udHZfdXNlYyA9IDA7CisJCQl9IGVsc2UgeworCQkJCXYudG0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ID0gLTFMOworCisJYXRvbWljX3NldCgmc2stPnNrX3JlZmNudCwgMSk7Cit9CisKK3ZvaWQgZmFzdGNhbGwgbG9ja19zb2NrKHN0cnVjdCBzb2NrICpzaykKK3sKKwltaWdodF9zbGVlcCgpOworCXNwaW5fbG9ja19iaCgmKHNrLT5za19sb2NrLnNsb2NrKSk7CisJaWYgKHNrLT5za19sb2NrLm93bmVyKQorCQlfX2xvY2tfc29jayhzayk7CisJc2stPnNrX2xvY2sub3duZXIgPSAodm9pZCAqKTE7CisJc3Bpbl91bmxvY2tfYmgoJihzay0+c2tfbG9jay5zbG9jaykpOworfQorCitFWFBPUlRfU1lNQk9MKGxvY2tfc29jayk7CisKK3ZvaWQgZmFzdGNhbGwgcmVsZWFzZV9zb2NrKHN0cnVjdCBzb2NrICpzaykKK3sKKwlzcGluX2xvY2tfYmgoJihzay0+c2tfbG9jay5zbG9jaykpOworCWlmIChzay0+c2tfYmFja2xvZy50YWlsKQorCQlfX3JlbGVhc2Vfc29jayhzayk7CisJc2stPnNrX2xvY2sub3duZXIgPSBOVUxMOworICAgICAgICBpZiAod2FpdHF1ZXVlX2FjdGl2ZSgmKHNrLT5za19sb2NrLndxKSkpCisJCXdha2VfdXAoJihzay0+c2tfbG9jay53cSkpOworCXNwaW5fdW5sb2NrX2JoKCYoc2stPnNrX2xvY2suc2xvY2spKTsKK30KK0VYUE9SVF9TWU1CT0wocmVsZWFzZV9zb2NrKTsKKworaW50IHNvY2tfZ2V0X3RpbWVzdGFtcChzdHJ1Y3Qgc29jayAqc2ssIHN0cnVjdCB0aW1ldmFsIF9fdXNlciAqdXNlcnN0YW1wKQoreyAKKwlpZiAoIXNvY2tfZmxhZyhzaywgU09DS19USU1FU1RBTVApKQorCQlzb2NrX2VuYWJsZV90aW1lc3RhbXAoc2spOworCWlmIChzay0+c2tfc3RhbXAudHZfc2VjID09IC0xKSAKKwkJcmV0dXJuIC1FTk9FTlQ7CisJaWYgKHNrLT5za19zdGFtcC50dl9zZWMg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kgIHZtX3dhaXQpOworCQlzay0+c2tfd3JpdGVfcGVuZGluZy0tOworCisJCWlmICh2bV93YWl0KSB7CisJCQl2bV93YWl0IC09IGN1cnJlbnRfdGltZW87CisJCQljdXJyZW50X3RpbWVvID0gKnRpbWVvX3A7CisJCQlpZiAoY3VycmVudF90aW1lbyAhPSBNQVhfU0NIRURVTEVfVElNRU9VVCAmJgorCQkJICAgIChjdXJyZW50X3RpbWVvIC09IHZtX3dhaXQpIDwgMCkKKwkJCQljdXJyZW50X3RpbWVvID0gMDsKKwkJCXZtX3dhaXQgPSAwOworCQl9CisJCSp0aW1lb19wID0gY3VycmVudF90aW1lbzsKKwl9CitvdXQ6CisJZmluaXNoX3dhaXQoc2stPnNrX3NsZWVwLCAmd2FpdCk7CisJcmV0dXJuIGVycjsKKworZG9fZXJyb3I6CisJZXJyID0gLUVQSVBFOworCWdvdG8gb3V0OworZG9fbm9uYmxvY2s6CisJZXJyID0gLUVBR0FJTjsKKwlnb3RvIG91dDsKK2RvX2ludGVycnVwdGVkOgorCWVyciA9IHNvY2tfaW50cl9lcnJubygqdGltZW9fcCk7CisJZ290byBvdXQ7Cit9CisKK0VYUE9SVF9TWU1CT0woc2tfc3RyZWFtX3dhaXRfbWVtb3J5KTsKKwordm9pZCBza19zdHJlYW1fcmZyZWUoc3RydWN0IHNrX2J1ZmYgKnNrYikKK3sKKwlzdHJ1Y3Qgc29jayAqc2sgPSBza2ItPnNrOworCisJYXRvbWljX3N1Yihza2ItPnRydWVzaXplLCAmc2stPnNrX3JtZW1fYWxsb2MpOworCXNrLT5za19mb3J3YXJkX2FsbG9jICs9IHNrYi0+dHJ1ZXNpemU7Cit9CisKK0VYUE9SVF9TWU1CT0woc2tfc3RyZWFtX3JmcmVlKTsKKworaW50IHNrX3N0cmVhbV9lcnJvcihzdHJ1Y3Qgc29jayAqc2ssIGludCBmbGFncywgaW50IGVycikKK3sKKwlpZiAoZXJyID09IC1FUElQRSkKKwkJZXJyID0gc29ja19lcnJvc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bmRsZXIgaGFuZGxpbmcKKyAqLworCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKiogSU5DTFVERVMgKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCisKKyNpbmNsdWRlIDxsaW51eC9jb25maWcuaD4JCS8qIE5vdCBuZWVkZWQgPz8/ICovCisjaW5jbHVkZSA8bGludXgvbW9kdWxlLmg+CisjaW5jbHVkZSA8bGludXgvdHlwZXMuaD4JCS8qIG9mZl90ICovCisjaW5jbHVkZSA8bGludXgvbmV0ZGV2aWNlLmg+CQkvKiBzdHJ1Y3QgaWZyZXEsIGRldl9nZXRfYnlfbmFtZSgpICovCisjaW5jbHVkZSA8bGludXgvcHJvY19mcy5oPgorI2luY2x1ZGUgPGxpbnV4L3J0bmV0bGluay5oPgkJLyogcnRuZXRsaW5rIHN0dWZmICovCisjaW5jbHVkZSA8bGludXgvc2VxX2ZpbGUuaD4KKyNpbmNsdWRlIDxsaW51eC9pbml0Lmg+CQkJLyogZm9yIF9faW5pdCAqLworI2luY2x1ZGUgPGxpbnV4L2lmX2FycC5oPgkJLyogQVJQSFJEX0VUSEVSICovCisKKyNpbmNsdWRlIDxsaW51eC93aXJlbGVzcy5oPgkJLyogUHJldHR5IG9idmlvdXMgKi8KKyNpbmNsdWRlIDxuZXQvaXdfaGFuZGxlci5oPgkJLyogTmV3IGRyaXZlciBBUEkgKi8KKworI2luY2x1ZGUgPGFzbS91YWNjZXNzLmg+CQkvKiBjb3B5X3RvX3VzZXIoKSAqLworCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKiBDT05TVEFOVFMgKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KKworLyogRGVidWdnaW5nIHN0dWZmICovCisjdW5kZWYgV0VfSU9DVExfREVCVUcJCS8qIERlYnVnIElPQ1RMIEFQSSAqLworI3VuZGVmIFdFX0VWRU5UX0RFQlVHCQkvKiBEZWJ1ZyBFdmVudCBkaXNwYXRjaGVyICovCisjdW5kZWYgV0VfU1BZX0RFQ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