Re: Attempting to port and app to linux but can't find an equivalent system call

From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 15:23:24 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve wrote:

> Hello I am trying to port a windows app I have written to linux, and
> cannot find anything in linux remotely like the following...
>
> FlushInstructionCache(GetCurrentProcess(),(LPCVOID)Address, Length);
> VirtualProtectEx(GetCurrentProcess(), (LPVOID)Address,
> Length,PAGE_EXECUTE_READWRITE, &oldperm);
> WriteProcessMemory(
> GetCurrentProcess(),
> (LPVOID)Address,
> (LPVOID)NewData,
> Length,
> NULL);
> VirtualProtectEx(GetCurrentProcess(), (LPVOID)Address, Length,
> oldperm, &tmp);
[snip]
> I think the main sticking point that I cannot seem to track down
> anywhere, is how on earth do I modify the memory in one program, using
> another.
[snip]

An Operating system that permits one process to modify another process' memory
in an uncontrolled, unaudited, unmanaged manner is a dangerous and insecure
operating system.

Linux, like it's Unix forefathers, does not permit such uncontrolled access.
There /are/ mechanisms that permit one Linux app to modify another's memory, but
they all require some amount of system-administrative permissions.

You can use the strace() syscall, so long as the process that applies the
modification through strace() is the parent process to the process being modified.

Or, if your modifying process has root permissions, it can open one of the
/dev/*mem or /proc/*/ files and write it's modifications.

Or, if both processes are "co-operative", they can use shared memory to permit
one process to modify memory used by the other process.

In your case, the strace() syscalls are probably the best bet.

- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAhCcqagVFX4UWr64RAgxwAKDFmmuEXhvREyByHzdr6cs4qjr4DwCghS6C
FA7hmcE1nOLqTfp+fDtEPwo=
=KBG4
-----END PGP SIGNATURE-----