~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/mem.h

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  4.0.2
 
5
 *
 
6
 * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this software and associated documentation files (the "Software"),
 
10
 * to deal in the Software without restriction, including without limitation
 
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
12
 * and/or sell copies of the Software, and to permit persons to whom the
 
13
 * Software is furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions 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 MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
21
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 */
 
25
/* $XFree86: xc/extras/Mesa/src/mem.h,v 1.9 2003/01/12 03:55:44 tsi Exp $ */
 
26
 
 
27
#ifndef MEM_H
 
28
#define MEM_H
 
29
 
 
30
 
 
31
#include "glheader.h"
 
32
/* Do not reference mtypes.h from this file.
 
33
 */
 
34
 
 
35
/*
 
36
 * Memory allocation
 
37
 */
 
38
#if defined(WIN32) && defined(_DEBUG)
 
39
#include <malloc.h>  
 
40
#ifndef _CRTDBG_MAP_ALLOC
 
41
# define _CRTDBG_MAP_ALLOC 1
 
42
#endif
 
43
#include <crtdbg.h>
 
44
 
 
45
#define _mesa_malloc(n)  _malloc_dbg( n, _NORMAL_BLOCK, __FILE__ , __LINE__ )
 
46
#define _mesa_calloc(n)  _calloc_dbg( 1, n, _NORMAL_BLOCK, __FILE__ , __LINE__ )
 
47
#define _mesa_free(p)    _free_dbg(p, _NORMAL_BLOCK )
 
48
 
 
49
extern void *_mesa_align_malloc_dbg(size_t bytes, unsigned long alignment, const char *_file, int _line );
 
50
extern void *_mesa_align_calloc_dbg(size_t bytes, unsigned long alignment, const char *_file, int _line );
 
51
extern void _mesa_align_free_dbg(void *ptr, const char *_file, int _line);
 
52
 
 
53
#define _mesa_align_malloc( s, a ) _mesa_align_malloc_dbg( s, a, __FILE__ , __LINE__ )
 
54
#define _mesa_align_calloc( s, a ) _mesa_align_calloc_dbg( s, a, __FILE__ , __LINE__ )
 
55
#define _mesa_align_free(p)        _mesa_align_free_dbg(p, __FILE__ , __LINE__)
 
56
 
 
57
#else /* WIN32 && _DEBUG */
 
58
 
 
59
extern void *_mesa_malloc(size_t bytes);
 
60
extern void *_mesa_calloc(size_t bytes);
 
61
extern void _mesa_free(void *ptr);
 
62
 
 
63
extern void *_mesa_align_malloc(size_t bytes, unsigned long alignment);
 
64
extern void *_mesa_align_calloc(size_t bytes, unsigned long alignment);
 
65
extern void _mesa_align_free(void *ptr);
 
66
 
 
67
#endif /* WIN32 && _DEBUG */
 
68
 
 
69
 
 
70
#ifdef DEBUG
 
71
 
 
72
/* call Mesa memory functions */
 
73
#define MALLOC(BYTES)      _mesa_malloc(BYTES)
 
74
#define CALLOC(BYTES)      _mesa_calloc(BYTES)
 
75
#define MALLOC_STRUCT(T)   (struct T *) _mesa_malloc(sizeof(struct T))
 
76
#define CALLOC_STRUCT(T)   (struct T *) _mesa_calloc(sizeof(struct T))
 
77
#define FREE(PTR)          _mesa_free(PTR)
 
78
 
 
79
#else
 
80
 
 
81
/* directly call C lib memory functions */
 
82
#define MALLOC(BYTES)      (void *) malloc(BYTES)
 
83
#define CALLOC(BYTES)      (void *) calloc(1, BYTES)
 
84
#define MALLOC_STRUCT(T)   (struct T *) malloc(sizeof(struct T))
 
85
#define CALLOC_STRUCT(T)   (struct T *) calloc(1,sizeof(struct T))
 
86
#define FREE(PTR)          free(PTR)
 
87
 
 
88
#endif
 
89
 
 
90
/* call Mesa N-byte aligned memory functions */
 
91
#define ALIGN_MALLOC(BYTES, N)     (void *) _mesa_align_malloc(BYTES, N)
 
92
#define ALIGN_CALLOC(BYTES, N)     (void *) _mesa_align_calloc(BYTES, N)
 
93
#define ALIGN_MALLOC_STRUCT(T, N)  (struct T *) _mesa_align_malloc(sizeof(struct T), N)
 
94
#define ALIGN_CALLOC_STRUCT(T, N)  (struct T *) _mesa_align_calloc(sizeof(struct T), N)
 
95
#define ALIGN_FREE(PTR)            _mesa_align_free(PTR)
 
96
 
 
97
 
 
98
#ifdef MESA_EXTERNAL_BUFFERALLOC
 
