static void * MapAlignedPages(size_t size, size_t alignment) { int recursions = -1; /* make up to OS2_MAX_RECURSIONS attempts to get an aligned block * of the right size by recursively allocating blocks of unaligned * free memory until only an aligned allocation is possible */ void *p = MapAlignedPagesRecursively(size, alignment, recursions); if (p) return p; /* if memory is heavily fragmented, the recursive strategy may fail; * instead, use the "expensive" strategy: allocate twice as much * as requested and return an aligned address within this block */ if (DosAllocMem(&p, 2 * size, OBJ_ANY | PAG_COMMIT | PAG_READ | PAG_WRITE)) { JS_ALWAYS_TRUE(DosAllocMem(&p, 2 * size, PAG_COMMIT | PAG_READ | PAG_WRITE) == 0); } jsuword addr = reinterpret_cast<jsuword>(p); addr = (addr + (alignment - 1)) & ~(alignment - 1); return reinterpret_cast<void *>(addr); }
/* * This function calls the allocation function depending on which * method was compiled into the library: it can be native allocation * (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free). * Actually, for pixel buffers that we use this function for, cairo * uses _cairo_malloc_abc, so we use that here, too. And use the * change to check the size argument */ void *_buffer_alloc (size_t a, size_t b, const unsigned int size) { size_t nbytes; void *buffer = NULL; if (!a || !b || !size || a >= INT32_MAX / b || a*b >= INT32_MAX / size) { return NULL; } nbytes = a * b * size; #ifdef OS2_USE_PLATFORM_ALLOC /* Using OBJ_ANY on a machine that isn't configured for hi-mem * will cause ERROR_INVALID_PARAMETER. If this occurs, or this * build doesn't have hi-mem enabled, fall back to using lo-mem. */ #ifdef OS2_HIGH_MEMORY if (!DosAllocMem (&buffer, nbytes, OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT)) return buffer; #endif if (DosAllocMem (&buffer, nbytes, PAG_READ | PAG_WRITE | PAG_COMMIT)) return NULL; #else /* Clear the malloc'd buffer the way DosAllocMem() does. */ buffer = malloc (nbytes); if (buffer) { memset (buffer, 0, nbytes); } #endif return buffer; }
MRESULT hia_wmCreate(HWND hwnd,MPARAM mp1,MPARAM mp2) { HIA *hia = NULL; HIABuf *hiabuf = NULL; HIANotifWnd *notifList = NULL; ULONG notifListAllocSize = HIA_NOTIFLIST_DEFAULT_SIZE; HWND hwndOwner = WinQueryWindow(hwnd,QW_OWNER); USHORT Id = WinQueryWindowUShort(hwnd,QWS_ID); int i; if (DosAllocMem((PPVOID)&hiabuf,sizeof(HIABuf),fALLOC)) return MRFROMLONG(TRUE); #ifdef DEBUG assert(hiabuf!=NULL); #endif HIABufClear(hiabuf); if (DosAllocMem((PPVOID)¬ifList,sizeof(HIANotifWnd)*notifListAllocSize,fALLOC)) return MRFROMLONG(TRUE); #ifdef DEBUG assert(notifList!=NULL); #endif for (i=0;i<notifListAllocSize;i++) { notifList[i].hwnd = NULLHANDLE; notifList[i].id = 0; } if (DosAllocMem((PPVOID)&hia,sizeof(HIA),fALLOC)) return MRFROMLONG(TRUE); #ifdef DEBUG assert(hia!=NULL); #endif hia->hwndHIA = hwnd; hia->inbuf = hiabuf; hia->kbdtype = HAN_KBD_2; hia->hanmode = HCH_ENG; hia->insertmode = HAN_INSERT; hia->hcode = HCH_JSY; hia->isHanjaKey = hia_defaultHanjaKey; hia->isSpecialCharKey = hia_defaultSpecialCharKey; hia->notifListAllocSize = notifListAllocSize; hia->notifList = notifList; hia->notifList[0].hwnd = hwndOwner; hia->notifList[0].id = Id; hia->responseTo = &(hia->notifList[0]); hia->hwndHCHLB = NULLHANDLE; hia->fRunningHCHLB = FALSE; hia->scselIndex = 0; if (!WinSetWindowPtr(hwnd,WINWORD_INSTANCE,(PVOID)hia)) return MRFROMLONG(TRUE); return 0L; }
ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t n) { void* allocation = NULL; if (DosAllocMem(&allocation, n, OBJ_ANY|PAG_COMMIT|PAG_READ|PAG_WRITE) && DosAllocMem(&allocation, n, PAG_COMMIT|PAG_READ|PAG_WRITE)) CRASH(); ExecutablePool::Allocation alloc = {reinterpret_cast<char*>(allocation), n}; return alloc; }
void APIENTRY ReadLoopThread() { THREAD *pstThd = pstThread; CONFIG *pCfg = &pstThd->stCfg; THREADCTRL *pThread = &pstThd->stThread; BOOL bReadComplete; CHAR *pString; APIRET rc; BOOL bSkipRead = FALSE; char szMessage[80]; ULONG ulStringLength; ULONG ulPostCount; // DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-28L,0); DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-10L,0); ulStringLength = pCfg->wReadStringLength; DosAllocMem((PPVOID)&pString,10010,(PAG_COMMIT | PAG_WRITE | PAG_READ)); while (!pThread->bStopThread) { if (ulStringLength != pCfg->wReadStringLength) { DosFreeMem(pString); ulStringLength = pCfg->wReadStringLength; DosAllocMem((PPVOID)&pString,(ulStringLength + 10),(PAG_COMMIT | PAG_WRITE | PAG_READ)); } if (pCfg->bHalfDuplex) { while ((rc = DosWaitEventSem(hevStartReadSem,10000)) != 0) if (rc == ERROR_SEM_TIMEOUT) { ErrorNotify(pstThd,"Read start semaphore timed out"); bSkipRead = TRUE; } else { sprintf(szMessage,"Read start semaphore error - rc = %u",rc); ErrorNotify(pstThd,szMessage); } DosResetEventSem(hevStartReadSem,&ulPostCount); } if (bSkipRead) bSkipRead = FALSE; else { if (!pCfg->bReadCharacters) bReadComplete = ReadString(pstThd,pString); else bReadComplete = ReadCharacters(pstThd,pString); if (bReadComplete) DosPostEventSem(hevStartWriteSem); } } DosFreeMem(pString); DosPostEventSem(hevKillReadThreadSem); DosExit(EXIT_THREAD,0); }
void getinfo() { char buf[1024]; char *pbuf,*pbuf1,*pbuf2; ULONG rc,ulEnv,ulPTDA,ulSeg,ulErrorClass,ulErrorAction,ulErrorLoc; PID pid; USHORT cb,usEnvHob,usEnvHar; FILE *f; char buf1[1000]; for (rc=0,pid=0;rc==0 && pid!=0x3a;) { rc=DosPerfSysCall(0xC5,(ULONG)buf,sizeof(buf),0); //get thread info pid=(PID)(*((USHORT*)&buf[18])); } ulPTDA=*(ULONG*)&buf[12]; printf("%i PID %X PTDA %X\n",rc,pid,ulPTDA); rc=DosPerfSysCall(0xC1,(ULONG)buf,sizeof(buf),ulPTDA); //get PTDA usEnvHob=*((USHORT*)&buf[272]); printf("%i ENVHOB %04X\n",rc,usEnvHob); rc=DosPerfSysCall(0xD0,(ULONG)buf,0x10,(ULONG)usEnvHob); //get env hob info usEnvHar=*((USHORT*)&buf[0]); printf("%i ENVHAR %04X\n",rc,usEnvHar); rc=DosPerfSysCall(0xCD,(ULONG)buf,0x16,(ULONG)usEnvHar); //get env arena record ulEnv=(ULONG)(*((USHORT*)&buf[6]))<<16; printf("%i ENV ADDR %08X\n",rc,ulEnv); DosAllocMem((void**)&pbuf2,0x1000,0x13); rc=DosPerfSysCall(0xDB,(ULONG)pbuf2,ulPTDA,0); printf("0xDB %i\n",rc); DosAllocMem((void**)&pbuf,0x1000,0x13); //get linear memory info rc=DosPerfSysCall(0xDC,(ULONG)pbuf,ulEnv,ulPTDA); printf("0xDC %i\n",rc); f=fopen("DC.TXT","w"); fwrite(pbuf,0x1000,1,f); fclose(f); DosAllocMem((void**)&pbuf1,0x114,0x13); memset(pbuf1,0,0x114); rc=DosPerfSysCall(0xD9,(ULONG)&pbuf1,0,0); printf("%i %p %p %s\n",rc,pbuf1,&pbuf1,pbuf1); f=fopen("D9.TXT","w"); fwrite(pbuf1,0x114,1,f); fclose(f); DosFreeMem(pbuf); DosFreeMem(pbuf1); DosFreeMem(pbuf2); }
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) { void* result = NULL; if (DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) && DosAllocMem(&result, bytes, protection(writable, executable))) { CRASH(); } return result; }
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) { void* result = NULL; if ( #if defined(MOZ_OS2_HIGH_MEMORY) DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) && #endif DosAllocMem(&result, bytes, protection(writable, executable))) { CRASH(); } return result; }
int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages) { NOREF(pThis); *ppvPages = NULL; int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY); if (rc == ERROR_INVALID_PARAMETER) rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY); if (!rc) rc = VINF_SUCCESS; else rc = RTErrConvertFromOS2(rc); return rc; }
// Frame_window - текстовое окно. VOID Clipper_PasteTextToVIOWindow( HWND Frame_window ) { // Если в Clipboard есть какие-то строки: CHAR Short_string[ 4 ] = ""; GetStringFromClipboard( Enhancer.Application, Short_string, 4 ); if( Short_string[ 0 ] != 0 ) { // Сбрасываем Clipboard и запоминаем строки еще раз как CF_TEXT. // Это необходимо делать потому, что если строки были взяты из другого текстового окна, // то при нажатой клавише Shift другие текстовые окна не могут вставить последние буквы. // Отводим память для текста. PCHAR Clipboard_text = NULL; INT Length = 16384; if( DosAllocMem( (PPVOID) &Clipboard_text, Length, PAG_ALLOCATE ) != NO_ERROR ) return; // Забираем текст из Clipboard и тут же добавляем его в Clipboard. GetStringFromClipboard( Enhancer.Application, Clipboard_text, Length ); PutStringIntoClipboard( Enhancer.Application, Clipboard_text ); // Освобождаем память. DosFreeMem( Clipboard_text ); Clipboard_text = NULL; // Узнаем окно картинки. HWND SysMenu_window = WinWindowFromID( Frame_window, FID_SYSMENU ); // Если в меню есть строка для вставки текста - посылаем в окно команду от нее. if( MenuItemIsPresent( SysMenu_window, SM_VIO_PASTE ) ) WinPostMsg( Frame_window, WM_SYSCOMMAND, (MPARAM) SM_VIO_PASTE, MPFROM2SHORT( CMDSRC_MENU, 0 ) ); } // Возврат. return; }
static void * usalo_getbuf(SCSI *usalp, long amt) { ULONG rc; #ifdef DEBUG fprintf((FILE *)usalp->errfile, "usalo_getbuf: %ld bytes\n", amt); #endif rc = DosAllocMem(&buffer, amt, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); if (rc) { fprintf((FILE *)usalp->errfile, "Cannot allocate buffer.\n"); return ((void *)0); } usalp->bufbase = buffer; #ifdef DEBUG fprintf((FILE *)usalp->errfile, "Buffer allocated at: 0x%x\n", usalp->bufbase); #endif /* Lock memory */ if (init_buffer(usalp->bufbase)) return (usalp->bufbase); fprintf((FILE *)usalp->errfile, "Cannot lock memory buffer.\n"); return ((void *)0); /* Error */ }
// Message - сообщение. VOID Log_PrintLogMessage( PCHAR Message ) { // Отводим память для текста. PCHAR Window_text = NULL; INT Length = 65536; if( DosAllocMem( (PPVOID) &Window_text, Length, PAG_ALLOCATE ) != NO_ERROR ) return; // Узнаем текст в поле ввода. HWND Field = Log_LogWindow(); WinQueryWindowText( Field, Length, Window_text ); // Добавляем сообщение в поле ввода. strcat( Window_text, Message ); strcat( Window_text, "\n" ); WinEnableWindowUpdate( Field, 0 ); WinSetWindowText( Field, Window_text ); WinEnableWindowUpdate( Field, 1 ); // Освобождаем память. DosFreeMem( Window_text ); Window_text = NULL; // Запоминаем, что поле ввода изменено. Log.RTSettings.Field_is_changed = 1; // Возврат. return; }
ULONG prc16ForEachProcess(PFNWP pfnwpCallback, HWND hwnd, ULONG ulMsg, MPARAM mp1) { ULONG ulrc = 0; PQPROCSTAT16 pps; PQPROCESS16 pProcess; PRCPROCESS prcp; if (!DosAllocMem((PVOID*)&pps, BUF_SIZE, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE)) { if (!DosQProcStatus(pps, BUF_SIZE)) for ( pProcess = (PQPROCESS16)PTR(pps->ulProcesses, 0); pProcess->ulType != 3; pProcess = (PQPROCESS16)PTR(pProcess->ulThreadList, pProcess->usThreads * sizeof(QTHREAD16)) ) { if (pfnwpCallback) { prcReport16(pProcess, &prcp); (*pfnwpCallback)(hwnd, ulMsg, mp1, &prcp); } ulrc++; } DosFreeMem(pps); } return ulrc; }
XBitmapFilter* XBitmap :: GetExportFilterStruct (const char* filename) { XBitmapFilter* filter; XBitmapFilter dummy; dummy.cbFix = 0; CheckFilterProfile (); XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB"); XGLibProcFltInit* func = (XGLibProcFltInit*) lib->LoadFunction ("OOL_GLIB_EXP_INIT"); DosSleep(100); if (NULL != func) { ULONG rc; if (0 == (rc = func (filename, __XBMFProfile__, NULL, 0))) OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc); DosAllocMem ((PPVOID) &filter, rc, PAG_READ | PAG_WRITE | PAG_COMMIT); filter->cbFix = rc; filter->hab = XApplication :: GetApplication ()->GetAnchorBlock (); if (BFE_OK != (rc = func (filename, __XBMFProfile__, filter, 0))) OOLThrow (GetLastErrorMessage (lib, &rc, filter), rc); lib->UnLoadFunction ((PFNWP) func); } else { ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ()); OOLThrow("Could not load function \"OOL_GLIB_EXP_INIT\" from library \"OOLGLIB.DLL\".", error); } delete lib; return filter; }
int copyaudio(HMMIO hmmiofrom, HMMIO hmmioto, LONG Bytes) { // method allocates a buffer and does a standard copy from from to to PCHAR pAudio = NULL; DosAllocMem((void **) &pAudio,COPYSIZE,PAG_WRITE | PAG_COMMIT); assert(pAudio!=NULL); long BytesRead,BytesWritten; long bytes_to_copy = Bytes; do { if (bytes_to_copy > COPYSIZE) { // // now read the FIRST file BytesRead = mmioRead(hmmiofrom,(PCHAR)pAudio,COPYSIZE); bytes_to_copy -= BytesRead; } else { BytesRead = mmioRead(hmmiofrom,(PCHAR)pAudio,bytes_to_copy); bytes_to_copy -= BytesRead; } cout << " Read " << BytesRead << " from source file, " << bytes_to_copy << " left " << endl; // // write the new file BytesWritten = mmioWrite(hmmioto,(PCHAR)pAudio,BytesRead); assert(BytesRead==BytesWritten); } while(bytes_to_copy!=0); DosFreeMem(pAudio); return 0; }
void *osd_alloc_executable(size_t size) { void *p; DosAllocMem( &p, size, fALLOC ); return p; }
_WCRTLINK unsigned _dos_allocmem( unsigned size, mem_id *p_mem ) // Note: size is in paragraphs of 16 bytes { APIRET rc; #if defined(__386__) || defined(__PPC__) /* Note: _dos_allocmem() needs better documentation for 32-bit since mem is an offset instead a selector value. */ void *mem; rc = DosAllocMem( &mem, size << 4, PAG_COMMIT | PAG_READ | PAG_WRITE ); #elif defined( _M_I86 ) SEL mem; USHORT number_segments, remaining_bytes; number_segments = size >> 12; // Number of 64k segments remaining_bytes = (size << 4) & 0xFFFF; // remainder, < 64k rc = DosAllocHuge( number_segments, remaining_bytes, &mem, 0, 0 ); #else #error platform not supported #endif *p_mem = mem; if( rc ) { return( __set_errno_dos_reterr( rc ) ); } return( 0 ); }
PQTOPLEVEL32 prc32GetInfo2(ULONG fl, // in: QS32_* flags APIRET *parc) // out: error, ptr can be NULL { APIRET arc; PQTOPLEVEL32 pReturn = NULL; #define BUFSIZE (1024 * 1024) // 1 meg if (!(arc = DosAllocMem((PVOID*)&pReturn, BUFSIZE, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE))) { if (arc = DosQuerySysState(fl, fl, // this was missing V0.9.10 (2001-04-08) [umoeller] 0, 0, (PCHAR)pReturn, BUFSIZE)) { DosFreeMem(pReturn); pReturn = NULL; } } if (parc) *parc = arc; return pReturn; }
static void test2( void ) { static const char *p1Str = "1234512345"; static const char *p2Str = "1234567890"; char *p1; char *p2; printf("***** Test2: Copy to source memory...\n"); DosAllocMem(( PPVOID )&p1, ALLOC_SIZE, fPERM | PAG_COMMIT ); strcpy( p1, p2Str); p2 = copyOnWrite( p1, COPY_SIZE ); printf("p1 = %p, p2 = %p\n", p1, p2 ); printf("p1 = [%s], p2 = [%s]\n", p1, p2 ); printf("Copying %.5s to ( p1 + 5 )\n", p1Str ); memcpy( p1 + 5, p1Str, 5 ); printf("p1 = [%s], p2 = [%s]\n", p1, p2 ); fprintf( stderr, "Test2: "); if( memcmp( p1, p1Str, strlen( p1Str )) || memcmp( p2, p2Str, strlen( p2Str ))) fprintf( stderr, "Failed\n"); else fprintf( stderr, "Succeeded\n"); DosFreeMem( p2 ); DosFreeMem( p1 ); }
void XBitmap :: CheckFilterProfile () { if (NULL == __XBMFProfile__) { XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB"); XGLibProcProfInit* func = (XGLibProcProfInit*) lib->LoadFunction ("OOL_GLIB_INIT"); XBitmapFilter dummy; dummy.cbFix = 0; DosSleep(100); if (NULL != func) { ULONG rc; if (0 == (rc = func (NULL, 0, 0, 0))) { ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ()); OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc); } DosAllocMem ((PPVOID) &__XBMFProfile__, rc, PAG_READ | PAG_WRITE | PAG_COMMIT); __XBMFProfile__->cbFix = rc; if (BFE_OK != (rc = func (__XBMFProfile__, 0, 0, 0))) { ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ()); OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc); } lib->UnLoadFunction ((PFNWP) func); } else { ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ()); OOLThrow("Could not load function \"OOL_GLIB_INIT\" from library \"OOLGLIB.DLL\".", error); } delete lib; } }
void FilesCnr::getFiles() { PFILEFINDBUF3 pffb = NULL; OString FileSpec(scanDirectory); ULONG bufSize = sizeof(FILEFINDBUF3) * 200; HDIR hdir = HDIR_CREATE; ULONG ulMaxFiles = 200; APIRET rc; freeItems(); FileList.reset(); DosAllocMem((PPVOID)&pffb, bufSize, PAG_READ | PAG_WRITE | PAG_COMMIT); if (!pffb) return; FileSpec + "\\*"; DosError(FERR_DISABLEHARDERR); rc = DosFindFirst(FileSpec.text, &hdir, FILE_NORMAL | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, pffb, bufSize, &ulMaxFiles, FIL_STANDARD); while(!rc) { insertFiles(pffb, ulMaxFiles); rc = DosFindNext(hdir, pffb, bufSize, &ulMaxFiles); } DosFindClose(hdir); DosError(FERR_ENABLEHARDERR); DosFreeMem(pffb); }
playfield::playfield ( int sizex, int sizey, int ofsX, int ofsY ) { maxX = sizex; maxY = sizey; pixOfsX = ofsX; pixOfsY = ofsY; numLoadedTiles = 0; numSprites = 0; ticker = 0; usrInput = move_left; // game data lives = 3; score = 0; // level data pill_duration = 400; ghost_hatch_time = 100; ghost_iq[0] = 10; ghost_iq[1] = 20; ghost_iq[2] = 30; ghost_iq[3] = 40; ghost_path_time = 32; dot_value = 10; big_dot_value = 50; fruit_frequency = 1000; fruit_duration = 100; fruit_value = 200; fruit_value_icon = 0; if ( DosAllocMem ( (PPVOID) &field, sizex * sizey * sizeof(int), (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) ) Eng_Abort("Error while opening up some system RAM for playfield."); if ( DosAllocMem ( (PPVOID) &frontBuffer, sizex * sizey * sizeof(backtile*), (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) ) Eng_Abort("Error while opening up some system RAM for display frontBuffer."); if ( DosAllocMem ( (PPVOID) &backBuffer, sizex * sizey * sizeof(backtile*), (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE) ) Eng_Abort("Error while opening up some system RAM for display backBuffer."); // don't try to release the objects in the buffer since they are invalid clean_buffer (frontBuffer,0); clean_buffer (backBuffer,0); }
void *os2ldcalloc(size_t num_elem, size_t size_elem) { APIRET rc; int ret; if (FirstTime) { if ((rc=DosAllocMem(&os2ldBase,RESERVED_BLOCKS * 4096, PAG_READ | PAG_WRITE | PAG_EXECUTE)) != 0) { xf86Msg(X_ERROR, "OS2LD: DosAllocMem failed, rc=%d\n", rc); return NULL; } /* Now commit the first 128Kb, the rest will * be done dynamically */ if ((rc=DosSetMem(os2ldBase, 32*4096, PAG_DEFAULT | PAG_COMMIT)) != 0) { xf86Msg(X_ERROR, "OS2LD: DosSetMem failed, rc=%d\n",rc); DosFreeMem(os2ldBase); return NULL; } os2ldCommitedTop = os2ldBase + 32*4096; os2ldTotalCommitedBlocks = 32; #ifdef DEBUG xf86Msg(X_INFO, "OS2LD: Initial heap at addr=%p\n", os2ldBase); #endif if ((os2ldHeap=_ucreate(os2ldBase, 32*4096, _BLOCK_CLEAN, _HEAP_REGULAR, os2ldAddToHeap, os2ldRemoveFromHeap)) == NULL) { xf86Msg(X_ERROR, "OS2LD: heap creation failed\n"); DosFreeMem(os2ldBase); return NULL; } if ((ret=_uopen(os2ldHeap)) != 0) { xf86Msg(X_ERROR, "OS2LD: heap open failed\n"); ret = _udestroy(os2ldHeap,_FORCE); DosFreeMem(os2ldBase); return(NULL); } FirstTime = FALSE; #ifdef DEBUG xf86Msg(X_INFO,"OS2LD: Created module heap at addr=%p\n", os2ldHeap); #endif } return _ucalloc(os2ldHeap,num_elem,size_elem); }
/* * RecordModHandle - save module handle for later reference */ static void RecordModHandle( ULONG value ) { if( ModHandles == NULL ) { DosAllocMem( (PPVOID)&ModHandles, sizeof(ULONG) * 512, PAG_COMMIT | PAG_READ | PAG_WRITE ); } ModHandles[NumModHandles] = value; ++NumModHandles; }
static APIRET vlc_DosDevIOCtl( HFILE hdevice, ULONG category, ULONG function, PVOID pParams, ULONG cbParamLenMax, PULONG pcbParamLen, PVOID pData, ULONG cbDataLenMax, PULONG pcbDataLen ) { PVOID pParamsLow = NULL; PVOID pDataLow = NULL; ULONG cbParamLenLow; ULONG cbDataLenLow; APIRET rc; rc = DosAllocMem( &pParamsLow, cbParamLenMax, fALLOC ); if( rc ) goto exit_free; rc = DosAllocMem( &pDataLow, cbDataLenMax, fALLOC ); if( rc ) goto exit_free; memcpy( pParamsLow, pParams, cbParamLenMax ); memcpy( pDataLow, pData, cbDataLenMax ); cbParamLenLow = *pcbParamLen; cbDataLenLow = *pcbDataLen; rc = DosDevIOCtl( hdevice, category, function, pParamsLow, cbParamLenMax, &cbParamLenLow, pDataLow, cbDataLenMax, &cbDataLenLow ); if( !rc ) { memcpy( pParams, pParamsLow, cbParamLenMax ); memcpy( pData, pDataLow, cbDataLenMax ); *pcbParamLen = cbParamLenLow; *pcbDataLen = cbDataLenLow; } exit_free: DosFreeMem( pParamsLow); DosFreeMem( pDataLow); return rc; }
void main(void) { APIRET rc; PVOID myhighmem; ULONG cbWritten; rc = DosWrite(HF_STDOUT,"Hello World!\r\n",14,&cbWritten); rc = DosAllocMem(&myhighmem, 1024*1024*1024, PAG_READ|PAG_WRITE | OBJ_ANY ); // allocate 1GB of HMA(obj_any) rw-able if(rc==0) { rc = DosWrite(HF_STDOUT,"allocation ok.!\r\n",17,&cbWritten); rc = DosFreeMem(myhighmem); } DosExit(EXIT_PROCESS,rc); }
BOOL GetMessageBuffer(PPVOID ppString,WORD wBufferLength) { if (*ppString != NULL) DosFreeMem(ppString); DosAllocMem(ppString,(wBufferLength + 1),(PAG_COMMIT | PAG_READ | PAG_WRITE)); if (*ppString == NULL) return(FALSE); return(TRUE); }
VOID CheckSystemConfig( VOID ) { // Проверяем настройки в файле "Config.sys". CHAR File_name[ SIZE_OF_NAME ] = "*:\\Config.sys"; ULONG Boot_drive = 0; DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PULONG) &Boot_drive, sizeof( Boot_drive ) ); File_name[ 0 ] = (CHAR) Boot_drive + 64; ULONG Action = OPEN_ACTION_OPEN_IF_EXISTS; ULONG Mode = OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY; HFILE File = NULLHANDLE; ULONG Report = 0; APIRET RC = DosOpen( File_name, &File, &Report, 0, FILE_NORMAL, Action, Mode, NULL ); // Если файл был открыт: if( RC == NO_ERROR ) { // Отводим память для текста. PCHAR Text = NULL; ULONG Length = 65536; if( DosAllocMem( (PPVOID) &Text, Length, PAG_ALLOCATE ) != NO_ERROR ) { DosClose( File ); DosExit( EXIT_PROCESS, 0 ); } // Читаем настройки. memset( Text, 0, Length ); DosRead( File, Text, Length, &Length ); // Проверяем, есть ли в настройках путь к каталогу расширителя. BYTE Path_is_present = 1; if( !stristr( "NICE\\ENHANCER", Text ) ) Path_is_present = 0; // Освобождаем память. DosFreeMem( Text ); Text = NULL; // Закрываем файл. DosClose( File ); File = NULLHANDLE; // Если настройки заданы неправильно: if( !Path_is_present ) { // Показываем сообщение. CHAR Title[ SIZE_OF_TITLE ] = ""; GetEnhancerWindowTitle( Title ); if( QuerySystemCodePage() == RUSSIAN ) WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_RU_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE ); else WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_EN_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE ); // Выход. DosExit( EXIT_PROCESS, 0 ); } } // Возврат. return; }
MRESULT khs_wmCreate( HWND hwnd, MPARAM mp1, MPARAM mp2 ) { PKHSCD pkhscd; WinSetWindowPtr( hwnd, 0, 0 ); if( DosAllocMem(( PPVOID )&pkhscd, sizeof( KHSCD ), fALLOC ) != 0 ) return MRFROMLONG( TRUE ); if( DosAllocSharedMem(( PPVOID )&pkhscd->pCursorPos, NULL, sizeof( RECTL ), fALLOCSHR ) != 0 ) { DosFreeMem( pkhscd ); return MRFROMLONG( TRUE ); } if( DosAllocMem(( PPVOID )&pkhscd->pQTopLevel, DOSQSS_BUFSIZE, fALLOC ) != 0 ) { DosFreeMem( pkhscd->pCursorPos ); DosFreeMem( pkhscd ); return MRFROMLONG( TRUE ); } pkhscd->list = hwndlistCreate(); if( pkhscd->list == NULL ) { DosFreeMem( pkhscd->pQTopLevel ); DosFreeMem( pkhscd->pCursorPos ); DosFreeMem( pkhscd ); return MRFROMLONG( TRUE ); } #ifdef DEBUG pkhscd->fp = fopen("debug.log", "wt"); #endif pkhscd->exceptListBuf = exceptCreateListBuf( EXCEPT_LIST_FILE ); WinSetWindowPtr( hwnd, 0, pkhscd ); return FALSE; }
unsigned long SysPutEA(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { unsigned long rc; /* Ret code */ unsigned long act; /* open action */ void *fealist; /* fealist buffer */ EAOP2 eaop; /* eaop structure */ PFEA2 pfea; /* pfea structure */ HFILE handle; /* file handle */ if (numargs != 3 || !RXVALIDSTRING(args[0]) || !RXVALIDSTRING(args[1])) return INVALID_ROUTINE; if (rc = DosOpen2(args[0].strptr, &handle, &act, 0L, 0, OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_READWRITE + OPEN_SHARE_DENYWRITE + OPEN_FLAGS_FAIL_ON_ERROR + OPEN_FLAGS_WRITE_THROUGH, NULL)) { RETVAL(rc) } if (DosAllocMem((PPVOID)&fealist, 0x00010000L, AllocFlag)) { BUILDRXSTRING(retstr, ERROR_NOMEM); return VALID_ROUTINE; } eaop.fpFEA2List = (PFEA2LIST)fealist;/* Set memory for the FEA */ eaop.fpGEA2List = NULL; /* GEA is unused */ pfea = &eaop.fpFEA2List->list[0]; /* point to first FEA */ pfea->fEA = '\0'; /* set the flags */ /* Size of FEA name field */ pfea->cbName = (BYTE)args[1].strlength; /* Size of Value for this one */ pfea->cbValue = (SHORT)args[2].strlength; /* Set the name of this FEA */ strcpy((PSZ)pfea->szName, args[1].strptr); /* Set the EA value */ memcpy((PSZ)pfea->szName+(pfea->cbName+1), args[2].strptr, args[2].strlength); pfea->oNextEntryOffset = 0; /* no next entry */ eaop.fpFEA2List->cbList = /* Set the total size var */ sizeof(ULONG) + sizeof(FEA2) + pfea->cbName + pfea->cbValue; /* set the file info */ rc = DosSetFileInfo(handle, 2, (PSZ)&eaop, sizeof(EAOP2)); DosClose(handle); /* Close the File */ DosFreeMem(fealist); /* Free the memory */ RETVAL(rc) }