Every person imprisoned or restrained of his liberty within this State, for any criminal or supposed criminal matter, or on any pretense whatsoever, except in cases specified in G.S. 17-4, may prosecute a writ of habeas corpus, according to the provisions of this Chapter, to inquire into the cause of such imprisonment or restraint, and, if illegal, to be delivered therefrom.
N.C. Gen. Stat. § 17-3