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