Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Cleanup and sanity-checking of integer overflow, null comparisons, dead code (Coverit...
[palacios.git] / palacios / src / devices / telnet_cons.c
index 98562af..b9080f7 100644 (file)
@@ -217,7 +217,7 @@ static const uint8_t bg_color_map[] = {
 static int send_update(struct cons_state * state, uint8_t  x, uint8_t  y, uint8_t attrib, uint8_t val) {
     uint8_t fg_color = fg_color_map[(attrib & 0x0f) % 16];
     uint8_t bg_color = bg_color_map[(attrib & 0xf0) % 16];
-    uint8_t buf[32];
+    uint8_t buf[64];
     int ret = 0;
     int i = 0;
 
@@ -264,7 +264,7 @@ static int send_update(struct cons_state * state, uint8_t  x, uint8_t  y, uint8_
        uint64_t start, end;
 
        rdtscll(start);
-       ret =  send_all(state->client_fd, buf, 32);
+       ret =  send_all(state->client_fd, buf, i);
        rdtscll(end);
 
        PrintDebug(VM_NONE, VCORE_NONE, "Sendall latency=%d cycles\n", (uint32_t)(end - start));
@@ -397,6 +397,8 @@ static int cons_free(struct cons_state * state) {
 
     // kill thread... ?
 
+    v3_lock_deinit(&(state->cons_lock));
+
     V3_Free(state);
     return 0;
 }
@@ -411,16 +413,8 @@ static struct v3_device_ops dev_ops = {
 static int key_handler( struct cons_state * state, uint8_t ascii) {
     PrintDebug(VM_NONE, VCORE_NONE, "Character recieved: 0x%x\n", ascii);
 
-    // printable
-    if (ascii < 0x80) {
-       const struct key_code * key = &(ascii_to_key_code[ascii]);
-
-       if (deliver_scan_code(state, (struct key_code *)key) == -1) {
-           PrintError(VM_NONE, VCORE_NONE, "Could not deliver scan code to vm\n");
-           return -1;
-       }
 
-    } else if (ascii == ESC_CHAR) { // Escape Key
+    if (ascii == ESC_CHAR) { // Escape Key
        // This means that another 2 characters are pending
        // receive it and deliver accordingly
        char esc_seq[2] = {0, 0};
@@ -455,7 +449,16 @@ static int key_handler( struct cons_state * state, uint8_t ascii) {
        } else if (esc_seq[1] == 'D') {         // LEFT ARROW
            struct key_code left = { 0x4B, 0 };
            deliver_scan_code(state, &left);
+       }   
+
+    } else if (ascii < 0x80) { // printable
+       const struct key_code * key = &(ascii_to_key_code[ascii]);
+
+       if (deliver_scan_code(state, (struct key_code *)key) == -1) {
+           PrintError(VM_NONE, VCORE_NONE, "Could not deliver scan code to vm\n");
+           return -1;
        }
+
     } else {
        PrintError(VM_NONE, VCORE_NONE, "Invalid character received from network (%c) (code=%d)\n",
                   ascii, ascii);
@@ -553,7 +556,7 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
     v3_console_register_cga(frontend, &cons_ops, state);
 
-    V3_CREATE_THREAD(cons_server, state, "Telnet Console Network Server");
+    V3_CREATE_AND_START_THREAD(cons_server, state, "Telnet Console Network Server", 0);
 
     return 0;
 }