comparison loader/ldt_keeper.c @ 21187:d9cedf7b8069

added mmap_anon to osdep lib. Used in loader for now
author nplourde
date Sat, 25 Nov 2006 01:22:20 +0000
parents 3bf0d70b4c7f
children 77038ef975ba
comparison
equal deleted inserted replaced
21186:d3b66895640c 21187:d9cedf7b8069
26 #include <fcntl.h> 26 #include <fcntl.h>
27 #include <sys/mman.h> 27 #include <sys/mman.h>
28 #include <sys/types.h> 28 #include <sys/types.h>
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <unistd.h> 30 #include <unistd.h>
31 #include "osdep/mmap_anon.h"
31 #ifdef __linux__ 32 #ifdef __linux__
32 #include <asm/unistd.h> 33 #include <asm/unistd.h>
33 #include <asm/ldt.h> 34 #include <asm/ldt.h>
34 // 2.5.xx+ calls this user_desc: 35 // 2.5.xx+ calls this user_desc:
35 #include <linux/version.h> 36 #include <linux/version.h>
198 if(ldt_fs->fd<0){ 199 if(ldt_fs->fd<0){
199 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: "); 200 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
200 return NULL; 201 return NULL;
201 } 202 }
202 fs_seg= 203 fs_seg=
203 ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, 204 ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, &ldt_fs->fd,
204 ldt_fs->fd, 0); 205 0);
205 if (ldt_fs->fs_seg == (void*)-1) 206 if (ldt_fs->fs_seg == (void*)-1)
206 { 207 {
207 perror("ERROR: Couldn't allocate memory for fs segment"); 208 perror("ERROR: Couldn't allocate memory for fs segment");
208 close(ldt_fs->fd); 209 close(ldt_fs->fd);
209 free(ldt_fs); 210 free(ldt_fs);
284 return; 285 return;
285 if (ldt_fs->prev_struct) 286 if (ldt_fs->prev_struct)
286 free(ldt_fs->prev_struct); 287 free(ldt_fs->prev_struct);
287 munmap((char*)ldt_fs->fs_seg, getpagesize()); 288 munmap((char*)ldt_fs->fs_seg, getpagesize());
288 ldt_fs->fs_seg = 0; 289 ldt_fs->fs_seg = 0;
290 if (ldt_fs->fd != -1)
289 close(ldt_fs->fd); 291 close(ldt_fs->fd);
290 free(ldt_fs); 292 free(ldt_fs);
291 } 293 }