So I am trying dynamic allocation of memory in C program with assembly (AT&T notation). The problem is that my allocation don't work. When I try too write a value into brk address I get segmentation fault (access violation). Also I compared brk address before and after allocation and they were the same so I guess it didn't worked. The information I want to add is that I want to allocate a bunch of memory pages. Code:
//...
long int PAGE_SIZE = sysconf(_SC_PAGESIZE); //rozmiar strony
int w = 64
int buffer_size = PAGE_SIZE * w;
int address = 0;
__asm__ volatile (
"movl $45, %%eax\n"
"xorl %%ebx, %%ebx\n"
"int $0x80\n" //sys_brk - get the address of brk
"movl %%eax, %%esi\n" //current position of brk
"movl %%eax, %%ebx\n"
"addl %1, %%ebx\n" //4096(bytes)*64
"movl $45, %%eax\n"
"int $0x80\n"
"movl %%esi, %%eax\n"
"movl %%esi, %0\n" //starting addres
"movl $42, (%%esi)\n"
:"=g"(address)
: "g"(buffer_size)
);
//...