예제 #1
0
파일: Initializers.c 프로젝트: BigEd/Cores
int InitializeType(TYP *tp)
{   
	int nbytes;

    switch(tp->type) {
	case bt_byte:
			nbytes = initbyte();
			break;
    case bt_char:
    case bt_enum:
            nbytes = initchar();
            break;
    case bt_short:
            nbytes = initshort();
            break;
    case bt_pointer:
            if( tp->val_flag)
                nbytes = InitializeArray(tp);
            else
                nbytes = InitializePointer();
            break;
    case bt_long:
            nbytes = initlong();
            break;
    case bt_struct:
            nbytes = InitializeStructure(tp);
            break;
    default:
        error(ERR_NOINIT);
        nbytes = 0;
    }
    return nbytes;
}
예제 #2
0
//
// Flushes all established global exemptions
//
DWORD DriverClient::FlushExemptions(
		IN HANDLE Driver,
		IN EXEMPTION_SCOPE Scope,
		IN EXEMPTION_TYPE Type)
{
	WEHNTRUST_EXEMPTION_INFO ExemptionInfo;
	DWORD                    Returned;
	DWORD                    Result = ERROR_SUCCESS;

	ZeroMemory(
			&ExemptionInfo,
			sizeof(ExemptionInfo));

	InitializeStructure(
			&ExemptionInfo,
			sizeof(ExemptionInfo));

	ExemptionInfo.Scope = Scope;
	ExemptionInfo.Type  = Type;

	if (!DeviceIoControl(
			Driver,
			IOCTL_WEHNTRUST_FLUSH_EXEMPTIONS,
			&ExemptionInfo,
			sizeof(ExemptionInfo),
			NULL,
			0,
			&Returned,
			NULL))
		Result = GetLastError();

	return Result;
}
예제 #3
0
//
// Initialize an exemption information context that will be passed up to the
// driver
//
PWEHNTRUST_EXEMPTION_INFO DriverClient::InitializeExemptionInfo(
		IN EXEMPTION_SCOPE Scope,
		IN EXEMPTION_TYPE Type,
		IN ULONG Flags,
		IN LPCTSTR ExemptionPath,
		IN BOOLEAN ExemptionPathIsNt,
		OUT LPDWORD ExemptionInfoSize)
{
	PWEHNTRUST_EXEMPTION_INFO ExemptionInfo = NULL;
	UNICODE_STRING            ExemptionNtPath = { 0 };
	DWORD                     Size = 0;

	//
	// Double check to see if the supplied path is an NT path
	//
	if (!StrCmpN(
			ExemptionPath,
			TEXT("\\??\\"),
			sizeof(TCHAR) * 4))
		ExemptionPathIsNt = TRUE;

	do
	{
		//
		// If we fail to acquire the NT path, break out
		//
		if (!GetNtPath(
				ExemptionPath,
				&ExemptionNtPath,
				ExemptionPathIsNt))
			break;

		Size = ExemptionNtPath.Length + sizeof(WEHNTRUST_EXEMPTION_INFO);

		//
		// If we fail to acquire storage for the exemption...
		//
		if (!(ExemptionInfo = (PWEHNTRUST_EXEMPTION_INFO)malloc(Size)))
			break;

		InitializeStructure(
				ExemptionInfo,
				sizeof(WEHNTRUST_EXEMPTION_INFO));

		ExemptionInfo->Type              = Type;
		ExemptionInfo->Scope             = Scope;
		ExemptionInfo->Flags             = Flags;
		ExemptionInfo->ExemptionPathSize = ExemptionNtPath.Length;

		memcpy(
				ExemptionInfo->ExemptionPath,
				ExemptionNtPath.Buffer,
				ExemptionNtPath.Length);

	} while (0);

	//
	// Free the NT path storage
	//
	if (ExemptionPathIsNt)
		free(
				ExemptionNtPath.Buffer);
	else
		FreeNtPath(
				&ExemptionNtPath);

	//
	// Set the out size
	//
	if (ExemptionInfoSize)
		*ExemptionInfoSize = Size;

	return ExemptionInfo;
}
예제 #4
0
  ESymSolverStatus
  TSymLinearSolver::MultiSolve(const SymMatrix& sym_A,
                               std::vector<SmartPtr<const Vector> >& rhsV,
                               std::vector<SmartPtr<Vector> >& solV,
                               bool check_NegEVals,
                               Index numberOfNegEVals)
  {
    DBG_START_METH("TSymLinearSolver::MultiSolve",dbg_verbosity);
    DBG_ASSERT(!check_NegEVals || ProvidesInertia());

    // Check if this object has ever seen a matrix If not,
    // allocate memory of the matrix structure and copy the nonzeros
    // structure (it is assumed that this will never change).
    if (!initialized_) {
      ESymSolverStatus retval = InitializeStructure(sym_A);
      if (retval != SYMSOLVER_SUCCESS) {
        return retval;
      }
    }

    DBG_ASSERT(nonzeros_triplet_== TripletHelper::GetNumberEntries(sym_A));

    // Check if the matrix has been changed
    DBG_PRINT((1,"atag_=%d sym_A->GetTag()=%d\n",atag_,sym_A.GetTag()));
    bool new_matrix = sym_A.HasChanged(atag_);
    atag_ = sym_A.GetTag();

    // If a new matrix is encountered, get the array for storing the
    // entries from the linear solver interface, fill in the new
    // values, compute the new scaling factors (if required), and
    // scale the matrix
    if (new_matrix || just_switched_on_scaling_) {
      GiveMatrixToSolver(true, sym_A);
      new_matrix = true;
    }

    // Retrieve the right hand sides and scale if required
    Index nrhs = (Index)rhsV.size();
    double* rhs_vals = new double[dim_*nrhs];
    for (Index irhs=0; irhs<nrhs; irhs++) {
      TripletHelper::FillValuesFromVector(dim_, *rhsV[irhs],
                                          &rhs_vals[irhs*(dim_)]);
      if (Jnlst().ProduceOutput(J_MOREMATRIX, J_LINEAR_ALGEBRA)) {
        Jnlst().Printf(J_MOREMATRIX, J_LINEAR_ALGEBRA,
                       "Right hand side %d in TSymLinearSolver:\n", irhs);
        for (Index i=0; i<dim_; i++) {
          Jnlst().Printf(J_MOREMATRIX, J_LINEAR_ALGEBRA,
                         "Trhs[%5d,%5d] = %23.16e\n", irhs, i,
                         rhs_vals[irhs*(dim_)+i]);
        }
      }
      if (use_scaling_) {
        if (HaveIpData()) {
          IpData().TimingStats().LinearSystemScaling().Start();
        }
        for (Index i=0; i<dim_; i++) {
          rhs_vals[irhs*(dim_)+i] *= scaling_factors_[i];
        }
        if (HaveIpData()) {
          IpData().TimingStats().LinearSystemScaling().End();
        }
      }
    }

    bool done = false;
    // Call the linear solver through the interface to solve the
    // system.  This is repeated, if the return values is S_CALL_AGAIN
    // after the values have been restored (this might be necessary
    // for MA27 if the size of the work space arrays was not large
    // enough).
    ESymSolverStatus retval;
    while (!done) {
      const Index* ia;
      const Index* ja;
      if (matrix_format_==SparseSymLinearSolverInterface::Triplet_Format) {
        ia = airn_;
        ja = ajcn_;
      }
      else {
        if (HaveIpData()) {
          IpData().TimingStats().LinearSystemStructureConverter().Start();
        }
        ia = triplet_to_csr_converter_->IA();
        ja = triplet_to_csr_converter_->JA();
        if (HaveIpData()) {
          IpData().TimingStats().LinearSystemStructureConverter().End();
        }
      }

      retval = solver_interface_->MultiSolve(new_matrix, ia, ja,
                                             nrhs, rhs_vals, check_NegEVals,
                                             numberOfNegEVals);
      if (retval==SYMSOLVER_CALL_AGAIN) {
        DBG_PRINT((1, "Solver interface asks to be called again.\n"));
        GiveMatrixToSolver(false, sym_A);
      }
      else {
        done = true;
      }
    }

    // If the solve was successful, unscale the solution (if required)
    // and transfer the result into the Vectors
    if (retval==SYMSOLVER_SUCCESS) {
      for (Index irhs=0; irhs<nrhs; irhs++) {
        if (use_scaling_) {
          if (HaveIpData()) {
            IpData().TimingStats().LinearSystemScaling().Start();
          }
          for (Index i=0; i<dim_; i++) {
            rhs_vals[irhs*(dim_)+i] *= scaling_factors_[i];
          }
          if (HaveIpData()) {
            IpData().TimingStats().LinearSystemScaling().End();
          }
        }
        if (Jnlst().ProduceOutput(J_MOREMATRIX, J_LINEAR_ALGEBRA)) {
          Jnlst().Printf(J_MOREMATRIX, J_LINEAR_ALGEBRA,
                         "Solution %d in TSymLinearSolver:\n", irhs);
          for (Index i=0; i<dim_; i++) {
            Jnlst().Printf(J_MOREMATRIX, J_LINEAR_ALGEBRA,
                           "Tsol[%5d,%5d] = %23.16e\n", irhs, i,
                           rhs_vals[irhs*(dim_)+i]);
          }
        }
        TripletHelper::PutValuesInVector(dim_, &rhs_vals[irhs*(dim_)],
                                         *solV[irhs]);
      }
    }

    delete[] rhs_vals;

    return retval;
  }