Skip to content

Commit e42c575

Browse files
authored
Create LinuxAPI_16_limits.asm
1 parent 79b1bce commit e42c575

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

ASM_x86/LinuxAPI_16_limits.asm

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; Mess with a resource limit of process and fail resource usages using get and setlimit API Calls
2+
; API calls found in this example program:
3+
; getpriority, setpriority, write, exit
4+
; High level description of what theis example program does:
5+
; Get current open file handle limit values using getlimit()
6+
; Set the value to 0 (even 2 would be too low to open a new handle; because STDIN/OUT/ERR)
7+
; Try to open a new file handle (get error)
8+
9+
section .text
10+
global _start
11+
12+
_start:
13+
14+
; How many file handles can we have open? (I got 1024 when I ran this)
15+
;------------------------------------------------------------------------------
16+
mov eax, 76 ; getlimit()
17+
mov ebx, 7
18+
mov ecx, rlimit ; data structure for rusage
19+
int 0x80
20+
21+
; Set the limit to none #lol
22+
;------------------------------------------------------------------------------
23+
mov eax, 75 ; setlimit()
24+
mov ebx, 7
25+
mov ecx, cpusoft ; data structure for rusage
26+
int 0x80
27+
28+
; Try opening a file
29+
;------------------------------------------------------------------------------
30+
mov eax, 5 ;open
31+
mov ebx, newfile ;pointer to the filename
32+
mov ecx, 0 ;Flags, for Read Only
33+
int 0x80
34+
; If the file exists, the return value should be error code ...ffffffe8
35+
; which is: EMFILE (Too many open files)
36+
37+
; Exit
38+
;------------------------------------------------------------------------------
39+
mov eax, 1
40+
int 0x80
41+
42+
section .data
43+
cpusoft dd 0
44+
cpuhard dd 0
45+
newfile db 'LinuxAPI_16_limits.asm', 0x00
46+
47+
section .bss
48+
rlimit resb 8
49+
filehandle resb 4
50+
51+
; rlimit data structure
52+
;------------------------------------------------------------------------------
53+
; soft limit
54+
; hard limit
55+
56+
; Resource Codes
57+
;------------------------------------------------------------------------------
58+
; 0 - CPU CPU time (seconds)
59+
; 1 - FSIZE File size (bytes)
60+
; 2 - DATA Process data segment (bytes)
61+
; 3 - STACK Size of stack segment (bytes)
62+
; 4 - CORE Core file size (bytes)
63+
; 5 - RSS Resident set size (bytes; not implemented)
64+
; 6 - NPROC Number of processes for real user ID
65+
; 7 - NOFILE Maximum file descriptor number plus one
66+
; 8 - MEMLOCK Locked memory (bytes)
67+
; 9 - AS Process virtual memory size (bytes)
68+
; 10 - LOCKS Number of locks
69+
; 11 - SIGPENDING Number of queued signals for real user ID
70+
; 12 - MSGQUEUE Bytes allocated for POSIX message queues for real user ID
71+
; 13 - NICE Nice value
72+
; 14 - RTPRIO Realtime scheduling priority
73+
; 15 - RTTIME Realtime CPU time (microseconds)

0 commit comments

Comments
 (0)