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 #pragma weak mlib_sincosf = __mlib_sincosf 52 53 #elif defined ( __GNUC__ ) /* defined ( __SUNPRO_C ) */ 54 55 __typeof__ ( __mlib_memmove) mlib_memmove 56 __attribute__ ((weak,alias("__mlib_memmove"))); 57 __typeof__ ( __mlib_malloc) mlib_malloc 58 __attribute__ ((weak,alias("__mlib_malloc"))); 59 __typeof__ ( __mlib_realloc) mlib_realloc 60 __attribute__ ((weak,alias("__mlib_realloc"))); 61 __typeof__ ( __mlib_free) mlib_free 62 __attribute__ ((weak,alias("__mlib_free"))); 63 __typeof__ ( __mlib_memset) mlib_memset 64 __attribute__ ((weak,alias("__mlib_memset"))); 65 __typeof__ ( __mlib_memcpy) mlib_memcpy 66 __attribute__ ((weak,alias("__mlib_memcpy"))); 67 68 void __mlib_sincosf (float x, float *s, float *c); 69 70 __typeof__ ( __mlib_sincosf) mlib_sincosf 71 __attribute__ ((weak,alias("__mlib_sincosf"))); 72 73 #else /* defined ( __SUNPRO_C ) */ 74 75 #error "unknown platform" 76 77 #endif /* defined ( __SUNPRO_C ) */ 78 #endif /* ! defined ( __MEDIALIB_OLD_NAMES ) */ 79 80 /***************************************************************/ 81 82 void *__mlib_malloc(mlib_u32 size) 83 { 84 #if defined(_MSC_VER) || defined(AIX) 85 /* 86 * Currently, all MS C compilers for Win32 platforms default to 8 byte 87 * alignment. -- from stdlib.h of MS VC++5.0. 88 * 89 * On AIX, the malloc subroutine returns a pointer to space suitably 90 * aligned for the storage of any type of object (see 'man malloc'). 91 */ 92 return (void *) malloc(size); 93 #elif defined(MACOSX) 94 return valloc(size); 95 #else 96 return (void *) memalign(8, size); 97 #endif /* _MSC_VER */ 98 } 99 100 void *__mlib_realloc(void *ptr, mlib_u32 size) 101 { 102 return realloc(ptr, size); 103 } 104 105 void __mlib_free(void *ptr) 106 { 107 free(ptr); 108 } 109 110 void *__mlib_memset(void *s, mlib_s32 c, mlib_u32 n) 111 { 112 return memset(s, c, n); 113 } 114 115 void *__mlib_memcpy(void *s1, void *s2, mlib_u32 n) 116 { 117 return memcpy(s1, s2, n); 118 } 119 120 void *__mlib_memmove(void *s1, void *s2, mlib_u32 n) 121 { 122 return memmove(s1, s2, n); 123 } 124 125 void __mlib_sincosf (mlib_f32 x, mlib_f32 *s, mlib_f32 *c) 126 { 127 *s = (mlib_f32)sin(x); 128 *c = (mlib_f32)cos(x); 129 }