ps_strings refactoring compat32 fix

2011-03-02 Thread Joerg Sonnenberger
Hi all,
all programs get the argument and environment placed onto the initial
stack in a structure called ps_strings. NetBSD currently doesn't export
the correct version of this structure for 32bit binaries as in it
doesn't use the 32bit version of it. This breaks setproctitle(3) and
other users of it. The attached patch refactors the access in procfs and
kern.proc as well as making it honour 32bit. The Darwin code likely is
still broken, if someone wants to use that, it should be easy to adopt
the changes from copyin_procargs.

Also attached are two programs to test the consistency of the structure
and updating it (so that ps(1) can be used to ensure it works), but I
will leave it to someone with more interest in atf(7) to turn them into
full test cases.

Joerg
Index: src/sys/arch/alpha/alpha/machdep.c
===
--- src/sys/arch/alpha/alpha/machdep.c
+++ src/sys/arch/alpha/alpha/machdep.c
@@ -1617,11 +1617,11 @@
 	tfp-tf_regs[FRAME_PC] = pack-ep_entry  ~3;
 
 	tfp-tf_regs[FRAME_A0] = stack;			/* a0 = sp */
 	tfp-tf_regs[FRAME_A1] = 0;			/* a1 = rtld cleanup */
 	tfp-tf_regs[FRAME_A2] = 0;			/* a2 = rtld object */
