clarify the purpose of this project
[nyanglibc.git] / misc / getusershell.s
blob06238bda548393f7949d625178ba1a1a449189c0
1 .text
2 .section .rodata.str1.1,"aMS",@progbits,1
3 .LC0:
4 .string "rce"
5 .LC1:
6 .string "/etc/shells"
7 .LC2:
8 .string "/bin/sh"
9 .LC3:
10 .string "/bin/csh"
11 .text
12 .p2align 4,,15
13 .type initshells, @function
14 initshells:
15 pushq %r13
16 pushq %r12
17 pushq %rbp
18 pushq %rbx
19 subq $152, %rsp
20 movq shells(%rip), %rdi
21 call free@PLT
22 movq strings(%rip), %rdi
23 movq $0, shells(%rip)
24 call free@PLT
25 leaq .LC0(%rip), %rsi
26 leaq .LC1(%rip), %rdi
27 movq $0, strings(%rip)
28 call _IO_new_fopen@PLT
29 testq %rax, %rax
30 je .L2
31 movq %rax, %rdi
32 movq %rax, %rbp
33 call fileno
34 movq %rsp, %rsi
35 movl %eax, %edi
36 call __fstat64
37 cmpl $-1, %eax
38 je .L4
39 movq 48(%rsp), %r13
40 movabsq $6917529027641081853, %rax
41 cmpq %rax, %r13
42 jbe .L55
43 .L4:
44 movq %rbp, %rdi
45 call _IO_new_fclose@PLT
46 .L2:
47 leaq .LC2(%rip), %rax
48 movq %rax, okshells(%rip)
49 leaq .LC3(%rip), %rax
50 movq %rax, 8+okshells(%rip)
51 leaq okshells(%rip), %rax
52 .L1:
53 addq $152, %rsp
54 popq %rbx
55 popq %rbp
56 popq %r12
57 popq %r13
58 ret
59 .p2align 4,,10
60 .p2align 3
61 .L55:
62 leaq 3(%r13), %r12
63 movq %r12, %rdi
64 call malloc@PLT
65 testq %rax, %rax
66 movq %rax, %rbx
67 movq %rax, strings(%rip)
68 je .L4
69 movq %r13, %rax
70 movabsq $6148914691236517206, %rdx
71 sarq $63, %r13
72 imulq %rdx
73 subq %r13, %rdx
74 leaq 0(,%rdx,8), %rdi
75 call malloc@PLT
76 testq %rax, %rax
77 movq %rax, %r13
78 movq %rax, shells(%rip)
79 je .L7
80 movq %rbx, %rax
81 .p2align 4,,10
82 .p2align 3
83 .L8:
84 movq %rbx, %rcx
85 movl %r12d, %esi
86 movq %rbp, %rdx
87 subq %rax, %rcx
88 movq %rbx, %rdi
89 subl %ecx, %esi
90 call fgets_unlocked
91 testq %rax, %rax
92 je .L14
93 movzbl (%rbx), %eax
94 cmpb $35, %al
95 jne .L53
96 jmp .L9
97 .p2align 4,,10
98 .p2align 3
99 .L10:
100 addq $1, %rbx
101 movzbl (%rbx), %eax
102 cmpb $35, %al
103 je .L9
104 .L53:
105 cmpb $47, %al
106 je .L9
107 testb %al, %al
108 jne .L10
109 .L11:
110 movq strings(%rip), %rax
111 jmp .L8
112 .p2align 4,,10
113 .p2align 3
114 .L9:
115 cmpb $35, %al
116 je .L11
117 testb %al, %al
118 je .L11
119 movzbl 1(%rbx), %eax
120 testb %al, %al
121 je .L11
122 movq __libc_tsd_CTYPE_B@gottpoff(%rip), %rdx
123 movsbq (%rbx), %rdi
124 leaq 8(%r13), %rsi
125 movq %rbx, 0(%r13)
126 movq %fs:(%rdx), %rcx
127 movq %rdi, %rdx
128 testb $32, 1(%rcx,%rdi,2)
129 jne .L12
130 testb %dil, %dil
131 setne %dil
132 cmpb $35, %dl
133 setne %dl
134 testb %dl, %dil
135 jne .L13
136 jmp .L12
137 .p2align 4,,10
138 .p2align 3
139 .L56:
140 cmpb $35, %al
141 setne %dl
142 testb %al, %al
143 setne %al
144 testb %al, %dl
145 je .L12
146 movzbl 1(%rbx), %eax
147 .L13:
148 movsbq %al, %rdx
149 addq $1, %rbx
150 testb $32, 1(%rcx,%rdx,2)
151 je .L56
152 .L12:
153 movb $0, (%rbx)
154 movq %rsi, %r13
155 addq $1, %rbx
156 movq strings(%rip), %rax
157 jmp .L8
158 .p2align 4,,10
159 .p2align 3
160 .L14:
161 movq $0, 0(%r13)
162 movq %rbp, %rdi
163 call _IO_new_fclose@PLT
164 movq shells(%rip), %rax
165 jmp .L1
166 .L7:
167 movq %rbx, %rdi
168 call free@PLT
169 movq $0, strings(%rip)
170 jmp .L4
171 .size initshells, .-initshells
172 .p2align 4,,15
173 .globl getusershell
174 .type getusershell, @function
175 getusershell:
176 movq curshell(%rip), %rdx
177 testq %rdx, %rdx
178 je .L69
179 movq (%rdx), %rax
180 testq %rax, %rax
181 je .L66
182 addq $8, %rdx
183 movq %rdx, curshell(%rip)
185 .p2align 4,,10
186 .p2align 3
187 .L66:
188 rep ret
189 .p2align 4,,10
190 .p2align 3
191 .L69:
192 subq $8, %rsp
193 call initshells
194 movq %rax, %rdx
195 movq %rax, curshell(%rip)
196 movq (%rax), %rax
197 testq %rax, %rax
198 je .L57
199 addq $8, %rdx
200 movq %rdx, curshell(%rip)
201 .L57:
202 addq $8, %rsp
204 .size getusershell, .-getusershell
205 .p2align 4,,15
206 .globl endusershell
207 .type endusershell, @function
208 endusershell:
209 subq $8, %rsp
210 movq shells(%rip), %rdi
211 call free@PLT
212 movq strings(%rip), %rdi
213 movq $0, shells(%rip)
214 call free@PLT
215 movq $0, strings(%rip)
216 movq $0, curshell(%rip)
217 addq $8, %rsp
219 .size endusershell, .-endusershell
220 .p2align 4,,15
221 .globl setusershell
222 .type setusershell, @function
223 setusershell:
224 subq $8, %rsp
225 call initshells
226 movq %rax, curshell(%rip)
227 addq $8, %rsp
229 .size setusershell, .-setusershell
230 .local strings
231 .comm strings,8,8
232 .local shells
233 .comm shells,8,8
234 .local curshell
235 .comm curshell,8,8
236 .local okshells
237 .comm okshells,24,16
238 .hidden fgets_unlocked
239 .hidden __fstat64
240 .hidden fileno