1
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 06:03:45 +01:00

Remove useless fd parameter for mmap_anon

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21264 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2006-11-26 13:09:46 +00:00
parent c95db8d583
commit 7142e36d1f
5 changed files with 7 additions and 21 deletions

View File

@ -248,7 +248,7 @@ LPVOID FILE_dommap( int unix_handle, LPVOID start,
if (unix_handle == -1) if (unix_handle == -1)
{ {
ret = mmap_anon( start, size_low, prot, flags, &fd, offset_low ); ret = mmap_anon( start, size_low, prot, flags, offset_low );
} }
else else
{ {
@ -365,12 +365,10 @@ HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr,
mmap_access |=PROT_READ|PROT_WRITE; mmap_access |=PROT_READ|PROT_WRITE;
if(anon) if(anon)
answer=mmap_anon(NULL, len, mmap_access, MAP_PRIVATE, &hFile, 0); answer=mmap_anon(NULL, len, mmap_access, MAP_PRIVATE, 0);
else else
answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0); answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
if(anon && hFile != -1)
close(hFile);
if(answer!=(LPVOID)-1) if(answer!=(LPVOID)-1)
{ {
if(fm==0) if(fm==0)
@ -395,8 +393,6 @@ HANDLE WINAPI CreateFileMappingA(HANDLE handle, LPSECURITY_ATTRIBUTES lpAttr,
fm->name=NULL; fm->name=NULL;
fm->mapping_size=len; fm->mapping_size=len;
if(anon && hFile != -1)
close(hFile);
return (HANDLE)answer; return (HANDLE)answer;
} }
return (HANDLE)0; return (HANDLE)0;
@ -495,11 +491,9 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
} }
answer=mmap_anon(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, answer=mmap_anon(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE, &fd, 0); MAP_PRIVATE, 0);
// answer=FILE_dommap(-1, address, 0, size, 0, 0, // answer=FILE_dommap(-1, address, 0, size, 0, 0,
// PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); // PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
if (fd != -1)
close(fd);
if (answer != (void *)-1 && address && answer != address) { if (answer != (void *)-1 && address && answer != address) {
/* It is dangerous to try mmap() with MAP_FIXED since it does not /* It is dangerous to try mmap() with MAP_FIXED since it does not

View File

@ -196,12 +196,10 @@ ldt_fs_t* Setup_LDT_Keeper(void)
return NULL; return NULL;
fs_seg= fs_seg=
ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, &ldt_fs->fd, ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, 0);
0);
if (ldt_fs->fs_seg == (void*)-1) if (ldt_fs->fs_seg == (void*)-1)
{ {
perror("ERROR: Couldn't allocate memory for fs segment"); perror("ERROR: Couldn't allocate memory for fs segment");
close(ldt_fs->fd);
free(ldt_fs); free(ldt_fs);
return NULL; return NULL;
} }
@ -282,7 +280,5 @@ void Restore_LDT_Keeper(ldt_fs_t* ldt_fs)
free(ldt_fs->prev_struct); free(ldt_fs->prev_struct);
munmap((char*)ldt_fs->fs_seg, getpagesize()); munmap((char*)ldt_fs->fs_seg, getpagesize());
ldt_fs->fs_seg = 0; ldt_fs->fs_seg = 0;
if (ldt_fs->fd != -1)
close(ldt_fs->fd);
free(ldt_fs); free(ldt_fs);
} }

View File

@ -9,7 +9,6 @@ extern "C"
typedef struct { typedef struct {
void* fs_seg; void* fs_seg;
char* prev_struct; char* prev_struct;
int fd;
} ldt_fs_t; } ldt_fs_t;
void Setup_FS_Segment(void); void Setup_FS_Segment(void);

View File

@ -31,7 +31,7 @@
* \param zerofd * \param zerofd
* \return a pointer to the mapped region upon successful completion, -1 otherwise. * \return a pointer to the mapped region upon successful completion, -1 otherwise.
*/ */
void *mmap_anon(void *addr, size_t len, int prot, int flags, int *zerofd, off_t offset) void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset)
{ {
int fd; int fd;
void *result; void *result;
@ -46,7 +46,6 @@ void *mmap_anon(void *addr, size_t len, int prot, int flags, int *zerofd, off_t
#ifdef MAP_ANONYMOUS #ifdef MAP_ANONYMOUS
/* BSD-style anonymous mapping */ /* BSD-style anonymous mapping */
fd = -1;
result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset); result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset);
#else #else
/* SysV-style anonymous mapping */ /* SysV-style anonymous mapping */
@ -57,11 +56,9 @@ void *mmap_anon(void *addr, size_t len, int prot, int flags, int *zerofd, off_t
} }
result = mmap(addr, len, prot, flags, fd, offset); result = mmap(addr, len, prot, flags, fd, offset);
close(fd);
#endif /* MAP_ANONYMOUS */ #endif /* MAP_ANONYMOUS */
if (zerofd)
*zerofd = fd;
return result; return result;
} }

View File

@ -3,6 +3,6 @@
#include <sys/types.h> #include <sys/types.h>
void *mmap_anon(void *, size_t, int, int, int *, off_t); void *mmap_anon(void *, size_t, int, int, off_t);
#endif /* _OSDEP_MMAP_ANON_H_ */ #endif /* _OSDEP_MMAP_ANON_H_ */