flat assembler
Message board for the users of flat assembler.

Index > Linux > FASM, trouble with shared memory in sys_calls

Author
Thread Post new topic Reply to topic
scurra



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



Joined: 09 Oct 2009
Posts: 430
Location: Australia
redsock 03 May 2016, 22:32
compilable/working code is required to assist you, but the two calls in C are easily reproduced:
Code:
int main(int argc, char *argv[]) {
        int id = shmget(0x571, 256, IPC_CREAT|IPC_EXCL|0666);
        if (id < 0) {
                printf("shmget fail\n");
                exit(1);
        }
        void *addr = shmat(id, NULL, 0);
        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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.