473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to set memory properties

Some APIs/SDKs are available to modify settings like "readable",
"writeable" or "executeable".
Examples:
-
http://msdn.microsoft.com/library/en..._constants.asp
- http://www.opengroup.org/onlinepubs/.../mprotect.html
- http://en.wikipedia.org/wiki/PaX

Would a companion function fit to the "realloc" programming interface
to
change such properties?
Is the management of such flags a part of the standard C library
already?
http://en.wikipedia.org/wiki/Malloc

I imagine to implement memory areas that are updated to be "read-only"
after an initial assignment.

Regards,
Markus

Nov 15 '05 #1
10 2070
Ma************@web.de wrote:
Some APIs/SDKs are available to modify settings like "readable",
"writeable" or "executeable".
Examples:
-
http://msdn.microsoft.com/library/en..._constants.asp
- http://www.opengroup.org/onlinepubs/.../mprotect.html
- http://en.wikipedia.org/wiki/PaX

Would a companion function fit to the "realloc" programming interface
to
change such properties?
A design might be worked out.
Is the management of such flags a part of the standard C library
already?
http://en.wikipedia.org/wiki/Malloc
No. The Standard recognizes the possibility that some
memory may be read-only, but does not require the capability
and provides no way to control it. Fancier attributes like
"okay to forget the content" or "likely to be used sequentially"
are not even dreamt of; they fall under the general heading of
platform-specific optimizations.
I imagine to implement memory areas that are updated to be "read-only"
after an initial assignment.


Most actual implementations handle attributes at a "memory
page" level, which could make it difficult to apply arbitrary
attributes to already-acquired memory: what if they conflict
with the attributes of other regions already allocated from the
same page? I think you'd need either a "copy this data somewhere
else and give it these attributes" interface, or else an "allocate
some memory whose attributes I can later change without blowing
up the Universe" sort of thing. The latter might be preferable
if you contemplate an "executable" attribute and cannot generate
position-independent code.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #2
In article <11**********************@g49g2000cwa.googlegroups .com>,
<Ma************@web.de> wrote:
:Some APIs/SDKs are available to modify settings like "readable",
:"writeable" or "executeable".

:Is the management of such flags a part of the standard C library
:already?

No.

:I imagine to implement memory areas that are updated to be "read-only"
:after an initial assignment.

I seem to recall hearing of such a property in C++, but not in
C -- at least not in C89. The 'const' attribute in C is handled at
the compiler level, not the OS level.

Generally speaking, the C standard disavows all knowledge of the
OS facilities beyond the existance of the narrowly-defined
file I/O operators. C does not require that memory protection
exists on the system at all.
--
Would you buy a used bit from this man??
Nov 15 '05 #3
> > Is the management of such flags a part of the standard
C library already?
http://en.wikipedia.org/wiki/Malloc


No. The Standard recognizes the possibility that some
memory may be read-only, but does not require the capability
and provides no way to control it. Fancier attributes like
"okay to forget the content" or "likely to be used sequentially"
are not even dreamt of; they fall under the general heading of
platform-specific optimizations.


Are there any chances that this kind of functionality can be added to
the standard API?

Regards,
Markus

Nov 15 '05 #4
In article <11*********************@g14g2000cwa.googlegroups. com>,
<Ma************@web.de> wrote:
> Is the management of such flags a part of the standard
> C library already?
No. The Standard recognizes the possibility that some
memory may be read-only, but does not require the capability
and provides no way to control it.
Are there any chances that this kind of functionality can be added to
the standard API?


Certainly. If you would like to see such functionality in the standard
API, all you have to do is help a large number of people "reclaim" or
"invest" their millions of dollars, then take the resulting funds and
bribe every single member of the ANSI committees who has voting rights
on the proposition.

Other than that... well, unless through corruption or business politics,
it seems more than a little unlikely to happen any time soon.
ANSI/ISO usually take fair efforts to avoid locking in any behaviour
that is not readily implemented on most machines, including those
that do not HAVE any kinds of memory protection or virtual memory.

