18 #include "mysys_priv.h"
19 #include "mysys_err.h"
34 uchar *my_malloc_lock(uint
size,myf MyFlags)
37 uint pagesize=sysconf(_SC_PAGESIZE);
39 struct st_mem_list *element;
40 DBUG_ENTER(
"my_malloc_lock");
42 size=((size-1) & ~(pagesize-1))+pagesize;
43 if (!(ptr=memalign(pagesize,size)))
45 if (MyFlags & (MY_FAE+MY_WME))
46 my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_FATALERROR),
size);
49 success = mlock((uchar*) ptr,size);
50 if (success != 0 && geteuid() == 0)
52 DBUG_PRINT(
"warning",(
"Failed to lock memory. errno %d\n",
54 fprintf(stderr,
"Warning: Failed to lock memory. errno %d\n",
60 if (!(element=(
struct st_mem_list*) my_malloc(
sizeof(*element),MyFlags)))
62 (void) munlock((uchar*) ptr,
size);
66 element->list.data=(uchar*) element;
70 mem_list=list_add(mem_list,&element->list);
77 void my_free_lock(uchar *ptr)
80 struct st_mem_list *element=0;
83 for (list=mem_list ; list ; list=list->next)
85 element=(
struct st_mem_list*) list->data;
86 if (ptr == element->page)
88 (void) munlock((uchar*) ptr,element->size);
89 mem_list=list_delete(mem_list,list);