~ubuntu-branches/ubuntu/vivid/mariadb-5.5/vivid

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/toku_include/toku_portability.h

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
 
3
#ident "$Id$"
 
4
/*
 
5
COPYING CONDITIONS NOTICE:
 
6
 
 
7
  This program is free software; you can redistribute it and/or modify
 
8
  it under the terms of version 2 of the GNU General Public License as
 
9
  published by the Free Software Foundation, and provided that the
 
10
  following conditions are met:
 
11
 
 
12
      * Redistributions of source code must retain this COPYING
 
13
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
14
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
15
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
16
        GRANT (below).
 
17
 
 
18
      * Redistributions in binary form must reproduce this COPYING
 
19
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
20
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
21
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
22
        GRANT (below) in the documentation and/or other materials
 
23
        provided with the distribution.
 
24
 
 
25
  You should have received a copy of the GNU General Public License
 
26
  along with this program; if not, write to the Free Software
 
27
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
28
  02110-1301, USA.
 
29
 
 
30
COPYRIGHT NOTICE:
 
31
 
 
32
  TokuDB, Tokutek Fractal Tree Indexing Library.
 
33
  Copyright (C) 2007-2013 Tokutek, Inc.
 
34
 
 
35
DISCLAIMER:
 
36
 
 
37
  This program is distributed in the hope that it will be useful, but
 
38
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
39
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
40
  General Public License for more details.
 
41
 
 
42
UNIVERSITY PATENT NOTICE:
 
43
 
 
44
  The technology is licensed by the Massachusetts Institute of
 
45
  Technology, Rutgers State University of New Jersey, and the Research
 
46
  Foundation of State University of New York at Stony Brook under
 
47
  United States of America Serial No. 11/760379 and to the patents
 
48
  and/or patent applications resulting from it.
 
49
 
 
50
PATENT MARKING NOTICE:
 
51
 
 
52
  This software is covered by US Patent No. 8,185,551.
 
53
  This software is covered by US Patent No. 8,489,638.
 
54
 
 
55
PATENT RIGHTS GRANT:
 
56
 
 
57
  "THIS IMPLEMENTATION" means the copyrightable works distributed by
 
58
  Tokutek as part of the Fractal Tree project.
 
59
 
 
60
  "PATENT CLAIMS" means the claims of patents that are owned or
 
61
  licensable by Tokutek, both currently or in the future; and that in
 
62
  the absence of this license would be infringed by THIS
 
63
  IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
 
64
 
 
65
  "PATENT CHALLENGE" shall mean a challenge to the validity,
 
66
  patentability, enforceability and/or non-infringement of any of the
 
67
  PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
 
68
 
 
69
  Tokutek hereby grants to you, for the term and geographical scope of
 
70
  the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
 
71
  irrevocable (except as stated in this section) patent license to
 
72
  make, have made, use, offer to sell, sell, import, transfer, and
 
73
  otherwise run, modify, and propagate the contents of THIS
 
74
  IMPLEMENTATION, where such license applies only to the PATENT
 
75
  CLAIMS.  This grant does not include claims that would be infringed
 
76
  only as a consequence of further modifications of THIS
 
77
  IMPLEMENTATION.  If you or your agent or licensee institute or order
 
78
  or agree to the institution of patent litigation against any entity
 
79
  (including a cross-claim or counterclaim in a lawsuit) alleging that
 
80
  THIS IMPLEMENTATION constitutes direct or contributory patent
 
81
  infringement, or inducement of patent infringement, then any rights
 
82
  granted to you under this License shall terminate as of the date
 
83
  such litigation is filed.  If you or your agent or exclusive
 
84
  licensee institute or order or agree to the institution of a PATENT
 
85
  CHALLENGE, then Tokutek may terminate any rights granted to you
 
86
  under this License.
 
87
*/
 
88
 
 
89
#ident "Copyright (c) 2007-2013 Tokutek Inc.  All rights reserved."
 
90
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
 
91
#ifndef TOKU_PORTABILITY_H
 
92
#define TOKU_PORTABILITY_H
 
93
 
 
94
#include "toku_config.h"
 