Maybe somewhere around C57 (approved in 2059, widely available about
2072).
--
Entropy is the logarithm of probability -- Boltzmann
Nov 15 '05 #5


Ma************@web.de wrote:
Is the management of such flags a part of the standard
C library already?
http://en.wikipedia.org/wiki/Malloc


No. The Standard recognizes the possibility that some
memory may be read-only, but does not require the capability
and provides no way to control it. Fancier attributes like
"okay to forget the content" or "likely to be used sequentially"
are not even dreamt of; they fall under the general heading of
platform-specific optimizations.

Are there any chances that this kind of functionality can be added to
the standard API?


The question might be better suited to comp.std.c than
to this newsgroup.

The committee that writes and revises the Standard seems
to look more favorably on "prior art" than on paper arguments
about a feature's usefulness. That is, a real implementation
seems to carry more weight than an "I'd like" plea, especially
if you can get lots of people to use the implementation and
tell the committee how much they like it.

--
Er*********@sun.com

Nov 15 '05 #6
>> > Is the management of such flags a part of the standard
> C library already?
> http://en.wikipedia.org/wiki/Malloc


No. The Standard recognizes the possibility that some
memory may be read-only, but does not require the capability
and provides no way to control it. Fancier attributes like
"okay to forget the content" or "likely to be used sequentially"
are not even dreamt of; they fall under the general heading of
platform-specific optimizations.


Are there any chances that this kind of functionality can be added to
the standard API?


About the only way to make this kind of functionality *USABLE* is to
provide a method of allocating memory which does not share a memory
page with any other allocated memory, where "memory page" is defined
as the minimum granularity for which attributes like "writable" and
"executable" can act. For i386 architecture, that is 4K bytes (or
sometimes 4M bytes) at the hardware level. Otherwise, when you
change the attributes of one piece of memory, you may alter the
attributes of others unexpectedly, and that makes use of the features
so unpredictable that they are useless.

Another possible approach would be to define "pools" of memory.
Any memory in a "pool" has the same attributes as other memory in
the same "pool", so you change the attributes of everything in a
pool all at once. Internally, no pool would share memory pages
with another pool. Then you allocate memory out of specific pools
with a new function like malloc() that takes a pool as a second
argument. This is perhaps not quite so wasteful as putting every
allocation in its own page.

Gordon L. Burditt
Nov 15 '05 #7
Eric Sosman wrote:
.... snip ...
The committee that writes and revises the Standard seems
to look more favorably on "prior art" than on paper arguments
about a feature's usefulness. That is, a real implementation
seems to carry more weight than an "I'd like" plea, especially
if you can get lots of people to use the implementation and
tell the committee how much they like it.


Which I consider to be right and proper. Without it the standards
would have all the ephermeral solidity of Microsoft systems, or
long term damage would be done similar to what Borland did to
Pascal. If anything they have gone too far in kowtowing to "I'd
like" and the result is features that are hard to implement and
integrate into the existing systems.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #8
Ma************@web.de wrote:
# Some APIs/SDKs are available to modify settings like "readable",
# "writeable" or "executeable".

Those kinds of things are usually apply to an entire memory page.

# Would a companion function fit to the "realloc" programming interface

malloc et al are not required to be page oriented. (Some are internally
page oriented, but that is not exposed across the interface.)

You can make a new kind of allocator that is page boundary aware,
but I think trying to shoehorn it into the realloc interface would
seem more trouble than it would be worth.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
There are subtler ways of badgering a witness.
Nov 15 '05 #9
CBFalconer wrote:
Eric Sosman wrote:

... snip ...
The committee that writes and revises the Standard seems
to look more favorably on "prior art" than on paper arguments
about a feature's usefulness. That is, a real implementation
seems to carry more weight than an "I'd like" plea, especially
if you can get lots of people to use the implementation and
tell the committee how much they like it.

Which I consider to be right and proper. Without it the standards
would have all the ephermeral solidity of Microsoft systems, or
long term damage would be done similar to what Borland did to
Pascal. If anything they have gone too far in kowtowing to "I'd
like" and the result is features that are hard to implement and
integrate into the existing systems.


Aha! I see you've experienced PL/I ;-)

