linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Somw questions [ MAYBE OFFTOPIC ]
@ 1999-04-01  9:16 Amol Mohite
  1999-04-02  9:35 ` ralf
  0 siblings, 1 reply; 6+ messages in thread
From: Amol Mohite @ 1999-04-01  9:16 UTC (permalink / raw)
  To: linux-mm

Hi!

These might be newbie like qs., but I would really appreciate it if anyone
could answer them.

1) How does the processor notify the OS of a pagefault ? or a null pointer
exception ?
 Now null pointer exception I know, is done using the expand down
attribute in descriptor. However, when the processor gp faults, how does
it know it is a null pointer exception ?

Where does it store the program counter ?

2) How are the following exceptions handled ;
	TLB Refill
	TLB Invalid
	TLB Modify ?

3) How does the processor differentiate between entries (PTE) in the TLB
belonging to different processes ? Is it a bit in this ?

4) Why is the vm_area_structs maintained as a circular list, AVL tree and
as a doubly linked list ?
	Why an AVL tree ? Any specific reason ?

5) What is the difference between SIGSEGV and a SIGBUS ? 

6) How does the processor signal memory access inan illegal way (i.e.
trying write access to memory when this is not allowed )

7) How does linux handle malloc function ?


I would really appreciate it if anyone could answer these.

Please cc any answers to me as I am not on this list.

Thanks a lot.



--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Somw questions [ MAYBE OFFTOPIC ]
  1999-04-01  9:16 Somw questions [ MAYBE OFFTOPIC ] Amol Mohite
@ 1999-04-02  9:35 ` ralf
  1999-04-02 18:56   ` Chris Atenasio
  1999-04-05  9:12   ` Amol Mohite
  0 siblings, 2 replies; 6+ messages in thread
From: ralf @ 1999-04-02  9:35 UTC (permalink / raw)
  To: Amol Mohite, linux-mm

On Thu, Apr 01, 1999 at 04:16:51AM -0500, Amol Mohite wrote:

> 1) How does the processor notify the OS of a pagefault ? or a null pointer
> exception ?
> Now null pointer exception I know, is done using the expand down
> attribute in descriptor. However, when the processor gp faults, how does
> it know it is a null pointer exception ?

A NULL pointer is just yet another invalid address.  There is no special
test for a NULL pointer.  Most probably for example (char *)0x12345678 will
be invalid as a pointer as well and treated the same.  The CPU detects this
when the TLB doesn't have a translation valid for the access being attempted.

> Where does it store the program counter ?

On the stack.

> 2) How are the following exceptions handled ;
> 	TLB Refill
> 	TLB Invalid
> 	TLB Modify ?

Not all architectures do provide these exceptions at all.  MIPS for
example does:

 - TLB Refill will just reload the entry from the page table into the TLB.
 - TLB Invalid checks if reading is allowed, then marks the entry in the
   page tables and TLB accessed.  If the access is not allowed the
   do_page_fault() is being called to do whatever is necessary.
 - TLB Invalid checks if writing is allowed, then marks the entry in the
   page tables and TLB accessed/dirty.  If the access is not allowed the
   do_page_fault() is being called to do whatever is necessary.

Some architectures like m68k or Intel do most of this in hardware.

> 3) How does the processor differentiate between entries (PTE) in the TLB
> belonging to different processes ? Is it a bit in this ?

Again that's architecture specific.  The simplemost way to deal with this
problem is to just flush the entire TLB on context switch.  More advanced
TLB architectures additionally can tag each TLB entry with an Address Space
ID (ASID) or Process ID (PID).  A search in the TLB only hits if the current
process has the same ASID/PID as the searched TLB entry.  Using this
architectural feature the number of TLB flushes can be greatly reduced.

> 4) Why is the vm_area_structs maintained as a circular list, AVL tree and
> as a doubly linked list ?
> Why an AVL tree ? Any specific reason ?

Certain applications like debugging with Electric Fence result in a large
number of exceptions that is searches in the vm_area_structs.  Not using
efficient data structures results in a dramatic slowdown of these.  It
makes little difference for the average case.

The list structures are also available since for certain cases the kernel
has to iterate through all the VMAs.

> 5) What is the difference between SIGSEGV and a SIGBUS ? 

SIGSEGV is being sent for accesses to memory using bad addresses, that is
for example where nothing has been mapped.  SIGBUS is for cases like
using an address outside of the allowable address range, that is for
example kernel addresses, when the hardware signals trouble with a physical
address, there is no more physical memory available to handle a fault or
similar.

> 6) How does the processor signal memory access inan illegal way (i.e.
> trying write access to memory when this is not allowed )

See above.

> 7) How does linux handle malloc function ?

