Skip to contentSkip to conversation

monitor: fix the wrong order of releasing keys

PATCH Applied Amos Kong 3 participants 4 messages Apr 16, 2013 – Apr 17, 2013

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 monitor: fix the wrong order of releasing keys

(qemu) sendkey ctrl_r-scroll_lock-scroll_lock

Executing this command could not let Windows guest panic, it caused by the wrong order of releasing keys. This problem was introduced by commit e4c8f004c55d9da3eae3e14df740238bf805b5d6.

The right release order should be starting from last item.

---
 ui/input.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
ui/input.c +3 -5
index 9abef0c..ecfeb43 100644
@@ -234,13 +234,11 @@ static void free_keycodes(void)
 
 static void release_keys(void *opaque)
 {
-    int i;
-
-    for (i = 0; i < keycodes_size; i++) {
-        if (keycodes[i] & 0x80) {
+    while (keycodes_size > 0) {
+        if (keycodes[--keycodes_size] & 0x80) {
             kbd_put_keycode(0xe0);
         }
-        kbd_put_keycode(keycodes[i]| 0x80);
+        kbd_put_keycode(keycodes[keycodes_size] | 0x80);
     }
 
     free_keycodes();
Signature · 1 line
1.7.1
#1 lore raw
Quoted 3 lines · Amos Kong

(qemu) sendkey ctrl_r-scroll_lock-scroll_lock

Executing this command could not let Windows guest panic, it caused by

"could not"?

Quoted 31 lines

the wrong order of releasing keys. This problem was introduced by commit e4c8f004c55d9da3eae3e14df740238bf805b5d6.

The right release order should be starting from last item.

---
 ui/input.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
ui/input.c +3 -5
index 9abef0c..ecfeb43 100644
@@ -234,13 +234,11 @@ static void free_keycodes(void)
 
 static void release_keys(void *opaque)
 {
-    int i;
-
-    for (i = 0; i < keycodes_size; i++) {
-        if (keycodes[i] & 0x80) {
+    while (keycodes_size > 0) {
+        if (keycodes[--keycodes_size] & 0x80) {
             kbd_put_keycode(0xe0);
         }
-        kbd_put_keycode(keycodes[i]| 0x80);
+        kbd_put_keycode(keycodes[keycodes_size] | 0x80);
     }
 
     free_keycodes();
#2 lore raw
Quoted 7 lines · On Tue, 16 Apr 2013 09:08:12 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 3 lines · Amos Kong

(qemu) sendkey ctrl_r-scroll_lock-scroll_lock

Executing this command could not let Windows guest panic, it caused by

"could not"?

You can use Windows' editor to setup Windows to panic on a key sequence, and that feature (or Windows itself) is sensible to the key release ordering.

This caught a problem with the sendkey command conversion to the qapi: we changed the release key ordering from last to first to first to last.

Quoted 32 lines
Quoted 31 lines

the wrong order of releasing keys. This problem was introduced by commit e4c8f004c55d9da3eae3e14df740238bf805b5d6.

The right release order should be starting from last item.

---
 ui/input.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
ui/input.c +3 -5
index 9abef0c..ecfeb43 100644
@@ -234,13 +234,11 @@ static void free_keycodes(void)
 
 static void release_keys(void *opaque)
 {
-    int i;
-
-    for (i = 0; i < keycodes_size; i++) {
-        if (keycodes[i] & 0x80) {
+    while (keycodes_size > 0) {
+        if (keycodes[--keycodes_size] & 0x80) {
             kbd_put_keycode(0xe0);
         }
-        kbd_put_keycode(keycodes[i]| 0x80);
+        kbd_put_keycode(keycodes[keycodes_size] | 0x80);
     }
 
     free_keycodes();
#3 lore raw
In reply to Amos Kong
Quoted 9 lines · On Tue, 16 Apr 2013 13:47:32 +0800 Amos Kong <[email protected]> wrote:

(qemu) sendkey ctrl_r-scroll_lock-scroll_lock

Executing this command could not let Windows guest panic, it caused by the wrong order of releasing keys. This problem was introduced by commit e4c8f004c55d9da3eae3e14df740238bf805b5d6.

The right release order should be starting from last item.

Applied to the qmp branch, thanks.

Quoted 25 lines
---
 ui/input.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
ui/input.c +3 -5
index 9abef0c..ecfeb43 100644
@@ -234,13 +234,11 @@ static void free_keycodes(void)
 
 static void release_keys(void *opaque)
 {
-    int i;
-
-    for (i = 0; i < keycodes_size; i++) {
-        if (keycodes[i] & 0x80) {
+    while (keycodes_size > 0) {
+        if (keycodes[--keycodes_size] & 0x80) {
             kbd_put_keycode(0xe0);
         }
-        kbd_put_keycode(keycodes[i]| 0x80);
+        kbd_put_keycode(keycodes[keycodes_size] | 0x80);
     }
 
     free_keycodes();