1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 #include <stdlib.h> 28 #include <string.h> 29 #ifdef MACOSX 30 #include <unistd.h> 31 #include <sys/param.h> 32 #else 33 #include <malloc.h> 34 #endif 35 #include <mlib_types.h> 36 #include <mlib_sys_proto.h> 37 #include "mlib_SysMath.h" 38 39 /***************************************************************/ 40 41 #if ! defined ( __MEDIALIB_OLD_NAMES ) 42 #if defined ( __SUNPRO_C ) 43 44 #pragma weak mlib_memmove = __mlib_memmove 45 #pragma weak mlib_malloc = __mlib_malloc 46 #pragma weak mlib_realloc = __mlib_realloc 47 #pragma weak mlib_free = __mlib_free 48 #pragma weak mlib_memset = __mlib_memset 49 #pragma weak mlib_memcpy = __mlib_memcpy 50 51 #ifdef MLIB_NO_LIBSUNMATH 52 #pragma weak mlib_sincosf = __mlib_sincosf 53 #endif /* MLIB_NO_LIBSUNMATH */ 54 55 #elif defined ( __GNUC__ ) /* defined ( __SUNPRO_C ) */ 56 57 __typeof__ ( __mlib_memmove) mlib_memmove 58 __attribute__ ((weak,alias("__mlib_memmove"))); 59 __typeof__ ( __mlib_malloc) mlib_malloc 60 __attribute__ ((weak,alias("__mlib_malloc"))); 61 __typeof__ ( __mlib_realloc) mlib_realloc 62 __attribute__ ((weak,alias("__mlib_realloc"))); 63 __typeof__ ( __mlib_free) mlib_free 64 __attribute__ ((weak,alias("__mlib_free"))); 65 __typeof__ ( __mlib_memset) mlib_memset 66 __attribute__ ((weak,alias("__mlib_memset"))); 67 __typeof__ ( __mlib_memcpy) mlib_memcpy 68 __attribute__ ((weak,alias("__mlib_memcpy"))); 69 70 #ifdef MLIB_NO_LIBSUNMATH 71 72 void __mlib_sincosf (float x, float *s, float *c); 73 74 __typeof__ ( __mlib_sincosf) mlib_sincosf 75 __attribute__ ((weak,alias("__mlib_sincosf"))); 76 #endif /* MLIB_NO_LIBSUNMATH */ 77 78 #else /* defined ( __SUNPRO_C ) */ 79 80 #error "unknown platform" 81 82 #endif /* defined ( __SUNPRO_C ) */ 83 #endif /* ! defined ( __MEDIALIB_OLD_NAMES ) */ 84 85 /***************************************************************/ 86 87 void *__mlib_malloc(mlib_u32 size) 88 { 89 #if defined(_MSC_VER) || defined(AIX) 90 /* 91 * Currently, all MS C compilers for Win32 platforms default to 8 byte 92 * alignment. -- from stdlib.h of MS VC++5.0. 93 */ 94 return (void *) malloc(size); 95 #elif defined(MACOSX) 96 return valloc(size); 97 #else 98 return (void *) memalign(8, size); 99 #endif /* _MSC_VER */ 100 } 101 102 void *__mlib_realloc(void *ptr, mlib_u32 size) 103 { 104 return realloc(ptr, size); 105 } 106 107 void __mlib_free(void *ptr) 108 { 109 free(ptr); 110 } 111 112 void *__mlib_memset(void *s, mlib_s32 c, mlib_u32 n) 113 { 114 return memset(s, c, n); 115 } 116 117 void *__mlib_memcpy(void *s1, void *s2, mlib_u32 n) 118 { 119 return memcpy(s1, s2, n); 120 } 121 122 void *__mlib_memmove(void *s1, void *s2, mlib_u32 n) 123 { 124 return memmove(s1, s2, n); 125 } 126 127 #ifdef MLIB_NO_LIBSUNMATH 128 129 void __mlib_sincosf (mlib_f32 x, mlib_f32 *s, mlib_f32 *c) 130 { 131 *s = (mlib_f32)sin(x); 132 *c = (mlib_f32)cos(x); 133 } 134 135 #endif /* MLIB_NO_LIBSUNMATH */