| Thread Synch AOSV 2020
    1.2
    LKM for exchanging messages between threads | 
 
 
 
Go to the documentation of this file.
   11 #include <linux/module.h>    
   12 #include <linux/kernel.h>    
   14 #include <linux/cdev.h>      
   15 #include <linux/device.h>    
   16 #include <linux/slab.h>      
   17 #include <linux/uaccess.h>   
   18 #include <linux/semaphore.h>     
   20 #include <linux/ioctl.h> 
   21 #include <linux/string.h>        
   23 #include <linux/idr.h> 
   24 #include <linux/errno.h> 
   25 #include <linux/cred.h>     
   33 #define INVALID_IOCTL_COMMAND   -1 
   35 #define MEM_ACCESS_ERR          -5 
   36 #define CLASS_EXISTS            -10 
   38 #define DEV_CREATION_ERR        -12 
   39 #define CDEV_ALLOC_ERR          -13 
   40 #define EMPTY_LIST              -20 
   41 #define NODE_NOT_FOUND          -21 
   42 #define CHDEV_ALLOC_ERR         -22 
   47 #define GROUP_MAX_MINORS    255 
   48 #define DEVICE_NAME_SIZE    64 
   50 #define DEFAULT_MSG_SIZE 256 
   51 #define DEFAULT_STORAGE_SIZE 1024 
   55 #define IOCTL_GET_GROUP_DESC _IOR('Q', 1, group_t*) 
   56 #define IOCTL_SET_STRICT_MODE _IOW('Q', 101, bool) 
   57 #define IOCTL_CHANGE_OWNER _IOW('Q', 102, uid_t) 
   60 #ifndef DISABLE_DELAYED_MSG 
   62     #define IOCTL_SET_SEND_DELAY _IOW('Y', 0, long) 
   63     #define IOCTL_REVOKE_DELAYED_MESSAGES _IO('Y', 1) 
   64     #define IOCTL_CANCEL_DELAY _IO('Y', 2) 
   68 #ifndef DISABLE_THREAD_BARRIER 
   70     #define IOCTL_SLEEP_ON_BARRIER _IO('Z', 0) 
   71     #define IOCTL_AWAKE_BARRIER _IO('Z', 1) 
   79 #define GROUP_CLASS_NAME "group_synch" 
   83 static int openGroup(
struct inode *inode, 
struct file *file);
 
   84 static int releaseGroup(
struct inode *inode, 
struct file *file);
 
   85 static ssize_t readGroupMessage(
struct file *file, 
char __user *user_buffer, 
size_t size, loff_t *offset);
 
   86 static ssize_t writeGroupMessage(
struct file *filep, 
const char __user *buf, 
size_t count, loff_t *f_pos);
 
   87 static long int groupIoctl(
struct file *filep, 
unsigned int ioctl_num, 
unsigned long ioctl_param);
 
   88 static int flushGroupMessage(
struct file *filep, fl_owner_t 
id);
 
   94 static struct file_operations group_operation = {
 
   97     .read = readGroupMessage,
 
   98     .write = writeGroupMessage,
 
   99     .release = releaseGroup,
 
  100     .flush = flushGroupMessage,
 
  101     .unlocked_ioctl = groupIoctl
 
  105 extern struct class *group_device_class;
 
  
void unregisterGroupDevice(group_data *grp_data, bool flag)
unregister a group device
Definition: group_manager.c:362
int openGroup(thread_group_t *group)
Open a group, the thread PID is added to group's active members.
Definition: thread_synch.c:404
void initParticipants(group_data *grp_data)
Initialize group_data participants' structures.
Definition: group_manager.c:220
int copy_group_t_from_user(__user group_t *user_group, group_t *kern_group)
Copy a 'group_t' structure to kernel space.
Definition: group_manager.c:889
Group device data structure.
Definition: types.h:207
int registerGroupDevice(group_data *grp_data, struct device *parent)
register a group device
Definition: group_manager.c:271
Handles all procedures releated to messages of a group device.
int installGroupClass(void)
Install the global 'group_device_class'.
Definition: group_manager.c:19
System-wide descriptor of a group.
Definition: types.h:139