Page 1 of 1

Syscall getrlimit

Posted: Tue Aug 03, 2010 1:19 pm
by 0000
Hi,

I've some problems about using this syscall in assembly, I tried to use it under different OS (BSD/Linux) but canĀ“t get it works.
For example, under FreeBSD (x86), here is how I do:

Code: Select all

.intel_syntax

.bss
.comm rlimit_t,16,8

[...]
push rlimit_t
push 0x02
mov eax, 0xc2
push eax
int 0x80
[...]
But after debugging, the structure rlimit_t is empty.
So, what is wrong ? Need I use the stack instead of the data section ? Or whatever ?

Re: Syscall getrlimit

Posted: Thu Aug 12, 2010 2:54 pm
by 0000
Damn it. I tried different way and nothing works... I tried to have similar code from libc.

Here is the getrlimit function from the libc:

Code: Select all

[...]
0x0804845f <main+15>:	sub    esp,0x30
0x08048462 <main+18>:	lea    eax,[ebp-24]
0x08048465 <main+21>:	mov    DWORD PTR [esp+4],eax
0x08048469 <main+25>:	mov    DWORD PTR [esp],0x2
0x08048470 <main+32>:	call   0x8048314 <_init+84>
[...]
(gdb) disass getrlimit
Dump of assembler code for function getrlimit:
0x28125180 <getrlimit+0>:	mov    eax,0xc2
0x28125185 <getrlimit+5>:	int    0x80
0x28125187 <getrlimit+7>:	jb     0x2812516c <sl_init+108>
0x28125189 <getrlimit+9>:	ret  
And here is my program:

Code: Select all

.intel_syntax noprefix
.global _start

.text
_start:
	mov ebp,esp
	sub esp, 0x30
	lea eax,dword ptr [ebp-24]
	mov dword ptr [esp+4],eax
	mov dword ptr [esp], 0x02
	mov eax, 194
	int 0x80

	mov eax, 0x01
	int 0x80
Debugging and looking at the stack:

Code: Select all

(gdb) info reg 
[...]
esp            0xbfbfe6b4       0xbfbfe6b4
ebp            0xbfbfe6e4       0xbfbfe6e4
[...]
(gdb) x/2gx 0xbfbfe6e4-24
0xbfbfe6cc:     0x0000000000000000      0x0000000000000000
(gdb)  
So, what a hell is wrong ?