> Called from a c program, shmat returns a pointer to address
> 0x40000000, which is correct.
[quoted text clipped - 4 lines]
> address, but not the correct start of the shared memory segment
> sought.
In almost most cases you should specify NULL with shmat() to let the
system choose an appropriate free address to attach the region. A
given segment will usually *not* attach at the same address in
different programs.
If you are already specifying NULL to attach the segment, forget the
idea that one particular address is the correct one. If not, try doing
so.
Have you tried specifying the correct segment size (not 0) in
shmget()?
While your program is running, use ipcs to see whether the segment is
attached to any processes. Use a tool like pmap <pid> to see the
current mappings for your process, or look in the process file system
to get the information.
Without seeing code, there isn't much more to say here. However there
is nothing inherently magic about using shmat() from JNI, I've done it
myself without any problems. I suspect your problems aren't related to
JNI per se, and suggest that an AIX group might be a more appropriate
place for this.
/gordon
--
jadrian@wi.rr.com - 10 May 2007 22:21 GMT
> Without seeing code, there isn't much more to say here. However there
> is nothing inherently magic about using shmat() from JNI, I've done it
> myself without any problems. I suspect your problems aren't related to
> JNI per se, and suggest that an AIX group might be a more appropriate
> place for this.
Hello Gordon,
Thanks again for your help and I have posted to comp.unix.aix as
well. I think the difference here is that the call to shmget and
shmat is not being made directly from the native library but instead
the native library is linking into an existing shared object library
which has wrapper functions to handle all the shared memory functions.
I understand that this pointer exists in the calling process space.
What I should have said is that the memory location this pointer
points to differs from when it is called from a c shared object
library function than from when it is called from the jni native
method, where ss is a char pointer that the void pointer shmat returns
is cast to:
(from c) &ss[0] == 0x40000000
(from native method) &ss[0] == 0xc0000000
My understanding is that both pointers should be pointing to the same
address, i.e. the specific location of that particular memory segment.
There was one reference I found that I thought might be relevant:
http://groups.google.com/group/comp.unix.aix/browse_frm/thread/aded525fb62cd729/
06d7f634fccadeb5?lnk=st&q=java+jni+shmat+aix&rnum=1#06d7f634fccadeb5
... but at this point I don't think that that is the problem.
Possibly a 64/32 bit issue? I don't think it's that either--the
kernel is 64-bit but the compiler is 32-bit for everything, at least
on the c side.
I think that the problem is derived ultimately from the fact that the
main process is java. By the way, my original problem with being able
to load the existing shared object library with the extern variables
turned out to be that the .imp file for the existing .so library
needed
#!.. (pound exclaim dot dot)
... on the first line instead of
#!. (pound exclaim dot)
The ld man page says the first form tells the linker to resolve
externs from the main module, the second form tells the linker to just
find them wherever, so you were right about it being a linking issue
rather than variable declaration syntax.
I'll try your suggestions to see if they lead anywhere and if you
think of anything else please let me know.
Thanks again.
Jeff
==================================
> > Called from a c program, shmat returns a pointer to address
> > 0x40000000, which is correct.
[quoted text clipped - 31 lines]
>
> --