Theory of space-charge layers in narrow-gap semiconductors