Files
retrobsd/sys/kernel/kern_glob.c
Serge Vakulenko 585773955b Fix include paths in the kernel sources.
Max32 kernel successfully compiled with kconfig utility.
2015-08-31 00:21:41 -07:00

62 lines
1022 B
C

/*
* Global memory area system.
*
* Works with two system calls:
*
* byte = rdglob(addr);
* success = wrglob(addr,byte);
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/user.h>
#ifndef GLOBSZ
#define GLOBSZ 256
#endif
unsigned char global_segment[GLOBSZ];
void rdglob()
{
struct a {
int addr;
} *uap = (struct a *)u.u_arg;
// Only root should have access to the shared memory block
if(u.u_uid!=0)
{
u.u_rval = -1;
return;
}
if(uap->addr>=GLOBSZ)
{
u.u_rval = -1;
return;
}
u.u_rval = global_segment[uap->addr];
}
void wrglob()
{
struct a {
int addr;
unsigned char value;
} *uap = (struct a *)u.u_arg;
// Only root should have access to the shared memory block
if(u.u_uid!=0)
{
u.u_rval = -1;
return;
}
if(uap->addr>=GLOBSZ)
{
u.u_rval = -1;
return;
}
u.u_rval = 0;
global_segment[uap->addr] = uap->value;
}