# uname -a
Linux main 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
It is necessary that the two processes communicate through shared memory
That piece of code problem
_start:> <------> <------> mov eax, 75h; system call number sys_ipc
<------> <------> <------> Mov ebx, 17h; shmget function
<------> <------> <------> Mov ecx, 571h; key, the first thing that came to mind
<------> <------> <------> Mov edx, 256; the size of the selected shared memory segment
<------> <------> <------> Mov esi, IPC_CREAT or IPC_EXCL or 666o; flag to create and access rights
<------> <------> <------> Int 0x80; do system call
<------> <------> <------> Test eax, eax; eax in all the beam, just do not understand why shmid turns zero.
<------> <------> <------> Jns next_0; if you make two consecutive calls, the second will be the type shmid 8001
<------> <------> <------> Mov eax, 4
<------> <------> <------> Mov ebx, 1
<------> <------> <------> Mov ecx, error_str
<------> <------> <------> Mov edx, 7
<------> <------> <------> Int 0x80; O error
<------> <------> <------> Jmp exit
next_0:> <------> <------> mov ecx, eax; shmid in ecx
<------> <------> <------> Mov eax, 75h; again sys_ipc
<------> <------> <------> Mov ebx, 15h; function shmat
<------> <------> <------> Xor edx, edx; in theory, the rest may be zero, then the system will select the very
<------> <------> <------> Xor esi, esi; adres.no I substituted a clear and an address for a shared memory segment
<------> <------> <------> Xor edi, edi; and different flags - all before the ass, because
<------> <------> <------> Int 80h; the system call returns a value in eax FFFFFFF2, which means
, Error 14, that is EFAULT
This error is not generally indicated in the description shmat. After the first system call can be checked
# Ipcs -m
------ Segments Joint. App. memory --------
Key shmid owner rights bytes nattch state
0x00000571 0 root 666 256 0
That yes, the segment is created, the code works.
but after the second system call
# Ipcs -m
------ Segments Joint. App. memory --------
Key shmid owner rights bytes nattch state
0x00000571 0 root 666 256 1
080480BB 31FF xor edi, edi
ald>
eax = 0x00000075 ebx = 0x00000015 ecx = 0x00000000 edx = 0x00000000
esp = 0xBFE4EAC0 ebp = 0x00000000 esi = 0x00000000 edi = 0x00000000
ds = 0x007B es = 0x007B fs = 0x0000 gs = 0x0000
ss = 0x007B cs = 0x0073 eip = 0x080480BD eflags = 0x00000246
Flags: PF ZF IF
080480BD CD80 int 0x80
ald>
eax = 0xFFFFFFF2 ebx = 0x00000015 ecx = 0x00000000 edx = 0x00000000
esp = 0xBFE4EAC0 ebp = 0x00000000 esi = 0x00000000 edi = 0x00000000
ds = 0x007B es = 0x007B fs = 0x0000 gs = 0x0000
ss = 0x007B cs = 0x0073 eip = 0x080480BF eflags = 0x00000246
Flags: PF ZF IF
although the ipcs and shows that segment is attached, but in eax returned an error, and not the address of the shared memory segment.
Help is needed. What's wrong?