Support of SPI Slave Mode has been in the Linux kernel from revision v4.13-rc1.
From SPI Documentation of Linux Kernel:
This document (and Linux) supports both the master and slave sides of SPI interactions.
[...]
A "struct spi_device" encapsulates the controller-side interface between those two types of drivers.
[...]
/sys/devices/.../CTLR/slave ... virtual file for (un)registering the slave device for an SPI slave controller.
Writing the driver name of an SPI slave handler to this file registers the slave device; writing "(null)" unregisters the slave device.
Reading from this file shows the name of the slave device ("(null)" if not registered).
/sys/class/spi_slave/spiB ... symlink (or actual device node) to a logical node which could hold class related state for the SPI slave controller on bus "B". When registered, a single spiB.* device is present here, possible sharing the physical SPI bus segment with other SPI slave devices.
I do not have any example C++/C code to support this off-hand.