Bug 93498

Summary: Request for implementing SIDT instruction
Product: [Developer tools] valgrind Reporter: Dennis Lubert <plasmahh>
Component: generalAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: wishlist CC: glider, tom
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: A patch for the SIDT and SGDT support in VEX on x86 and amd64

Description Dennis Lubert 2004-11-18 13:26:20 UTC
As stated on http://invisiblethings.org/papers/redpill.html the SIDT instruction
can be used by programs to detect if they run on a vm or not. It would be nice
if valgrind could implement it such that a program is not able to distingiush
between real and valgrind, so one can create a skin for analysing such tools.
Comment 1 Alexander Potapenko 2010-04-06 13:21:04 UTC
*** Bug 230085 has been marked as a duplicate of this bug. ***
Comment 2 Alexander Potapenko 2010-04-06 15:58:06 UTC
Created attachment 42530 [details]
A patch for the SIDT and SGDT support in VEX on x86 and amd64

This patch implements the SIDT and SGDT instructions support via a dirty helper that invokes native (x86/amd64) S{I,G}DT instructions. The approach is transparent for the client applications, so the redpill method is not able to distinguish between a native run and a Valgrind run.
Comment 3 Tom Hughes 2010-04-06 16:21:06 UTC
Can you provide some rationale as to why simply passing these instructions through is valid? Given that, as I understand it, the descriptor tables affect the interpretation of segment registers I would have though valgrind would need to be aware of any changes made to the descriptor tables?
Comment 4 Alexander Potapenko 2010-04-06 17:17:07 UTC
(In reply to comment #3)
> Can you provide some rationale as to why simply passing these instructions
> through is valid? Given that, as I understand it, the descriptor tables affect
> the interpretation of segment registers I would have though valgrind would need
> to be aware of any changes made to the descriptor tables?

IIUC, the SIDT and SGDT instructions do not modify the descriptor tables, only LIDT/LGDT do (which are harder to implement). Reading the descriptor tables shouldn't affect the segment registers. Am I missing something?
Comment 5 Tom Hughes 2010-04-06 17:45:20 UTC
Ah OK I had my load/store ideas the wrong way round. That should be fine then. Obviously as it's a VEX issue Julian will need to deal with it anyway.
Comment 6 Julian Seward 2010-04-12 23:29:57 UTC
Alexander, can you explain why you want to use this instruction?
According to the Intel documentation "SIDT is only useful in
operating-system software; however it can be used in application
programs without causing an exception to be generated."
Comment 7 Alexander Potapenko 2010-04-13 11:08:02 UTC
(In reply to comment #6)
The SIDT instruction is for some strange reason used by the client code in Mac OS 10.6 (see https://bugs.kde.org/show_bug.cgi?id=205241#c36), so Valgrind can't work on Snow Leopard without having it implemented.

> Alexander, can you explain why you want to use this instruction?
> According to the Intel documentation "SIDT is only useful in
> operating-system software; however it can be used in application
> programs without causing an exception to be generated."