Passing struct pointer to magic function causing segmentation fault

51 views
Skip to first unread message

Shaikhul Hadi

unread,
Aug 28, 2021, 11:02:05 PM8/28/21
to Sniper simulator
Hi,
For a magic function , within function handleMatgic() from sift/recorder/recorder_control.cc file , I read couple of register value from register and put them in a struct varaible "magicArguments" . Then in

   " res = thread_data[threadid].output->Magic(gax, gbx, (uint64_t)&magicArguments );"

I pass reference or address of the magicArguments struct instead of gcx ( Just like MagicMarkerType struct is passed as argument of callHooks () in magic_server.cc file  ).  I have printed address of the struct before passing as argument and from within my magic function to check in both cases, if the address I have received is same or some error occurred in the address value. I receive same address value associated with the struct variable. Yet whenever I tried to access the address to retrieve value, it causes segmentation fault. 

Struct :
 struct CASValue
{
         uint64_t compare;
         uint64_t swap;
     } ;


Code of interest in recorder_control.cc :
ADDRINT handleMagicExt(THREADID threadid, CONTEXT * ctxt, ADDRINT gax, ADDRINT gbx, ADDRINT gcx, PIN_REGISTER * pin_gdx)
  {
// Just ignore Ext part of the function name, this function is being called properly 
    CASValue magicArgument = {compare: pin_gdx->qword[0], swap: gcx };
      //pin_qdx->qword[0] gives value of register rdx
    uint64_t res = gax; // Default: don't modify gax
 
    if (KnobUseResponseFiles.Value() && thread_data[threadid].running && thread_data[threadid].output)
    {
      res = thread_data[threadid].output->Magic(gax, gbx, (uint64_t)&magicArgument);

    }


Code of interest in hooked function :
    MagicServer::MagicMarkerType* m_args;
    m_args = (MagicServer::MagicMarkerType *)args;  // m_args->arg1 will have the content of thrid argument passed in Magic() function
   CASValue* magicArgument = NULL;
   magicArgument = (CASValue *) m_args->arg1;

Now if I try to access magicArgument like magicArgument->compare or magicArgument->swap will cause segmentation fault. Could anyone could point me out what is causing the issue? 

Thanks in advance 






Reply all
Reply to author
Forward
0 new messages