@@ -143,55 +143,41 @@ int kpatch_process_mem_iter_peek_ulong(struct process_mem_iter *iter,
143
143
return kpatch_process_mem_iter_peek (iter , dst , sizeof (* dst ), remote_addr );
144
144
}
145
145
146
- /* FIXME(pboldin): read these from /proc/pid/auxv */
147
146
int kpatch_ptrace_get_entry_point (struct kpatch_ptrace_ctx * pctx ,
148
147
unsigned long * pentry_point )
149
148
{
150
- int ret ;
151
- unsigned long * rstack , val ;
152
- struct user_regs_struct regs ;
153
- struct process_mem_iter * iter ;
149
+ int fd , ret ;
150
+ unsigned long entry [2 ] = { AT_NULL , 0 };
151
+ char path [sizeof ("/proc/0123456789/auxv" )];
154
152
155
153
kpdebug ("Looking for entry point..." );
156
154
157
- ret = ptrace (PTRACE_GETREGS , pctx -> pid , NULL , & regs );
158
- if (ret < 0 ) {
159
- kplogerror ("can't get regs\n" );
160
- return -1 ;
161
- }
162
-
163
- iter = kpatch_process_mem_iter_init (pctx -> proc );
164
- if (!iter ) {
165
- kplogerror ("can't allocate iterator\n" );
155
+ sprintf (path , "/proc/%d/auxv" , pctx -> pid );
156
+ fd = open (path , O_RDONLY );
157
+ if (fd == -1 ) {
158
+ kplogerror ("can't open %s\n" , path );
166
159
return -1 ;
167
160
}
168
161
169
- /* Read stack and look for AUX data */
170
- rstack = (unsigned long * )regs .rsp ;
171
-
172
- /* rstack now points to envs */
173
- rstack += PEEK_ULONG (rstack ) + 2 ;
174
-
175
- /* Skip envs */
176
- for (; PEEK_ULONG (rstack ); rstack ++ )
177
- continue ;
162
+ do {
163
+ ret = read (fd , entry , sizeof (entry ));
164
+ if (ret < 0 && errno == EINTR )
165
+ continue ;
166
+ if (ret != sizeof (entry ))
167
+ break ;
178
168
179
- /* Now got to AUX */
180
- for (rstack ++ ; (val = PEEK_ULONG (rstack )) != AT_NULL ; rstack += 2 ) {
181
- if (val == AT_ENTRY ) {
182
- * pentry_point = PEEK_ULONG (rstack + 1 );
169
+ if (entry [0 ] == AT_ENTRY ) {
170
+ * pentry_point = entry [1 ];
183
171
break ;
184
172
}
185
- }
173
+ } while ( 1 );
186
174
187
- if (val != AT_ENTRY )
188
- kpdebug ("FAIL\n" );
189
- else
190
- kpdebug ("OK\n" );
175
+ if (ret < 0 )
176
+ kplogerror ("reading %s\n" , path );
191
177
192
- kpatch_process_mem_iter_free ( iter );
178
+ close ( fd );
193
179
194
- return val == AT_ENTRY ? 0 : -1 ;
180
+ return entry [ 0 ] == AT_ENTRY ? 0 : -1 ;
195
181
}
196
182
197
183
#define BREAK_INSN_LENGTH 1
0 commit comments