📄 rtai_shm.h
字号:
/*COPYRIGHT (C) 1999 Paolo Mantegazza (mantegazza@aero.polimi.it)This library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.*/#define REAL_SIZE(x) (((x) - 1) & PAGE_MASK) + PAGE_SIZEextern void *rtai_kmalloc_f(int name, int size, unsigned long pid);#define rtai_kmalloc(x, y) rtai_kmalloc_f((x), (y), (unsigned long)(&(__this_module)));extern void rtai_kfree_f(int name, unsigned long pid);#define rtai_kfree(x) rtai_kfree_f((x), (unsigned long)(&(__this_module)));static inline unsigned long nam2num(const char *name){ int i = 0; union { struct { long num; char eos; } num; char name[5]; } retval; if (!name[0]) { return 0x454e4f4e; // "NULL" } retval.num.eos = 0; while (i < 4 && (retval.name[i] = name[i])) { i++; } return retval.num.num;}static inline void num2nam(unsigned long num, char *name){ int i = 0; union { struct { long num; char eos; } num; char name[5]; } retval; retval.num.num = num; retval.num.eos = 0; while (i < 4 && (name[i] = retval.name[i])) { i++; }}#ifndef MODULE#include <asm/page.h>static void *rtai_malloc(unsigned long name, int size){ void *adr; int hook; struct { unsigned long name, size; } arg; if (size <= 0) { return 0; } if ((hook = open("/dev/rtai_shm", O_RDWR)) < 0) { return 0; } arg.name = name; arg.size = size; if (!(size = ioctl(hook, 1, (unsigned long)(&arg)))) { return 0; } adr = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED|MAP_FILE, hook, 0);// the if-else below is just for testing { if ((size = ioctl(hook, 4, name)) < 0) { printf("REAL ALLOCATION OF %d BYTES FOR %lx.\n", -size, name); } else { printf("JUST A REMAP OF %d BYTES FOR %lx.\n", size, name); } } close(hook); return adr;}static inline void rtai_free(int name, void *adr){ int size, hook; if ((size = ioctl(hook = open("/dev/rtai_shm", O_RDWR), 2, name))) {// the if-else below is just for testing { int lsize; if ((lsize = ioctl(hook, 4, name)) < 0) { printf("FREED %d BYTES OF %lx.\n", -lsize, name); } else { printf("UNMAPPED %d BYTES OF %lx.\n", lsize, name); } } munmap(adr, size); ioctl(hook, 3, name); } close(hook);}// all what's below is just for testingstatic inline void rtai_check(unsigned long name){ int hook; ioctl(hook = open("/dev/rtai_shm", O_RDWR), 5, name); close(hook);}static inline int rtai_is_closable(void){ int hook, retval; retval = ioctl(hook = open("/dev/rtai_shm", O_RDWR), 6, 0); close(hook); return retval;}static inline void rtai_make_closable(void){ int hook; ioctl(hook = open("/dev/rtai_shm", O_RDWR), 7, 0); close(hook);}static inline void rtai_not_closable(void){ int hook; ioctl(hook = open("/dev/rtai_shm", O_RDWR), 8, 0); close(hook);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -