Thread Synch AOSV 2020  1.2
LKM for exchanging messages between threads
group_manager.h
Go to the documentation of this file.
1 
7 #ifndef GRP_MAN_H
8 #define GRP_MAN_H
9 
10 
11 #include <linux/module.h> /* MODULE_*, module_* */
12 #include <linux/kernel.h> /* We're doing kernel work */
13 #include <linux/fs.h> /* file_operations, alloc_chrdev_region, unregister_chrdev_region */
14 #include <linux/cdev.h> /* cdev, dev_init(), cdev_add(), cdev_del() */
15 #include <linux/device.h> /* class_create(), class_destroy(), device_create(), device_destroy() */
16 #include <linux/slab.h> /* kmalloc(), kfree() */
17 #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
18 #include <linux/semaphore.h> /* used acces to semaphore, process management syncronization behaviour */
19 
20 #include <linux/ioctl.h>
21 #include <linux/string.h> //For snprintf
22 
23 #include <linux/idr.h>
24 #include <linux/errno.h>
25 #include <linux/cred.h> //For current_uid()
26 
27 
28 #include "message.h"
29 
30 /*------------------------------------------------------------------------------
31  Error Codes
32 ------------------------------------------------------------------------------*/
33 #define INVALID_IOCTL_COMMAND -1
34 #define ALLOC_ERR -2
35 #define MEM_ACCESS_ERR -5
36 #define CLASS_EXISTS -10
37 #define CLASS_ERR -11
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
43 
44 
45 
46 
47 #define GROUP_MAX_MINORS 255
48 #define DEVICE_NAME_SIZE 64
49 
50 #define DEFAULT_MSG_SIZE 256
51 #define DEFAULT_STORAGE_SIZE 1024
52 
53 //IOCTLS
54 
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)
58 
59 
60 #ifndef DISABLE_DELAYED_MSG
61 
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)
65 
66 #endif
67 
68 #ifndef DISABLE_THREAD_BARRIER
69 
70  #define IOCTL_SLEEP_ON_BARRIER _IO('Z', 0)
71  #define IOCTL_AWAKE_BARRIER _IO('Z', 1)
72 
73 #endif
74 
75 
76 
77 
78 
79 #define GROUP_CLASS_NAME "group_synch"
80 
81 
82 
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);
89 
90 
91 inline void initParticipants(group_data *grp_data);
92 int installGroupClass(void);
93 
94 static struct file_operations group_operation = {
95  .owner = THIS_MODULE,
96  .open = openGroup,
97  .read = readGroupMessage,
98  .write = writeGroupMessage,
99  .release = releaseGroup,
100  .flush = flushGroupMessage,
101  .unlocked_ioctl = groupIoctl
102 };
103 
104 
105 extern struct class *group_device_class;
106 
107 int registerGroupDevice(group_data *grp_data, struct device* parent);
108 void unregisterGroupDevice(group_data *grp_data, bool flag);
109 int copy_group_t_from_user(__user group_t *user_group, group_t *kern_group);
110 
111 #endif //GRP_MAN_H
unregisterGroupDevice
void unregisterGroupDevice(group_data *grp_data, bool flag)
unregister a group device
Definition: group_manager.c:362
openGroup
int openGroup(thread_group_t *group)
Open a group, the thread PID is added to group's active members.
Definition: thread_synch.c:404
initParticipants
void initParticipants(group_data *grp_data)
Initialize group_data participants' structures.
Definition: group_manager.c:220
copy_group_t_from_user
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_data
Group device data structure.
Definition: types.h:207
registerGroupDevice
int registerGroupDevice(group_data *grp_data, struct device *parent)
register a group device
Definition: group_manager.c:271
message.h
Handles all procedures releated to messages of a group device.
installGroupClass
int installGroupClass(void)
Install the global 'group_device_class'.
Definition: group_manager.c:19
group_t
System-wide descriptor of a group.
Definition: types.h:139