BYTE CheckUserInput (P_PROGRAMSTATE Program_state, P_THREADSTATE Thread_local_state, P_USERINPUT User_input) 
{
  ULONG Layer_id = 0; ULONG Error_code = NO_ERROR;      

  EXCEPTIONRECORD Record = {
                            .Handler = CheckUserInputExceptionHandler,          
                            .Program_state = Program_state,
                            .Thread_context = Thread_local_state,
                            .Local_pointer = User_input,
                            .Complete_label = &&complete,
                            .Stack_frame_array_length = 12,
                            .Exception_layer = &Layer_id,
                            .Error_code = &Error_code
                           };

  DosSetExceptionHandler (&Record);

  ú
  ú
  ú

complete:

  DosUnsetExceptionHandler (&Record);

  DosUnsetVariables (&Layer_id);

  return (Error_code == NO_ERROR) ? 1 : 0;
}

ULONG APIENTRY CheckUserInputExceptionHandler (P_EXCEPTION    Exception,
                                               P_PROGRAMSTATE Program_state,
                                               P_THREADSTATE  Thread_local_state,
                                               P_USERINPUT    User_input)
{
  WRTLOG_ARG Record = {
                       .Stream = Program_state->Logger.Output_handle,
                       .Writer_name = __FUNCTION__ ", " __FILE__,
                       .Error_code = Exception->Number,
                       .Exception_flags = Exception->Flags,
                       .Byte_array = User_input->Byte_array,
                       .Byte_array_length = User_input->Length,
                       .Stack_frame_array = Exception->Stack_frame_array.Pointers,
                       .Stack_frame_length = Exception->Stack_frame_array.Length
                      };

  WriteErrorLog (&Record);

  return XCPT_CONTINUE_EXECUTION;
}
