1*d3273b5bSchristos /* $NetBSD: win32_alloc.c,v 1.2 2017/01/28 21:31:50 christos Exp $ */
2b9d004c6Schristos
3b9d004c6Schristos /***********************************************************************
4b9d004c6Schristos * Copyright (c) 2012, Secure Endpoints Inc.
5b9d004c6Schristos * All rights reserved.
6b9d004c6Schristos *
7b9d004c6Schristos * Redistribution and use in source and binary forms, with or without
8b9d004c6Schristos * modification, are permitted provided that the following conditions
9b9d004c6Schristos * are met:
10b9d004c6Schristos *
11b9d004c6Schristos * - Redistributions of source code must retain the above copyright
12b9d004c6Schristos * notice, this list of conditions and the following disclaimer.
13b9d004c6Schristos *
14b9d004c6Schristos * - Redistributions in binary form must reproduce the above copyright
15b9d004c6Schristos * notice, this list of conditions and the following disclaimer in
16b9d004c6Schristos * the documentation and/or other materials provided with the
17b9d004c6Schristos * distribution.
18b9d004c6Schristos *
19b9d004c6Schristos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20b9d004c6Schristos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21b9d004c6Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22b9d004c6Schristos * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23b9d004c6Schristos * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24b9d004c6Schristos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25b9d004c6Schristos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26b9d004c6Schristos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27b9d004c6Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28b9d004c6Schristos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29b9d004c6Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30b9d004c6Schristos * OF THE POSSIBILITY OF SUCH DAMAGE.
31b9d004c6Schristos *
32b9d004c6Schristos **********************************************************************/
33b9d004c6Schristos #include <config.h>
34b9d004c6Schristos #include <krb5/roken.h>
35b9d004c6Schristos #undef calloc
36b9d004c6Schristos #undef malloc
37b9d004c6Schristos #undef free
38b9d004c6Schristos #undef strdup
39b9d004c6Schristos #undef wcsdup
40b9d004c6Schristos
41b9d004c6Schristos /*
42b9d004c6Schristos * Windows executables and dlls suffer when memory is
43b9d004c6Schristos * allocated with one allocator and deallocated with
44b9d004c6Schristos * another because each allocator is backed by a separate
45b9d004c6Schristos * heap. Reduce the exposure by ensuring that all
46b9d004c6Schristos * binaries that are built using roken will build against
47b9d004c6Schristos * same allocator.
48b9d004c6Schristos */
49b9d004c6Schristos
50b9d004c6Schristos ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
rk_calloc(size_t elements,size_t size)51b9d004c6Schristos rk_calloc(size_t elements, size_t size)
52b9d004c6Schristos {
53b9d004c6Schristos return calloc( elements, size);
54b9d004c6Schristos }
55b9d004c6Schristos
56b9d004c6Schristos ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
rk_free(void * ptr)57b9d004c6Schristos rk_free(void * ptr)
58b9d004c6Schristos {
59b9d004c6Schristos free( ptr);
60b9d004c6Schristos }
61b9d004c6Schristos
62b9d004c6Schristos ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
rk_malloc(size_t size)63b9d004c6Schristos rk_malloc(size_t size)
64b9d004c6Schristos {
65b9d004c6Schristos return malloc( size);
66b9d004c6Schristos }
67b9d004c6Schristos
68b9d004c6Schristos ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
rk_strdup(const char * str)69b9d004c6Schristos rk_strdup(const char *str)
70b9d004c6Schristos {
71b9d004c6Schristos return strdup( str);
72b9d004c6Schristos }
73b9d004c6Schristos
74b9d004c6Schristos ROKEN_LIB_FUNCTION unsigned short * ROKEN_LIB_CALL
rk_wcsdup(const unsigned short * str)75b9d004c6Schristos rk_wcsdup(const unsigned short *str)
76b9d004c6Schristos {
77b9d004c6Schristos return wcsdup( str);
78b9d004c6Schristos }
79