C++ memory writing without API - multithreading

How do I enable my program to read/write another process's memory in C++ without using anything like Windows.h?
I'm running on visual studio in windows 10.
Thanks.

The simple answer is that you can't. Process memory management is inherently OS specific so you need to work with the OS.

Related

How to simulate ThreadX application on Windows OS

I have an application using ThreadX 5.1 as the kernel.
The Image is flashed on to a hardware running an ARM 9 processor.
I'm trying to build a Simulator for the application that can be run on Windows (say XP, 32-bit).
Is there any way I can make it run on Windows, without modifying the entire source code to start calling win32 system calls?
You can build a Simulator for the application that can be run on Windows with "ThreadX for Win32".
"ThreadX for Win32"'s specification is hear.
http://rtos.com/products/threadx/Win32
Yes you can if you are willing to put in the work.
First observe that each threadx system call has an equivalent posix call except for events.
So your threadx program can run as a single process using posix threads, mutexes, etc.
Events can be handled by an external library (there are a few out there).
If you find this difficult in windows then the simplest thing to do is set up a linux vm. I use an ubuntu vm running on Virtual Box. It is very easy to set up. All you will need is the cdt version of eclipse.
Next you need to stub out all of your low level system calls.
This is also easier than you might think. For example, if you have a SPI driver to read and write to flash, you can replace your flash with a big array which is quite easy to work with at this level.
Having said all this, you may get more mileage if your threadx application is modular. Then you can test each module on it's own and you don't need to mess with threads, etc.
As a first approximation this may give you what you need without going the distance to port the whole thing to run under posix.
I have done this successfully in the past and developed a full set of unit tests for a module that allowed me to develop and test it (on my mac) before going to the target. Development is much faster and reliable this way.
Another option you may want to consider is to find a qemu project that supports your microprocessor. With some work you can develop a complete simulator for your platform and then run the real firmware under the emulator.
Good luck.

Native windows Linux

I know about several projects for cross compiling between linux and Windows.
The Wine project is great for running windows application inside Linux.
andLinux is a linux running inside Windows.
My question is, can we compile a complete linux OS with a Windows compiler (like mingw32, visual studio , ...) in order to get a linux system which is fully compatible with the Windows PE executable format ?
As wine demonstrates, the PE format isn't really the problem with compatibility.
PE only defines how the program is pieced together at load time. Under windows, RUNDLL interprets it, loads all the program sections to memory, loads all the supporting dlls to memory and patches up the function pointers so that there is a program sitting in memory ready to go. (See http://msdn.microsoft.com/en-us/library/ms809762.aspx for more details. Its a good read!)
There is little stopping you writing a kernel module to do all of this. With the details in the page linked above it may not be to hard and someone may already have done it.
The real issue is the fundamentals of the operating system. Even if linux could load a PE, there would be problems around the fundamental difference in file names (\ or /) as well as the permissions model which is different and the windows registry which doesn't exist under linux. That's before you get into the different windowing model for GUIs.
Therefore the task of getting a windows program to run under linux is less about the program loader and much more about emulating all of the windows DLLs under Linux. As i understand it, this is the main heart of wine.

Qt Symbian Memory, unexpected application termination on device

Recently I did develop a Symbian application. In Qt simulator it works perfect but in actual device the application terminates unexpectedly. I suspect this is a memory leak issue.
Already i have followed all possible(following) memory cleaning mechanisms:
Creating new objects as pointers.
deleting the objects after use
using 'delete' keyword. using deleteLater() function on ui objects.
But still the application terminates on the device.
please suggest me possible solutions for this.
You can try increasing the Heap and/or Stack sizes using the EPOCHEAPSIZE and EPOCSTACKSIZE statements in your .PRO file
http://qt-project.org/doc/qt-4.8/qmake-platform-notes.html#stack-and-heap-size
Although it may depend on which Qt SDK you are using as the documentation now states that the Qt toolchain already sets these to the maximum possible values.

how to get correct physical memory and virtual memory

I use this windows API,
http://msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx
GlobalMemoryStatusEx to get memory information
my computer total physcial memory is 4096MB ,why the program shows 3.XG
My computer's virtual memory is 3063MB ,but i use program which show 2047MB
my develop enviroment is visual studio 2008
how to modify this problem
thanks
Aren't other programs using your system as well? I suspect the memory you're "missing" is due to the OS itself and whatever other programs you're running. See if having a bunch of other applications open changes the virtual memory size that your program is able to see.
Assuming you are running a 32bit version of windows, then this is a limit of windows itself. See this Microsoft page for the details. By default you will only be able to access 2GB of RAM in a single process. There is a compiler switch in visual studio which will give you access to 3GB. This is the /LARGEADDRESSAWARE switch. Beyond that you just need to upgrade to a 64bit operating system.
By the way, the basic reason why you don't automatically get 4GB of address space is because part of it is reserved for the operating system. Those system calls and references to operating system resources have to live somewhere.

How well does Valgrind handle threads and machine-level synchronization instructions?

I have a highly parallel Windows program that uses lots of threads, hand-coded machine synchronization instructions, and home-rolled parallel-safe storage allocators. Alas, the
storage management has a hole (not a synchonization hole in the allocators,
I'm pretty sure) and I'd like to find it.
Valgrind has been suggested as a good tool for finding storage management errors.
Any experience here with Valgrind used under these circumstances?
Valgrind does not run on Windows, but it does work with Windows programs running under Wine on Linux. If your program will run under Wine, it has a decent chance of working with valgrind. See winehq.org for details.
The latest version is pretty good at handling all the 32-bit x86 instructions. It can handle programs that create many threads, just don't expect them to run simultaneously under valgrind. It will run only one thread at a time, as if it was run on a single core machine.

Resources