Not at all.  Malloc(3) is part of libc.  It's implemented using brk(2)
and mmap(2) of /dev/zero.

  Ralf
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Somw questions [ MAYBE OFFTOPIC ]
  1999-04-02  9:35 ` ralf
@ 1999-04-02 18:56   ` Chris Atenasio
  1999-04-05  9:12   ` Amol Mohite
  1 sibling, 0 replies; 6+ messages in thread
From: Chris Atenasio @ 1999-04-02 18:56 UTC (permalink / raw)
  To: Amol Mohite; +Cc: ralf, linux-mm

> A NULL pointer is just yet another invalid address.  There is no special
> test for a NULL pointer.  Most probably for example (char *)0x12345678 will
> be invalid as a pointer as well and treated the same.  The CPU detects this
> when the TLB doesn't have a translation valid for the access being attempted.

Which is why you can do -=*fun*=- things such as:

fd = open("/dev/kmem", O_RDWR);
mmap(0,64000,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_FIXED,fd,0xB8000);

:)   ^                                       ^^^^^^^^^

- Chris
-----------------------------------------------------------------------------
Chris Atenasio <chrisa@ultranet.com> - Friends don't let friends use Windows.
Send mail with subject "send pgp key" or "word of the day" for auto-response.
Today's word of the day: masculinity

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Somw questions [ MAYBE OFFTOPIC ]
  1999-04-02  9:35 ` ralf
  1999-04-02 18:56   ` Chris Atenasio
@ 1999-04-05  9:12   ` Amol Mohite
  1999-04-06 10:55     ` ralf
  1999-04-06 22:51     ` Stephen C. Tweedie
  1 sibling, 2 replies; 6+ messages in thread
From: Amol Mohite @ 1999-04-05  9:12 UTC (permalink / raw)
  To: ralf; +Cc: linux-mm

> A NULL pointer is just yet another invalid address.  There is no special
> test for a NULL pointer.  Most probably for example (char *)0x12345678 will
> be invalid as a pointer as well and treated the same.  The CPU detects this
> when the TLB doesn't have a translation valid for the access being attempted.
> 


Yes but how does it know it is a null pointer ?

On that note, when c does not allow u to dereference a void pointer , is
this compiler  doing the trick ?

Ok , about the expand down attribute, thats how 32 bit windows does it, so
i was wondering if linux also does the same.

16 bit windows accesses a null pointer with a 0: descriptor.

Apparently intel allows u to load a 0 but not dererence it.



--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Somw questions [ MAYBE OFFTOPIC ]
  1999-04-05  9:12   ` Amol Mohite
@ 1999-04-06 10:55     ` ralf
  1999-04-06 22:51     ` Stephen C. Tweedie
  1 sibling, 0 replies; 6+ messages in thread
From: ralf @ 1999-04-06 10:55 UTC (permalink / raw)
  To: Amol Mohite; +Cc: linux-mm

On Mon, Apr 05, 1999 at 05:12:50AM -0400, Amol Mohite wrote:

> > A NULL pointer is just yet another invalid address.  There is no special
> > test for a NULL pointer.  Most probably for example (char *)0x12345678
> > will be invalid as a pointer as well and treated the same.  The CPU
> > detects this when the TLB doesn't have a translation valid for the
> > access being attempted.
> 
> Yes but how does it know it is a null pointer ?

Again, it doesn't know that it is a *NULL* pointer.  The kernel just knows
that a user program resulted in the CPU throwing an exception for attempting
an illegal access, that is insufficient permissions for the mapping or
no mapping for the address at all.

> On that note, when c does not allow u to dereference a void pointer , is
> this compiler doing the trick ?

Only ANSI/ISO C doesn't allow to dereference void pointers, GCC allows this
as an extension of the language.  Most machines only have untyped pointers,
for them void * or not would only a difference to the compiler, not the
machine - if the compiler allows it.

> Ok , about the expand down attribute, thats how 32 bit windows does it, so
> i was wondering if linux also does the same.
> 
> 16 bit windows accesses a null pointer with a 0: descriptor.
> 
> Apparently intel allows u to load a 0 but not dererence it.

  Ralf
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Somw questions [ MAYBE OFFTOPIC ]
  1999-04-05  9:12   ` Amol Mohite
  1999-04-06 10:55     ` ralf
@ 1999-04-06 22:51     ` Stephen C. Tweedie
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen C. Tweedie @ 1999-04-06 22:51 UTC (permalink / raw)
  To: Amol Mohite; +Cc: ralf, linux-mm

Hi,

On Mon, 5 Apr 1999 05:12:50 -0400 (EDT), Amol Mohite
<amol@m-net.arbornet.org> said:

>> A NULL pointer is just yet another invalid address.  There is no
>> special test for a NULL pointer.  Most probably for example (char
>> *)0x12345678 will be invalid as a pointer as well and treated the
>> same.  The CPU detects this when the TLB doesn't have a translation
>> valid for the access being attempted.

> Yes but how does it know it is a null pointer ?

It doesn't.  It just looks up the current VM page tables and looks for
the mapping for that page.  If there isn't such a mapping, it just
invokes a page fault handler in the O/S.

It is then up to the kernel to decide whether the pointer was just a
page which is swapped out, or a real invalid pointer.  If the kernel has
a mapping installed for that address, then it can install a valid page
in the process's address space and, if necessary, read the appropriate
page of disk to initialise it (for mmap or swap).  Otherwise, it just
generates a SEGV signal.

> On that note, when c does not allow u to dereference a void pointer , is
> this compiler  doing the trick ?

It is undefined in C.  Dereferencing a null pointer might return zero,
might return garbage or might generate a SEGV; the language doesn't do
anything special about it.  It is all up to the operating system.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-04-06 22:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-01  9:16 Somw questions [ MAYBE OFFTOPIC ] Amol Mohite
1999-04-02  9:35 ` ralf
1999-04-02 18:56   ` Chris Atenasio
1999-04-05  9:12   ` Amol Mohite
1999-04-06 10:55     ` ralf
1999-04-06 22:51     ` Stephen C. Tweedie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox