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 > Posix_memalign

Author
Thread Post new topic Reply to topic
sakkiesalm



Joined: 07 Feb 2011
Posts: 9
Posix_memalign
Hi

What is wrong with this code ? ,why does it give me a "Program received signal SIGSEGV, Segmentation fault." error

I allocate 134217728 bytes in 128 byte alignment


Code:
  hashkeymask equ 134217727     
            hashsize equ 134217728

            lea rdi,[HashBuffer]
            mov rsi,128
            mov rdx,hashsize
            call posix_memalign
            mov rax,[HashBuffer]
            mov [HashBuffer + hashsize - 256],45



Why can't i allocate the memory,although it is less than the memory i have set aside/allocated ?
Post 02 Oct 2015, 12:01
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3434
Location: Bulgaria
Why not to run it in a debugger and see on what instruction you get segmentation fault?
If you are importing posix_memalign from a dynamic library, you should call it indirectly:

Code:
call [posix_memalign]



P.S. It is a bad style IMHO to use "EQU" for numeric constants. Use "=" instead. In FASM these two are not equal.
Post 02 Oct 2015, 12:22
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
sakkiesalm



Joined: 07 Feb 2011
Posts: 9

JohnFound wrote:
Why not to run it in a debugger and see on what instruction you get segmentation fault?
If you are importing posix_memalign from a dynamic library, you should call it indirectly:

Code:
call [posix_memalign]



P.S. It is a bad style IMHO to use "EQU" for numeric constants. Use "=" instead. In FASM these two are not equal.



hi,thanks

Yes i did run it in debugger and i get error when accessing that memory part

Code:
mov [HashBuffer + hashsize - 256],45



If i use a smaller number for example

Code:
mov [HashBuffer + 1000000 - 256],45



i do not get an error.But why cannot i use the whole allocated amount ?
I tried = also now still same error

I did check,memory gets allocated correctly,in task manager after running

Code:
call posix_memalign

Post 02 Oct 2015, 12:31
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 72
Location: UK
Hi sakkiesalm,

It looks like you are treating HashBuffer as a pointer when really it's a pointer to a pointer. You had the right idea when you moved the result into rax. Try replacing the segfaulting line with this:


Code:
mov qword [rax + hashsize - 256], 45

Post 02 Oct 2015, 23:12
View user's profile Send private message Reply with quote
sakkiesalm



Joined: 07 Feb 2011
Posts: 9

ProphetOfDoom wrote:
Hi sakkiesalm,

It looks like you are treating HashBuffer as a pointer when really it's a pointer to a pointer. You had the right idea when you moved the result into rax. Try replacing the segfaulting line with this:


Code:
mov qword [rax + hashsize - 256], 45




hi ProphetOfDoom

Thank you,that seems to solve the problem! Smile
Post 03 Oct 2015, 04:34
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.