@@ -143,55 +143,41 @@ int kpatch_process_mem_iter_peek_ulong(struct process_mem_iter *iter,
143143 return kpatch_process_mem_iter_peek (iter , dst , sizeof (* dst ), remote_addr );
144144}
145145
146- /* FIXME(pboldin): read these from /proc/pid/auxv */
147146int kpatch_ptrace_get_entry_point (struct kpatch_ptrace_ctx * pctx ,
148147 unsigned long * pentry_point )
149148{
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" )];
154152
155153 kpdebug ("Looking for entry point..." );
156154
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 );
166159 return -1 ;
167160 }
168161
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 ;
178168
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 ];
183171 break ;
184172 }
185- }
173+ } while ( 1 );
186174
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 );
191177
192- kpatch_process_mem_iter_free ( iter );
178+ close ( fd );
193179
194- return val == AT_ENTRY ? 0 : -1 ;
180+ return entry [ 0 ] == AT_ENTRY ? 0 : -1 ;
195181}
196182
197183#define BREAK_INSN_LENGTH 1
0 commit comments