Re: C and Low-level Storage (was: I need a new compiler...
- From: Richard <riplin@xxxxxxxxxxxx>
- Date: Thu, 18 Dec 2008 20:23:32 -0800 (PST)
On Dec 19, 4:35 pm, Paul <paul-nospamatall.rauler...@xxxxxxx> wrote:
On 2008-12-18 21:12:25 -0600, Richard <rip...@xxxxxxxxxxxx> said:
On Dec 19, 3:30 pm, Paul <paul-nospamatall.rauler...@xxxxxxx> wrote:
On 2008-12-18 13:03:40 -0600, Richard <rip...@xxxxxxxxxxxx> said:
On Dec 19, 5:26 am, PR <paul.rauler...@xxxxxxxxx> wrote:
On Dec 18, 12:46 am, Richard <rip...@xxxxxxxxxxxx> wrote:
:On Dec 18, 4:32 pm, Paul <paul-nospamatall.rauler...@xxxxxxx> wrote
On 2008-12-16 22:25:13 -0600, Richard <rip...@xxxxxxxxxxxx> said:
te:On Dec 17, 4:41 pm, Paul <paul-nospamatall.rauler...@xxxxxxx> wro
On 2008-12-16 17:02:31 -0600, "William M. Klein"
<wmkl...@xxxxxxxxxxxxxxxxxxxx> said:
<much debate snipped>
or a pMichael Wojick,
I can't tell. Have you been debating a "real-world" issue
hilosophical
one?
requirIn other words, are there existing implementations of C that (as
"geted)
support "pointers" but do NOT allow (or support) pointers that
the
program" to system-level storage?
at doI am NOT a C programmer, but when I have interacted with those th
e C pruse it,
it seems to me that all implementations that they use DO allow th
storaogram to
access (at least "read") data at "system controlled" (low-level?)
ge.
(or AIt is also true, that some "systems" do NOT allow the "average" C
hat isssembler
or whatever) program to MODIFY "system-controlled" storage, but t
a
different question (to me) than accessing such storage.
read"If there are C implementations that do not allow programmers to "
erestethe
storage where "system control blocks, etc" reside, I would be int
d in
which C and on what platforms these exist.
, thenIf you are just stating that the C Standard does not REQUIRE this
ions Dthat may
be "nice to know" - but is different from what actual implementat
O.
If I understand what you are saying Bill, you are asking if C the
language can access "system memory."
ssTechnically, C can access any address the machine can provide acce
to, including any system storage.
are,Practially speaking, the Operating System, and sometimes the hardw
protects some areas of memory. This is especially true in all our
modern systems like z/OS, Linux, z/VM, and even Windows, since
applications run in a designed application space.
ual*For example, on my zLinux systems, every application in the system
loads and run from address X'400000'. Of couse, that is a *virt
romaddress, which means there may be a thousand applcations running f
tsthe virtual address, but from 1000 different real addresses. It ge
n thecomplex, because sometimes text (code) sections are designated
read-only in memory, and only one copy of them is loaded. (This is
Linux,
drives z/OS programmers crazy because they cannot store variable i
le'scode section - at least if they ever intend to change those variab
values... :)
ofAnd then you get into shared memory segments. Take the same chunk
real memory, attach it to one or more applications - at different
virtual addresses.
Like I said, it gets complex. Fun though. :)
lAnother point to consider, most of Unix, including the kernel leve
emorycode (which by the way, usually *does* have access to every real m
Just aaddress, system and application....) is written in plain old C.
s ofcouple or three thousand lines of assembler, and the rest, million
lines of code, in C.
And how have you established that it is the C code (and not the
assembler) that "*does* have access to every real memory address",
fBecause I look at the assembler code that the C compiler generates o
0course.
The following code will generate an error, because memory address 10
is protected
by MacOS and UNIX.
#include <stdio.h>
int main(int argc, char *argv[]) {
char *aCharPointer;
char aCharVariable;
aCharPointer = 100;
aCharVariable = *aCharPointer;
}
No, it is not the 'operating system' that causes the error, it is the
hardware. Your code is not attempting to access real address 100, it
is only attempting to access an address within the virtual machine
created for your program. Given that Intel is little-endian the
pointer has some segment reference that does not exist within that
virtual machine.
On a Z80 or 8086 a pointer to 0:100 would actually access the real
address 100, but that was a 30 years ago.
dIn protected mode the machine is _not_ a Z80 or 8086. You cannot
simply set a pointer to an arbitrary value and expect it to access
some data. Pointers are segment:offset and the only valid segments
that you can use without the hardware dumping you are the ones allowe
in your virtual machine.
In Intel (or Wintel Parlance)
.text
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl $100, -16(%ebp)
movl -16(%ebp), %eax
movzbl (%eax), %eax
movb %al, -9(%ebp)
leave
ret
.subsections_via_symbols
Easier to see in mainframe GAS assembler I suppose:
.file "test.c"
.text
.align 4
.globl main
.type main, @function
main:
.LFB3:
stm %r11,%r15,44(%r15)
.LCFI0:
ahi %r15,-112
.LCFI1:
lr %r11,%r15
.LCFI2:
st %r2,96(%r11)
st %r3,100(%r11)
lhi %r1,100
st %r1,104(%r11)
l %r1,104(%r11)
mvc 108(1,%r11),0(%r1)
lhi %r1,0
lr %r2,%r1
lm %r11,%r15,156(%r11)
br %r14
SThe line I bolded above is the one that is doing "aCharVariable
*aCharPointer;"
A moments study will show that R1 has the value 100 in it, so in HLA
M,
it would
look like this:
LHI R1,100
LA R2,aCharVariable
MVI 0(R2),0(R1)
It is the same on Linux, VMS, AIX, MacOS, and so on, with varying
degrees of complexity.
By the way, MVI 0(R2),0(R1) is using indirect memory references; in
essence R1 and R2 are pointers.
ator
indeed that it is the C code that puts the machine into the mode th
allows access by real memory address, sans which it cannot be done.
oWhether the C code is *allowed* permission to access a particular
memory address or not has nothing to do with C, it has to do with
whether or not the Operating System will allow the running applicati
n
to do so.
No. Wrong. In protected mode it is the hardware that will prevent you
accessing arbitrary addresses. Even then these would be virtual
addresses and not the real address that you think you can get at.
Are you by some chance thinking that the hardware controls whether it
is in protected mode or not?
If so, then you need to go do some study. It is the OS that
determines what mode, and *what addressing
mode* is used.
Certainly the OS is in control of what goes on. In many cases it is
the hardware that will do address translation and checking
permissions.The exception may well be passed back to the OS to deal
with but the OS is not usually involved with examining every CPU
cycle. (In fact that would require CPU cycles to do so, which it would
have to examine, which ...)
If it quacks like a duck and it acts like a duck - it ain't no armidillo.
Are you saying that an OS can magically run without a CPU or the ancillary
chips that make up a computer?
I don't think that is what you mean of course, but that is the logical
equivalent
of what you are saying.
In what way is your nonsense 'equivalent' ? How do you derive this
from what I said ?
Your claim was that the OS will prevent access to specific addresses.
While the OS may well set up the address translation table it is the
hardware (CPU + MMU) that will actually prevent an illegal access.
The only nonsense here is what you are sprouting.
I claimed the OS will prevent access to specific addresses and it will. The
CPU and MMU did not just magically set themselves up, as you seem to be
claiming.
You think computers run without software or something?
When the program attempts to execute an instruction that accesses an
arbitrary address, say, address 100 then on a real mode machine the
access will occur, on a protected mode machine where this address is
not allowed then it is the hardware (eg CPU/MMU/..) that detects that
the access is invalid.
The OS is not looking at every memory access made by the program and
determining whether it is allowed or not, the hardware is.
While the OS does create the ADT which forms the basis of what is
_allowed_ it is the hardware that uses these to detect when an access
is _outside_ those allowed and will prevent this.
Of course we assume that an OS runs on a computer,e,
and uses the facilities of said computer, be it CPU, MMU, or whatever els
with some effect.
By the way, under Windows, that *does* access physical memory address
100. Applications are ran in a flat memory model, and an absolute
address, like the one I entered, actually does map to the same
physical address.
You are claiming that the address translation tables do not do
anything.
...
read more »
.
- References:
- I need a new compiler...
- From: Paul H
- Re: I need a new compiler...
- From:
- Re: I need a new compiler...
- From: Michael Wojcik
- Re: I need a new compiler...
- From:
- Re: I need a new compiler...
- From: Howard Brazee
- Re: I need a new compiler...
- From:
- Re: I need a new compiler...
- From: Michael Wojcik
- C and Low-level Storage (was: I need a new compiler...
- From: William M. Klein
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Paul
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Richard
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Paul
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Richard
- Re: C and Low-level Storage (was: I need a new compiler...
- From: PR
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Richard
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Paul
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Richard
- Re: C and Low-level Storage (was: I need a new compiler...
- From: Paul
- I need a new compiler...
- Prev by Date: Re: C and Low-level Storage
- Next by Date: Re: C and Low-level Storage
- Previous by thread: Re: C and Low-level Storage (was: I need a new compiler...
- Next by thread: Re: C and Low-level Storage (was: I need a new compiler...
- Index(es):
Relevant Pages
|