From: <mic...@us...> - 2007-04-28 16:18:58
|
Revision: 96 http://svn.sourceforge.net/pearcolator/?rev=96&view=rev Author: michael_baer Date: 2007-04-28 09:18:58 -0700 (Sat, 28 Apr 2007) Log Message: ----------- - Moved setBrk() / getBrk() to LinuxSystemCalls Modified Paths: -------------- src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java src/org/binarytranslator/arch/arm/os/process/linux/abi/EABI.java src/org/binarytranslator/arch/arm/os/process/linux/abi/Legacy.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java Modified: src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-04-28 16:18:58 UTC (rev 96) @@ -1,6 +1,5 @@ package org.binarytranslator.arch.arm.os.process.linux; -import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.arm.os.abi.linux.ARM_LinuxSystemCalls; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.arm.os.process.ARM_Registers; @@ -10,7 +9,6 @@ import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; import org.binarytranslator.generic.os.loader.Loader; -import org.binarytranslator.generic.os.loader.elf.ELF_Loader; public class ARM_LinuxProcessSpace extends ARM_ProcessSpace { @@ -33,7 +31,7 @@ private int[] auxVector; public ARM_LinuxProcessSpace() { - sysCallGenerator = new Legacy(this, 0xEBADADD); + sysCallGenerator = new Legacy(this); sysCalls = new ARM_LinuxSystemCalls(this, sysCallGenerator); } @@ -49,7 +47,7 @@ @Override public void initialise(Loader loader, int pc, int brk) { registers.set(ARM_Registers.PC, pc); - sysCallGenerator.setBrk(brk); + sysCalls.initialize(brk); // initialize the stack auxVector = new int[] { Modified: src/org/binarytranslator/arch/arm/os/process/linux/abi/EABI.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/abi/EABI.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/arch/arm/os/process/linux/abi/EABI.java 2007-04-28 16:18:58 UTC (rev 96) @@ -1,7 +1,6 @@ package org.binarytranslator.arch.arm.os.process.linux.abi; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; -import org.binarytranslator.generic.memory.MemoryMapException; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.process.ProcessSpace; @@ -29,18 +28,12 @@ /** The process space that we're running on. */ private final ARM_LinuxProcessSpace ps; private final ArgumentIterator args; - private int brk; - public EABI(ARM_LinuxProcessSpace ps, int brk) { + public EABI(ARM_LinuxProcessSpace ps) { this.ps = ps; - this.brk = brk; this.args = new ArgumentIterator(); } - public int getBrk() { - return brk; - } - public ProcessSpace getProcessSpace() { return ps; } @@ -54,19 +47,6 @@ return ps.registers.get(7); } - public void setBrk(int address) { - - try { - ps.memory.ensureMapped(brk, address); - } catch (MemoryMapException e) { - throw new Error(String.format( - "Error changing top of BSS from 0x%x to address 0x%x", brk, address), - e); - } - - brk = address; - } - public void setSysCallError(int r) { ps.registers.set(0, -r); } Modified: src/org/binarytranslator/arch/arm/os/process/linux/abi/Legacy.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/abi/Legacy.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/arch/arm/os/process/linux/abi/Legacy.java 2007-04-28 16:18:58 UTC (rev 96) @@ -4,7 +4,6 @@ import org.binarytranslator.arch.arm.decoder.ARM_InstructionDecoder; import org.binarytranslator.arch.arm.decoder.ARM_Instructions; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; -import org.binarytranslator.generic.memory.MemoryMapException; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.process.ProcessSpace; @@ -32,30 +31,11 @@ * system call */ private final ArgumentIterator syscallArgs; - private int brk; - - - public Legacy(ARM_LinuxProcessSpace ps, int brk) { + public Legacy(ARM_LinuxProcessSpace ps) { this.ps = ps; - this.brk = brk; syscallArgs = new ArgumentIterator(); } - public int getBrk() { - return brk; - } - - public void setBrk(int address) { - try { - ps.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; - } - public ProcessSpace getProcessSpace() { return ps; } Modified: src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-28 16:18:58 UTC (rev 96) @@ -40,11 +40,6 @@ final PPC_LinuxSyscallArgumentIterator syscallArgs; /** - * The top of the bss segment - */ - private int brk; - - /** * The top of the stack */ private static final int STACK_TOP = 0x80000000; @@ -74,8 +69,8 @@ */ public void initialise(Loader loader, int pc, int brk) { this.pc = pc; - this.brk = brk; this.r1 = initialiseStack(loader, pc); + syscalls.initialize(brk); } /** @@ -178,27 +173,6 @@ setCR_bit(0, true); } - /** - * Get the top of the BSS segment (the heap that reside below the stack in - * memory) - * - * @return top of BSS segment - */ - public int getBrk() { - return brk; - } - - /** - * Set the top of the BSS segment (the heap that reside below the stack in - * memory) - * - * @param address - * new top of BSS segment - */ - public void setBrk(int address) { - brk = address; - } - public GdbTarget getGdbTarget() { return this; } 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-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-28 16:18:58 UTC (rev 96) @@ -40,11 +40,6 @@ private final X86_LinuxSyscallArgumentIterator syscallArgs; /** - * The top of the bss segment - */ - private int brk; - - /** * The top of the stack */ private static final int STACK_TOP = 0xC0000000; @@ -71,7 +66,7 @@ */ public void initialise(Loader loader, int pc, int brk) { registers.eip = pc; - this.brk = brk; + registers.writeGP32(X86_Registers.ESP, initialiseStack(loader, pc)); if (useSysInfoPage) { try { @@ -83,6 +78,8 @@ memory.store8(0xffffe400, 0x80); // 80h memory.store8(0xffffe400, 0xC3); // RET } + + syscalls.initialize(brk); } /** @@ -146,29 +143,6 @@ registers.writeGP32(X86_Registers.EAX, -r); } - /** - * Get the top of the BSS segment (the heap that reside below the - * stack in memory) - * @return top of BSS segment - */ - public int getBrk() { - return brk; - } - /** - * Set the top of the BSS segment (the heap that reside below the - * stack in memory) - * @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; - } - public void setStackPtr(int ptr) {} public int[] getAuxVector() { Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java 2007-04-28 16:18:58 UTC (rev 96) @@ -8,7 +8,6 @@ */ package org.binarytranslator.generic.os.abi.linux; -import org.binarytranslator.generic.memory.MemoryMapException; import org.binarytranslator.generic.os.process.ProcessSpace; /** @@ -52,27 +51,7 @@ * @param r the error value */ public void setSysCallError(int r); - /** - * Write to the memory of the system call generator a 32bit value - * @param address where to write - * @param data value to store - */ - - /** - * Returns the process space that this call originated from. - */ + + /** Returns the process space that this call originated from.*/ public ProcessSpace getProcessSpace(); - - /** - * Get the top of the BSS segment (the heap that reside below the - * stack in memory) - * @return top of BSS segment - */ - public int getBrk(); - /** - * Set the top of the BSS segment (the heap that reside below the - * stack in memory) - * @param address new top of BSS segment - */ - public void setBrk(int address); } Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-27 15:03:23 UTC (rev 95) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-28 16:18:58 UTC (rev 96) @@ -44,12 +44,15 @@ protected LinuxStructureFactory structures; /** List of currently opened files. */ - private OpenFileList openFiles; + protected OpenFileList openFiles; + + /** The top of the bss segment */ + protected int brk; /** * Maximum number of system calls */ - private static final int MAX_SYSCALLS = 294; + protected static final int MAX_SYSCALLS = 294; /** * Array to de-multiplex Linux system calls. NB we will have to @@ -89,7 +92,7 @@ * @param address where to read * @return the String read */ - private String memoryReadString(int address) { + protected String memoryReadString(int address) { Memory m = src.getProcessSpace().memory; StringBuffer str = new StringBuffer(); @@ -106,7 +109,7 @@ * @param address where to read * @param data the String to write */ - public void memoryWriteString(int address, String data) { + protected void memoryWriteString(int address, String data) { Memory m = src.getProcessSpace().memory; if (data != null) { @@ -117,6 +120,17 @@ m.store8(address + data.length(), (byte) 0); } } + + /** + * Sets up the linux operating space + * + * @param brk + * the initial value for the top of BSS + */ + public void initialize(int brk) { + LinuxSystemCalls.this.brk = brk; + src.getProcessSpace().memory.ensureMapped(brk, brk+1); + } /** * Constructor @@ -397,12 +411,14 @@ public class SysBrk extends SystemCall { public void doSysCall() { - int brk = arguments.nextInt(); - if (brk != 0) { + int newBrk = arguments.nextInt(); + if (newBrk != 0) { // Request to set the current top of bss. - src.setBrk(brk); + brk = newBrk; + src.getProcessSpace().memory.ensureMapped(brk, brk+1); } - src.setSysCallReturn(src.getBrk()); + + src.setSysCallReturn(brk); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |