EXCLUSIVE

Tupac's mother guarded his music and financial legacy in life, and TMZ has learned Afeni Shakur took extraordinary steps to do the same in death.

Afeni had set up a trust to control all of Tupac's music rights, and a rep for his estate tells us the paperwork is flawless. She also named the perfect executor, Tom Whalley -- former head of Warner Bros. Records -- to handle Tupac's valuable catalog.

We're told the trust is very specific about heirs, and the money is going to select charities and family. Afeni is survived by her sister, Gloria, and a daughter, Sekyiwa Shakur ... Tupac's half sister.

Her estranged husband, Gust Davis, is not mentioned in the trust -- so Tupac's money and music will be virtually untouchable in that divorce.