loader.efi: handle efi_cons_init() failure cases better

if we fail to allocate buffer, set up the TERM_EMU and continue.
On output, use TERM_EMU in case we did fail to allocate buffer.
This commit is contained in:
Toomas Soome 2020-03-18 22:21:42 +00:00
parent 9dfa078252
commit 34edaae605

View File

@ -855,27 +855,28 @@ efi_cons_update_mode(void)
tp.tp_row = rows;
tp.tp_col = cols;
buffer = malloc(rows * cols * sizeof(*buffer));
if (buffer == NULL)
return (false);
if (buffer != NULL) {
teken_set_winsize(&teken, &tp);
a = teken_get_defattr(&teken);
teken_set_winsize(&teken, &tp);
a = teken_get_defattr(&teken);
snprintf(env, sizeof(env), "%d", a->ta_fgcolor);
env_setenv("teken.fg_color", EV_VOLATILE, env,
efi_set_colors, env_nounset);
snprintf(env, sizeof(env), "%d", a->ta_bgcolor);
env_setenv("teken.bg_color", EV_VOLATILE, env,
efi_set_colors, env_nounset);
snprintf(env, sizeof(env), "%d", a->ta_fgcolor);
env_setenv("teken.fg_color", EV_VOLATILE, env, efi_set_colors,
env_nounset);
snprintf(env, sizeof(env), "%d", a->ta_bgcolor);
env_setenv("teken.bg_color", EV_VOLATILE, env, efi_set_colors,
env_nounset);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
buffer[col + row * tp.tp_col].c = ' ';
buffer[col + row * tp.tp_col].a = *a;
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
buffer[col + row * tp.tp_col].c = ' ';
buffer[col + row * tp.tp_col].a = *a;
}
}
}
} else {
}
#ifdef TERM_EMU
if (buffer == NULL) {
conout->SetAttribute(conout, EFI_TEXT_ATTR(DEFAULT_FGCOLOR,
DEFAULT_BGCOLOR));
end_term();
@ -883,8 +884,8 @@ efi_cons_update_mode(void)
curs_move(&curx, &cury, curx, cury);
fg_c = DEFAULT_FGCOLOR;
bg_c = DEFAULT_BGCOLOR;
#endif
}
#endif
snprintf(env, sizeof (env), "%u", (unsigned)rows);
setenv("LINES", env, 1);
@ -1011,15 +1012,12 @@ efi_cons_putchar(int c)
* Don't use Teken when we're doing pure serial, or a multiple console
* with video "primary" because that's also serial.
*/
if ((mode & (RB_SERIAL | RB_MULTIPLE)) != 0) {
if ((mode & (RB_SERIAL | RB_MULTIPLE)) != 0 || buffer == NULL) {
input_byte(ch);
return;
}
if (buffer != NULL)
teken_input(&teken, &ch, sizeof (ch));
else
efi_cons_efiputchar(c);
teken_input(&teken, &ch, sizeof (ch));
}
static int