예제 #1
0
파일: push.c 프로젝트: Volkanite/Push
VOID
PushAddToFileList( FILE_LIST* FileList, FILE_LIST_ENTRY *FileEntry )
{
    FILE_LIST_ENTRY *fileListEntry;
    WCHAR *name;

    name = (WCHAR*)Memory_Allocate(
            /*PushHeapHandle,
            0,*/
            (String_GetLength(FileEntry->Name) + 1) * sizeof(WCHAR)
            );

    String_Copy(name, FileEntry->Name);

    if (*FileList == NULL)
    {
        FILE_LIST_ENTRY *fileList;

        *FileList = (FILE_LIST)Memory_Allocate(
            /*PushHeapHandle,
            0,*/
            sizeof(FILE_LIST_ENTRY)
            );

        fileList = *FileList;

        fileList->NextEntry = NULL;
        fileList->Bytes = FileEntry->Bytes;
        fileList->Name = name;
        fileList->Cache = FileEntry->Cache;

        return;
    }

    fileListEntry = (FILE_LIST_ENTRY*) *FileList;

    while (fileListEntry->NextEntry != 0)
    {
        fileListEntry = fileListEntry->NextEntry;
    }

    fileListEntry->NextEntry = (FILE_LIST_ENTRY *)Memory_Allocate(
        /*PushHeapHandle,
        0,*/
        sizeof(FILE_LIST_ENTRY)
        );

    fileListEntry = fileListEntry->NextEntry;

    fileListEntry->Bytes = FileEntry->Bytes;
    fileListEntry->Name = name;
    fileListEntry->Cache = FileEntry->Cache;
    fileListEntry->NextEntry = 0;
}
예제 #2
0
void LinkList_Insert(LINKLIST* pll, LINKLISTINFO* plliNext, PVOID pObject) {
	LINKLISTINFO* plliPrev;
	LINKLISTINFO* plliNew;

	if (!plliNext) {
		LinkList_Add(pll, pObject);
	} else {

		plliPrev = plliNext->plliPrev;

		plliNew = Memory_Allocate(sizeof(LINKLISTINFO));
		plliNew->pObject = pObject;
		plliNew->plliNext = plliNext;
		plliNew->plliPrev = plliPrev;

		if (plliPrev) {
			plliPrev->plliNext = plliNew;
		} else {
			pll->plliHead = plliNew;
		}

		plliNext->plliPrev = plliNew;
	}

}
예제 #3
0
LINKLIST* LinkList_Create() {
	LINKLIST* pll;

	pll = Memory_Allocate(sizeof(LINKLIST));
	pll->plliHead = NULL;
	pll->plliTail = NULL;

	return pll;
}
예제 #4
0
파일: hardware.c 프로젝트: Volkanite/Push
VOID GetHardwareInfo()
{
    int i = 0;
    int monitorCount;
    HANDLE gdi32;
    int cores = 0;

    //use 64 bits to force allmul() on 32 bit builds
    UINT64 physicalPages;
    UINT64 pageSize;

    InitGpuHardware();
    GPU_Initialize(PushSharedMemory->HarwareInformation.DisplayDevice.pciAddress);

    PushSharedMemory->HarwareInformation.DisplayDevice.FrameBuffer.Total = GPU_GetTotalMemory();
    PushSharedMemory->HarwareInformation.DisplayDevice.EngineClockMax = GPU_GetMaximumEngineClock();
    PushSharedMemory->HarwareInformation.DisplayDevice.MemoryClockMax = GPU_GetMaximumMemoryClock();
    PushSharedMemory->HarwareInformation.DisplayDevice.VoltageMax = GPU_GetMaximumVoltage();

    if (Ini_ReadBoolean(L"Settings", L"GpuUsageD3DKMT", FALSE, L".\\" PUSH_SETTINGS_FILE))
        PushGpuLoadD3DKMT = TRUE;

    // Get the number of processors in the system
    NtQuerySystemInformation(SystemBasicInformation, &HwInfoSystemBasicInformation, sizeof(SYSTEM_BASIC_INFORMATION), 0);

    PushSharedMemory->HarwareInformation.Processor.NumberOfThreads = HwInfoSystemBasicInformation.NumberOfProcessors;

    physicalPages = HwInfoSystemBasicInformation.NumberOfPhysicalPages;
    pageSize = HwInfoSystemBasicInformation.PageSize;

    //byte => megabytes
    PushSharedMemory->HarwareInformation.Memory.Total = (physicalPages * pageSize) / 1048576;

    cores = CPU_Intialize();

    PushSharedMemory->HarwareInformation.Processor.NumberOfCores = cores;
    PushSharedMemory->HarwareInformation.Processor.TjMax = CPU_GetTemperatureMaximal();
    PushSharedMemory->HarwareInformation.Processor.MhzBase = CPU_GetBaseSpeed();

    // Monitors
    gdi32 = Module_Load(L"gdi32.dll");

    GetNumberOfPhysicalMonitors = Module_GetProcedureAddress(gdi32, "GetNumberOfPhysicalMonitors");
    GetPhysicalMonitors = Module_GetProcedureAddress(gdi32, "GetPhysicalMonitors");
    DDCCIGetTimingReport = Module_GetProcedureAddress(gdi32, "DDCCIGetTimingReport");
    DDCCIGetVCPFeature = Module_GetProcedureAddress(gdi32, "DDCCIGetVCPFeature");
    DDCCISetVCPFeature = Module_GetProcedureAddress(gdi32, "DDCCISetVCPFeature");

    monitorCount = GetSystemMetrics(SM_CMONITORS);
    MonitorWidth = GetSystemMetrics(SM_CXSCREEN);
    MonitorHeight = GetSystemMetrics(SM_CYSCREEN);

    MonitorHandles = Memory_Allocate(sizeof(HANDLE) * monitorCount);

    EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, NULL);
}
예제 #5
0
void MemoryBuffer_Resize(StState *st, MemoryBuffer *mbuff, size_t newSize)
{
    if (mbuff->buffer == NULL)
    {
        mbuff->buffer = Memory_Allocate(st, newSize);
    }
    else
    {
        mbuff->buffer = Memory_Reallocate(st, mbuff->buffer, newSize);
    }
}
예제 #6
0
void LinkList_Add(LINKLIST* pll, PVOID pObject) {
	LINKLISTINFO* plliNew;

	plliNew = Memory_Allocate(sizeof(LINKLISTINFO));

	plliNew->pObject = pObject;

	if (!pll->plliHead) {
		pll->plliHead = plliNew;
		pll->plliTail = plliNew;
	} else {
		plliNew->plliPrev = pll->plliTail;
		pll->plliTail->plliNext = plliNew;
		pll->plliTail = plliNew;
	}
}
예제 #7
0
파일: buffer.c 프로젝트: mrDIMAS/OldTech
bool Buffer_LoadFile( TBuffer * buf, const char * fileName, unsigned int * crc32 ) {
    FILE * file = fopen( fileName, "rb" );
    if( !file ) {
        return false;
    };
    fseek( file, 0, SEEK_END );
    buf->size = ftell( file );
    fseek( file, 0, SEEK_SET );
    buf->data = Memory_Allocate( buf->size );
    fread( buf->data, buf->size, 1, file );
    if( crc32 ) {
        *crc32 = CRC32( 0, buf->data, buf->size );
    }
    buf->pointer = 0;
    buf->file = NULL;
    fclose( file );
    return true;
}
예제 #8
0
파일: main.c 프로젝트: Mynogs/CN1
 void DumpDirectory(const char *path, const char *title)
 {
   //return;
   uint32_t fre_sect = 0;
   FATFS *fs;
   DWORD fre_clust;
   if (f_getfree(path, &fre_clust, &fs) == FR_OK) 
     fre_sect = fre_clust * fs->csize;
   DEBUG("\n  Directory of %s (%s)\n", path, title);
   DIR dir;
   int result = f_opendir(&dir, path);
   if (result == FR_OK) {
     uint16_t fileCount = 0, dirCount = 0;
     FILINFO fno;
     fno.lfname = Memory_Allocate(_MAX_LFN + 1, 0);
     fno.lfsize = _MAX_LFN + 1;
     for (;;) {
       result = f_readdir(&dir, &fno);
       if ((result != FR_OK) || (fno.fname[0] == 0) || (fno.fname[0] == 0xFF))
         break;
       if (fno.fattrib & AM_DIR) {
         DEBUG("                           <DIR>       %s\n", fno.lfname[0] ? fno.lfname : fno.fname);
         dirCount++;
       } else {
         DEBUG(
           "    %u/%02u/%02u %02u:%02u %c%c%c%c %12u %s\n",
           (fno.fdate >> 9) + 1980,
           fno.fdate >> 5 & 15,
           fno.fdate & 31,
           fno.ftime >> 11,
           fno.ftime >> 5 & 63,
           (fno.fattrib & AM_RDO) ? 'R' : '-',
           (fno.fattrib & AM_HID) ? 'H' : '-',
           (fno.fattrib & AM_SYS) ? 'S' : '-',
           (fno.fattrib & AM_ARC) ? 'A' : '-',
           fno.fsize,
           fno.lfname[0] ? fno.lfname : fno.fname
         );
         fileCount++;
       }
     }
     Memory_Free(fno.lfname, _MAX_LFN + 1);
     DEBUG("  Files: %u, directorys %u, free %u kB\n\n", fileCount, dirCount, fre_sect / 2);
   } else
예제 #9
0
파일: mtask.c 프로젝트: hikalium/chnos
UI_TaskControl *Initialize_MultiTask_Control(IO_MemoryControl sysmemctrl)
{
	UI_TaskControl *ctrl;
	UI_Task *maintask;

	ctrl = Memory_Allocate(sysmemctrl, sizeof(UI_TaskControl));
	ctrl->now = 0;
	ctrl->sysmemctrl = sysmemctrl;

	maintask = MultiTask_Task_Initialize(ctrl, 0);

	Load_TR(maintask->selector << 3);

	ctrl->start = maintask;
	ctrl->now = maintask;

	maintask->flags.linked = True;
	maintask->flags.running = True;
	maintask->flags.first_run = False;
	FIFO32_Set_Task(maintask->fifo, maintask);

	return ctrl;
}
예제 #10
0
파일: folder.c 프로젝트: Volkanite/Push
NTSTATUS Directory_Enum(
    WCHAR* Directory,
    WCHAR* SearchPattern,
    SL_ENUM_DIRECTORY Callback
    )
{
    NTSTATUS status;
    IO_STATUS_BLOCK isb;
    BOOLEAN firstTime = TRUE;
    VOID *directoryHandle, *buffer;
    UINT32 bufferSize = 0x400;
    UINT32 i;
    UNICODE_STRING pattern;

    status = File_Create(
        &directoryHandle,
        Directory,
        FILE_LIST_DIRECTORY | SYNCHRONIZE,
        FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
        FILE_OPEN,
        FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
        NULL
        );

    if (!NT_SUCCESS(status))
        return status;

    buffer = Memory_Allocate(bufferSize);

    UnicodeString_Init(&pattern, SearchPattern);

    while (TRUE)
    {
        // Query the directory, doubling the buffer each time NtQueryDirectoryFile fails.
        while (TRUE)
        {
            status = NtQueryDirectoryFile(
                directoryHandle,
                NULL,
                NULL,
                NULL,
                &isb,
                buffer,
                bufferSize,
                FileDirectoryInformation,
                FALSE,
                &pattern,
                firstTime
                );

            // Our ISB is on the stack, so we have to wait for the operation to complete
            // before continuing.
            if (status == STATUS_PENDING)
            {
                status = NtWaitForSingleObject(directoryHandle, FALSE, NULL);

                if (NT_SUCCESS(status))
                    status = isb.Status;
            }

            if (status == STATUS_BUFFER_OVERFLOW || status == STATUS_INFO_LENGTH_MISMATCH)
            {
                Memory_Free(buffer);

                bufferSize *= 2;
                buffer = Memory_Allocate(bufferSize);
            }
            else
            {
                break;
            }

        }

        // If we don't have any entries to read, exit.
        if (status == STATUS_NO_MORE_FILES)
        {
            status = STATUS_SUCCESS;
            break;
        }

        if (!NT_SUCCESS(status))
            break;

        // Read the batch and execute the callback function for each file.

        i = 0;

        while (TRUE)
        {
            FILE_DIRECTORY_INFORMATION *information;

            information = (FILE_DIRECTORY_INFORMATION *)(((UINT_B)(buffer)) + i);

            if (Callback)
                Callback(Directory, information);

            if (information->NextEntryOffset != 0)
                i += information->NextEntryOffset;
            else
                break;
        }

        firstTime = FALSE;
    }

    Memory_Free(buffer);

    NtClose(directoryHandle);

    return status;
}
예제 #11
0
void mexFunction(int nlhs, mxArray *plhs[], int	nrhs, const mxArray *prhs[])
{
  FILE *log;
  Options_Interface *o;
  Void *timer;
  MCP *m;
  MCP_Termination t;
  Information info;

  double *tempZ;
  double *status, *tot_time;
  double dnnz;
  int i, len;

  mat_install_error();
  mat_install_memory();

  log = fopen("logfile.tmp", "w");
  Output_SetLog(log);

  /* Options.
     1.  Get options associated with the algorithm
     2.  Set to default values
     3.  Read in an options file
     4.  Print out the options */

  o = Options_Create();
  Path_AddOptions(o);
  Options_Default(o);

  if (nrhs < 7) {
    Error("Not enough input arguments.\n");
  }

  if (nlhs < 2) {
    Error("Not enough output arguments.\n");
  }

  nMax = (int) mxGetScalar(prhs[0]);
  nnzMax = (int) mxGetScalar(prhs[1]);

  plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
  plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL);

  if (nlhs > 2) {
    plhs[2] = mxCreateDoubleMatrix(nMax,1,mxREAL);
  }

  if (nlhs > 3) {
    plhs[3] = mxCreateDoubleMatrix(nMax,1,mxREAL);
  }

  /* Create a timer and start it. */
  timer = Timer_Create();
  Timer_Start(timer);

  /* Derefencing to get the status argument. */
  status = mxGetPr(plhs[0]);
  tot_time = mxGetPr(plhs[1]);

  /* First print out some version information.  */
  Output_Printf(Output_Log | Output_Status | Output_Listing,
		"%s: Matlab Link\n", Path_Version());

  /* Now check the arguments.

     If the dimension of the problem is 0, there is nothing to do.
  */

  if (nMax == 0) {
    Output_Printf(Output_Log | Output_Status,
		  "\n ** EXIT - solution found (degenerate model).\n");
    (*status) = 1.0;
    (*tot_time) = Timer_Query(timer);

    Timer_Destroy(timer);
    Options_Destroy(o);
    fclose(log);
    return;
  }

  /* Check size of the jacobian.  nnz < n*n.  Need to convert to double
     so we do not run out of integers.

     dnnz - max number of nonzeros as a double
  */

  dnnz = MIN(1.0*nnzMax, 1.0*nMax*nMax);
  if (dnnz > INT_MAX) {
    Output_Printf(Output_Log | Output_Status,
		  "\n ** EXIT - model too large.\n");
    (*status) = 0.0;
    (*tot_time) = Timer_Query(timer);

    Timer_Destroy(timer);
    Options_Destroy(o);
    fclose(log);
    return;
  }
  nnzMax = (int) dnnz;

  /* Have correct number of nonzeros.  Print some statistics.
     Print out the density.  */

  Output_Printf(Output_Log | Output_Status | Output_Listing,
		"%d row/cols, %d non-zeros, %3.2f%% dense.\n\n",
		nMax, nnzMax, 100.0*nnzMax/(1.0*nMax*nMax));

  if (nnzMax == 0) {
    nnzMax++;
  }

  zp = mxGetPr(prhs[2]);
  lp = mxGetPr(prhs[3]);
  up = mxGetPr(prhs[4]);

  m_start = mxGetJc(prhs[5]);
  m_row = mxGetIr(prhs[5]);
  m_data = mxGetPr(prhs[5]);
  m_len = (int *)Memory_Allocate(nMax*sizeof(int));

  for (i = 0; i < nMax; i++) {
    m_len[i] = m_start[i+1] - m_start[i];
    m_start[i]++;
  }
  actualNnz = m_start[nMax];

  for (i = 0; i < actualNnz; i++) {
    m_row[i]++;
  }

  q = mxGetPr(prhs[6]);
     
  /* Create a structure for the problem. */
  m = MCP_Create(nMax, nnzMax);
  MCP_Jacobian_Structure_Constant(m, 1);
  MCP_Jacobian_Data_Contiguous(m, 1);
  install_interface(m);

  Options_Read(o, "path.opt");
  Options_Display(o);

  info.generate_output = Output_Log | Output_Status | Output_Listing;
  info.use_start = True;
  info.use_basics = True;

  /* Solve the problem.  
     m - MCP to solve, info - information, t - termination */

  t = Path_Solve(m, &info);

  /* Read in the results.  First get the solution vector. The report. */

  tempZ = MCP_GetX(m);
  for (i = 0; i < nMax; i++) {
    zp[i] = tempZ[i];
  }

  /* If the final function evaluation is wanted, report it. */
  if (nlhs > 2) {
    double *fval = mxGetPr(plhs[2]);

    tempZ = MCP_GetF(m);
    for (i = 0; i < nMax; i++) {
      fval[i] = tempZ[i];
    }
  }

  /* If the final basis is wanted, report it. */
  if (nlhs > 3) {
    double *bval = mxGetPr(plhs[3]);
    int *tempB;

    tempB = MCP_GetB(m);
    for (i = 0; i < nMax; i++) {
      switch(tempB[i]) {
      case Basis_LowerBound:
	bval[i] = -1;
	break;

      case Basis_UpperBound:
	bval[i] = 1;
	break;

      default:
	bval[i] = 0;
	break;
      }
    }
  }

  switch(t) {
  case MCP_Solved:
    *status = 1.0;
    break;

  default:
    *status = 0.0;
    break;
  }
     
  /* Stop the timer and report the results. */
  (*tot_time) = Timer_Query(timer);
  Timer_Destroy(timer);

  /* Clean up.  Deallocate memory used and close the log. */
  MCP_Destroy(m);
  Memory_Free(m_len);
  Options_Destroy(o);

  fclose(log);
  return;
}
예제 #12
0
파일: mtask.c 프로젝트: hikalium/chnos
UI_Task *MultiTask_Task_Initialize(UI_TaskControl *ctrl, uint tss_additional_size)
{
	UI_Task *task;

	task = Memory_Allocate(ctrl->sysmemctrl, sizeof(UI_Task));
	task->tss = Memory_Allocate(ctrl->sysmemctrl, sizeof(CPU_TaskStateSegment) + tss_additional_size);

	task->tss->reserve00		= 0;
	task->tss->reserve01		= 0;
	task->tss->reserve02		= 0;
	task->tss->reserve03		= 0;
	task->tss->reserve04		= 0;
	task->tss->reserve05		= 0;
	task->tss->reserve06		= 0;
	task->tss->reserve07		= 0;
	task->tss->reserve08		= 0;
	task->tss->reserve09		= 0;
	task->tss->reserve10		= 0;
	task->tss->reserve11		= 0;

	task->tss->backlink		= 0;
	task->tss->esp0			= 0;
	task->tss->ss0			= 0;
	task->tss->esp1			= 0;
	task->tss->ss1			= 0;
	task->tss->esp2			= 0;
	task->tss->ss2			= 0;

	task->tss->cr3			= 0;
	task->tss->eip			= 0;
	task->tss->eflags.eflags	= 0x00000202;	//bit1=True, IF=True

	task->tss->eax			= 0;
	task->tss->ecx			= 0;
	task->tss->edx			= 0;
	task->tss->ebx			= 0;
	task->tss->esp			= 0;
	task->tss->ebp			= 0;
	task->tss->esi			= 0;
	task->tss->edi			= 0;

	task->tss->es			= 0;
	task->tss->cs			= 0;
	task->tss->ss			= 0;
	task->tss->ds			= 0;
	task->tss->fs			= 0;
	task->tss->gs			= 0;

	task->tss->ldtr			= 0;
	task->tss->flag_trap		= False;
	task->tss->iomap_base		= 0x00004000;	//TSSリミット以上なら無効

	task->selector = System_SegmentDescriptor_Set(sizeof(CPU_TaskStateSegment) + tss_additional_size - 1, (uint)task->tss, AR_TSS32);

	task->next = 0;
	task->count = 0;

	task->fifo = FIFO32_Initialize(ctrl->sysmemctrl, TASK_FIFOSIZE);

	task->flags.initialized = True;
	task->flags.linked = False;
	task->flags.first_run = True;

	return task;
}
예제 #13
0
파일: push.c 프로젝트: Volkanite/Push
HANDLE OpenProcess( DWORD ProcessId )
{
    HANDLE processHandle = 0;

    processHandle = Process_Open(
        ProcessId,
        PROCESS_VM_OPERATION |
        PROCESS_VM_READ |
        PROCESS_VM_WRITE |
        PROCESS_VM_OPERATION |
        PROCESS_CREATE_THREAD |
        PROCESS_QUERY_INFORMATION |
        SYNCHRONIZE
        );

    if (!processHandle)
    {
        NTSTATUS status;
        ULONG bufferSize;
        SECURITY_DESCRIPTOR* securityDescriptor;

        bufferSize = 0x100;
        securityDescriptor = (SECURITY_DESCRIPTOR*)Memory_Allocate(bufferSize);

        // Get the DACL of this process since we know we have all rights in it.
        status = NtQuerySecurityObject(
            NtCurrentProcess(),
            DACL_SECURITY_INFORMATION,
            securityDescriptor,
            bufferSize,
            &bufferSize
            );

        if (status == STATUS_BUFFER_TOO_SMALL)
        {
            Memory_Free(securityDescriptor);
            securityDescriptor = (SECURITY_DESCRIPTOR*)Memory_Allocate(bufferSize);

            status = NtQuerySecurityObject(
                NtCurrentProcess(),
                DACL_SECURITY_INFORMATION,
                securityDescriptor,
                bufferSize,
                &bufferSize
                );
        }

        if (!NT_SUCCESS(status))
        {
            Memory_Free(securityDescriptor);
            return NULL;
        }

        // Open it with WRITE_DAC access so that we can write to the DACL.
        processHandle = Process_Open(ProcessId, (0x00040000L)); //WRITE_DAC

        if (processHandle == 0)
        {
            Memory_Free(securityDescriptor);
            return NULL;
        }

        status = NtSetSecurityObject(
            processHandle,
            DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION,
            securityDescriptor
            );

        if (!NT_SUCCESS(status))
        {
            Memory_Free(securityDescriptor);
            return NULL;
        }

        // The DACL is overwritten with our own DACL. We
        // should be able to open it with the requested
        // privileges now.

        Process_Close(processHandle);

        processHandle = 0;
        Memory_Free(securityDescriptor);

        processHandle = Process_Open(
            ProcessId,
            PROCESS_VM_OPERATION |
            PROCESS_VM_READ |
            PROCESS_VM_WRITE |
            PROCESS_VM_OPERATION |
            PROCESS_CREATE_THREAD |
            PROCESS_QUERY_INFORMATION |
            SYNCHRONIZE
            );
    }

    if (!processHandle)
    {
        return NULL;
    }

    return processHandle;
}
예제 #14
0
파일: push.c 프로젝트: Volkanite/Push
INT32 __stdcall start( )
{
    HANDLE sectionHandle, *hMutex;
    HANDLE eventHandle;
    HANDLE threadHandle;
    DWORD sectionSize;
    MSG messages;
    OBJECT_ATTRIBUTES objAttrib = {0};
    PTEB threadEnvironmentBlock;
    UNICODE_STRING eventSource;
    LDR_DATA_TABLE_ENTRY *module;
    SECTION_BASIC_INFORMATION sectionInfo;
    LARGE_INTEGER newSectionSize;

    InitializeCRT();

    threadEnvironmentBlock = NtCurrentTeb();

    PushProcessId = threadEnvironmentBlock->ClientId.UniqueProcess;
    PushHeapHandle = threadEnvironmentBlock->ProcessEnvironmentBlock->ProcessHeap;
    PushSessionId = threadEnvironmentBlock->ProcessEnvironmentBlock->SessionId;

    // Check if already running
    hMutex = CreateMutexW(0, FALSE, L"PushOneInstance");

    if (threadEnvironmentBlock->LastErrorValue == ERROR_ALREADY_EXISTS
        || threadEnvironmentBlock->LastErrorValue == ERROR_ACCESS_DENIED)
    {
        MessageBoxW(0, L"Only one instance!", 0,0);
        ExitProcess(0);
    }


    //create image event
    eventHandle = NULL;

    UnicodeString_Init(&eventSource, L"Global\\" PUSH_IMAGE_EVENT_NAME);

    objAttrib.Length = sizeof(OBJECT_ATTRIBUTES);
    objAttrib.RootDirectory = BaseGetNamedObjectDirectory();
    objAttrib.ObjectName = &eventSource;
    objAttrib.Attributes = OBJ_OPENIF;
    objAttrib.SecurityDescriptor = NULL;
    objAttrib.SecurityQualityOfService = NULL;

    NtCreateEvent(&eventHandle, EVENT_ALL_ACCESS, &objAttrib, NotificationEvent, FALSE);

    // populate file name and path
    module = (LDR_DATA_TABLE_ENTRY*)threadEnvironmentBlock->ProcessEnvironmentBlock->Ldr->InLoadOrderModuleList.Flink;

    Memory_Copy(PushFilePath, module->FullDllName.Buffer, module->FullDllName.Length);

    PushFilePath[module->FullDllName.Length] = L'\0';

    // Start Driver.
    Driver_Extract();
    PushDriverLoaded = Driver_Load();

    //initialize instance
    PushInstance = Module_GetHandle(L"Push.exe");

    // Create interface
    MwCreateMainWindow();

    // Create section.
    sectionSize = sizeof(PUSH_SHARED_MEMORY) + OSD_GetSize();

    PushSharedMemory = (PUSH_SHARED_MEMORY*)Memory_MapViewOfSection(PUSH_SECTION_NAME, sectionSize, &sectionHandle);

    if (!PushSharedMemory)
    {
        Log(L"Could not create shared memory");
        return 0;
    }

    Log(L"Created section of size %i bytes", sectionSize);

    //zero struct
    Memory_Clear(PushSharedMemory, sizeof(PUSH_SHARED_MEMORY));

    //initialize window handle used by overlay
    //PushSharedMemory->WindowHandle = PushMainWindow->Handle;

    //initialize default font properties for overlay
    String_Copy(PushSharedMemory->FontName, L"Verdana");
    PushSharedMemory->FontBold = TRUE;

    if (File_Exists(PUSH_SETTINGS_FILE))
    {
        wchar_t *buffer;
        wchar_t marker;

        // Check if file is UTF-16LE.
        buffer = (WCHAR*) File_Load(PUSH_SETTINGS_FILE, NULL);
        marker = buffer[0];

        Memory_Free(buffer);

        if (marker == 0xFEFF)
            //is UTF-LE.
        {
            // Init settings from ini file.

            buffer = Memory_Allocate(100 * sizeof(WCHAR));

            Ini_GetString(L"Settings", L"FrameLimit", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE);
            PushSharedMemory->FrameLimit = _wtoi(buffer);

            if (Ini_ReadBoolean(L"Settings", L"ThreadOptimization", FALSE, L".\\" PUSH_SETTINGS_FILE))
                PushSharedMemory->ThreadOptimization = TRUE;

            if (Ini_ReadBoolean(L"Settings", L"KeepFps", FALSE, L".\\" PUSH_SETTINGS_FILE))
                PushSharedMemory->KeepFps = TRUE;

            Ini_GetString(L"Settings", L"OverlayInterface", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE);

            if (String_Compare(buffer, L"PURE") == 0)
                PushOverlayInterface = OVERLAY_INTERFACE_PURE;
            else if (String_Compare(buffer, L"RTSS") == 0)
                PushOverlayInterface = OVERLAY_INTERFACE_RTSS;

            Ini_GetString(L"Settings", L"KeyboardHookType", L"AUTO", buffer, 10, L".\\" PUSH_SETTINGS_FILE);

            if (String_Compare(buffer, L"AUTO") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_AUTO;
            }
            else if (String_Compare(buffer, L"SUBCLASS") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_SUBCLASS;
            }
            else if (String_Compare(buffer, L"MESSAGE") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_MESSAGE;
            }
            else if (String_Compare(buffer, L"KEYBOARD") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_KEYBOARD;
            }
            else if (String_Compare(buffer, L"DETOURS") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_DETOURS;
            }
            else if (String_Compare(buffer, L"RAW") == 0)
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_RAW;
            }
            else
            {
                PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_AUTO;
            }

            Ini_GetString(L"Settings", L"EngineClockMax", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE);
            PushSharedMemory->HarwareInformation.DisplayDevice.EngineOverclock = _wtoi(buffer);

            Ini_GetString(L"Settings", L"MemoryClockMax", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE);
            PushSharedMemory->HarwareInformation.DisplayDevice.MemoryOverclock = _wtoi(buffer);

            Ini_GetString(L"Settings", L"ControllerTimeout", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE);
            PushSharedMemory->ControllerTimeout = _wtoi(buffer);

            Ini_GetString(L"Settings", L"FontName", L"Verdana", buffer, 100, L".\\" PUSH_SETTINGS_FILE);
            String_Copy(PushSharedMemory->FontName, buffer);

            Memory_Free(buffer);

            if (Ini_ReadBoolean(L"Settings", L"FontBold", FALSE, L".\\" PUSH_SETTINGS_FILE))
                PushSharedMemory->FontBold = TRUE;
        }
        else
        {
            MessageBoxW(
                NULL,
                L"Settings file not UTF-16LE! "
                L"Resave the file as \"Unicode\" or Push won't read it!",
                L"Bad Settings file",
                NULL
                );
        }
    }

    if (!PushDriverLoaded)
    {
        wchar_t driverPath[260];

        Resource_Extract(L"DRIVERALT", L"WinRing0x64.sys");
        GetDriverPath(L"WinRing0x64.sys", driverPath);
        Wr0DriverLoaded = Wr0Initialize(driverPath);
    }

    //initialize HWInfo
    GetHardwareInfo();

    //initialize OSD items

    NtQuerySection(
        sectionHandle,
        SectionBasicInformation,
        &sectionInfo,
        sizeof(SECTION_BASIC_INFORMATION),
        NULL
        );

    newSectionSize.QuadPart = OSD_Initialize() + sizeof(PUSH_SHARED_MEMORY);

    if (newSectionSize.QuadPart > sectionInfo.MaximumSize.QuadPart)
    {
        Log(L"Shared memory too small!");
    }

    //Check for controllers/gamepads/bluetooth adapters
    //EnumerateDevices();

    // Check for running games
    Process_EnumProcesses(ProcessEnum);

    // Activate process monitoring
    if (PushDriverLoaded)
    {
        PushToggleProcessMonitoring(TRUE);
    }
    else
    {
        HANDLE overlayLib = NULL;
        void* prcAddress = 0;

        Resource_Extract(L"OVERLAY32", PUSH_LIB_NAME_32);

        overlayLib = Module_Load(L"overlay32.dll");
        prcAddress = Module_GetProcedureAddress(overlayLib, "InstallOverlayHook");

        if (prcAddress)
        {
            InstallOverlayHook = (TYPE_InstallOverlayHook)prcAddress;
            InstallOverlayHook();
        }
    }

    g_szPrevGame[5] = '\0';

    NtCreateThreadEx(
        &PushMonitorThreadHandle,
        THREAD_ALL_ACCESS,
        NULL,
        NtCurrentProcess(),
        &MonitorThread,
        NULL,
        NoThreadFlags,
        0, 0, 0,
        NULL
        );

    NtCreateThreadEx(
        &threadHandle,
        THREAD_ALL_ACCESS,
        NULL,
        NtCurrentProcess(),
        &PipeThread,
        NULL,
        NoThreadFlags,
        0, 0, 0,
        NULL
        );

    // Handle messages

    while(GetMessageW(&messages, 0,0,0))
    {
        TranslateMessage(&messages);

        DispatchMessageW(&messages);
    }

    ExitProcess(0);

    return 0;
}
예제 #15
0
파일: hardware.c 프로젝트: Volkanite/Push
VOID InitGpuHardware()
{
    DWORD bar;
    UINT32 size;

    PushSharedMemory->HarwareInformation.DisplayDevice.pciAddress = FindPciDeviceByClass(0x03, 0x00, 0x00, 0);

    Wr0ReadPciConfig(
        PushSharedMemory->HarwareInformation.DisplayDevice.pciAddress,
        REGISTER_VENDORID,
        (BYTE *)&PushSharedMemory->HarwareInformation.DisplayDevice.VendorId,
        sizeof(PushSharedMemory->HarwareInformation.DisplayDevice.VendorId)
        );

    switch (PushSharedMemory->HarwareInformation.DisplayDevice.VendorId)
    {
    case NVIDIA:
    case INTEL:
        bar = REGISTER_BAR0;
        break;
    case AMD:
        bar = REGISTER_BAR2;
        gpubios = R0MapPhysicalMemory(0x000C0000, 63488);
        //File_Dump(L"bios.rom", gpubios, 63488);
        break;
    default:
        return;
        break;
    }

    PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress = GetBarAddress(bar);
    size = GetBarSize(PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress);

    if (PushSharedMemory->HarwareInformation.DisplayDevice.VendorId == INTEL)
    {
        DWORD mchBar = 0xFED10000;

        // 16-Byte alligned address;
        mchBar = (mchBar & 0x0fffffff0);

        PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress = 0xFED10000;

        size = 0x6000;
    }

    if (PushDriverLoaded)
    {
        MemoryMappedIO = TRUE;
    }

    if (MemoryMappedIO)
    {
        if (PagedMMIO)
        {
            int i;

            if (PushSharedMemory->HarwareInformation.DisplayDevice.VendorId == AMD)
            {
                size = 4096;
            }

            numPages = sizeof(pages) / sizeof(pages[0]);

            mmioPages = Memory_Allocate(sizeof(void*)* (sizeof(pages) / sizeof(pages[0])));

            for (i = 0; i < sizeof(pages) / sizeof(pages[0]); i++)
            {
                ULONG address;

                address = PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress;

                if (pages[i] > 0)
                {
                    address = pages[i] * 4096;
                    address += PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress;
                }

                mmioPages[i] = R0MapPhysicalMemory(address, size);
            }
        }
        else
        {
            HwMmio = R0MapPhysicalMemory(PushSharedMemory->HarwareInformation.DisplayDevice.BarAddress, size);
        }
    }
}
예제 #16
0
파일: main.c 프로젝트: Mynogs/CN1
 void* ff_memalloc(size_t size)
 {
   return Memory_Allocate(size, 0);
 }
