Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.system > #582

Re: How to create a fixed address for a vaiable ??

From Lusotec <nomail@nomail.not>
Newsgroups comp.os.linux.development.system
Subject Re: How to create a fixed address for a vaiable ??
Followup-To comp.os.linux.development.system
Date 2014-01-21 10:57 +0000
Organization A noiseless patient Spider
Message-ID <lbljr6$3ol$1@dont-email.me> (permalink)
References <ecedda60-477b-4732-bca3-70310bd33792@googlegroups.com>

Followups directed to: comp.os.linux.development.system

Show all headers | View raw


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

hemanthvenkatappa@gmail.com wrote:
> Example : int a[30];
> 
> If i initialize as above in my c program. How to make that variable to
> have a fixed address. So that I can use the variable name and addresses in
> the A2l file. I am using QNX momentics IDE (QNX RTOS) and Eclipse ide (for
> Linux RTOS).
> 
> If I run the program multiple times then the address will be keep on
> changing.
> Could anyone tell me how to get a fixed address for the variable ??

I don't know why you would need/want this but here is how you can do it. 
Note that I'm assuming the address in question is for normal memory and not 
some device DMA or IO.

#include <sys/mman.h>

int main() {
void* const address = (void*)0x0000000010000000; //Example address
const size_t size = sizeof(int[30]);

void* mmap_address = mmap(address, size, PROT_READ | PROT_WRITE, MAP_PRIVATE 
| MAP_FIXED | MAP_ANONYMOUS, -1, 0);

if( mmap_address != address ) {
  return 1; // mmap failed
}

int* a = (int*)address;
a[0] = 0;
a[29] = 0;

return 0;
}

Regards.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iF4EAREIAAYFAlLeUqUACgkQGQjO2ccW76oEUQD5AY4ratFRZ2UDuUYLXslC8KSw
sRaagXoRSzzFdx8+kpgA/2kZht0uZvpeVmY3THBNyta9Mfn8u5VduipyV+sXEBuE
=TF/A
-----END PGP SIGNATURE-----

Back to comp.os.linux.development.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to create a fixed address for a vaiable ?? hemanthvenkatappa@gmail.com - 2014-01-20 16:23 -0800
  Re: How to create a fixed address for a vaiable ?? Lusotec <nomail@nomail.not> - 2014-01-21 10:57 +0000
  Re: How to create a fixed address for a vaiable ?? Tim Roberts <timr@probo.com> - 2014-01-21 22:26 -0800
    Re: How to create a fixed address for a vaiable ?? Hemanth Venkatappa <hemanthvenkatappa@gmail.com> - 2014-01-22 01:03 -0800
      Re: How to create a fixed address for a vaiable ?? Hemanth Venkatappa <hemanthvenkatappa@gmail.com> - 2014-01-22 01:05 -0800
        Re: How to create a fixed address for a vaiable ?? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-01-22 15:24 +0000
          Re: How to create a fixed address for a vaiable ?? Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2014-01-22 21:16 +0200
            Re: How to create a fixed address for a vaiable ?? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-01-22 20:04 +0000
              Re: How to create a fixed address for a vaiable ?? Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2014-01-22 22:47 +0200

csiph-web