Merge remote-tracking branch 'mareko/r300g-draw-instanced' into pipe-video
[mesa.git] / src / gallium / auxiliary / os / os_memory_win32k.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 /*
30 * OS memory management abstractions for Windows kernel.
31 */
32
33
34 #ifndef _OS_MEMORY_H_
35 #error "Must not be included directly. Include os_memory.h instead"
36 #endif
37
38
39 #include "pipe/p_compiler.h"
40
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
48
49 void * __stdcall
50 EngAllocMem(unsigned long Flags,
51 unsigned long MemSize,
52 unsigned long Tag);
53
54 void __stdcall
55 EngFreeMem(void *Mem);
56
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)
60
61 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
62
63 void *
64 ExAllocatePool(unsigned long PoolType,
65 size_t NumberOfBytes);
66
67 void
68 ExFreePool(void *P);
69
70 #define os_malloc(_size) ExAllocatePool(0, _size)
71 #define _os_free(_ptr) ExFreePool(_ptr)
72
73 static INLINE void *
74 os_calloc(unsigned count, unsigned size)
75 {
76 void *ptr = os_malloc(count * size);
77 if (ptr) {
78 memset(ptr, 0, count * size);
79 }
80 return ptr;
81 }
82
83 #else
84
85 #error "Unsupported subsystem"
86
87 #endif
88
89
90 static INLINE void
91 os_free( void *ptr )
92 {
93 if (ptr) {
94 _os_free(ptr);
95 }
96 }
97
98
99 static INLINE void *
100 os_realloc(void *old_ptr, unsigned old_size, unsigned new_size)
101 {
102 void *new_ptr = NULL;
103
104 if (new_size != 0) {
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);
109 }
110 }
111
112 os_free(old_ptr);
113
114 return new_ptr;
115 }
116
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122
123 #include "os_memory_aligned.h"