예제 #17
0
static void create(int variables, int constraints,
	           int q_nnz, int *q_i, int *q_j, double *q_ij, double *c,
	           int a_nnz, int *a_i, int *a_j, double *a_ij, double *b,
	           int *c_type, double *z, double *pi, 
		   double *lb, double *ub)
{
  double inf;
  int q_index;
  int a_index;
  int m_count;
  int i;

  inf = 1e20;

  problem.n = variables + constraints;
  problem.nnz = q_nnz + 2*a_nnz;

  problem.z = (double *)Memory_Allocate(sizeof(double)*problem.n);
  problem.lb = (double *)Memory_Allocate(sizeof(double)*problem.n);
  problem.ub = (double *)Memory_Allocate(sizeof(double)*problem.n);

  problem.m_start = (int *)Memory_Allocate(sizeof(int)*problem.n);
  problem.m_len = (int *)Memory_Allocate(sizeof(int)*problem.n);
  problem.m_row = (int *)Memory_Allocate(sizeof(int)*problem.nnz+1);
  problem.m_data = (double *)Memory_Allocate(sizeof(double)*problem.nnz+1);

  problem.q = (double *)Memory_Allocate(sizeof(double)*problem.n);

  sort(variables, variables, q_nnz, q_i, q_j, q_ij);
  sort(constraints, variables, a_nnz, a_i, a_j, a_ij);

  for (i = 0; i < variables; i++) {
    problem.z[i] = z[i];

    problem.q[i] = c[i];
    problem.lb[i] = lb[i];
    problem.ub[i] = ub[i];
  }

  for (i = 0; i < constraints; i++) {
    problem.z[i + variables] = pi[i];
    problem.q[i + variables] = -b[i];
    switch(c_type[i]) {
    case QP_LE:		/* <= constraint */
      problem.lb[i + variables] = -inf;
      problem.ub[i + variables] = 0;
      break;

    case QP_GE:		/* >= constraint */
      problem.lb[i + variables] = 0;
      problem.ub[i + variables] = inf;
      break;

    case QP_EQ:
      problem.lb[i + variables] = -inf;
      problem.ub[i + variables] = inf;
      break;
    }
  }

  q_index = 0;
  a_index = 0;
  m_count = 0;
  for (i = 0; i < variables; i++) {
    problem.m_start[i] = m_count + 1;
    problem.m_len[i] = 0;

    while ((q_index < q_nnz) && (q_j[q_index] <= i + 1)) {
      if (q_ij[q_index] != 0) {
	problem.m_len[i]++;
	problem.m_row[m_count] = q_i[q_index];
	problem.m_data[m_count] = q_ij[q_index];
	m_count++;
      }
      q_index++;
    }

    while ((a_index < a_nnz) && (a_j[a_index] <= i + 1)) {
      if (a_ij[a_index] != 0) {
	problem.m_len[i]++;
	problem.m_row[m_count] = a_i[a_index] + variables;
	problem.m_data[m_count] = a_ij[a_index];
	m_count++;
      }
      a_index++;
    }
  }

  sort(variables, constraints, a_nnz, a_j, a_i, a_ij);
  a_index = 0;

  for (i = 0; i < constraints; i++) {
    problem.m_start[i + variables] = m_count + 1;
    problem.m_len[i + variables] = 0;

    while ((a_index < a_nnz) && (a_i[a_index] <= i + 1)) {
      if (a_ij[a_index] != 0) {
	problem.m_len[i + variables]++;
	problem.m_row[m_count] = a_j[a_index];
	problem.m_data[m_count] = -a_ij[a_index];
	m_count++;
      }
      a_index++;
    }
  }

  problem.nnz = m_count;
  return;
}
예제 #18
0
static void sort(int rows, int cols, int elements,
		 int *row, int *col, double *data)
{
  double *m_data;
  int *m_start;
  int *m_len;
  int *m_row;

  int i, cs, ce;

  m_start = (int *)Memory_Allocate(sizeof(int)*(cols + 1));
  m_len = (int *)Memory_Allocate(sizeof(int)*(cols + 1));
  m_row = (int *)Memory_Allocate(sizeof(int)*(elements + 1));
  m_data = (double *)Memory_Allocate(sizeof(double)*(elements + 1));

  for(i = 0; i < cols; i++) {
    m_len[i] = 0;
  }

  for(i = 0; i < elements; i++) {
    if ((col[i] < 1) || (col[i] > cols)) {
      Error("column incorrect.\n");
    }

    if ((row[i] < 1) || (row[i] > rows)) {
      Error("column incorrect.\n");
    }

    m_len[col[i] - 1]++;
  }

  m_start[0] = 0;
  for (i = 1; i < cols; i++) {
    m_start[i] = m_start[i - 1] + m_len[i - 1];
    m_len[i - 1] = 0;
  }
  m_len[i - 1] = 0;

  for(i = 0; i < elements; i++) {
    cs = col[i] - 1;
    ce = m_start[cs] + m_len[cs];
    m_row[ce] = row[i];
    m_data[ce] = data[i];
    m_len[cs]++;
  }

  elements = 0;
  for (i = 0; i < cols; i++) {
    cs = m_start[i];
    ce = cs + m_len[i];

    while (cs < ce) {
      row[elements] = m_row[cs];
      col[elements] = i + 1;
      data[elements] = m_data[cs];
      elements++;
      cs++;
    }
  }

  Memory_Free(m_data);
  Memory_Free(m_row);
  Memory_Free(m_len);
  Memory_Free(m_start);
  return;
}