99
/*
 
100
 * If you want Mesa's depth/stencil/accum/etc buffers to be allocated
 
101
 * with a specialized allocator you can define MESA_EXTERNAL_BUFFERALLOC
 
102
 * and implement _ext_mesa_alloc/free_pixelbuffer() in your app.
 
103
 * Contributed by Gerk Huisma (gerk@five-d.demon.nl).
 
104
 */
 
105
extern void *_ext_mesa_alloc_pixelbuffer( unsigned int size );
 
106
extern void _ext_mesa_free_pixelbuffer( void *pb );
 
107
 
 
108
#define MESA_PBUFFER_ALLOC(BYTES)  (void *) _ext_mesa_alloc_pixelbuffer(BYTES)
 
109
#define MESA_PBUFFER_FREE(PTR)     _ext_mesa_free_pixelbuffer(PTR)
 
110
#else
 
111
/* Default buffer allocation uses the aligned allocation routines: */
 
112
#define MESA_PBUFFER_ALLOC(BYTES)  (void *) _mesa_align_malloc(BYTES, 512)
 
113
#define MESA_PBUFFER_FREE(PTR)     _mesa_align_free(PTR)
 
114
#endif
 
115
 
 
116
 
 
117
/* Memory copy: */
 
118
#ifdef SUNOS4
 
119
#define MEMCPY( DST, SRC, BYTES) \
 
120
        memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) )
 
121
#else
 
122
#define MEMCPY( DST, SRC, BYTES) \
 
123
        memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) )
 
124
#endif
 
125
 
 
126
 
 
127
/* Memory set: */
 
128
#ifdef SUNOS4
 
129
#define MEMSET( DST, VAL, N ) \
 
130
        memset( (char *) (DST), (int) (VAL), (int) (N) )
 
131
#else
 
132
#define MEMSET( DST, VAL, N ) \
 
133
        memset( (void *) (DST), (int) (VAL), (size_t) (N) )
 
134
#endif
 
135
 
 
136
extern void _mesa_memset16( GLushort *dst, GLushort val, size_t n );
 
137
 
 
138
#define MEMSET16( DST, VAL, N ) \
 
139
        _mesa_memset16( (GLushort *) (DST), (GLushort) (VAL), (size_t) (N) )
 
140
 
 
141
 
 
142
/* On some systems we might want to use bzero() (but is bzero portable?) */
 
143
#if defined(__FreeBSD__)
 
144
#define BZERO( ADDR, N ) \
 
145
        bzero( (void *) (ADDR), (size_t) (N) )
 
146
#else
 
147
#define BZERO( ADDR, N ) \
 
148
        memset( (void *) (ADDR), 0, (size_t) (N) )
 
149
#endif
 
150
 
 
151
 
 
152
/* MACs and BeOS don't support static larger than 32kb, so... */
 
153
#if defined(macintosh) && !defined(__MRC__)
 
154
/*extern char *AGLAlloc(int size);*/
 
155
/*extern void AGLFree(char* ptr);*/
 
156
#  define DEFARRAY(TYPE,NAME,SIZE)                      TYPE *NAME = (TYPE*)MALLOC(sizeof(TYPE)*(SIZE))
 
157
#  define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2)              TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])MALLOC(sizeof(TYPE)*(SIZE1)*(SIZE2))
 
158
#  define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3)       TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])MALLOC(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
 
159
 
 
160
#  define CHECKARRAY(NAME,CMD)                          do {if (!(NAME)) {CMD;}} while (0)
 
161
#  define UNDEFARRAY(NAME)                              do {if ((NAME)) {FREE((char*)NAME);}  }while (0)
 
162
#elif defined(__BEOS__)
 
163
#  define DEFARRAY(TYPE,NAME,SIZE)                      TYPE *NAME = (TYPE*)malloc(sizeof(TYPE)*(SIZE))
 
164
#  define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2)              TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
 
165
#  define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3)       TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
 
166
#  define CHECKARRAY(NAME,CMD)                          do {if (!(NAME)) {CMD;}} while (0)
 
167
#  define UNDEFARRAY(NAME)                              do {if ((NAME)) {free((char*)NAME);}  }while (0)
 
168
#else
 
169
#  define DEFARRAY(TYPE,NAME,SIZE)                      TYPE NAME[SIZE]
 
170
#  define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2)              TYPE NAME[SIZE1][SIZE2]
 
171
#  define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3)       TYPE NAME[SIZE1][SIZE2][SIZE3]
 
172
#  define CHECKARRAY(NAME,CMD)                          do {} while(0)
 
173
#  define UNDEFARRAY(NAME)
 
174
#endif
 
175
 
 
176
 
 
177
 
 
178
 
 
179
#endif