ZGlmZiAtLWdpdCBhL2FwL2FwcC9jY2FwcC9zb2Z0X3RpbWVyLmMgYi9hcC9hcHAvY2NhcHAvc29mdF90aW1lci5jCm5ldyBmaWxlIG1vZGUgMTAwNjQ0CmluZGV4IDAwMDAwMDAuLjUwMzJmMmYKLS0tIC9kZXYvbnVsbAorKysgYi9hcC9hcHAvY2NhcHAvc29mdF90aW1lci5jCkBAIC0wLDAgKzEsNDkzIEBACisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCisqILDmyKjL+dPQIChDKTIwMDgsIMnu29rK0NbQ0MvNqNG2ucm33dPQz965q8u+oaMKKyogCisqIM7EvP7D+7PGo7ogc29mdF90aW1lci5jCisqIM7EvP6x6sq2o7ogCisqIMTayN3VqtKqo7ogtqjS5c2o08O1xMjtvP62qMqxxvfP37PMv+IKKyogxuTL/Mu1w/ejuiAKKyogtbHHsLDmsb6juiBWMS4wCisqINf3ICAgINXfo7og1qPT8ebDCisqIM3qs8nI1cbao7ogMjAxMC0wOS0wMgorKiAKKyog0N64xLzHwrwxo7oKKyogICAg0N64xMjVxtqjujIwMTAtMDktMDIKKyogICAgsOYgsb4gusWjulYxLjAKKyogICAg0N4guMQgyMujutaj0/HmwworKiAgICDQ3rjExNrI3aO6s/XKvLDmsb4KKyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KKyNpbmNsdWRlICA8c3RkaW8uaD4KKyNpbmNsdWRlICA8c3RkbGliLmg+CisjaW5jbHVkZSAgPHNpZ25hbC5oPgorI2luY2x1ZGUgIDxzeXMvdGltZS5oPgorI2luY2x1ZGUgIDxzeXNsb2cuaD4KKyNpbmNsdWRlIDxmY250bC5oPgorI2luY2x1ZGUgIDxwdGhyZWFkLmg+CisjaW5jbHVkZSA8c3RkbGliLmg+CisjaW5jbHVkZSA8c3RyaW5nLmg+CisjaW5jbHVkZSA8ZXJybm8uaD4KKyNpbmNsdWRlICAic29mdF90aW1lci5oIgorCisvKgorI2RlZmluZSBTT0ZUX1RJTUVSX0RFQlVHIDEKKyovCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIE1hY3JvIGRlY2xhcmF0aW9uCisgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KKyNkZWZpbmUgTkVXX1RJTUVSX1NURVAgMTAKKyNkZWZpbmUgTUFYX1RJTUVSX1BPT0xfTlVNICAzMworCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIHN0YXRpYyB2YXJpYWJsZXMKKyAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworc3RhdGljIFNPRlRfVElNRVIgZ190aW1lcl9wb29sW01BWF9USU1FUl9QT09MX05VTV0gPSB7MH07CitzdGF0aWMgU09GVF9USU1FUiAqZ19wVGltZXJIZWFkZXIgPSBOVUxMOworc3RhdGljIGludCBnX3RpbWVyX2luaXRpYWxpemVkID0gMDsKKworcHRocmVhZF9tdXRleF90IGdfdGltZXJfbXV0ZXggPSBQVEhSRUFEX01VVEVYX0lOSVRJQUxJWkVSOworCitzdGF0aWMgdm9pZCogU29mdFRpbWVyX0xvb3Aodm9pZCAqYXJncyk7CisKKy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgorICogU29mdFRpbWVyX0luaXQKKyAqIGluaXRpYWxpemUgZ2xvYmFsIHZhcmlhYmxlcworICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCitzdGF0aWMgaW50IFNvZnRUaW1lcl9Jbml0KHZvaWQpCit7CisgICAgaW50ICByZXN1bHQgPSAwOworICAgIHB0aHJlYWRfYXR0cl90IGF0dHJpYnV0ZTsKKyAgICBwdGhyZWFkX3Qgc3RIYW5kbGU7CisKKyAgICBpZigwID09IGdfdGltZXJfaW5pdGlhbGl6ZWQpCisgICAgeworICAgICAgICBnX3RpbWVyX2luaXRpYWxpemVkID0gMTsKKworICAgICAgICBwdGhyZWFkX2F0dHJfaW5pdCgmYXR0cmlidXRlKTsKKyAgICAgICAgcHRocmVhZF9hdHRyX3NldHN0YWNrc2l6ZSgmYXR0cmlidXRlLCAzMioxMDI0KTsKKworCQkjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgICAgICBwcmludGYoIkNyZWF0ZSBzb2Z0IHRpbWVyIGZpcnN0IHRpbWUsIG11c3QgY3JlYXRlIGEgdGhyZWFkIG5vdyFcbiIpOworCQkjZW5kaWYKKyAgICAgICAgcmVzdWx0ID0gcHRocmVhZF9jcmVhdGUoJnN0SGFuZGxlLCAmYXR0cmlidXRlLCBTb2Z0VGltZXJfTG9vcCwgTlVMTCk7CisgICAgICAgIGlmKDAgIT0gcmVzdWx0KQorICAgICAgICB7CisJCSAgICAjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgICAgICAgICAgcHJpbnRmKCJTdGFydFNvZnRUaW1lciBmYWlsZWQsIGNyZWF0ZSB0aHJlYWQgZmFpbCAlZCFcbiIsIHJlc3VsdCk7CisJCQkjZW5kaWYKKyAgICAgICAgICAgIHJldHVybiBFUlJPUjsKKyAgICAgICAgfQorCisgICAgICAgIGdfcFRpbWVySGVhZGVyID0gJmdfdGltZXJfcG9vbFswXTsKKyAgICAgICAgZ19wVGltZXJIZWFkZXItPm5leHQgPSBnX3BUaW1lckhlYWRlcjsKKyAgICAgICAgZ19wVGltZXJIZWFkZXItPnByZXYgPSBnX3BUaW1lckhlYWRlcjsKKyAgICAgICAgZ19wVGltZXJIZWFkZXItPnVzZWQgPSAxOworICAgIH0KKworICAgIHJldHVybiBPSzsKK30KKworLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCisgKiBTZXRCYXNpY1RpbWVyRXgKKyAqIGNhbGwgW3NldGl0aW1lcl0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qKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIFNvZnRUaW1lcl9BZGQKKyAqIGFkZCBhIHNvZnQgdGltZXIgdG8gZG91YmxlIGxpbmtlZCBsaXN0CisgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KK3N0YXRpYyBpbnQgU29mdFRpbWVyX0FkZChTT0ZUX1RJTUVSICpwSGVhZGVyLCBTT0ZUX1RJTUVSICpwSXRlbSkKK3sKKyAgICBTT0ZUX1RJTUVSICpwVG1wID0gcEhlYWRlcjsKKworICAgIGlmKE5VTEwgPT0gcEhlYWRlciB8fCBOVUxMID09IHBJdGVtKQorICAgIHsKKyAgICAgICAgcmV0dXJuIC0xOworICAgIH0KKworICAgIGRvCisgICAgeworICAgICAgICBpZihwVG1wLT50aW1lclZhbHVlIDw9IHBJdGVtLT50aW1lclZhbHVlKQorICAgICAgICB7CisgICAgICAgICAgICBwVG1wID0gcFRtcC0+bmV4dDsKKyAgICAgICAgfQorICAgICAgICBlbHNlCisgICAgICAgIHsKKyAgICAgICAgICAgIGJyZWFrOworICAgICAgICB9CisgICAgfSB3aGlsZShwVG1wICE9IHBIZWFkZXIpOworCisgICAgaWYocFRtcCAhPSBwSGVhZGVyKQorICAgIHsKKyAgICAgICAgcEl0ZW0tPm5leHQgPSBwVG1wOworICAgICAgICBwSXRlbS0+cHJldiA9IHBUbXAtPnByZXY7CisgICAgICAgIHBUbXAtPnByZXYtPm5leHQgPSBwSXRlbTsKKyAgICAgICAgcFRtcC0+cHJldiA9IHBJdGVtOworICAgIH0KKyAgICBlbHNlCisgICAgeworICAgICAgICBwSXRlbS0+bmV4dCA9IHBUbXA7CisgICAgICAgIHBJdGVtLT5wcmV2ID0gcFRtcC0+cHJldjsKKyAgICAgICAgcFRtcC0+cHJldi0+bmV4dCA9IHBJdGVtOworICAgICAgICBwVG1wLT5wcmV2ID0gcEl0ZW07CisgICAgfQorCisgICAgcmV0dXJuIDA7Cit9CisKKy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgorICogU29mdFRpbWVyX0RlbGV0ZQorICogZGVsZXRlIGEgc29mdCB0aW1lciBmcm9tIGRvdWJsZSBsaW5rZWQgbGlzdAorICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCitzdGF0aWMgaW50IFNvZnRUaW1lcl9EZWxldGUoU09GVF9USU1FUiAqcEhlYWRlciwgU09GVF9USU1FUiAqcEl0ZW0pCit7CisgICAgaWYoTlVMTCA9PSBwSGVhZGVyIHx8IE5VTEwgPT0gcEl0ZW0pCisgICAgeworICAgICAgICByZXR1cm4gLTE7CisgICAgfQorCisgICAgaWYocEl0ZW0gPT0gcEhlYWRlcikKKyAgICB7CisgICAgICAgIHJldHVybiAwOworICAgIH0KKworICAgIHBJdGVtLT5wcmV2LT5uZXh0ID0gcEl0ZW0tPm5leHQ7CisgICAgcEl0ZW0tPm5leHQtPnByZXYgPSBwSXRlbS0+cHJldjsKKworICAgIHJldHVybiAwOworfQorCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIFNvZnRUaW1lcl9HZXRTaXplCisgKiBnZXQgdG90YWwgc2l6ZSBvZiBkb3VibGUgbGlua2VkIGxpc3QKKyAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworc3RhdGljIGludCBTb2Z0VGltZXJfR2V0U2l6ZShTT0ZUX1RJTUVSICpwSGVhZGVyKQoreworICAgIGludCBzaXplID0gMDsKKyAgICBTT0ZUX1RJTUVSICpwVG1wID0gcEhlYWRlci0+bmV4dDsKKworICAgIHdoaWxlKHBUbXAgIT0gcEhlYWRlcikKKyAgICB7CisgICAgICAgIHNpemUrKzsKKyAgICAgICAgcFRtcCA9IHBUbXAtPm5leHQ7CisgICAgfQorCisJI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKKyAgICBwcmludGYoIlNvZnRUaW1lcl9HZXRTaXplOiBzaXplPSVkXG4iLCBzaXplKTsKKwkjZW5kaWYKKyAgICByZXR1cm4gc2l6ZTsKK30KKworLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCisgKiBTb2Z0VGltZXJfQWRqdXN0CisgKiBhZGp1c3Qgc29mdC10aW1lcidzIHZhbHVlIGluIHRoZSBkb3VibGUgbGlua2VkIGxpc3QKKyAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworc3RhdGljIGludCBTb2Z0VGltZXJfQWRqdXN0VGltZXJWYWx1ZShTT0ZUX1RJTUVSICpwSGVhZGVyLCBpbnQgdmFsdWUpCit7CisgICAgU09GVF9USU1FUiAqcFRtcCA9IHBIZWFkZXItPm5leHQ7CisKKyAgICB3aGlsZShwVG1wICE9IHBIZWFkZXIpCisgICAgeworICAgICAgICBwVG1wLT50aW1lclZhbHVlIC09IHZhbHVlOworICAgICAgICBwVG1wID0gcFRtcC0+bmV4dDsKKyAgICB9CisgICAgcmV0dXJuIDA7Cit9CisKKy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgorICogU29mdFRpbWVyX0hhbmRsZXIKKyAqIGhhbmRsZXIgb2Ygc29mdC10aW1lcgorICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCitzdGF0aWMgdm9pZCBTb2Z0VGltZXJfSGFuZGxlcih2b2lkKQoreworICAgIGludCBpbmRleDsKKyAgICBTT0ZUX1RJTUVSICpwSGVhZGVyID0gZ19wVGltZXJIZWFkZXI7CisgICAgU09GVF9USU1FUiAqcFRtcCA9IHBIZWFkZXItPm5leHQ7CisgICAgdW5zaWduZWQgaW50IGN1clRpbWUgPSAwOworCisgICAgY3VyVGltZSA9IChwVG1wICE9IHBIZWFkZXI/cFRtcC0+dGltZXJWYWx1ZTowKTsKKworCSNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCisgICAgcHJpbnRmKCJTb2Z0VGltZXJfT3BzOiBjdXJUaW1lPSVkXG4iLCBjdXJUaW1lKTsKKwkjZW5kaWYKKworICAgIHB0aHJlYWRfbXV0ZXhfbG9jaygmZ190aW1lcl9tdXRleCk7CisKKyAgICB3aGlsZShwVG1wICE9IHBIZWFkZXIpCisgICAgeworICAgICAgICBwVG1wLT50aW1lclZhbHVlIC09IGN1clRpbWU7CisgICAgICAgIGlmKHBUbXAtPnRpbWVyVmFsdWUgPD0gMCkKKyAgICAgICAgeworICAgICAgICAgICAgcFRtcC0+cHJvY0NhbGxCYWNrKHBUbXAtPmFyZ3MpOworCisgICAgICAgICAgICBpZihUSU1FUl9GTEFHX1JFU1RBUlQgPT0gcFRtcC0+dWNGbGFnKQorICAgICAgICAgICAgeworICAgICAgICAgICAgICAgIHBUbXAtPnRpbWVyVmFsdWUgPSBwVG1wLT51bE5leHRJbnRlcnZhbDsKKyAgICAgICAgICAgIH0KKyAgICAgICAgICAgIGVsc2UKKyAgICAgICAgICAgIHsKKyAgICAgICAgICAgICAgICBwVG1wLT50aW1lclZhbHVlID0gLTE7CisgICAgICAgICAgICB9CisgICAgICAgICAgICBwVG1wLT5kb25lID0gMTsKKyAgICAgICAgfQorICAgICAgICBwVG1wID0gcFRtcC0+bmV4dDsKKyAgICB9CisKKwkjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgIHByaW50ZigiU29mdFRpbWVyX09wczpbMV0gJWRcbiIsIFNvZnRUaW1lcl9HZXRTaXplKHBIZWFkZXIpKTsKKwkjZW5kaWYKKworICAgIGZvcihpbmRleCA9IDE7IGluZGV4IDwgTUFYX1RJTUVSX1BPT0xfTlVNOyBpbmRleCsrKQorICAgIHsKKyAgICAgICAgaWYoZ190aW1lcl9wb29sW2luZGV4XS51c2VkICYmIGdfdGltZXJfcG9vbFtpbmRleF0uZG9uZSkKKyAgICAgICAgeworICAgICAgICAgICAgZ190aW1lcl9wb29sW2luZGV4XS5kb25lID0gMDsKKworICAgICAgICAgICAgU29mdFRpbWVyX0RlbGV0ZShwSGVhZGVyLCAmZ190aW1lcl9wb29sW2luZGV4XSk7CisKKyAgICAgICAgICAgIGlmKGdfdGltZXJfcG9vbFtpbmRleF0udGltZXJWYWx1ZSA+IDApCisgICAgICAgICAgICB7CisgICAgICAgICAgICAgICAgU29mdFRpbWVyX0FkZChwSGVhZGVyLCAmZ190aW1lcl9wb29sW2luZGV4XSk7CisgICAgICAgICAgICB9CisgICAgICAgICAgICBlbHNlCisgICAgICAgICAgICB7CisgICAgICAgICAgICAgICAgbWVtc2V0KCZnX3RpbWVyX3Bvb2xbaW5kZXhdLCAwLCBzaXplb2YoU09GVF9USU1FUikpOworICAgICAgICAgICAgfQorICAgICAgICB9CisgICAgfQorCisJI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKKyAgICBwcmludGYoIlNvZnRUaW1lcl9PcHM6WzJdICVkXG4iLCBTb2Z0VGltZXJfR2V0U2l6ZShwSGVhZGVyKSk7CisJI2VuZGlmCisKKyAgICBTZXRCYXNpY1RpbWVyRXgocEhlYWRlci0+bmV4dC0+dGltZXJWYWx1ZSk7CisKKyAgICBwdGhyZWFkX211dGV4X3VubG9jaygmZ190aW1lcl9tdXRleCk7CisKKwkjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgIHByaW50ZigiU29mdFRpbWVyX09wczogbmV4dFRpbWU9JWRcbiIsIHBIZWFkZXItPm5leHQtPnRpbWVyVmFsdWUpOworICAgICNlbmRpZgorCisgICAgcmV0dXJuOworfQorCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIFNvZnRUaW1lcl9Mb29wCisgKiBBIHRocmVhZCBlbnRyeSBmb3Igc29mdC10aW1lciEKKyAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLworc3RhdGljIHZvaWQqIFNvZnRUaW1lcl9Mb29wKHZvaWQgKmFyZ3MpCit7CisgICAgc3RydWN0IHNpZ2FjdGlvbiBhY3Q7CisKKyAgICBhY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JnN0VGltZXIpOworCQkJI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKKyAgICAgICAgICAgIHByaW50ZigiQ3JlYXRlU29mdFRpbWVyOiB0dl9zZWM9JWQsIHR2X3VzZWM9JWRcbiIsIHN0VGltZXIuaXRfdmFsdWUudHZfc2VjLCBzdFRpbWVyLml0X3ZhbHVlLnR2X3VzZWMpOworICAgICAgICAgICAgI2VuZGlmCisgICAgICAgICAgICBsZWZ0VGltZVZhbHVlID0gc3RUaW1lci5pdF92YWx1ZS50dl9zZWMgKiAxMDAwICsgKHN0VGltZXIuaXRfdmFsdWUudHZfdXNlYy8xMDAwKTsKKworICAgICAgICAgICAgdWxSZXNpZHVlID0gbGVmdFRpbWVWYWx1ZSAlIE5FV19USU1FUl9TVEVQOworICAgICAgICAgICAgaWYgKDAgIT0gdWxSZXNpZHVlKQorICAgICAgICAgICAgeworICAgICAgICAgICAgICAgIHVsUXVvdGllbnQgPSBsZWZ0VGltZVZhbHVlIC8gTkVXX1RJTUVSX1NURVA7CisgICAgICAgICAgICAgICAgbGVmdFRpbWVWYWx1ZSA9ICh1bFF1b3RpZW50ICsgMSkgKiBORVdfVElNRVJfU1RFUDsKKyAgICAgICAgICAgIH0KKyAgICAgICAgICAgICNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCisgICAgICAgICAgICBwcmludGYoIkNyZWF0ZVNvZnRUaW1lcjogb2xkVGltZVZhbHVlPSVkLCBsZWZ0VGltZVZhbHVlPSVkXG4iLCBvbGRUaW1lVmFsdWUsIGxlZnRUaW1lVmFsdWUpOworICAgICAgICAgICAgI2VuZGlmCisgICAgICAgICAgICBpZihvbGRUaW1lVmFsdWUgLSBsZWZ0VGltZVZhbHVlID49ICBORVdfVElNRVJfU1RFUCkKKyAgICAgICAgICAgIHsKKyAgICAgICAgICAgICAgICBTb2Z0VGltZXJfQWRqdXN0VGltZXJWYWx1ZShnX3BUaW1lckhlYWRlciwgb2xkVGltZVZhbHVlIC0gbGVmdFRpbWVWYWx1ZSk7CisgICAgICAgICAgICB9CisKKyAgICAgICAgICAgIFNvZnRUaW1lcl9BZGQoZ19wVGltZXJIZWFkZXIsICYoIGdfdGltZXJfcG9vbFtmcmVlSW5kZXhdKSk7CisgICAgICAgICAgICBTZXRCYXNpY1RpbWVyRXgoZ19wVGltZXJIZWFkZXItPm5leHQtPnRpbWVyVmFsdWUpOworICAgICAgICB9CisgICAgfQorfQorCisvKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKyAqIENyZWF0ZVNvZnRUaW1lcgorICogY3JlYXRlIGEgbmV3IHNvZnQtdGltZXIhCisgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KK0xPTkcgQ3JlYXRlU29mdFRpbWVyKFVTSE9SVCB1c1RpbWVySUQsCisgICAgICAgICAgICAgICAgICAgICBVQ0hBUiB1Y0ZsYWcsCisgICAgICAgICAgICAgICAgICAgICBVTE9ORyB1bEludGVydmFsLAorICAgICAgICAgICAgICAgICAgICAgdm9pZCAqICgqcHJvY0NhbGxCYWNrKSh2b2lkICopLAorICAgICAgICAgICAgICAgICAgICAgdm9pZCAqYXJncykKK3sKKyAgICBpbnQgdWNJbmRleCA9IDA7CisgICAgaW50IGZyZWVJbmRleCA9IDA7CisKKyAgICBVTE9ORyB1bFJlc2lkdWUgPSAwOworICAgIFVMT05HIHVsUXVvdGllbnQgPSAwOworCisgICAgaWYgKE5VTEwgPT0gcHJvY0NhbGxCYWNrKQorICAgIHsKKwkgICAgI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKKyAgICAgICAgcHJpbnRmKCJDcmVhdGVTb2Z0VGltZXIgZmFpbGVkLCBwcm9jQ2FsbEJhY2sgaXMgTlVMTCFcbiIpOworCQkjZW5kaWYKKyAgICAgICAgcmV0dXJuIEVSUk9SOworICAgIH0KKworICAgIHB0aHJlYWRfbXV0ZXhfbG9jaygmZ190aW1lcl9tdXRleCk7CisKKyAgICBpZihPSyAhPSBTb2Z0VGltZXJfSW5pdCgpKQorICAgIHsKKyAgICAgICAgcHRocmVhZF9tdXRleF91bmxvY2soJmdfdGltZXJfbXV0ZXgpOworICAgICAgICByZXR1cm4gRVJST1I7CisgICAgfQorCisgICAgZm9yKHVjSW5kZXggPSAxLCBmcmVlSW5kZXggPSAwOyB1Y0luZGV4IDwgTUFYX1RJTUVSX1BPT0xfTlVNOyB1Y0luZGV4KyspCisgICAgeworICAgICAgICAvKnNhbWUgdGltZXIgaWQgZXhpc3QsIHdhcm5pbmcsIHJldHVybiBlcnJvciovCisgICAgICAgIGlmIChnX3RpbWVyX3Bvb2xbdWNJbmRleF0udXNlZCAmJiAodXNUaW1lcklEID09IGdfdGltZXJfcG9vbFt1Y0luZGV4XS51c1RpbWVySUQpKQorICAgICAgICB7CisJCSAgICAjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgICAgICAgICAgcHJpbnRmKCJTYW1lIHRpbWVyIGlkIDB4JTA0eCBleGlzdCFcbiIsIHVzVGltZXJJRCk7CisJCQkjZW5kaWYKKyAgICAgICAgICAgIHB0aHJlYWRfbXV0ZXhfdW5sb2NrKCZnX3RpbWVyX211dGV4KTsKKyAgICAgICAgICAgIHJldHVybiBFUlJPUjsKKyAgICAgICAgfQorICAgICAgICBpZiAoKDAgPT0gZ190aW1lcl9wb29sW3VjSW5kZXhdLnVzZWQpICYmICgwID09IGZyZWVJbmRleCkpCisgICAgICAgIHsKKyAgICAgICAgICAgIGZyZWVJbmRleCA9IHVjSW5kZXg7CisgICAgICAgIH0KKyAgICB9CisKKyAgICAvKiBObyBlbXB0eSB0aW1lciBsZWZ0ICovCisgICAgaWYgKDAgPT0gZnJlZUluZGV4KQorICAgIHsKKwkgICAgI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKKyAgICAgICAgcHJpbnRmKCJTdGFydFNvZnRUaW1lciAweCUwNHggZmFpbGVkLCBxdWV1ZSBmdWxsIVxuIiwgdXNUaW1lcklEKTsKKwkJI2VuZGlmC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BpbmRleCAlZCBzdWNjZXNzOiBcbiIKKyAgICAgICAgICAgInVzVGltZXJJRCA9ICVkLCBcbiIKKyAgICAgICAgICAgInVjRmxhZyA9ICVkLCBcbiIKKyAgICAgICAgICAgInVsQ3VySW50ZXJ2YWwgPSAlbGQsIFxuIgorICAgICAgICAgICAidWxOZXh0SW50ZXJ2YWwgPSAlbGQsIFxuIgorICAgICAgICAgICAicHJvY0NhbGxCYWNrID0gJXAsIFxuIgorICAgICAgICAgICAiYXJncyA9ICAlcC4gXG4iLAorICAgICAgICAgICBmcmVlSW5kZXgsCisgICAgICAgICAgIHVzVGltZXJJRCwKKyAgICAgICAgICAgdWNGbGFnLAorICAgICAgICAgICB1bEludGVydmFsLAorICAgICAgICAgICB1bEludGVydmFsLAorICAgICAgICAgICBwcm9jQ2FsbEJhY2ssCisgICAgICAgICAgIGFyZ3MpOworICAgICNlbmRpZgorICAgIHB0aHJlYWRfbXV0ZXhfdW5sb2NrKCZnX3RpbWVyX211dGV4KTsKKworICAgIHJldHVybiBPSzsKK30KKworLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCisgKiBEZWxldGVTb2Z0VGltZXIKKyAqIGRlbGV0ZSBhIHNvZnQtdGltZXIhCisgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KK0xPTkcgRGVsZXRlU29mdFRpbWVyKFVTSE9SVCB1c1RpbWVySUQpCit7CisgICAgVUNIQVIgdWNJbmRleCA9IDA7CisKKyAgICBwdGhyZWFkX211dGV4X2xvY2soJmdfdGltZXJfbXV0ZXgpOworCisgICAgZm9yKHVjSW5kZXggPSAxOyB1Y0luZGV4IDwgTUFYX1RJTUVSX1BPT0xfTlVNOyB1Y0luZGV4KyspCisgICAgeworICAgICAgICBpZihnX3RpbWVyX3Bvb2xbdWNJbmRleF0udXNlZCAmJiAodXNUaW1lcklEID09IGdfdGltZXJfcG9vbFt1Y0luZGV4XS51c1RpbWVySUQpKQorICAgICAgICB7CisgICAgICAgICAgICBicmVhazsKKyAgICAgICAgfQorICAgIH0KKworICAgIGlmICh1Y0luZGV4ID49IE1BWF9USU1FUl9QT09MX05VTSkKKyAgICB7CisJICAgICNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCisgICAgICAgIHByaW50ZigiRGVsZXRlU29mdFRpbWVyIDB4JTA0eCBmYWlsZWQsIG5vdCBleGlzdCFcbiIsIHVzVGltZXJJRCk7CisJCSNlbmRpZgorICAgICAgICBwdGhyZWFkX211dGV4X3VubG9jaygmZ190aW1lcl9tdXRleCk7CisgICAgICAgIHJldHVybiBFUlJPUjsKKyAgICB9CisKKyAgICBTb2Z0VGltZXJfRGVsZXRlKGdfcFRpbWVySGVhZGVyLCAmKCBnX3RpbWVyX3Bvb2xbdWNJbmRleF0pKTsKKyAgICBtZW1zZXQoJmdfdGltZXJfcG9vbFt1Y0luZGV4XSwgMCwgc2l6ZW9mKFNPRlRfVElNRVIpKTsKKyAgICAjaWZkZWYgU09GVF9USU1FUl9ERUJVRworICAgIHByaW50ZigiRGVsZXRlU29mdFRpbWVyIDB4JTA0eCBzdWNjZXNzIVxuIiwgdXNUaW1lcklEKTsKKyAgICAjZW5kaWYKKyAgICBwdGhyZWFkX211dGV4X3VubG9jaygmZ190aW1lcl9tdXRleCk7CisgICAgcmV0dXJuIE9LOworfQo=