95
 
 
96
// Tokutek portability layer
 
97
 
 
98
#if defined(__clang__)
 
99
#  define constexpr_static_assert(a, b)
 
100
#else
 
101
#  define constexpr_static_assert(a, b) static_assert(a, b)
 
102
#endif
 
103
 
 
104
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(__ICL))
 
105
 
 
106
#define TOKU_WINDOWS 1
 
107
#define DEV_NULL_FILE "NUL"
 
108
 
 
109
# if defined(_WIN64)
 
110
#  define TOKU_WINDOWS_32 0
 
111
#  define TOKU_WINDOWS_64 1
 
112
# else
 
113
#  define TOKU_WINDOWS_32 1
 
114
#  define TOKU_WINDOWS_64 2
 
115
#endif
 
116
 
 
117
#else
 
118
 
 
119
#define TOKU_WINDOWS 0
 
120
#define TOKU_WINDOWS_32 0
 
121
#define TOKU_WINDOWS_64 0
 
122
#define DEV_NULL_FILE "/dev/null"
 
123
 
 
124
#endif
 
125
 
 
126
// include here, before they get deprecated
 
127
#include <toku_atomic.h>
 
128
 
 
129
#if TOKU_WINDOWS
 
130
// Windows
 
131
 
 
132
#define DO_GCC_PRAGMA(x)      /* Nothing */
 
133
 
 
134
#if defined(__ICL)
 
135
#define __attribute__(x)      /* Nothing */
 
136
#endif
 
137
 
 
138
#include <malloc.h>
 
139
#include "toku_stdint.h"
 
140
 
 
141
#ifndef TOKU_OFF_T_DEFINED
 
142
#define TOKU_OFF_T_DEFINED
 
143
typedef int64_t toku_off_t;
 
144
#endif
 
145
 
 
146
#include <direct.h>
 
147
#include <sys/types.h>
 
148
#include "unistd.h"
 
149
#include "misc.h"
 
150
#include "toku_pthread.h"
 
151
 
 
152
#define UNUSED_WARNING(a) a=a /* To make up for missing attributes */
 
153
 
 
154
#define cast_to_typeof(v)
 
155
 
 
156
#elif defined(__INTEL_COMPILER)
 
157
 
 
158
#define DO_GCC_PRAGMA(x)      /* Nothing */
 
159
 
 
160
#if defined(__ICC)
 
161
// Intel linux
 
162
 
 
163
#include <alloca.h>
 
164
#include <toku_stdint.h>
 
165
#include <unistd.h>
 
166
#include <sys/types.h>
 
167
#include <sys/time.h>
 
168
#include <stdio.h>
 
169
 
 
170
#define static_assert(foo, bar)
 
171
#endif 
 
172
 
 
173
#if defined(__cplusplus)
 
174
# define cast_to_typeof(v) (decltype(v))
 
175
#else
 
176
# define cast_to_typeof(v) (__typeof__(v))
 
177
#endif
 
178
 
 
179
#elif defined(__GNUC__)
 
180
// GCC linux
 
181
 
 
182
#define DO_GCC_PRAGMA(x) _Pragma (#x)
 
183
 
 
184
#include <toku_stdint.h>
 
185
#include <unistd.h>
 
186
#include <sys/types.h>
 
187
#include <sys/time.h>
 
188
#include <sys/stat.h>
 
189
#include <stdio.h>
 
190
#if __FreeBSD__
 
191
#include <stdarg.h>
 
192
#endif
 
193
#if defined(HAVE_ALLOCA_H)
 
194
# include <alloca.h>
 
195
#endif
 
196
#if defined(__cplusplus)
 
197
# include <type_traits>
 
198
#endif
 
199
 
 
200
#if defined(__cplusplus)
 
201
# define cast_to_typeof(v) (decltype(v))
 
202
#else
 
203
# define cast_to_typeof(v) (__typeof__(v))
 
204
#endif
 
205
 
 
206
#else
 
207
 
 
208
#error Not ICC and not GNUC.  What compiler?
 
209
 
 
210
#endif
 
211
 
 
212
// Define some constants for Yama in case the build-machine's software is too old.
 
