You can use the dot product of a world up vector with an up vector relative to the player. If both of these vectors are normalized, you're results will be between 1 and -1. With 2d vectors the dot product is calculated by taking the product of the x components and adding them to the product of the y components.
Given the vectors
A = (x,y) and
B = (X,Y). The dot product is
x*X + y*Y. So, if the world up vector is (0, 1), we can see that:
if player up vector is (0, 1), then the dot product of the up vectors is 0*0 + 1*1 = 1, and, if the player up vector is (0, -1), then the dot product is 0*0 + -1*1 = -1. This tells us the player is upside down. If the player is standing on the side of a wall (1, 0), perpendicular to the world up vector. Then the dot product is 1*0 + 0*1 = 0.
So, to recap, if the dot product is 1, the player is up right, as the dot product approaches 0, the player becomes more and more perpendicular to the world, and is perpendicular with the result is 0. As the dot product turns negative, then player's head starts angling towards the ground, and the player is completely upside down when the dot product is -1.