Silicon photonic integrated circuits allow very efficient manipulation of light in a compact size but suffer from strong dependence on temperature variations and fabrication tolerances. Local stabilization of the working point of each photonic device in a circuit is thus needed, made possible by integrated sensors and actuators that are operated by an external electronic controller. However, this approach is what currently limits the scaling of photonic complexity to few tens of devices, due to practical limitations in the number of connections between the chip and the control electronics. Monolithic integration of electronic functionalities into the photonic systems is therefore essential to enable new sophisticated architectures, but it requires to fully preserve the optical quality. Here we demonstrate the possibility of fabricating CMOS integrated electronic circuits on a technological platform specifically conceived and optimized only for photonic devices. By exploiting the silicon waveguide layer and with zero changes to the photonic process flow, fully functional MOS transistors have been integrated on the side walls of the waveguide layer, showing a threshold voltage of 1.84 V, a gain factor of 4 μA/V^2, an Early voltage of 35 V and an inverse subthreshold slope of 250 mV/dec. By combining digital gates and analog switches, we demonstrate the operation of an analog multiplexer integrated into a 16-to-1 optical router to sequentially read 16 on-chip photodetectors with only one connection towards the external electronics. This enables time-multiplexed closed-loop control and stabilization of the router to thermal instabilities with less than 10 ms transient time and a power penalty of just 0.3 dB on the transmission of 10 Gb/s modulated signals. We envision that this first example of co-integrated electronic layer to support the optics and counteract its weaknesses can definitely unleash the full potential of the photonic technology towards a new realm of innovative architectures and applications.