Skip to content

Commit a6f05a6

Browse files
author
H. Peter Anvin
committed
x86-64: make compat_start_thread() match start_thread()
For no real good reason, compat_start_thread() was embedded inline in <asm/elf.h> whereas the native start_thread() lives in process_*.c. Move compat_start_thread() to process_64.c, remove gratuitious differences, and fix a few items which mostly look like bit rot. In particular, compat_start_thread() didn't do free_thread_xstate(), which means it was hanging on to the xstate store area even when it was not needed. It was also not setting old_rsp, but it looks like that generally shouldn't matter for a 32-bit process. Note: compat_start_thread *has* to be a macro, since it is tested with start_thread_ia32() as the out of line function name. Signed-off-by: H. Peter Anvin <hpa@zytor.com> Acked-by: Suresh Siddha <suresh.b.siddha@intel.com>
1 parent 36a0790 commit a6f05a6

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

arch/x86/include/asm/elf.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,6 @@ do { \
157157

158158
#define compat_elf_check_arch(x) elf_check_arch_ia32(x)
159159

160-
static inline void start_ia32_thread(struct pt_regs *regs, u32 ip, u32 sp)
161-
{
162-
loadsegment(fs, 0);
163-
loadsegment(ds, __USER32_DS);
164-
loadsegment(es, __USER32_DS);
165-
load_gs_index(0);
166-
regs->ip = ip;
167-
regs->sp = sp;
168-
regs->flags = X86_EFLAGS_IF;
169-
regs->cs = __USER32_CS;
170-
regs->ss = __USER32_DS;
171-
}
172-
173160
static inline void elf_common_init(struct thread_struct *t,
174161
struct pt_regs *regs, const u16 ds)
175162
{
@@ -191,11 +178,8 @@ do { \
191178
#define COMPAT_ELF_PLAT_INIT(regs, load_addr) \
192179
elf_common_init(&current->thread, regs, __USER_DS)
193180

194-
#define compat_start_thread(regs, ip, sp) \
195-
do { \
196-
start_ia32_thread(regs, ip, sp); \
197-
set_fs(USER_DS); \
198-
} while (0)
181+
void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp);
182+
#define compat_start_thread start_thread_ia32
199183

200184
#define COMPAT_SET_PERSONALITY(ex) \
201185
do { \

arch/x86/kernel/process_64.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
356356
percpu_write(old_rsp, new_sp);
357357
regs->cs = __USER_CS;
358358
regs->ss = __USER_DS;
359-
regs->flags = 0x200;
359+
regs->flags = X86_EFLAGS_IF;
360360
set_fs(USER_DS);
361361
/*
362362
* Free the old FP and other extended state
@@ -365,6 +365,27 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
365365
}
366366
EXPORT_SYMBOL_GPL(start_thread);
367367

368+
#ifdef CONFIG_IA32_EMULATION
369+
void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
370+
{
371+
loadsegment(fs, 0);
372+
loadsegment(ds, __USER32_DS);
373+
loadsegment(es, __USER32_DS);
374+
load_gs_index(0);
375+
regs->ip = new_ip;
376+
regs->sp = new_sp;
377+
percpu_write(old_rsp, new_sp);
378+
regs->cs = __USER32_CS;
379+
regs->ss = __USER32_DS;
380+
regs->flags = X86_EFLAGS_IF;
381+
set_fs(USER_DS);
382+
/*
383+
* Free the old FP and other extended state
384+
*/
385+
free_thread_xstate(current);
386+
}
387+
#endif
388+
368389
/*
369390
* switch_to(x,y) should switch tasks from x to y.
370391
*

0 commit comments

Comments
 (0)