Re: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()

2023-08-25 Thread Jayaprakash, N
Reviewed the changes and it looks good.
Also verified that the fix solves the problem.

Reviewed-by : Jayaprakash N 

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Jayaprakash, N
Sent: Thursday, August 24, 2023 10:04 PM
To: devel@edk2.groups.io
Cc: Jayaprakash, N ; Rebecca Cran ; 
Kinney, Michael D ; Kloper, Dimitry 

Subject: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump 
to 0, 0 issue in lseek()

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531

Python code opens console file descriptor and uses lseek() with position == 0 
and SEEK_CUR as 'do nothing, check console is alive' operation.

Current implementation of daConsole ignores whence argument, this is wrong in 
case lseek(0, SEEK_CUR) will send cursor to (0,0).
This fix is not generic, but solves the particular situation.

Cc: Rebecca Cran 
Cc: Michael D Kinney 
Cc: Jayaprakash N 
Signed-off-by: Kloper Dimitry 
---
 StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c 
b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
index 56571af..ba031d6 100644
--- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
+++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
@@ -141,8 +141,16 @@ da_ConSeek(
 EFIerrno = RETURN_UNSUPPORTED;
 return -1;
   }
-  // Everything is OK to do the final verification and "seek".
+
   Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+
+  if(Position == 0 && whence == SEEK_CUR) {
+CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
+CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
+return CursorPos.Offset;
+  }
+
+  // Everything is OK to do the final verification and "seek".
   CursorPos.Offset = Position;
 
   EFIerrno = Proto->SetCursorPosition(Proto,
--
2.40.0.windows.1








-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108035): https://edk2.groups.io/g/devel/message/108035
Mute This Topic: https://groups.io/mt/100952873/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()

2023-08-24 Thread Pedro Falcato
On Thu, Aug 24, 2023 at 5:34 PM Jayaprakash, N  wrote:
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531
>
> Python code opens console file descriptor and uses lseek()
> with position == 0 and SEEK_CUR as
> 'do nothing, check console is alive' operation.
>
> Current implementation of daConsole ignores whence argument,
> this is wrong in case lseek(0, SEEK_CUR) will send cursor to (0,0).
> This fix is not generic, but solves the particular situation.
>
> Cc: Rebecca Cran 
> Cc: Michael D Kinney 
> Cc: Jayaprakash N 
> Signed-off-by: Kloper Dimitry 
> ---
>  StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c 
> b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> index 56571af..ba031d6 100644
> --- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> +++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
> @@ -141,8 +141,16 @@ da_ConSeek(
>  EFIerrno = RETURN_UNSUPPORTED;
>  return -1;
>}
> -  // Everything is OK to do the final verification and "seek".
> +
>Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
> +
> +  if(Position == 0 && whence == SEEK_CUR) {
> +CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
> +CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
> +return CursorPos.Offset;
> +  }
> +
> +  // Everything is OK to do the final verification and "seek".
>CursorPos.Offset = Position;
>
>EFIerrno = Proto->SetCursorPosition(Proto,
> --
> 2.40.0.windows.1

ttys are historically not seekable devices.

per Linux lseek(2): "On Linux, using lseek() on a terminal device
fails with the error ESPIPE"

So this function (and consequently this patch) is wrong.

-- 
Pedro


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108025): https://edk2.groups.io/g/devel/message/108025
Mute This Topic: https://groups.io/mt/100938751/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: Fix console jump to 0, 0 issue in lseek()

2023-08-24 Thread Jayaprakash, N
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4531

Python code opens console file descriptor and uses lseek()
with position == 0 and SEEK_CUR as
'do nothing, check console is alive' operation.

Current implementation of daConsole ignores whence argument,
this is wrong in case lseek(0, SEEK_CUR) will send cursor to (0,0).
This fix is not generic, but solves the particular situation.

Cc: Rebecca Cran 
Cc: Michael D Kinney 
Cc: Jayaprakash N 
Signed-off-by: Kloper Dimitry 
---
 StdLib/LibC/Uefi/Devices/Console/daConsole.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c 
b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
index 56571af..ba031d6 100644
--- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
+++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
@@ -141,8 +141,16 @@ da_ConSeek(
 EFIerrno = RETURN_UNSUPPORTED;
 return -1;
   }
-  // Everything is OK to do the final verification and "seek".
+
   Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
+
+  if(Position == 0 && whence == SEEK_CUR) {
+CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;
+CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
+return CursorPos.Offset;
+  }
+
+  // Everything is OK to do the final verification and "seek".
   CursorPos.Offset = Position;
 
   EFIerrno = Proto->SetCursorPosition(Proto,
-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108016): https://edk2.groups.io/g/devel/message/108016
Mute This Topic: https://groups.io/mt/100938751/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-