Linux-Development-Sys Digest #630, Volume #7     Sun, 27 Feb 00 02:13:13 EST

Contents:
  Re: complex math in a device driver (Grant Edwards)
  Re: Binary compatibility: what kind of crack are they smoking? (Mario Klebsch)
  How debug linux modules (Hernan)
  Re: Binary compatibility: what kind of crack are they smoking? (Anders Larsen)
  Detecting installed Harddrives (Benjamin Lippelt)
  Problem Booting Linux (GriffD2000)
  Re: pci driver example (Lee Webb)
  How does get_user()/put_user() work in kernel 2.2.x? (simba)
  Re: unable to open a file (Juergen Heinzl)
  Re: Linux or Windows ("Paul D. Smith")
  Re: booting a different system from within Linux ([EMAIL PROTECTED])
  Re: complex math in a device driver ("Norm Dresner")
  switch from protected mode to real mode in kernel ([EMAIL PROTECTED])
  Re: the init of wait queue? (Kaz Kylheku)
  Re: complex math in a device driver ([EMAIL PROTECTED])
  Re: the init of wait queue? (Linus Torvalds)
  Re: BUS ERROR WITH MMAP (Erik de Castro Lopo)
  Re: BUS ERROR WITH MMAP (Erik de Castro Lopo)

----------------------------------------------------------------------------

From: [EMAIL PROTECTED] (Grant Edwards)
Subject: Re: complex math in a device driver
Date: Sat, 26 Feb 2000 20:50:35 GMT

In article <89782j$[EMAIL PROTECTED]>, Oliver Bandel wrote:
>
>Dan Miller <[EMAIL PROTECTED]> wrote:
>> I need to access some math library function in my device driver.  I believe
>> I've read here that one cannot do that, and I don't actually see a way to do
>[...]
>
>Why should you use math in a device driver?

To provide a layer of abstraction.  For example, if I have a set of
analog inputs, and I make an IOCTL call to read the voltages, it's
awfully nice to get answers in volts.  That way the driver has to keep
track of the peculiarities of the hardware rather than the user
software.  Much like SCSI hides the whole cylinders, heads, sectors
stuff from the user program, it would be nice if device drivers could
hide the ugly details of A/D and D/A hardware from the user.

>Don't mix the different levels of software!