213
#if !defined(HAVE_PR_SET_PTRACER)
 
214
/*
 
215
 * Set specific pid that is allowed to ptrace the current task.
 
216
 * A value of 0 mean "no process".
 
217
 */
 
218
// Well defined ("Yama" in ascii)
 
219
#define PR_SET_PTRACER 0x59616d61
 
220
#endif
 
221
#if !defined(HAVE_PR_SET_PTRACER_ANY)
 
222
#define PR_SET_PTRACER_ANY ((unsigned long)-1)
 
223
#endif
 
224
 
 
225
#if defined(__cplusplus)
 
226
// decltype() here gives a reference-to-pointer instead of just a pointer,
 
227
// just use __typeof__
 
228
# define CAST_FROM_VOIDP(name, value) name = static_cast<__typeof__(name)>(value)
 
229
#else
 
230
# define CAST_FROM_VOIDP(name, value) name = cast_to_typeof(name) (value)
 
231
#endif
 
232
 
 
233
#ifndef TOKU_OFF_T_DEFINED
 
234
#define TOKU_OFF_T_DEFINED
 
235
typedef int64_t toku_off_t;
 
236
#endif
 
237
 
 
238
#include "toku_os.h"
 
239
#include "toku_htod.h"
 
240
#include "toku_assert.h"
 
241
#include "toku_crash.h"
 
242
 
 
243
#define UU(x) x __attribute__((__unused__))
 
244
 
 
245
#if defined(__cplusplus)
 
246
extern "C" {
 
247
#endif
 
248
 
 
249
// Deprecated functions.
 
250
#if !defined(TOKU_ALLOW_DEPRECATED)
 
251
#   if defined(__ICL) || defined(__ICC) // Intel Compiler
 
252
#       pragma deprecated (creat, fstat, stat, getpid, syscall, sysconf, mkdir, strdup)
 
253
//#       pragma poison   off_t
 
254
//#       pragma poison   pthread_attr_t       pthread_t
 
255
//#       pragma poison   pthread_mutexattr_t  pthread_mutex_t
 
256
//#       pragma poison   pthread_condattr_t   pthread_cond_t
 
257
//#       pragma poison   pthread_rwlockattr_t pthread_rwlock_t
 
258
//#       pragma poison   timespec
 
259
#    ifndef DONT_DEPRECATE_WRITES
 
260
#       pragma poison   write                pwrite
 
261
#    endif
 
262
#    ifndef DONT_DEPRECATE_MALLOC
 
263
#       pragma deprecated (malloc, free, realloc)
 
264
#    endif
 
265
#    ifndef DONT_DEPRECATE_ERRNO
 
266
#       pragma deprecated (errno)
 
267
#    endif
 
268
#    ifndef TOKU_WINDOWS_ALLOW_DEPRECATED
 
269
#       pragma poison   dup2
 
270
#       pragma poison   _dup2
 
271
#    endif
 
272
#   else
 
273
int      creat(const char *pathname, mode_t mode)   __attribute__((__deprecated__));
 
274
int      fstat(int fd, struct stat *buf)            __attribute__((__deprecated__));
 
275
int      stat(const char *path, struct stat *buf)   __attribute__((__deprecated__));
 
276
int      getpid(void)                               __attribute__((__deprecated__));
 
277
#    if defined(__FreeBSD__) || defined(__APPLE__)
 
278
int syscall(int __sysno, ...)             __attribute__((__deprecated__));
 
279
#    else
 
280
long int syscall(long int __sysno, ...)             __attribute__((__deprecated__));
 
281
#    endif
 
282
// Sadly, dlmalloc needs sysconf, and on linux this causes trouble with -combine.  So let the warnings show up under windows only.
 
283
// long int sysconf(int)                   __attribute__((__deprecated__));
 
284
int      mkdir(const char *pathname, mode_t mode)   __attribute__((__deprecated__));
 
285
int      dup2(int fd, int fd2)                      __attribute__((__deprecated__));
 
286
int      _dup2(int fd, int fd2)                     __attribute__((__deprecated__));
 
287
// strdup is a macro in some libraries.
 
288
#undef strdup
 
289
#    if defined(__FreeBSD__)
 
290
char*    strdup(const char *)         __malloc_like __attribute__((__deprecated__));
 
291
#    elif defined(__APPLE__)
 
292
char*    strdup(const char *)         __attribute__((__deprecated__));
 
293
#    else
 
294
char*    strdup(const char *)         __THROW __attribute_malloc__ __nonnull ((1)) __attribute__((__deprecated__));
 
295
#    endif
 
296
#undef __strdup
 
297
char*    __strdup(const char *)         __attribute__((__deprecated__));
 
298
#    ifndef DONT_DEPRECATE_WRITES
 
299
ssize_t  write(int, const void *, size_t)           __attribute__((__deprecated__));
 
300
ssize_t  pwrite(int, const void *, size_t, off_t)   __attribute__((__deprecated__));
 
301
#endif
 
302
#    ifndef DONT_DEPRECATE_MALLOC
 
303
#     if defined(__FreeBSD__)
 
304
extern void *malloc(size_t)                    __malloc_like __attribute__((__deprecated__));
 
305
extern void free(void*)                        __attribute__((__deprecated__));
 
306
extern void *realloc(void*, size_t)            __malloc_like __attribute__((__deprecated__));
 
307
#     elif defined(__APPLE__)
 
308
extern void *malloc(size_t)                    __attribute__((__deprecated__));
 
309
extern void free(void*)                        __attribute__((__deprecated__));
 
310
extern void *realloc(void*, size_t)            __attribute__((__deprecated__));
 
311
#     else
 
312
extern void *malloc(size_t)                    __THROW __attribute__((__deprecated__));
 
313
extern void free(void*)                        __THROW __attribute__((__deprecated__));
 
314
extern void *realloc(void*, size_t)            __THROW __attribute__((__deprecated__));
 
315
#     endif
 
316
#    endif
 
317
#    ifndef DONT_DEPRECATE_ERRNO
 
318
//extern int errno __attribute__((__deprecated__));
 
319
#    endif
 
320
#if !defined(__APPLE__)
 
321
// Darwin headers use these types, we should not poison them
 
322
# pragma GCC poison u_int8_t
 
323
# pragma GCC poison u_int16_t
 
324
# pragma GCC poison u_int32_t
 
325
# pragma GCC poison u_int64_t
 
326
# pragma GCC poison BOOL
 
327
# pragma GCC poison FALSE
 
328
# pragma GCC poison TRUE
 
329
#endif
 
330
#pragma GCC poison __sync_fetch_and_add
 
331
#pragma GCC poison __sync_fetch_and_sub
 
332
#pragma GCC poison __sync_fetch_and_or
 
333
#pragma GCC poison __sync_fetch_and_and
 
334
#pragma GCC poison __sync_fetch_and_xor
 
335
#pragma GCC poison __sync_fetch_and_nand
 
336
#pragma GCC poison __sync_add_and_fetch
 
337
#pragma GCC poison __sync_sub_and_fetch
 
338
#pragma GCC poison __sync_or_and_fetch
 
339
#pragma GCC poison __sync_and_and_fetch
 
340
#pragma GCC poison __sync_xor_and_fetch
 
341
#pragma GCC poison __sync_nand_and_fetch
 
342
#pragma GCC poison __sync_bool_compare_and_swap
 
343
#pragma GCC poison __sync_val_compare_and_swap
 
344
#pragma GCC poison __sync_synchronize
 
345
#pragma GCC poison __sync_lock_test_and_set
 
346
#pragma GCC poison __sync_release
 
347
#   endif
 
348
#endif
 
349
 
 
350
#if defined(__cplusplus)
 
351
};
 
352
#endif
 
353
 
 
354
void *os_malloc(size_t) __attribute__((__visibility__("default")));
 
355
// Effect: See man malloc(2)
 
356
 
 
357
void *os_malloc_aligned(size_t /*alignment*/, size_t /*size*/) __attribute__((__visibility__("default")));
 
358
// Effect: Perform a malloc(size) with the additional property that the returned pointer is a multiple of ALIGNMENT.
 
