summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libw32dll/wine/ext.c48
-rw-r--r--src/libw32dll/wine/ldt_keeper.c6
-rw-r--r--src/libw32dll/wine/module.c2
3 files changed, 41 insertions, 15 deletions
diff --git a/src/libw32dll/wine/ext.c b/src/libw32dll/wine/ext.c
index dee474d39..49e7d0719 100644
--- a/src/libw32dll/wine/ext.c
+++ b/src/libw32dll/wine/ext.c
@@ -456,13 +456,30 @@ static virt_alloc* vm=0;
LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protection)
{
void* answer;
- int fd=open("/dev/zero", O_RDWR);
+ int fd;
+ long pgsz;
+
+ if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL;
+
+ fd=open("/dev/zero", O_RDWR);
if(fd<0){
perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
return NULL;
}
- size=(size+0xffff)&(~0xffff);
- //printf("VirtualAlloc(0x%08X, %d)\n", address, size);
+
+ if (type&MEM_RESERVE && (unsigned)address&0xffff) {
+ size += (unsigned)address&0xffff;
+ (unsigned)address &= ~0xffff;
+ }
+ pgsz = sysconf(_SC_PAGESIZE);
+ if (type&MEM_COMMIT && (unsigned)address%pgsz) {
+ size += (unsigned)address%pgsz;
+ address -= (unsigned)address%pgsz;
+ }
+
+ if (type&MEM_RESERVE && size<0x10000) size = 0x10000;
+ if (size%pgsz) size += pgsz - size%pgsz;
+
if(address!=0)
{
//check whether we can allow to allocate this
@@ -474,7 +491,7 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
str=str->prev;
continue;
}
- if((unsigned)address+size<(unsigned)str->address)
+ if((unsigned)address+size<=(unsigned)str->address)
{
str=str->prev;
continue;
@@ -482,29 +499,34 @@ LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type, DWORD protec
if(str->state==0)
{
#warning FIXME
- if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
+ if( ((unsigned)address >= (unsigned)str->address)
+ && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size)
+ && (type & MEM_COMMIT))
{
close(fd);
return address; //returning previously reserved memory
}
- return NULL;
}
close(fd);
return NULL;
}
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED | MAP_PRIVATE, fd, 0);
}
- else
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE, fd, 0);
+
+ answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE, fd, 0);
// answer=FILE_dommap(-1, address, 0, size, 0, 0,
// PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
close(fd);
+ if (answer != (void *)-1 && address && answer != address) {
+ /* It is dangerous to try mmap() with MAP_FIXED since it does not
+ always detect conflicts or non-allocation and chaos ensues after
+ a successful call but an overlapping or non-allocated region. */
+ munmap(answer, size);
+ answer = (void *) -1;
+ errno = EINVAL;
+ }
if(answer==(void*)-1)
{
- printf("Error no %d\n", errno);
- printf("VirtualAlloc(0x%p, %ld) failed\n", address, size);
return NULL;
}
else
diff --git a/src/libw32dll/wine/ldt_keeper.c b/src/libw32dll/wine/ldt_keeper.c
index ff8497e35..6941dca39 100644
--- a/src/libw32dll/wine/ldt_keeper.c
+++ b/src/libw32dll/wine/ldt_keeper.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: ldt_keeper.c,v 1.12 2004/06/12 23:19:56 miguelfreitas Exp $
+ * $Id: ldt_keeper.c,v 1.13 2004/09/21 19:35:57 hadess Exp $
*
*
* contents:
@@ -258,7 +258,8 @@ ldt_fs_t* Setup_LDT_Keeper(void)
{
unsigned char *ldt = malloc((TEB_SEL_IDX+1)*8);
unsigned int limit;
-
+
+ memset (ldt, 0, (TEB_SEL_IDX+1)*8);
modify_ldt(0, ldt, (TEB_SEL_IDX+1)*8);
/*
printf("ldt_keeper: old LDT entry = [%x] [%x]\n",
@@ -305,6 +306,7 @@ ldt_fs_t* Setup_LDT_Keeper(void)
return NULL;
}
*(void**)((char*)ldt_fs->fs_seg+0x18) = ldt_fs->fs_seg;
+ memset (&array, 0, sizeof (array));
array.base_addr=(int)ldt_fs->fs_seg;
array.entry_number=TEB_SEL_IDX;
array.limit=getpagesize()-1;
diff --git a/src/libw32dll/wine/module.c b/src/libw32dll/wine/module.c
index 052aece0f..a1d281cde 100644
--- a/src/libw32dll/wine/module.c
+++ b/src/libw32dll/wine/module.c
@@ -374,6 +374,8 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
while (wm == 0 && listpath[++i])
{
+ memset (&path, 0, sizeof (path));
+
if (i < 2)
{
if (i == 0)