Re: shm and MacOs

From: Kinkie <gkinkie_at_gmail.com>
Date: Mon, 14 Apr 2014 22:00:23 +0200

testRock does:

shm_open(0x7FA3B9C06140, 0x202, 0x180) = 4 0
ftruncate(0x4, 0x10418, 0x0) = -1 Err#22

The test program:
write_nocancel(0x1, "start\n\0", 0x6) = 6 0
shm_open(0x10A183EC0, 0x202, 0x180) = 3 0
write_nocancel(0x1, "fd: 3\n\0", 0x6) = 6 0
write_nocancel(0x1, "sz: 66584\n\0", 0xA) = 10 0
ftruncate(0x3, 0x10418, 0x7FFF77B30638) = 0 0
write_nocancel(0x1, "mmap\n\0", 0x5) = 5 0
mmap(0x0, 0x10418, 0x3, 0x1, 0x3, 0x0) = 0x10A1BF000 0
write_nocancel(0x1, "mem at 0x10a1bf000\n\0", 0x13) = 19 0
shm_unlink(0x10A183EC0, 0x320000003200, 0x7FFF77B30638) = 0 0
write_nocancel(0x1, "ok!\n\0", 0x4) = 4 0

I changed the segment name slightly, I don't expect to be getting
leftover junk, and unlink the segment.

err 22 is EINVAL. I am quite curious about where the third argument to
ftruncate comes from, and why it differs in the two runs.

A possible alternative: since ftruncate is used to extend the shm
area, what bout simply writing to it to extend it? Would it work in
your opinion?

On Mon, Apr 14, 2014 at 9:22 PM, Alex Rousskov
<rousskov_at_measurement-factory.com> wrote:
> On 04/14/2014 01:01 PM, Kinkie wrote:
>
>> The attached test program runs just fine on MacOS Mavericks; testRock
>> fails, yet the code looks really the same as in src/ipc/mem/Segment.cc
>> to me (after removing the O_TRUNC flag to shm_open).. can anyone spot
>> a difference I can't see?
>
> Perhaps strace (or equivalent) would expose the critical difference?
>
> Also, this is a wild guess, but you may want to double check that old
> shared memory segments are not interfering with one of your test cases.
>
> Alex.
>
>
>> output:
>> --------------
>> mini:shm_test kinkie$ ./shm_test 66584
>> start
>> fd: 3
>> sz: 66584
>> mmap
>> mem at 0x10dd9b000
>> ok!
>> --------------
>> testRock:
>> mini:squid kinkie$ gdb-apple ./src/tests/testRock
>> [...]
>>
>> Program received signal EXC_BAD_ACCESS, Could not access memory.
>> Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000068
>> 0x00007fff92ff8eca in flockfile ()
>>
>> (gdb) bt
>> #0 0x00007fff92ff8eca in flockfile ()
>> #1 0x00007fff93001b10 in vfprintf_l ()
>> #2 0x00007fff92ffa68e in fprintf ()
>> #3 0x000000010000b4fb in fatal_common (message=0x1000fb8b0
>> "Ipc::Mem::Segment::create failed to
>> ftruncate(/squid-testRock_Store_i.shm, 66584): (22) Invalid
>> argument\n") at fatal.cc:44
>> #4 0x000000010000b4ab in fatal (message=0x1000fb8b0
>> "Ipc::Mem::Segment::create failed to
>> ftruncate(/squid-testRock_Store_i.shm, 66584): (22) Invalid
>> argument\n") at fatal.cc:88
>> #5 0x000000010000b600 in fatalf (fmt=<value temporarily unavailable,
>> due to optimizations>) at fatal.cc:99
>> #6 0x00000001000b257b in Ipc::Mem::Segment::create (this=0x100306810,
>> aSize=66584) at mem/Segment.cc:78
>> [...]
>>
>>
>>
>>
>>
>

-- 
    Francesco
Received on Mon Apr 14 2014 - 20:00:32 MDT

This archive was generated by hypermail 2.2.0 : Tue Apr 15 2014 - 12:00:30 MDT