The most direct way to disable and enable interrupts are:
asm volatile ("di"); /* Disable interrupts. */
asm volatile ("ei"); /* Enable interrupts. */
These are assembler instructions written as inline assembly in C.
They manipulate the general interrupt enable flag in
the system control coprocessor CP0 in the MIPS core.
The register containing this bit is named: 'Status' and may be watched in the debugger as a SFR register.
See PIC32 Family Reference Manual section 2:http://ww1.microchip.com/downloads/en/DeviceDoc/61113E.pdf
As far as I know, these interrupt disable and enable instructions are the same for MZ.
There are other differences described is another document for PIC32MZ.
If you disable and enable interrupts in general code with nested subroutines,
it is recommended to read the current state of the interrupt flag before changing it,
and restore it to what it was before:
unsigned int status = 0;
asm volatile("di %0" : "=r"(status)); /* This will get the current setting, and then disable interrupts */
/* Critical section of code ... */
asm volatile("ei %0" : "=r"(status)); /* Enable interrupts if enabled before. */
There also exists built in functions in XC32 compiler to handle these operations:
unsigned int saved_state;
/* Save current Interrupt Enable state and Disable Interrupts. */
saved_state = __builtin_get_isr_state();
/* Other code ... */
__builtin_set_isr_state(saved_state); /* Set back to what was before. */
See XC32 Compiler User's Guide.
Then in libraries like Harmony or Plib, there exists wrappers for these operations.