1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-04 22:53:08 +02:00

libubb/swuart.c: use mlockall to prevent page faults with interrupts off

This commit is contained in:
Werner Almesberger 2012-12-28 22:55:06 -03:00
parent 5487578ee7
commit e4f8b97e36

View File

@ -12,7 +12,9 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <ubb/ubb.h>
#include <ubb/regs4740.h>
@ -232,6 +234,15 @@ void swuart_clear_errors(void)
int swuart_open(uint32_t tx, uint32_t rx, int bps)
{
/*
* Make sure code and rx/tx buffers are locked into memory before we
* disable interrupts in swuart_trx.
*/
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
perror("mlockall");
return -1;
}
ticks = TCLK/bps-1;
tx_mask = tx;
rx_mask = rx;
@ -247,4 +258,6 @@ int swuart_open(uint32_t tx, uint32_t rx, int bps)
void swuart_close(void)
{
if (munlockall())
perror("munlockall");
}