As things currently exist, you read an analog input value and you get
an integer.  You have no way of knowing what that integer actually
means unless the user-software has some a-priori knowledge about the
exact hardware (and it's current configuration).  Knowledge that should
be encapsulated within the driver.  Requiring user software to know
exactly what hardware it's talking to and how it's currently
configured violates the whole reason for having device drivers in the
first place.  An analogy: if user software had to know what Ethernet
controller, what phy chip, and what sort of baud rate and magnetics
were being used in order to open a TCP/IP connection, people would
scream bloody murder.  Not allowing analog I/O drivers to do floating
point places their users in that same situation.

I realize that doing floating point in drivers would complicate
things, but let's not pretend that there are no cases where it would
be appropriate.

The REAL answer to the question "why can't you do floating point in a
device driver?" is the same as most other "why doesn't Linux's X do Y?"
questions:

Because the people who designed X had no need to do Y.

If somebody really wants to do floating point in a device driver,
they'll hack the kernel to make it work.  Otherwise they just ramble
on about it like me.

-- 
Grant Edwards                   grante             Yow!  My LIBRARY CARD
                                  at               expired...
                               visi.com            

------------------------------

From: [EMAIL PROTECTED] (Mario Klebsch)
Crossposted-To: comp.os.linux.advocacy,comp.os.linux.setup
Subject: Re: Binary compatibility: what kind of crack are they smoking?
Date: Sat, 26 Feb 2000 21:18:14 +0100

[EMAIL PROTECTED] (Miquel van Smoorenburg) writes:

>You must be kidding, or you are using a weird system. I can run
>libc5, glibc 2.0 and glibc 2.1 X based applications at the same
>time without any problems.

I can run them at the same tine, too, but when the dynamic linker
schoeses the set of X11 libs linked against libc5 for a program using
libc6, I usually get errors about missing symbols. Here is one example:

./xisdnload: error in loading shared libraries: /usr/libc5/lib/libX11.so.6: undefined 
symbol: _xstat

The shared library libX11 does have the same name (libX11.so.6), no
matter wether it requires libc5 or libc6. So I have to files called
libX11.so.6 on my system. I even observed situations, were an
application loaded both libcs, libc5 and libc6. :-(

73, Mario
-- 
Mario Klebsch                                           [EMAIL PROTECTED]

------------------------------

From: Hernan <[EMAIL PROTECTED]>
Subject: How debug linux modules
Date: Sat, 26 Feb 2000 18:14:18 -0300
Reply-To: [EMAIL PROTECTED]

i want learn how to write linux network devices drivers, so i want trace
a module to look how it work, if any body know how it work i apreciate
your help                                       Thanks Hernan

------------------------------

From: Anders Larsen <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.advocacy,comp.os.linux.setup
Subject: Re: Binary compatibility: what kind of crack are they smoking?
Date: Sat, 26 Feb 2000 23:06:09 +0100

Mario Klebsch wrote:
> 
> Anders Larsen <[EMAIL PROTECTED]> writes:
> 
> >If the Windows ABI is really such a "well defined subset", how come
> >that's not common knownledge (except, perhaps, within Microsoft, Inc.) ?
> 
> The absense of common knowledge about the OSes from Microsoft always
> irritated me. After switching from CP/M-80 to MS-DOS, I was loocking
> for the manuals describing the interface of the OS for years! They
> were included in CP/M, but were missing in MS-DOS. I finally gave up
> and til today I did not find those manuals.

That really confirms my suspicion.
You talk a lot about a "Windows ABI", but if documentation of it is not
available, then, as a consequence, that "ABI" is nothing but hot air.

-- 
Anders Larsen

------------------------------

Date: Sat, 26 Feb 2000 23:44:29 +0100
From: Benjamin Lippelt <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.apps
Subject: Detecting installed Harddrives

Hi,

how can I find out which harddrives are installed (e.g. /dev/hdc1) on a
Computer ? Is there a configuration-file or a kernel-function ?

Thx Benni

------------------------------

From: [EMAIL PROTECTED] (GriffD2000)
Subject: Problem Booting Linux
Date: 26 Feb 2000 22:53:00 GMT

i just compiled a 2.2.14 kernel and i have a couple questions:
sbpcd worked before w/ 2.0.35 and now it doesn't work - it doesn't even load. 
i have the IDE/CD option checked - i can't find an option for
panasonic/matsishitu 562 drive.  where is it?
also, my kernel locks up half the time with the last message being:
lp0: using parport0 (polling)

Any Ideas?
Thanx
[EMAIL PROTECTED]


------------------------------

From: Lee Webb <[EMAIL PROTECTED]>
Subject: Re: pci driver example
Date: Sat, 26 Feb 2000 23:00:59 +0000

You may want to have a look at Michael Johnson's paper on writing device drivers
at:
http://people.redhat.com/johnsonm/devices.html

However, it's from '95 and so will be out of date.

Failing that, have you considered buying, or are willing to buy, a book on the
subject? If so, there's two that I know off:

1. Linux Device Drivers by Alessandro Rubini, published by O'Reilly
   Has been given mixed reviews (some not very good)

2. Beginning Linux Programming by Stones & Matthew, published by Wrox has around
80 pages on the subject -    creating them, debugging them etc...

Hope this helps.
Lee

Karsten wrote:
> 
> I want to port a pci device driver to linux.
> Is there an cookbook or howto to program one?
> I need only the basics at first:
> - where to place the files for an module resp. what files I need for a
> module
> - headers to include
> - naming conventions
> - how to make the node in /dev
> - are there files like foo.sm or foo.master as under IRIX?
> 
> I now there are the kernel sources but pci drivers like ne2k-pci or bttv
> are spread over
> many files and to complex (for me) to get the essence.
> 
> thanks in advance
> karsten

------------------------------

From: simba <[EMAIL PROTECTED]>
Subject: How does get_user()/put_user() work in kernel 2.2.x?
Date: Sun, 27 Feb 2000 08:50:17 +0900

Before kerenl 2.2.x, I knew get_user()/put_user() could access user
space using fs segment register.
But in case of kernel 2.2.x the code was changed and I can't understand
how does get_user()/put_user() can access the user space!

Is there anybody who can hack the code in <asm/uaccess.h> and explain
the operation ?

Thanks in advance

kerdosa


------------------------------

From: [EMAIL PROTECTED] (Juergen Heinzl)
Subject: Re: unable to open a file
Date: Sat, 26 Feb 2000 23:27:09 GMT

In article <nBNt4.22$[EMAIL PROTECTED]>, ChoongHwan Lee wrote:
>  I'm programming with gcc under Linux Redhat 6.0, Kernel 2.2.5-15 on a
>sparc.
>
>  My program tries to open a file, but can't open it.

*hit happens 8)

>  I tried both C standard function 'fopen' and System call 'open', but these
>calls made errors with errorno = 2

Yup.
[...]
>  But, I'm sure that the file which I want to open exists. In order to
>confirm existence, I made another program which opens that file,
>and it works well.
[...]

Typo perhaps ? Try a strace thisbloodythingdoesnotwork -o /tmp/output
and see which file it actually is trying to open.
[...]

Cheers,
Juergen

-- 
\ Real name     : J�rgen Heinzl                 \       no flames      /
 \ EMail Private : [EMAIL PROTECTED] \ send money instead /

------------------------------

From: "Paul D. Smith" <[EMAIL PROTECTED]>
Crossposted-To: 3dfx.linux.apps.other
Subject: Re: Linux or Windows
Date: 26 Feb 2000 19:36:51 -0500
Reply-To: [EMAIL PROTECTED]

%% R.M <[EMAIL PROTECTED]> writes:

  >> I am debating wheather to run Linux on my computer or to stick with
  >> windows.  I know very little about linux and want to know which is
  >> best.  I want to be able to run it on the same computer as
  >> windows. Help please.

  rm> Put two hard disk IDE in your computer. One for Windows, one for
  rm> Linux. It is a fine solution.

You don't even need two hard disks.  You can put a very respectable
Linux installation in 2G (I've loaded usable ones in 750M).

Most systems these days come with HDs of 6+G, so there's plenty of room
for both OS's on one system, even if Windows is, uh, a bit "fatter" than
Linux ;).

I dual-boot with a menu at boot time that lets me choose which I want,
and it works great.

-- 
===============================================================================
 Paul D. Smith <[EMAIL PROTECTED]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
===============================================================================
   These are my opinions---Nortel Networks takes no responsibility for them.

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: booting a different system from within Linux
Date: Sun, 27 Feb 2000 02:41:32 GMT

On Thu, 24 Feb 2000 09:53:08 +0000 Etienne Lorrain <[EMAIL PROTECTED]> wrote:
| [EMAIL PROTECTED] wrote:
|> I want to have my BIOS boot up Linux directly, and then from within Linux,
|> cause another system (Linux, BSD, Solaris, NT, W2K) to be booted from a
|> different partition.  Is it possible to get the kernel to do this?  What
|> I am wanting to do is have Linux be the "builder" that loads an OS from a
|> an image obtained elsewhere, makes changes to it according to my own code,
|> then boot it directly (replacing the current running Linux with that OS).
|> What tools and/or kernel patches might be out there for such a thing?

|   In short, you want to load LINUX, start it so it can activate
|  all the hardware buffers of the chipset it has recognised, download
|  its own microcode to the SCSI card, initialise special device... ,
|  and then load Windows - patch it to support the new hardware config,
|  "changes to it according to my own code" to correct all bugs of this OS,
|  remove the BSOD because it is no more necessary and wastes memory space,
|  and the run the new OS ? (sorry, I could not resist)

Nope.

Actually I want to load the image of the 2nd OS from the network then run it.


|   You cannot run another OS without going through a "cold" restart (reset).

I know this is not true.  The very fact that the BIOS has a warm restart,
and the very fact that Linux can invoke it, makes this obvious.  The very
fact that a program like LILO can run and decide which OS to start up also
makes this obvious.

The problem is not whether a warm restart can be done, but rather, how to
do so with a different OS selected.  The BIOS probably has no means to make
a different choice as left behind by the previous OS.

One suggestion someone gave me on IRC was to change the LILO configuration
to default to the 2nd OS then simply do a clean shutdown to reboot.  Then
LILO would boot the 2nd OS.  The catch is that after the 2nd OS runs, I need
to switch back to the 1st OS, including after a hard reset or power cycle.
So LILO isn't a solution for repeating this process.

If a loader like LILO were written in such a way that it could detect the
presence of some piece of data left on the machine by the 1st OS, and choose
an alternate OS to default to (and be sure to clear that data so the next
time the 1st OS is started again) then this would accomplish my goal.  Maybe
LILO can be modified to do this (but I would have no idea where to stuff
some piece of info for the loader to find).


|> I'd prefer not to have to do this with vmware, but would consider it if
|> vmware can be totally automated (e.g. start up the other OS w/o anyone
|> being present anywhere to manually bring it up).  But I haven't heard
|> that any support for BSD or Solaris (as guest) exists.
|
|   IHMO VMWARE is emulating some/all hardware (for instance the video board)
|  and does not let the new OS use native drivers, it has his own drivers.

The video part would not be of much concern as these would be unattended
servers.


|   Etienne.

-- 
| Phil Howard - KA9WGN | for headlines that | Just say no to absurd patents |
| [EMAIL PROTECTED] | really matter:     | Boycott Amazon.Com (AMZN)     |
| Dallas - Texas - USA | linuxhomepage.com  | Shop http://bn.com/ instead   |

------------------------------

Reply-To: "Norm Dresner" <[EMAIL PROTECTED]>
From: "Norm Dresner" <[EMAIL PROTECTED]>
Subject: Re: complex math in a device driver
Date: Sun, 27 Feb 2000 03:06:26 GMT

There is a way, but not in mainstream Linux.  You have to install Real-Time
Linux (IIRC, www.rtlinux.org) and they allow FP in rt-modules.

    Norm

Bryan Hackney <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> Andreas Jaeger wrote:
> >
> [...]
> >
> > You can't use any floating point in the kernel at all.  No chance
> > AFAIK.  You have to solve this differently.  Are you sure that this
> > cannot done in userspace?
> >
> > Andreas
> > --
> [...]
>
> There has to be a way. I think the problem is that the kernel does not
> save FP state - you would have to figure out how to push and pop FP state,
> and make absolutely sure your code is atomic.
>
> Now, the fact that this is not done and apparently never has been done
would
> seem to indicate much smarter people than we have never had an absolute
need
> for such.
>
>
> --
>                                  Bryan Hackney / BHC / [EMAIL PROTECTED]
>                                         http://www.FreeClassAds.com/
>                                         http://bhconsult.com/
>                                         http://bhconsult.com/bh/pgp.key


------------------------------

From: [EMAIL PROTECTED]
Subject: switch from protected mode to real mode in kernel
Date: Sun, 27 Feb 2000 03:05:05 GMT

Does anyone have code that would show how to switch from protected mode
back to 8086 compatible real mode that x86 processors always start in?
I would be doing this at the end of a shutdown before the kernel would
otherwise do its final halt/reboot.

-- 
| Phil Howard - KA9WGN | for headlines that | Just say no to absurd patents |
| [EMAIL PROTECTED] | really matter:     | Boycott Amazon.Com (AMZN)     |
| Dallas - Texas - USA | linuxhomepage.com  | Shop http://bn.com/ instead   |

------------------------------

From: [EMAIL PROTECTED] (Kaz Kylheku)
Subject: Re: the init of wait queue?
Reply-To: [EMAIL PROTECTED]
Date: Sun, 27 Feb 2000 05:51:36 GMT

On Sat, 26 Feb 2000 09:57:32 -0700, Weiguang Shi <[EMAIL PROTECTED]> wrote:
>Line 20 should be equivalent to the sentence below:
>        *q = (struct wait_queue*)(q-1);
>
>Here the content of q is set to the address right before q but which has
>not been initialized to anything. There is even no gurantee this is a
>valid address for the process. Why should this be done? What's the effect?

This is just a hack to save space in the storage of a queue.

Note how a queue node is defined: it has a task pointer and a pointer
to the next node. 

Now task queues are circular.  In a circular list, you often have a sentinel
node which marks the beginning and end of the list. The sentinel  node normally
has the same type as other nodes.

If fully fledged ``struct wait_queue'' sentinel node were used in Linux wait
queues, an empty queue would look like this:

    +--------+
    | task   | <---+
    +--------+     |
    | next *-------+
    +--------+

In other words, the sentinel's next pointer would point back at the sentinel.

Now suppose you want to save space. Most queues in the system are short
or empty most of the time, after all.  The task pointer in the sentinel node
is not used. So why not remove it? So the picture now looks like this:

    + - - - -+
    :        : <---+
    +- - - - +     |
    | next *-------+
    +--------+

A queue is just a single pointer. When it is empty, it points to the
non-existent task pointer which would be there if the queue were a complete
sentinel node. Hence  the funny subtraction of one.

The following rewrite should make the intent somewhat clearer, as
well as somewhat more correct:

    /* given pointer to next field, compute pointer to struct */
    #define WAIT_QUEUE_HEAD(X) \
      ((struct wait_queue *)((char *)(X) - offsetof(struct wait_queue, next)))

Either way, this is extremely skanky C coding. What I do not understand is why
the wait queue is not defined so that the next pointer is the first member.
Then this trick would be implemented much more neatly without the arithmetic! 

I suppose that Linus wanted the task pointer to be the first member for some
optimization reason, and the trick works on all architectures.

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: complex math in a device driver
Date: Sun, 27 Feb 2000 06:02:49 GMT

On Sat, 26 Feb 2000 20:50:35 GMT Grant Edwards <[EMAIL PROTECTED]> wrote:

|>Why should you use math in a device driver?
|
| To provide a layer of abstraction.  For example, if I have a set of
| analog inputs, and I make an IOCTL call to read the voltages, it's
| awfully nice to get answers in volts.  That way the driver has to keep
| track of the peculiarities of the hardware rather than the user
| software.  Much like SCSI hides the whole cylinders, heads, sectors
| stuff from the user program, it would be nice if device drivers could
| hide the ugly details of A/D and D/A hardware from the user.

Let the device driver pass parameters about the hardware through the
ioctl calls.  Then let the library function integrate those parameters
by applying the mathematics.  Then the abstraction is to call the
library function.  That's not unlike what is already done now with
libraries like stdio in C.


| As things currently exist, you read an analog input value and you get
| an integer.  You have no way of knowing what that integer actually
| means unless the user-software has some a-priori knowledge about the
| exact hardware (and it's current configuration).  Knowledge that should
| be encapsulated within the driver.  Requiring user software to know
| exactly what hardware it's talking to and how it's currently
| configured violates the whole reason for having device drivers in the
| first place.  An analogy: if user software had to know what Ethernet
| controller, what phy chip, and what sort of baud rate and magnetics
| were being used in order to open a TCP/IP connection, people would
| scream bloody murder.  Not allowing analog I/O drivers to do floating
| point places their users in that same situation.

That knowledge could be passed to the library.

Floating point is not something you can depend on even being present.
If it is not present it has to be emulated, but such emulation is done
for processes, not for the kernel itself.  Encountering an floating
point instruction causes a trap when the instruction is not implemented.
That trap in a process allows the kernel to intercept it, emulate it,
and resume the process.  If the trap occurs in the kernel code itself,
this is far more difficult to do, and as implemented now I believe would
cause a panic.


| I realize that doing floating point in drivers would complicate
| things, but let's not pretend that there are no cases where it would
| be appropriate.
|
| The REAL answer to the question "why can't you do floating point in a
| device driver?" is the same as most other "why doesn't Linux's X do Y?"
| questions:
|
| Because the people who designed X had no need to do Y.

No.  Because of a combination of less need to do Y and an increased
difficulty to implement X to do Y.

Allowing floating point in the kernel is more difficult than just saving
the FP state on every interrupt.  Obviously the kernel does know how to
do FP state saving, as it must between process dispatches.  But to allow
the instructions to be executed _in_ the kernel itself is more difficult
because the emulation has to be implemented in such a way that kernel
traps themselves can be handled through emulation.

Also, the more that things can be implemented in user space, such as in a
library, the more reliable the whole system is.  IMHO, much of what is in
the kernel now needs to be moved out to user process space.  Perhaps the
big reason a lot of that is in the kernel was that nothing happened to be
in the way (as floating point is for the A/D D/A drivers) and the authors
just did it and got away with it.


| If somebody really wants to do floating point in a device driver,
| they'll hack the kernel to make it work.  Otherwise they just ramble
| on about it like me.

Or implement it in a library and make the ioctl interface smart enough
to allow the driver to pass back to the library the parameters about the
device to let the library do the math to figure out the values.

-- 
| Phil Howard - KA9WGN | for headlines that | Just say no to absurd patents |
| [EMAIL PROTECTED] | really matter:     | Boycott Amazon.Com (AMZN)     |
| Dallas - Texas - USA | linuxhomepage.com  | Shop http://bn.com/ instead   |

------------------------------

From: [EMAIL PROTECTED] (Linus Torvalds)
Subject: Re: the init of wait queue?
Date: 26 Feb 2000 22:42:28 -0800

In article <[EMAIL PROTECTED]>,
Kaz Kylheku <[EMAIL PROTECTED]> wrote:
>
>The following rewrite should make the intent somewhat clearer, as
>well as somewhat more correct:
>
>    /* given pointer to next field, compute pointer to struct */
>    #define WAIT_QUEUE_HEAD(X) \
>      ((struct wait_queue *)((char *)(X) - offsetof(struct wait_queue, next)))
>
>Either way, this is extremely skanky C coding. What I do not understand is why
>the wait queue is not defined so that the next pointer is the first member.
>Then this trick would be implemented much more neatly without the arithmetic! 
>
>I suppose that Linus wanted the task pointer to be the first member for some
>optimization reason, and the trick works on all architectures.

Actually, the real reason was that the wait-queue cleanups were done
fairly early during a stable kernel cycle, and I didn't want to break
some binary modules.  Bad reason, as they ended up being broken not much
later anyway.  But the not breaking modules meant that the wait-queue
head had to look identical with the new setup, which it did. 

Of course, in 2.3.x we cleaned it up for good using the new "struct list",
so the issue is pretty moot these days, except for the silly historical
reasons for why things get done certain ways...

                Linus

------------------------------

From: Erik de Castro Lopo <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.system
Subject: Re: BUS ERROR WITH MMAP
Date: Sun, 27 Feb 2000 06:50:25 +0000

David wrote:
> 
> My code is:
> 
> struct SHARED_ZONE
> {
>         int data ;
>         ...
> } *SHARED_ZONE ;
> 
> ...
> 
>       int fd_shmem = open( "./TP" , O_RDWR | O_CREAT , 0777 ) ;
>       if ( fd_shmem == -1 )
>         {
>           perror( "OPEN SH_MEM" ) ;
>           exit( -1 ) ;
>         }
> 
>       if ( (SHARED_ZONE= (struct DATA_2_SHARE *)
>             mmap( 0 , sizeof( struct DATA_2_SHARE ) ,
>                   PROT_READ | PROT_WRITE , MAP_SHARED ,
>                   fd_shmem , 0 )) == MAP_FAILED )
>         {
>           perror( "MMAP" ) ;
>           exit( -1 ) ;
>         }
> 
>       SHARE_ZONE -> data = 0 ;
> 
> I recive an BUS ERROR when SHARE_ZONE -> data = 0 execute.

I see two problems in the code above.

1) You open/create the file and then mmap it before the file
   has any data in it.
2) sizeof (*SHARED_ZONE) == sizeof (int) while a mmaped area
   must be a page size (man getpagesize). 