--
Eric Sosman
es*****@acm-dot-org.invalid

Nov 15 '05 #10
On Thu, 14 Jul 2005 14:29:35 +0000 (UTC), ro******@ibd.nrc-cnrc.gc.ca
(Walter Roberson) wrote:
In article <11**********************@g49g2000cwa.googlegroups .com>,
<Ma************@web.de> wrote: <snip> :I imagine to implement memory areas that are updated to be "read-only"
:after an initial assignment.

I seem to recall hearing of such a property in C++, but not in
C -- at least not in C89. The 'const' attribute in C is handled at
the compiler level, not the OS level.
No more in C++ than C. There are two other things you (or anyone else)
might have confused with this:

In C++ as in C you have const-qualified objects, and members of a
struct (in C++ also class), which can be initialized in the defining
declaration (of an instance) but not assigned to thereafter. If a
struct or class instance is const this means you can't assign to it or
to any member of it -- const 'distributes'. In C++ you can declare a
member 'mutable' which means that it can be assigned even in an
instance that is const or is 'promoted' to const; this is intended to
be used for 'hidden' (at least protected) data which is used within
the class's methods but does not affect the OO-ish state, such as
memoization/cache, hidden resources, debugging, etc.

C++ allows definitions of class instances (const or not) to specify
initial values that imply running a (particular) constructor rather
than just storing a value or list of values. This includes
static-duration objects, which in C (and in C++ for C-like 'POD'
types) can be and normally are 'initialized' at compile/link time. To
allow this C++ breaks initialization of statics into two pieces --
'static initialization' which has the same capabilities as C (zeros,
fixed values, addresses of other static objects) and is normally done
in the executable file, and 'dynamic initialization' which can be and
usually is done by running the constructor at runtime, after process
startup but before the object is used. An implementation thus _might_
reasonably put const-qualified static objects in a memory area that is
writable while it does the dynamic initialization and is then made
unwritable. (But I don't know of any that actually do.)
Generally speaking, the C standard disavows all knowledge of the
OS facilities beyond the existance of the narrowly-defined
file I/O operators. C does not require that memory protection
exists on the system at all.


And optionally ability to execute commands (of some sort); and real
(wall) and CPU clocks. And (things that might map to) signals.

And in C99 with optional 60559, certain controls and inquiries on FPU
settings, which might involve OS or might just go to hardware.

- David.Thompson1 at worldnet.att.net
Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Piscopo | last post by:
Memory leak and .NET -- like oil and water :- I've written a distributed system for parallel processing of large tasks. Each machine has an agent on it that sends processor usage information back...
0
by: Bill Burwell | last post by:
Which memory properties, or what combinations of memory properties, provide useful information about a program's memory usage when that program has just started leaking memory? While I have...
9
by: Jimmy Cerra | last post by:
I am a little confused how the memory for objects is allocated in JavaScript. David Flanagan, in "JavaScript: The Definitive Guide," states that each property of a class takes up memory space when...
5
by: Ron Mexico | last post by:
I have written a graphing engine (very similar to what BigCharts.com offers). Basically, it's an ASPX page that accepts parameters and calls back-end business objects (dlls) to create a graph. ...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
2
by: Peter Hartlén | last post by:
Hi! The basic questions here is how an object is stored in memory. I have an list of a custom object, where the object has a couple of fields, properties and methods. If we pretend that he...
0
by: jeffrijo | last post by:
One of my SQL Server is confiured as follow: IBM Hardware 16 proc and 32GB of memory OS = Windows 2003 Data Center Ed /pae switch enabled SQL Server 2000 EE with AWE enabled Max SQL Server...
3
by: =?Utf-8?B?VG9tKys7?= | last post by:
When I create an object in VB.NET I define both properties (data) and methods (code). If I have 1,000 instances of this object stored in a Dictionary as Dictionary(of int32, object) then I am...
1
by: Jonathan Wilson | last post by:
I have a closed source app. I have a .dll plugin for this app (which I am writing). This plugin contains a bug somewhere which seems to clobber memory in a "random" fashion (as in, its not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.