Every person imprisoned or otherwise restrained of his liberty, except in the cases in the following section specified, may prosecute a writ of habeas corpus, according to the provisions of this chapter, to obtain relief from such imprisonment or restraint, if it proves to be unlawful.
NMS § 44-1-1