flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > FASM, trouble with shared memory in sys_calls

Author
Thread Post new topic Reply to topic
scurra



Joined: 03 May 2016
Posts: 1
FASM, trouble with shared memory in sys_calls

Code:
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

Code:
_start:> <------> <------> mov eax75h; system call number sys_ipc
<------> <------> <------> Mov ebx17h; shmget function
<------> <------> <------> Mov ecx571h; key, the first thing that came to mind
<------> <------> <------> Mov edx256; the size of the selected shared memory segment
<------> <------> <------> Mov esiIPC_CREAT or IPC_EXCL or 666o; flag to create and access rights
<------> <------> <------> Int 0x80; do system call
<------> <------> <------> Test eaxeax; 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 eax4
<------> <------> <------> Mov ebx1
<------> <------> <------> Mov ecxerror_str
<------> <------> <------> Mov edx7
<------> <------> <------> Int 0x80; O error
<------> <------> <------> Jmp exit
next_0:> <------> <------> mov ecxeax; shmid in ecx
<------> <------> <------> Mov eax75h; again sys_ipc
<------> <------> <------> Mov ebx15h; function shmat
<------> <------> <------> Xor edxedx; in theory, the rest may be zero, then the system will select the very
<------> <------> <------> Xor esiesi; adres.no I substituted a clear and an address for a shared memory segment
<------> <------> <------> Xor ediedi; and different flags - all before the ass, because
<------> <------> <------> Int 80h; the system call returns a value in eax FFFFFFF2, which means
           Error 14that is EFAULT


This error is not generally indicated in the description shmat. After the first system call can be checked

Code:
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

Code:
Ipcs -m

------ Segments Joint. App. memory --------
Key shmid owner rights bytes nattch state
0x00000571 0 root 666 256 1



Code:
080480BB 31FF xor ediedi
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

FlagsPF 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

FlagsPF 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?
Post 03 May 2016, 10:33
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 251
Location: Australia
compilable/working code is required to assist you, but the two calls in C are easily reproduced:

Code:
int main(int argcchar *argv[]) {
        int id = shmget(0x571256IPC_CREAT|IPC_EXCL|0666);
        if (id < 0) {
                printf("shmget fail\n");
                exit(1);
        }
        void *addr = shmat(idNULL0);
        if (!addr) {
                printf("shmat fail\n");
                exit(1);
        }
        exit(0);
}

First time this code runs, no error is detected and the segment shows up in the IPCS listing correctly. Second time, shmget fails due to the use of the IPC_EXCL flag as it should.

Post your complete test code that is failing Smile

_________________
2 Ton Digital - https://2ton.com.au/
Post 03 May 2016, 22:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.