Thread Synch AOSV 2020  1.2
LKM for exchanging messages between threads
message.h
Go to the documentation of this file.
1 
7 #ifndef MSG_H
8 #define MSG_H
9 
10 #include <linux/init.h>
11 #include <linux/module.h> /* MODULE_*, module_* */
12 #include <linux/kernel.h> /* We're doing kernel work */
13 #include <linux/slab.h> /* kmalloc(), kfree() */
14 #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
15 #include <linux/semaphore.h> /* used acces to semaphore, process management syncronization behaviour */
16 #include <linux/proc_fs.h>
17 #include <linux/mutex.h>
18 #include <linux/spinlock.h>
19 #include <linux/atomic.h>
20 
21 
22 #include "types.h"
23 
24 
25 #define NO_MSG_PRESENT 0
26 #define ALLOC_ERR -2
27 #define USER_COPY_ERR -3
28 #define SEM_INIT_ERR -4
29 #define MSG_INVALID_FORMAT -11
30 #define MSG_SIZE_ERROR -12
31 #define MEMORY_ERROR -13
32 #define STORAGE_SIZE_ERR -14
33 #define ALLOC_ERR -2
34 #define CLASS_EXISTS -10
35 #define CLASS_ERR -11
36 #define DEV_CREATION_ERR -12
37 #define CDEV_ALLOC_ERR -13
38 #define EMPTY_LIST -20
39 #define NODE_NOT_FOUND -21
40 #define INVALID_IOCTL_COMMAND -1
41 #define CHDEV_ALLOC_ERR -22
42 
43 
44 
45 #define DEFAULT_GC_RATIO 3
46 
47 
48 
49 
50 
51 msg_manager_t *createMessageManager(const u_int _max_storage_size, const u_int _max_message_size, garbage_collector_t *garbageCollector);
52 
53 int writeMessage(msg_t *message, msg_manager_t *manager);
54 int readMessage(msg_t *dest_buffer, msg_manager_t *manager);
55 
56 int copy_msg_from_user(msg_t *kmsg, const char *umsg, const ssize_t _size);
57 int copy_msg_to_user(const msg_t *kmsg, __user char *ubuffer, const ssize_t _size);
58 
59 void queueGarbageCollector(struct work_struct *work);
60 
61 
62 #ifndef DISABLE_DELAYED_MSG
63  bool isDelaySet(const msg_manager_t *manager);
64  void delayedMessageCallback(struct timer_list *timer);
65  int queueDelayedMessage(msg_t *message, msg_manager_t *manager);
66  int revokeDelayedMessage(msg_manager_t *manager);
67  int cancelDelay(msg_manager_t *manager);
68 #endif
69 
70 
71 #endif //MSG_H
types.h
Defines all structures and global variables needed by the module.
readMessage
int readMessage(msg_t *dest_buffer, msg_manager_t *manager)
Read a message from the corresponding queue.
Definition: message.c:740
copy_msg_to_user
int copy_msg_to_user(const msg_t *kmsg, __user char *ubuffer, const ssize_t _size)
copy a msg_t structure from kernel-space to user-space
Definition: message.c:546
cancelDelay
int cancelDelay(msg_manager_t *manager)
Set the delay of messages in the delay queue to zero.
Definition: message.c:206
isDelaySet
bool isDelaySet(const msg_manager_t *manager)
Check if the message delay is greater than zero on a group.
Definition: message.c:37
copy_msg_from_user
int copy_msg_from_user(msg_t *kmsg, const char *umsg, const ssize_t _size)
copy a msg_t structure from user-space to kernel-space
Definition: message.c:583
createMessageManager
msg_manager_t * createMessageManager(const u_int _max_storage_size, const u_int _max_message_size, garbage_collector_t *garbageCollector)
Allocate and initialize all the members of a 'msg_manager_t' struct.
Definition: message.c:624
delayedMessageCallback
void delayedMessageCallback(struct timer_list *timer)
Called when a timer for a delayed message expires.
Definition: message.c:54
queueGarbageCollector
void queueGarbageCollector(struct work_struct *work)
Remove a message from the queue when it was completely delivered.
Definition: message.c:831
writeMessage
int writeMessage(msg_t *message, msg_manager_t *manager)
write message on a group queue
Definition: message.c:666
queueDelayedMessage
int queueDelayedMessage(msg_t *message, msg_manager_t *manager)
Insert a delayed message into the pending queue.
Definition: message.c:109
revokeDelayedMessage
int revokeDelayedMessage(msg_manager_t *manager)
Remove all the delayed message from the queue.
Definition: message.c:163