Solved

Memory Error!! Pls help

Posted on 2004-10-01
3
449 Views
Last Modified: 2012-05-05
I have written a code like this in visaul c++ using a win32 API function in a WIN2000 Proffessional.

#include <windows.h>
#include <winbase.h>
void main()
{
     CopyMemory((LPVOID)0xffffffff,(void *)0x0000ffff,1);
}


i am getting an error The instruction at "0x00408410" referenced
memory at "0x0000ffff". The memory could not be "read".

I am gettinng the same error when i try to access a memory address of any hex value.
Wot could be the problem?


Thanks in advance!!,
 Abin.
0
Comment
Question by:Abin Thomas
  • 2
3 Comments
 
LVL 2

Expert Comment

by:demingj1
ID: 12201170
you are accessing memory not in user block for that program, you can't just copy memory from somewhere in RAM, it needs to be memory you have allocated in the program you are writing or a much more complex system of IPC communication.
0
 

Author Comment

by:Abin Thomas
ID: 12235485
dear demingj1,
  i m  plannming to develop a memory tester program,
  which can read and write to a given memory location.
  so could u help me out in giving ideas or urls?  
 
0
 
LVL 2

Accepted Solution

by:
demingj1 earned 50 total points
ID: 12238453
This seems a pretty good resource for general information regarding memory and memory management across various platforms and languages.  However, most of the information seems pretty general.

http://www.memorymanagement.org/

I think what you need to do however is run your app in as simple an envronment as possible.  By this I mean run it in DOS or a barebones *nix build.  OS's are a buffer between user programs and memory.  Although it is possible in C++ to map to specific addresses I believe those addresses are in terms of virtual memory and have no bearing on where the data actually lies in RAM.  

When you run your user program you recieve an allocated amount of memory for reading, writing and storing your programs instruction set.  It varies depending on the size and nature of your app, but it is all managed by the OS.  If you try to write (or read) from another programs memory space the OS catches that request, denies it, and terminates your program since it cannot continue after not being able to retrieve the data it needs to continue it's execution.  When you boot a DOS (or Windows 98 Boot Disk) for example, the autoexec.bat file begins calling all programs to set up your environment.  Some of these programs are UMB and/or XMS Memory management and other Memory Management apps, these apps perform the same function by ensuring that the OS's (DOS in this case) memory is protected and not overwritten otherwise even the standard commands like "dir" and "edit" could not guarentee thier integrity since part of their instruction set could be overwritten.

Perhaps I am rambling in error, perhaps what you meant by a memory tester program is a program to test what exact memory space is available test if you can write to certain addresses while inside the Windows OS.  In this case I still don't know how to get through the virtual memory layer, it is embedded pretty deeply into the OS, perhaps somewhere you can find an API or existing native class to access memory directly which also tells Windows Virtual Memory Management to reserve that block of RAM for your code and not write there.  If you found this software you would want to make calls to read/write to a certain block and intercept windows error flags which would be triggering the exception/failure/crash of your program and interpret those error flags appropriately (i.e. your call to CopyMemory((LPVOID)0xffffffff,(void *)0x0000ffff,1); above throws a flag "memory cannot be read") you need to intercept that flag/error before it gets to the OS and the OS terminates your program, if you can intercept the flag you can handle it appropriately inside your program and your program can continue execution.

Hope this helps a bit.

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now