To (hopefully) fix this, you should write at least a page of
data to the file before mmap()ping it (Use getpagesize() to find 
the page size).

Hope this helps,
Erik
-- 
+-------------------------------------------------+
     Erik de Castro Lopo     [EMAIL PROTECTED]
+-------------------------------------------------+
Microsoft is not the answer.
Microsoft is the question. NO is the answer.

------------------------------

From: Erik de Castro Lopo <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.system
Subject: Re: BUS ERROR WITH MMAP
Date: Sun, 27 Feb 2000 06:50:25 +0000

David wrote:
> 
> My code is:
> 
> struct SHARED_ZONE
> {
>         int data ;
>         ...
> } *SHARED_ZONE ;
> 
> ...
> 
>       int fd_shmem = open( "./TP" , O_RDWR | O_CREAT , 0777 ) ;
>       if ( fd_shmem == -1 )
>         {
>           perror( "OPEN SH_MEM" ) ;
>           exit( -1 ) ;
>         }
> 
>       if ( (SHARED_ZONE= (struct DATA_2_SHARE *)
>             mmap( 0 , sizeof( struct DATA_2_SHARE ) ,
>                   PROT_READ | PROT_WRITE , MAP_SHARED ,
>                   fd_shmem , 0 )) == MAP_FAILED )
>         {
>           perror( "MMAP" ) ;
>           exit( -1 ) ;
>         }
> 
>       SHARE_ZONE -> data = 0 ;
> 
> I recive an BUS ERROR when SHARE_ZONE -> data = 0 execute.

I see two problems in the code above.

1) You open/create the file and then mmap it before the file
   has any data in it.
2) sizeof (*SHARED_ZONE) == sizeof (int) while a mmaped area
   must be a page size (man getpagesize). 

To (hopefully) fix this, you should write at least a page of
data to the file before mmap()ping it (Use getpagesize() to find 
the page size).

Hope this helps,
Erik
-- 
+-------------------------------------------------+
     Erik de Castro Lopo     [EMAIL PROTECTED]
+-------------------------------------------------+
Microsoft is not the answer.
Microsoft is the question. NO is the answer.

------------------------------


** FOR YOUR REFERENCE **

The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:

    Internet: [EMAIL PROTECTED]

You can send mail to the entire list (and comp.os.linux.development.system) via:

    Internet: [EMAIL PROTECTED]

Linux may be obtained via one of these FTP sites:
    ftp.funet.fi                                pub/Linux
    tsx-11.mit.edu                              pub/linux
    sunsite.unc.edu                             pub/Linux

End of Linux-Development-System Digest
******************************

Reply via email to