1 /**************************************************************************
3 * Copyright 2008-2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * OS memory management abstractions for Windows kernel.
35 #error "Must not be included directly. Include os_memory.h instead"
39 #include "pipe/p_compiler.h"
47 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
50 EngAllocMem(unsigned long Flags
,
51 unsigned long MemSize
,
55 EngFreeMem(void *Mem
);
57 #define os_malloc(_size) EngAllocMem(0, _size, 'D3AG')
58 #define os_calloc(_count, _size) EngAllocMem(1, (_count)*(_size), 'D3AG')
59 #define _os_free(_ptr) EngFreeMem(_ptr)
61 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
64 ExAllocatePool(unsigned long PoolType
,
65 size_t NumberOfBytes
);
70 #define os_malloc(_size) ExAllocatePool(0, _size)
71 #define _os_free(_ptr) ExFreePool(_ptr)
74 os_calloc(unsigned count
, unsigned size
)
76 void *ptr
= os_malloc(count
* size
);
78 memset(ptr
, 0, count
* size
);
85 #error "Unsupported subsystem"
100 os_realloc(void *old_ptr
, unsigned old_size
, unsigned new_size
)
102 void *new_ptr
= NULL
;
105 unsigned copy_size
= old_size
< new_size
? old_size
: new_size
;
106 new_ptr
= os_malloc( new_size
);
107 if (new_ptr
&& old_ptr
&& copy_size
) {
108 memcpy(new_ptr
, old_ptr
, copy_size
);
123 #include "os_memory_aligned.h"