LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqILDmyKjL+dPQIChDKTIwMDgsIMnu29rK0NbQ0MvNqNG2ucm33dPQz965q8u+oaMKKiAKKiDOxLz+w/uzxqO6IHNvZnRfdGltZXIuYwoqIM7EvP6x6sq2o7ogCiogxNrI3dWq0qqjuiC2qNLlzajTw7XEyO28/raoyrHG98/fs8y/4goqIMbky/zLtcP3o7ogCiogtbHHsLDmsb6juiBWMS4wCiog1/cgICAg1d+juiDWo9Px5sMKKiDN6rPJyNXG2qO6IDIwMTAtMDktMDIKKiAKKiDQ3rjEvMfCvDGjugoqICAgINDeuMTI1cbao7oyMDEwLTA5LTAyCiogICAgsOYgsb4gusWjulYxLjAKKiAgICDQ3iC4xCDIy6O61qPT8ebDCiogICAg0N64xMTayN2jurP1yryw5rG+CioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KI2luY2x1ZGUgIDxzdGRpby5oPgojaW5jbHVkZSAgPHN0ZGxpYi5oPgojaW5jbHVkZSAgPHNpZ25hbC5oPgojaW5jbHVkZSAgPHN5cy90aW1lLmg+CiNpbmNsdWRlICA8c3lzbG9nLmg+CiNpbmNsdWRlIDxmY250bC5oPgojaW5jbHVkZSAgPHB0aHJlYWQuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxlcnJuby5oPgojaW5jbHVkZSAgInNvZnRfdGltZXIuaCIKCi8qCiNkZWZpbmUgU09GVF9USU1FUl9ERUJVRyAxCiovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBNYWNybyBkZWNsYXJhdGlvbgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KI2RlZmluZSBORVdfVElNRVJfU1RFUCAxMAojZGVmaW5lIE1BWF9USU1FUl9QT09MX05VTSAgMzMKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBzdGF0aWMgdmFyaWFibGVzCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgU09GVF9USU1FUiBnX3RpbWVyX3Bvb2xbTUFYX1RJTUVSX1BPT0xfTlVNXSA9IHswfTsKc3RhdGljIFNPRlRfVElNRVIgKmdfcFRpbWVySGVhZGVyID0gTlVMTDsKc3RhdGljIGludCBnX3RpbWVyX2luaXRpYWxpemVkID0gMDsKCnB0aHJlYWRfbXV0ZXhfdCBnX3RpbWVyX211dGV4ID0gUFRIUkVBRF9NVVRFWF9JTklUSUFMSVpFUjsKCnN0YXRpYyB2b2lkKiBTb2Z0VGltZXJfTG9vcCh2b2lkICphcmdzKTsKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBTb2Z0VGltZXJfSW5pdAogKiBpbml0aWFsaXplIGdsb2JhbCB2YXJpYWJsZXMKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQgU29mdFRpbWVyX0luaXQodm9pZCkKewogICAgaW50ICByZXN1bHQgPSAwOwogICAgcHRocmVhZF9hdHRyX3QgYXR0cmlidXRlOwogICAgcHRocmVhZF90IHN0SGFuZGxlOwoKICAgIGlmKDAgPT0gZ190aW1lcl9pbml0aWFsaXplZCkKICAgIHsKICAgICAgICBnX3RpbWVyX2luaXRpYWxpemVkID0gMTsKCiAgICAgICAgcHRocmVhZF9hdHRyX2luaXQoJmF0dHJpYnV0ZSk7CiAgICAgICAgcHRocmVhZF9hdHRyX3NldHN0YWNrc2l6ZSgmYXR0cmlidXRlLCAzMioxMDI0KTsKCgkJI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKICAgICAgICBwcmludGYoIkNyZWF0ZSBzb2Z0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SGVhZGVyIHx8IE5VTEwgPT0gcEl0ZW0pCiAgICB7CiAgICAgICAgcmV0dXJuIC0xOwogICAgfQoKICAgIGRvCiAgICB7CiAgICAgICAgaWYocFRtcC0+dGltZXJWYWx1ZSA8PSBwSXRlbS0+dGltZXJWYWx1ZSkKICAgICAgICB7CiAgICAgICAgICAgIHBUbXAgPSBwVG1wLT5uZXh0OwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9IHdoaWxlKHBUbXAgIT0gcEhlYWRlcik7CgogICAgaWYocFRtcCAhPSBwSGVhZGVyKQogICAgewogICAgICAgIHBJdGVtLT5uZXh0ID0gcFRtcDsKICAgICAgICBwSXRlbS0+cHJldiA9IHBUbXAtPnByZXY7CiAgICAgICAgcFRtcC0+cHJldi0+bmV4dCA9IHBJdGVtOwogICAgICAgIHBUbXAtPnByZXYgPSBwSXRlbTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBwSXRlbS0+bmV4dCA9IHBUbXA7CiAgICAgICAgcEl0ZW0tPnByZXYgPSBwVG1wLT5wcmV2OwogICAgICAgIHBUbXAtPnByZXYtPm5leHQgPSBwSXRlbTsKICAgICAgICBwVG1wLT5wcmV2ID0gcEl0ZW07CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBTb2Z0VGltZXJfRGVsZXRlCiAqIGRlbGV0ZSBhIHNvZnQgdGltZXIgZnJvbSBkb3VibGUgbGlua2VkIGxpc3QKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQgU29mdFRpbWVyX0RlbGV0ZShTT0ZUX1RJTUVSICpwSGVhZGVyLCBTT0ZUX1RJTUVSICpwSXRlbSkKewogICAgaWYoTlVMTCA9PSBwSGVhZGVyIHx8IE5VTEwgPT0gcEl0ZW0pCiAgICB7CiAgICAgICAgcmV0dXJuIC0xOwogICAgfQoKICAgIGlmKHBJdGVtID09IHBIZWFkZXIpCiAgICB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgcEl0ZW0tPnByZXYtPm5leHQgPSBwSXRlbS0+bmV4dDsKICAgIHBJdGVtLT5uZXh0LT5wcmV2ID0gcEl0ZW0tPnByZXY7CgogICAgcmV0dXJuIDA7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBTb2Z0VGltZXJfR2V0U2l6ZQogKiBnZXQgdG90YWwgc2l6ZSBvZiBkb3VibGUgbGlua2VkIGxpc3QKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQgU29mdFRpbWVyX0dldFNpemUoU09GVF9USU1FUiAqcEhlYWRlcikKewogICAgaW50IHNpemUgPSAwOwogICAgU09GVF9USU1FUiAqcFRtcCA9IHBIZWFkZXItPm5leHQ7CgogICAgd2hpbGUocFRtcCAhPSBwSGVhZGVyKQogICAgewogICAgICAgIHNpemUrKzsKICAgICAgICBwVG1wID0gcFRtcC0+bmV4dDsKICAgIH0KCgkjaWZkZWYgU09GVF9USU1FUl9ERUJVRwogICAgcHJpbnRmKCJTb2Z0VGltZXJfR2V0U2l6ZTogc2l6ZT0lZFxuIiwgc2l6ZSk7CgkjZW5kaWYKICAgIHJldHVybiBzaXplOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogU29mdFRpbWVyX0FkanVzdAogKiBhZGp1c3Qgc29mdC10aW1lcidzIHZhbHVlIGluIHRoZSBkb3VibGUgbGlua2VkIGxpc3QKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQgU29mdFRpbWVyX0FkanVzdFRpbWVyVmFsdWUoU09GVF9USU1FUiAqcEhlYWRlciwgaW50IHZhbHVlKQp7CiAgICBT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sYWcpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBUbXAtPnRpbWVyVmFsdWUgPSBwVG1wLT51bE5leHRJbnRlcnZhbDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBUbXAtPnRpbWVyVmFsdWUgPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBwVG1wLT5kb25lID0gMTsKICAgICAgICB9CiAgICAgICAgcFRtcCA9IHBUbXAtPm5leHQ7CiAgICB9CgoJI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKICAgIHByaW50ZigiU29mdFRpbWVyX09wczpbMV0gJWRcbiIsIFNvZnRUaW1lcl9HZXRTaXplKHBIZWFkZXIpKTsKCSNlbmRpZgoKICAgIGZvcihpbmRleCA9IDE7IGluZGV4IDwgTUFYX1RJTUVSX1BPT0xfTlVNOyBpbmRleCsrKQogICAgewogICAgICAgIGlmKGdfdGltZXJfcG9vbFtpbmRleF0udXNlZCAmJiBnX3RpbWVyX3Bvb2xbaW5kZXhdLmRvbmUpCiAgICAgICAgewogICAgICAgICAgICBnX3RpbWVyX3Bvb2xbaW5kZXhdLmRvbmUgPSAwOwoKICAgICAgICAgICAgU29mdFRpbWVyX0RlbGV0ZShwSGVhZGVyLCAmZ190aW1lcl9wb29sW2luZGV4XSk7CgogICAgICAgICAgICBpZihnX3RpbWVyX3Bvb2xbaW5kZXhdLnRpbWVyVmFsdWUgPiAwKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBTb2Z0VGltZXJfQWRkKHBIZWFkZXIsICZnX3RpbWVyX3Bvb2xbaW5kZXhdKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG1lbXNldCgmZ190aW1lcl9wb29sW2luZGV4XSwgMCwgc2l6ZW9mKFNPRlRfVElNRVIpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCgkj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gICAgICAgICBpZiAoMCAhPSB1bFJlc2lkdWUpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVsUXVvdGllbnQgPSBsZWZ0VGltZVZhbHVlIC8gTkVXX1RJTUVSX1NURVA7CiAgICAgICAgICAgICAgICBsZWZ0VGltZVZhbHVlID0gKHVsUXVvdGllbnQgKyAxKSAqIE5FV19USU1FUl9TVEVQOwogICAgICAgICAgICB9CiAgICAgICAgICAgICNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCiAgICAgICAgICAgIHByaW50ZigiQ3JlYXRlU29mdFRpbWVyOiBvbGRUaW1lVmFsdWU9JWQsIGxlZnRUaW1lVmFsdWU9JWRcbiIsIG9sZFRpbWVWYWx1ZSwgbGVmdFRpbWVWYWx1ZSk7CiAgICAgICAgICAgICNlbmRpZgogICAgICAgICAgICBpZihvbGRUaW1lVmFsdWUgLSBsZWZ0VGltZVZhbHVlID49ICBORVdfVElNRVJfU1RFUCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgU29mdFRpbWVyX0FkanVzdFRpbWVyVmFsdWUoZ19wVGltZXJIZWFkZXIsIG9sZFRpbWVWYWx1ZSAtIGxlZnRUaW1lVmFsdWUpOwogICAgICAgICAgICB9CgogICAgICAgICAgICBTb2Z0VGltZXJfQWRkKGdfcFRpbWVySGVhZGVyLCAmKCBnX3RpbWVyX3Bvb2xbZnJlZUluZGV4XSkpOwogICAgICAgICAgICBTZXRCYXNpY1RpbWVyRXgoZ19wVGltZXJIZWFkZXItPm5leHQtPnRpbWVyVmFsdWUpOwogICAgICAgIH0KICAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqIENyZWF0ZVNvZnRUaW1lcgogKiBjcmVhdGUgYSBuZXcgc29mdC10aW1lciEKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkxPTkcgQ3JlYXRlU29mdFRpbWVyKFVTSE9SVCB1c1RpbWVySUQsCiAgICAgICAgICAgICAgICAgICAgIFVDSEFSIHVjRmxhZywKICAgICAgICAgICAgICAgICAgICAgVUxPTkcgdWxJbnRlcnZhbCwKICAgICAgICAgICAgICAgICAgICAgdm9pZCAqICgqcHJvY0NhbGxCYWNrKSh2b2lkICopLAogICAgICAgICAgICAgICAgICAgICB2b2lkICphcmdzKQp7CiAgICBpbnQgdWNJbmRleCA9IDA7CiAgICBpbnQgZnJlZUluZGV4ID0gMDsKCiAgICBVTE9ORyB1bFJlc2lkdWUgPSAwOwogICAgVUxPTkcgdWxRdW90aWVudCA9IDA7CgogICAgaWYgKE5VTEwgPT0gcHJvY0NhbGxCYWNrKQogICAgewoJICAgICNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCiAgICAgICAgcHJpbnRmKCJDcmVhdGVTb2Z0VGltZXIgZmFpbGVkLCBwcm9jQ2FsbEJhY2sgaXMgTlVMTCFcbiIpOwoJCSNlbmRpZgogICAgICAgIHJldHVybiBFUlJPUjsKICAgIH0KCiAgICBwdGhyZWFkX211dGV4X2xvY2soJmdfdGltZXJfbXV0ZXgpOwoKICAgIGlmKE9LICE9IFNvZnRUaW1lcl9Jbml0KCkpCiAgICB7CiAgICAgICAgcHRocmVhZF9tdXRleF91bmxvY2soJmdfdGltZXJfbXV0ZXgpOwogICAgICAgIHJldHVybiBFUlJPUjsKICAgIH0KCiAgICBmb3IodWNJbmRleCA9IDEsIGZyZWVJbmRleCA9IDA7IHVjSW5kZXggPCBNQVhfVElNRVJfUE9PTF9OVU07IHVjSW5kZXgrKykKICAgIHsKICAgICAgICAvKnNhbWUgdGltZXIgaWQgZXhpc3QsIHdhcm5pbmcsIHJldHVybiBlcnJvciovCiAgICAgICAgaWYgKGdfdGltZXJfcG9vbFt1Y0luZGV4XS51c2VkICYmICh1c1RpbWVySUQgPT0gZ190aW1lcl9wb29sW3VjSW5kZXhdLnVzVGltZXJJRCkpCiAgICAgICAgewoJCSAgICAjaWZkZWYgU09GVF9USU1FUl9ERUJVRwogICAgICAgICAgICBwcmludGYoIlNhbWUgdGltZXIgaWQgMHglMDR4IGV4aXN0IVxuIiwgdXNUaW1lcklEKTsKCQkJI2VuZGlmCiAgICAgICAgICAgIHB0aHJlYWRfbXV0ZXhfdW5sb2NrKCZnX3RpbWVyX211dGV4KTsKICAgICAgICAgICAgcmV0dXJuIEVSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoKDAgPT0gZ190aW1lcl9wb29sW3VjSW5kZXhdLnVzZWQpICYmICgwID09IGZyZWVJbmRleCkpCiAgICAgICAgewogICAgICAgICAgICBmcmVlSW5kZXggPSB1Y0luZGV4OwogICAgICAgIH0KICAgIH0KCiAgICAvKiBObyBlbXB0eSB0aW1lciBsZWZ0ICovCiAgICBpZiAoMCA9PSBmcmVlSW5kZXgpCiAgICB7CgkgICAgI2lmZGVmIFNPRlRfVElNRVJfREVCVUcKICAgICAgICBwcmludGYoIlN0YXJ0U29mdFRpbWVyIDB4JTA0eCBmYWlsZWQsIHF1ZXVlIGZ1bGwhXG4iLCB1c1RpbWVySUQpOwoJCSNlbmRpZgogICAgICAgIHB0aHJlYWRfbXV0ZXhfdW5sb2NrKCZnX3RpbWVyX211dGV4KTsKICAgICAgICByZXR1cm4gRVJST1I7CiAgICB9CgogICAgLyogQWRqdXN0IGludGVydmFsIHZhbHVlLCBpdCBtdXN0IG11bHRpcGxlIG9mIDEwICovCiAgICB1bFJlc2lkdWUgPSB1bEludGVydmFsICUgTkVXX1RJTUVSX1NURVA7CiAgICBpZiAoMCAhPSB1bFJlc2lkdWUpCiAgICB7CiAgICAgICAgdWxRdW90aWVudCA9IHVsSW50ZXJ2YWwgLyBORVdfVElNRVJfU1RFUDsKICAgICAgICB1bEludGVydmFsID0gKHVsUXVvdGllbnQgKyAxKSAqIE5FV19USU1FUl9TVEVQOwogICAgfQoKICAgIGdfdGltZXJfcG9vbFtmcmVlSW5kZXhdLnVzZWQgPSAxOwogICAgZ190aW1lcl9wb29sW2ZyZWVJbmRleF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9tdXRleCk7CgogICAgcmV0dXJuIE9LOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogRGVsZXRlU29mdFRpbWVyCiAqIGRlbGV0ZSBhIHNvZnQtdGltZXIhCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpMT05HIERlbGV0ZVNvZnRUaW1lcihVU0hPUlQgdXNUaW1lcklEKQp7CiAgICBVQ0hBUiB1Y0luZGV4ID0gMDsKCiAgICBwdGhyZWFkX211dGV4X2xvY2soJmdfdGltZXJfbXV0ZXgpOwoKICAgIGZvcih1Y0luZGV4ID0gMTsgdWNJbmRleCA8IE1BWF9USU1FUl9QT09MX05VTTsgdWNJbmRleCsrKQogICAgewogICAgICAgIGlmKGdfdGltZXJfcG9vbFt1Y0luZGV4XS51c2VkICYmICh1c1RpbWVySUQgPT0gZ190aW1lcl9wb29sW3VjSW5kZXhdLnVzVGltZXJJRCkpCiAgICAgICAgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CgogICAgaWYgKHVjSW5kZXggPj0gTUFYX1RJTUVSX1BPT0xfTlVNKQogICAgewoJICAgICNpZmRlZiBTT0ZUX1RJTUVSX0RFQlVHCiAgICAgICAgcHJpbnRmKCJEZWxldGVTb2Z0VGltZXIgMHglMDR4IGZhaWxlZCwgbm90IGV4aXN0IVxuIiwgdXNUaW1lcklEKTsKCQkjZW5kaWYKICAgICAgICBwdGhyZWFkX211dGV4X3VubG9jaygmZ190aW1lcl9tdXRleCk7CiAgICAgICAgcmV0dXJuIEVSUk9SOwogICAgfQoKICAgIFNvZnRUaW1lcl9EZWxldGUoZ19wVGltZXJIZWFkZXIsICYoIGdfdGltZXJfcG9vbFt1Y0luZGV4XSkpOwogICAgbWVtc2V0KCZnX3RpbWVyX3Bvb2xbdWNJbmRleF0sIDAsIHNpemVvZihTT0ZUX1RJTUVSKSk7CiAgICAjaWZkZWYgU09GVF9USU1FUl9ERUJVR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