Fix a kgets() thread-switcing bug
This commit is contained in:
parent
6b2ee875d4
commit
5fa42a5d34
@ -177,12 +177,10 @@ kgets_handler(
|
|||||||
if (kgets_special == 1) {
|
if (kgets_special == 1) {
|
||||||
if (ch == 91) {
|
if (ch == 91) {
|
||||||
kgets_special = 2;
|
kgets_special = 2;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
kgets_special = 0;
|
kgets_special = 0;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (kgets_special == 2) {
|
if (kgets_special == 2) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@ -235,17 +233,16 @@ kgets_handler(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
kgets_special = 0;
|
kgets_special = 0;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch == 0x08) {
|
if (ch == 0x08) {
|
||||||
/* Backspace */
|
/* Backspace */
|
||||||
if (kgets_collected != 0) {
|
if (kgets_collected != 0) {
|
||||||
if (kgets_offset == 0) {
|
if (kgets_offset == 0) {
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
}
|
||||||
} /* Clear the previous character */
|
/* Clear the previous character */
|
||||||
kwrite(0x08);
|
kwrite(0x08);
|
||||||
kwrite(' ');
|
kwrite(' ');
|
||||||
kwrite(0x08);
|
kwrite(0x08);
|
||||||
@ -270,30 +267,22 @@ kgets_handler(
|
|||||||
kgets_offset--;
|
kgets_offset--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
} else if (ch == '\x0c') {
|
} else if (ch == '\x0c') {
|
||||||
kprintf("\033[H\033[2J");
|
kprintf("\033[H\033[2J");
|
||||||
if (kgets_redraw_func) {
|
if (kgets_redraw_func) {
|
||||||
kgets_redraw_func();
|
kgets_redraw_func();
|
||||||
}
|
}
|
||||||
kgets_redraw_buffer();
|
kgets_redraw_buffer();
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
} else if (ch == '\t' && kgets_tab_complete_func) {
|
} else if (ch == '\t' && kgets_tab_complete_func) {
|
||||||
if (current_process != kgets_client) {
|
|
||||||
/* Switch page directories into the caller so we can write to its buffers */
|
|
||||||
switch_page_directory(kgets_client->thread.page_directory);
|
|
||||||
}
|
|
||||||
kgets_tab_complete_func(kgets_buffer);
|
kgets_tab_complete_func(kgets_buffer);
|
||||||
kgets_collected = strlen(kgets_buffer);
|
kgets_collected = strlen(kgets_buffer);
|
||||||
kgets_offset = kgets_collected;
|
kgets_offset = kgets_collected;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
} else if (ch == 27) {
|
} else if (ch == 27) {
|
||||||
kgets_special = 1;
|
kgets_special = 1;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
} else if (ch == '\n') {
|
} else if (ch == '\n') {
|
||||||
/* Newline finishes off the kgets() */
|
/* Newline finishes off the kgets() */
|
||||||
while (kgets_offset < kgets_collected) {
|
while (kgets_offset < kgets_collected) {
|
||||||
@ -304,14 +293,9 @@ kgets_handler(
|
|||||||
}
|
}
|
||||||
kwrite('\n');
|
kwrite('\n');
|
||||||
kgets_newline = 1;
|
kgets_newline = 1;
|
||||||
IRQ_ON;
|
goto _cleanup;
|
||||||
return;
|
|
||||||
} /* Add this character to the buffer. */
|
} /* Add this character to the buffer. */
|
||||||
if (kgets_offset != kgets_collected) {
|
if (kgets_offset != kgets_collected) {
|
||||||
if (current_process != kgets_client) {
|
|
||||||
/* Switch page directories into the caller so we can write to its buffers */
|
|
||||||
switch_page_directory(kgets_client->thread.page_directory);
|
|
||||||
}
|
|
||||||
for (int i = kgets_collected; i > kgets_offset; --i) {
|
for (int i = kgets_collected; i > kgets_offset; --i) {
|
||||||
kgets_buffer[i] = kgets_buffer[i-1];
|
kgets_buffer[i] = kgets_buffer[i-1];
|
||||||
}
|
}
|
||||||
@ -332,16 +316,16 @@ kgets_handler(
|
|||||||
} else {
|
} else {
|
||||||
kwrite(ch);
|
kwrite(ch);
|
||||||
if (kgets_collected < kgets_want) {
|
if (kgets_collected < kgets_want) {
|
||||||
if (current_process != kgets_client) {
|
|
||||||
/* Switch page directories into the caller so we can write to its buffers */
|
|
||||||
switch_page_directory(kgets_client->thread.page_directory);
|
|
||||||
}
|
|
||||||
kgets_buffer[kgets_collected] = ch;
|
kgets_buffer[kgets_collected] = ch;
|
||||||
kgets_buffer[++kgets_collected] = '\0';
|
kgets_buffer[++kgets_collected] = '\0';
|
||||||
kgets_offset++;
|
kgets_offset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_cleanup:
|
||||||
IRQ_ON;
|
IRQ_ON;
|
||||||
|
if (current_process != kgets_client) {
|
||||||
|
switch_page_directory(current_process->thread.page_directory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kgets_redraw_buffer() {
|
void kgets_redraw_buffer() {
|
||||||
|
@ -37,7 +37,7 @@ int main(int argc, char ** argv) {
|
|||||||
int pid = fork();
|
int pid = fork();
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("%c\n", i + 'A');
|
printf("%c", i + 'A');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
npid = pid;
|
npid = pid;
|
||||||
|
Loading…
Reference in New Issue
Block a user