-	tfp-tf_regs[FRAME_A3] = (u_int64_t)l-l_proc-p_psstr;	/* a3 = ps_strings */
+	tfp-tf_regs[FRAME_A3] = l-l_proc-p_psstrp;	/* a3 = ps_strings */
 	tfp-tf_regs[FRAME_T12] = tfp-tf_regs[FRAME_PC];	/* a.k.a. PV */
 
 	l-l_md.md_flags = ~MDP_FPUSED;
 	if (__predict_true((l-l_md.md_flags  IEEE_INHERIT) == 0)) {
 		l-l_md.md_flags = ~MDP_FP_C;

Index: src/sys/arch/amd64/amd64/machdep.c
===
--- src/sys/arch/amd64/amd64/machdep.c
+++ src/sys/arch/amd64/amd64/machdep.c
@@ -1032,11 +1032,11 @@
 	tf-tf_es = LSEL(LUDATA_SEL, SEL_UPL);
 	cpu_fsgs_zero(l);
 	tf-tf_rdi = 0;
 	tf-tf_rsi = 0;
 	tf-tf_rbp = 0;
-	tf-tf_rbx = (uint64_t)l-l_proc-p_psstr;
+	tf-tf_rbx = l-l_proc-p_psstrp;
 	tf-tf_rdx = 0;
 	tf-tf_rcx = 0;
 	tf-tf_rax = 0;
 	tf-tf_rip = pack-ep_entry;
 	tf-tf_cs = LSEL(LUCODE_SEL, SEL_UPL);

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
===
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c
@@ -159,11 +159,11 @@
 	cpu_fsgs_zero(l);
 	cpu_fsgs_reload(l, tf-tf_ds, tf-tf_es);
 	tf-tf_rdi = 0;
 	tf-tf_rsi = 0;
 	tf-tf_rbp = 0;
-	tf-tf_rbx = (uint64_t)p-p_psstr;
+	tf-tf_rbx = (uint32_t)p-p_psstrp;
 	tf-tf_rdx = 0;
 	tf-tf_rcx = 0;
 	tf-tf_rax = 0;
 	tf-tf_rip = pack-ep_entry;
 	tf-tf_cs = LSEL(LUCODE32_SEL, SEL_UPL);

Index: src/sys/arch/amiga/amiga/machdep.c
===
--- src/sys/arch/amiga/amiga/machdep.c
+++ src/sys/arch/amiga/amiga/machdep.c
@@ -301,11 +301,11 @@
 	frame-f_regs[D5] = 0;
 	frame-f_regs[D6] = 0;
 	frame-f_regs[D7] = 0;
 	frame-f_regs[A0] = 0;
 	frame-f_regs[A1] = 0;
-	frame-f_regs[A2] = (int)l-l_proc-p_psstr;
+	frame-f_regs[A2] = l-l_proc-p_psstrp;
 	frame-f_regs[A3] = 0;
 	frame-f_regs[A4] = 0;
 	frame-f_regs[A5] = 0;
 	frame-f_regs[A6] = 0;
 	frame-f_regs[SP] = stack;

Index: src/sys/arch/arm/arm/arm_machdep.c
===
--- src/sys/arch/arm/arm/arm_machdep.c
+++ src/sys/arch/arm/arm/arm_machdep.c
@@ -153,11 +153,11 @@
 
 	pcb = lwp_getpcb(l);
 	tf = pcb-pcb_tf;
 
 	memset(tf, 0, sizeof(*tf));
-	tf-tf_r0 = (u_int)l-l_proc-p_psstr;
+	tf-tf_r0 = l-l_proc-p_psstrp;
 	tf-tf_r12 = stack;			/* needed by pre 1.4 crt0.c */
 	tf-tf_usr_sp = stack;
 	tf-tf_usr_lr = pack-ep_entry;
 	tf-tf_svc_lr = 0x;		/* Something we can see */
 	tf-tf_pc = pack-ep_entry;

Index: src/sys/arch/atari/atari/machdep.c
===
--- src/sys/arch/atari/atari/machdep.c
+++ src/sys/arch/atari/atari/machdep.c
@@ -250,11 +250,11 @@
 	frame-f_regs[D5] = 0;
 	frame-f_regs[D6] = 0;
 	frame-f_regs[D7] = 0;
 	frame-f_regs[A0] = 0;
 	frame-f_regs[A1] = 0;
-	frame-f_regs[A2] = (int)l-l_proc-p_psstr;
+	frame-f_regs[A2] = l-l_proc-p_psstrp;
 	frame-f_regs[A3] = 0;
 	frame-f_regs[A4] = 0;
 	frame-f_regs[A5] = 0;
 	frame-f_regs[A6] = 0;
 	frame-f_regs[SP] = stack;

Index: src/sys/arch/cesfic/cesfic/machdep.c
===
--- src/sys/arch/cesfic/cesfic/machdep.c
+++ src/sys/arch/cesfic/cesfic/machdep.c
@@ -299,11 +299,11 @@
 	frame-f_regs[D5] = 0;
 	frame-f_regs[D6] = 0;
 	frame-f_regs[D7] = 0;
 	frame-f_regs[A0] = 0;
 	frame-f_regs[A1] = 0;
-	frame-f_regs[A2] = (int)l-l_proc-p_psstr;
+	frame-f_regs[A2] = l-l_proc-p_psstrp;
 	frame-f_regs[A3] = 0;
 	frame-f_regs[A4] = 0;
 	frame-f_regs[A5] = 0;
 	frame-f_regs[A6] = 0;
 	frame-f_regs[SP] = stack;

Index: src/sys/arch/hp300/hp300/machdep.c
===
--- src/sys/arch/hp300/hp300/machdep.c
+++ src/sys/arch/hp300/hp300/machdep.c
@@ -359,11 +359,11 @@
 	frame-f_regs[D5] = 

Re: ps_strings refactoring compat32 fix

2011-03-02 Thread Paul Goyette

On Wed, 2 Mar 2011, Joerg Sonnenberger wrote:


Hi all,
all programs get the argument and environment placed onto the initial
stack in a structure called ps_strings. NetBSD currently doesn't export
the correct version of this structure for 32bit binaries as in it
doesn't use the 32bit version of it. This breaks setproctitle(3) and
other users of it. The attached patch refactors the access in procfs and
kern.proc as well as making it honour 32bit. The Darwin code likely is
still broken, if someone wants to use that, it should be easy to adopt
the changes from copyin_procargs.

Also attached are two programs to test the consistency of the structure
and updating it (so that ps(1) can be used to ensure it works), but I
will leave it to someone with more interest in atf(7) to turn them into
full test cases.


If the patch gets committed, I'll take on the job of atf-ifying the 
tests.



-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-