2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __MSG_MEMORY_H__
18 #define __MSG_MEMORY_H__
21 /*==================================================================================================
23 ==================================================================================================*/
29 /*==================================================================================================
31 ==================================================================================================*/
32 #define GETSP() ({ unsigned int sp; asm volatile ("mov %0,sp " : "=r"(sp) ); sp;})
34 #define PAGE_SIZE (1 << 12)
35 #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
36 #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
37 #define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
40 /*==================================================================================================
42 ==================================================================================================*/
49 unsigned int stacktop;
54 snprintf(buf, BUF_SIZE, "/proc/%d/maps",getpid());
55 file = fopen(buf,"r");
56 while(fgets(buf, BUF_SIZE, file) != NULL) {
57 if(strstr(buf, "[stack]")){
65 sscanf(buf,"%x-",&stacktop);
66 if(madvise((void*)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp)-stacktop, MADV_DONTNEED) < 0)
67 perror("stack madvise fail");
72 void MsgReleaseMemory();
75 #endif // __MSG_MEMORY_H__