359
// Requires: alignment is a power of two.
 
360
 
 
361
 
 
362
void *os_realloc(void*,size_t) __attribute__((__visibility__("default")));
 
363
// Effect: See man realloc(2)
 
364
 
 
365
void *os_realloc_aligned(size_t/*alignment*/, void*,size_t) __attribute__((__visibility__("default")));
 
366
// Effect: Perform a realloc(p, size) with the additional property that the returned pointer is a multiple of ALIGNMENT.
 
367
// Requires: alignment is a power of two.
 
368
 
 
369
void os_free(void*) __attribute__((__visibility__("default")));
 
370
// Effect: See man free(2)
 
371
 
 
372
size_t os_malloc_usable_size(const void *p) __attribute__((__visibility__("default")));
 
373
// Effect: Return an estimate of the usable size inside a pointer.  If this function is not defined the memory.cc will
 
374
//  look for the jemalloc, libc, or darwin versions of the function for computing memory footprint.
 
375
 
 
376
// full_pwrite and full_write performs a pwrite, and checks errors.  It doesn't return unless all the data was written. */
 
377
void toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
 
378
void toku_os_full_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
 
379
 
 
380
// os_write returns 0 on success, otherwise an errno.
 
381
ssize_t toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
 
382
int toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
 
383
 
 
384
// wrappers around file system calls
 
385
FILE * toku_os_fdopen(int fildes, const char *mode);    
 
386
FILE * toku_os_fopen(const char *filename, const char *mode);
 
387
int toku_os_open(const char *path, int oflag, int mode);
 
388
int toku_os_open_direct(const char *path, int oflag, int mode);
 
389
int toku_os_close(int fd);
 
390
int toku_os_fclose(FILE * stream);
 
391
ssize_t toku_os_read(int fd, void *buf, size_t count);
 
392
ssize_t toku_os_pread(int fd, void *buf, size_t count, off_t offset);
 
393
void toku_os_recursive_delete(const char *path);
 
394
 
 
395
// wrapper around fsync
 
396
void toku_file_fsync_without_accounting(int fd);
 
397
void toku_file_fsync(int fd);
 
398
int toku_fsync_directory(const char *fname);
 
399
 
 
400
// get the number of fsync calls and the fsync times (total)
 
401
void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time, uint64_t *long_fsync_threshold, uint64_t *long_fsync_count, uint64_t *long_fsync_time);
 
402
 
 
403
void toku_set_func_fsync (int (*fsync_function)(int));
 
404
void toku_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
 
405
void toku_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
 
406
void toku_set_func_write (ssize_t (*)(int, const void *, size_t));
 
407
void toku_set_func_full_write (ssize_t (*)(int, const void *, size_t));
 
408
void toku_set_func_fdopen (FILE * (*)(int, const char *));
 
409
void toku_set_func_fopen (FILE * (*)(const char *, const char *));
 
410
void toku_set_func_open (int (*)(const char *, int, int));
 
411
void toku_set_func_fclose(int (*)(FILE*));
 
412
void toku_set_func_read(ssize_t (*)(int, void *, size_t));
 
413
void toku_set_func_pread (ssize_t (*)(int, void *, size_t, off_t));
 
414
 
 
415
int toku_portability_init(void);
 
416
void toku_portability_destroy(void);
 
417
 
 
418
static inline uint64_t roundup_to_multiple(uint64_t alignment, uint64_t v)
 
419
// Effect: Return X, where X the smallest multiple of ALIGNMENT such that X>=V.
 
420
// Requires: ALIGNMENT is a power of two
 
421
{
 
422
    assert(0==(alignment&(alignment-1)));  // alignment must be a power of two
 
423
    uint64_t result = (v+alignment-1)&~(alignment-1);
 
424
    assert(result>=v);                     // The result is >=V.
 
425
    assert(result%alignment==0);           // The result is a multiple of alignment.
 
426
    assert(result<v+alignment);            // The result is the smallest such multiple of alignment.
 
427
    return result;
 
428
}
 
429
    
 
430
 
 
431
#endif /* TOKU_PORTABILITY_H */