From: <cap...@us...> - 2007-04-23 10:23:20
|
Revision: 83 http://svn.sourceforge.net/pearcolator/?rev=83&view=rev Author: captain5050 Date: 2007-04-23 03:23:21 -0700 (Mon, 23 Apr 2007) Log Message: ----------- Fixes to brk system call Modified Paths: -------------- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/DebugMemory.java src/org/binarytranslator/generic/memory/IntAddressedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-23 10:23:21 UTC (rev 83) @@ -160,6 +160,12 @@ * @param address new top of BSS segment */ public void setBrk(int address) { + try { + memory.ensureMapped(brk, address); + } catch (MemoryMapException e) { + throw new Error("Error changing top of BSS to address 0x"+Integer.toHexString(address)+ + " from 0x" + Integer.toHexString(brk), e); + } brk = address; } Modified: src/org/binarytranslator/generic/memory/ByteAddressedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/ByteAddressedMemory.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/memory/ByteAddressedMemory.java 2007-04-23 10:23:21 UTC (rev 83) @@ -319,11 +319,11 @@ readableMemory[getPTE(addr + i)] = null; unmapped_something = true; } - if (readableMemory[getPTE(addr + i)] != null) { + if (writableMemory[getPTE(addr + i)] != null) { writableMemory[getPTE(addr + i)] = null; unmapped_something = true; } - if (readableMemory[getPTE(addr + i)] != null) { + if (executableMemory[getPTE(addr + i)] != null) { executableMemory[getPTE(addr + i)] = null; unmapped_something = true; } @@ -335,6 +335,24 @@ } /** + * Is the given address mapped into memory? + * @param addr to check + * @return true => memory is mapped + */ + public boolean isMapped(int addr) { + return ((readableMemory[getPTE(addr)] != null) || + (writableMemory[getPTE(addr)] != null) || + (executableMemory[getPTE(addr)] != null)); + } + + /** + * @return the size of a page + */ + public int getPageSize() { + return PAGE_SIZE; + } + + /** * Is the given address aligned on a page boundary? * * @param addr Modified: src/org/binarytranslator/generic/memory/DebugMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/DebugMemory.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/memory/DebugMemory.java 2007-04-23 10:23:21 UTC (rev 83) @@ -306,8 +306,26 @@ } } } - + /** + * Is the given address mapped into memory? + * @param addr to check + * @return true => memory is mapped + */ + public boolean isMapped(int addr) { + return ((readableMemory[getPTE(addr)] != null) || + (writableMemory[getPTE(addr)] != null) || + (executableMemory[getPTE(addr)] != null)); + } + + /** + * @return the size of a page + */ + public int getPageSize() { + return PAGE_SIZE; + } + + /** * Is the given address aligned on a page boundary? * * @param addr Modified: src/org/binarytranslator/generic/memory/IntAddressedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedMemory.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/memory/IntAddressedMemory.java 2007-04-23 10:23:21 UTC (rev 83) @@ -98,6 +98,24 @@ } /** + * Is the given address mapped into memory? + * @param addr to check + * @return true => memory is mapped + */ + public boolean isMapped(int addr) { + return ((readableMemory[getPTE(addr)] != null) || + (writableMemory[getPTE(addr)] != null) || + (executableMemory[getPTE(addr)] != null)); + } + + /** + * @return the size of a page + */ + public int getPageSize() { + return PAGE_SIZE; + } + + /** * Is the given address aligned on a page boundary? * * @param addr Modified: src/org/binarytranslator/generic/memory/Memory.java =================================================================== --- src/org/binarytranslator/generic/memory/Memory.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/memory/Memory.java 2007-04-23 10:23:21 UTC (rev 83) @@ -21,38 +21,24 @@ public abstract class Memory { /** * Map an anonymous page of memory - * - * @param addr - * the address to map or NULL if don't care - * @param len - * the amount of memory to map - * @param read - * is the page readable - * @param write - * is the page writable - * @param exec - * is the page executable + * @param addr the address to map or NULL if don't care + * @param len the amount of memory to map + * @param read is the page readable + * @param write is the page writable + * @param exec is the page executable */ public abstract int map(int addr, int len, boolean read, boolean write, boolean exec) throws MemoryMapException; /** * Map a page of memory from file - * - * @param file - * the file map in from - * @param offset - * the offset of the file to map from - * @param addr - * the address to map or NULL if don't care - * @param len - * the amount of memory to map - * @param read - * is the page readable - * @param write - * is the page writable - * @param exec - * is the page executable + * @param file the file map in from + * @param offset the offset of the file to map from + * @param addr the address to map or NULL if don't care + * @param len the amount of memory to map + * @param read is the page readable + * @param write is the page writable + * @param exec is the page executable */ public abstract int map(RandomAccessFile file, long offset, int addr, int len, boolean read, boolean write, boolean exec) @@ -60,131 +46,126 @@ /** * Unmap a page of memory - * - * @param addr - * the address to unmap - * @param len - * the amount of memory to unmap + * @param addr the address to unmap + * @param len the amount of memory to unmap */ public abstract void unmap(int addr, int len); /** + * Is the given address mapped into memory? + * @param addr to check + * @return true => memory is mapped + */ + public abstract boolean isMapped(int addr); + + /** + * Ensure memory between start and end is mapped + * @param startAddr starting address for mapped memory + * @param endAddr ending address for mapped memory + */ + public void ensureMapped(int startAddr, int endAddr) throws MemoryMapException { + startAddr = truncateToPage(startAddr); + endAddr = truncateToNextPage(endAddr); + for (;startAddr < endAddr; startAddr += getPageSize()) { + if (!isMapped(startAddr)) { + map(startAddr, getPageSize(), true, true, false); + } + } + } + + /** * Is the given address aligned on a page boundary? - * - * @param addr - * the address to check + * @param addr the address to check * @return whether the address is aligned */ public abstract boolean isPageAligned(int addr); /** * Make the given address page aligned to the page beneath it - * - * @param addr - * the address to truncate + * @param addr the address to truncate * @return the truncated address */ public abstract int truncateToPage(int addr); /** * Make the given address page aligned to the page above it - * - * @param addr - * the address to truncate + * @param addr the address to truncate * @return the truncated address */ public abstract int truncateToNextPage(int addr); /** + * @return the size of a page + */ + public abstract int getPageSize(); + + /** * Perform a byte load where the sign extended result fills the return value - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the sign extended result */ public abstract int loadSigned8(int addr); /** * Perform a byte load where the zero extended result fills the return value - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the zero extended result */ public abstract int loadUnsigned8(int addr); /** * Perform a 16bit load where the sign extended result fills the return value - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the sign extended result */ public abstract int loadSigned16(int addr); /** * Perform a 16bit load where the zero extended result fills the return value - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the zero extended result */ public abstract int loadUnsigned16(int addr); /** * Perform a 32bit load - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the result */ public abstract int load32(int addr); /** * Perform a 8bit load from memory that must be executable - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the result */ public abstract int loadInstruction8(int addr); /** * Perform a 32bit load from memory that must be executable - * - * @param addr - * the address of the value to load + * @param addr the address of the value to load * @return the result */ public abstract int loadInstruction32(int addr); /** * Perform a byte store - * - * @param value - * the value to store - * @param addr - * the address of where to store + * @param value the value to store + * @param addr the address of where to store */ public abstract void store8(int addr, int value); /** * Perform a 16bit store - * - * @param value - * the value to store - * @param addr - * the address of where to store + * @param value the value to store + * @param addr the address of where to store */ public abstract void store16(int addr, int value); /** * Perform a 32bit store - * - * @param value - * the value to store - * @param addr - * the address of where to store + * @param value the value to store + * @param addr the address of where to store */ public abstract void store32(int addr, int value); @@ -197,11 +178,8 @@ /** * Generate the IR code for a byte load where the sign extended result fills * the register - * - * @param dest - * the register to hold the result - * @param addr - * the address of the value to load + * @param dest the register to hold the result + * @param addr the address of the value to load */ public abstract void translateLoadSigned8(OPT_Operand addr, OPT_RegisterOperand dest); @@ -209,11 +187,8 @@ /** * Generate the IR code for a byte load where the zero extended result fills * the register - * - * @param dest - * the register to hold the result - * @param addr - * the address of the value to load + * @param dest the register to hold the result + * @param addr the address of the value to load */ public abstract void translateLoadUnsigned8(OPT_Operand addr, OPT_RegisterOperand dest); @@ -221,11 +196,8 @@ /** * Generate the IR code for a 16bit load where the sign extended result fills * the register - * - * @param dest - * the register to hold the result - * @param addr - * the address of the value to load + * @param dest the register to hold the result + * @param addr the address of the value to load */ public abstract void translateLoadSigned16(OPT_Operand addr, OPT_RegisterOperand dest); @@ -233,68 +205,50 @@ /** * Generate the IR code for a 16bit load where the zero extended result fills * the register - * - * @param dest - * the register to hold the result - * @param addr - * the address of the value to load + * @param dest the register to hold the result + * @param addr the address of the value to load */ public abstract void translateLoadUnsigned16(OPT_Operand addr, OPT_RegisterOperand dest); /** * Generate the IR code for a 32bit load - * - * @param dest - * the register to hold the result - * @param addr - * the address of the value to load + * @param dest the register to hold the result + * @param addr the address of the value to load */ public abstract void translateLoad32(OPT_Operand addr, OPT_RegisterOperand dest); /** * Generate the IR code for a byte store - * - * @param src - * the register that holds the value to store - * @param addr - * the address of the value to store + * @param src the register that holds the value to store + * @param addr the address of the value to store */ - public abstract void translateStore8(OPT_Operand addr, - OPT_RegisterOperand src); + public abstract void translateStore8(OPT_Operand addr, OPT_RegisterOperand src); /** * Generate the IR code for a 16bit store - * - * @param src - * the register that holds the value to store - * @param addr - * the address of the value to store + * @param src the register that holds the value to store + * @param addr the address of the value to store */ public abstract void translateStore16(OPT_Operand addr, OPT_RegisterOperand src); /** * Generate the IR code for a 32bit store - * - * @param src - * the register that holds the value to store - * @param addr - * the address of the value to store + * @param src the register that holds the value to store + * @param addr the address of the value to store */ public abstract void translateStore32(OPT_Operand addr, OPT_RegisterOperand src); /** * Get method reference if linking a call - * - * @param callAddress - * the address associated with this call + * @param callAddress the address associated with this call */ @Uninterruptible public VM_MethodReference getMethodRef(int callAddress) { throw new Error("Error linking method at " + callAddress + " for memory model " + this.getClass()); } -} +} \ No newline at end of file Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java 2007-04-23 10:23:21 UTC (rev 83) @@ -377,7 +377,7 @@ initialStackSize = memory.truncateToNextPage(initialStackSize); try { - memory.map(stackTop - initialStackSize - 8192, initialStackSize + 8192, + memory.map(stackTop - initialStackSize - (128*1024), initialStackSize + (128*1024), true, true, false); // read/write/no execute } catch (MemoryMapException e) { // Failing to create the stack is a fatal error Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-23 09:23:22 UTC (rev 82) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-23 10:23:21 UTC (rev 83) @@ -746,15 +746,11 @@ public class SysBrk extends SystemCall { public void doSysCall() { int brk = arguments.nextInt(); - - if(brk == 0) { - // Request for the current top of bss. - src.setSysCallReturn(src.getBrk()); - } - else { - // Changing the value. + if(brk != 0) { + // Request to set the current top of bss. src.setBrk(brk); } + src.setSysCallReturn(src.getBrk()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |