Solution (source code)

= Solution

For constant density $\rho_c$,
$$
m(r)=\frac{4\pi}{3}\rho_cr^3,
\qquad
\frac{dP}{dr}=-\rho_c\frac{Gm(r)}{r^2}
=-\frac{4\pi G\rho_c^2}{3}r.
$$
Imposing $P(R_p)=0$ and using $g=GM_p/R_p^2=4\pi G\rho_cR_p/3$ gives
$$
\boxed{P(r)=\frac{2\pi G\rho_c^2}{3}(R_p^2-r^2)
=\frac12\rho_cgR_p
\left(1-\frac{r^2}{R_p^2}\right)}.
$$