Merge branch 'dev' of 106.109.8.71:/srv/git/dbi into dev
[kernel/swap-modules.git] / driver / device_driver.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           device_driver.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       device_driver.h
9 //      AUTHOR:         L.Komkov, S.Dianov, S.Grekhov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19 #include "device_driver.h"      // device driver
20 #include "handlers_core.h"
21 #include <linux/notifier.h>
22 #include "sspt/sspt_procs.h"
23
24 #ifdef OVERHEAD_DEBUG
25 extern unsigned long swap_sum_time;
26 extern unsigned long swap_sum_hit;
27 #endif
28
29
30 extern unsigned long imi_sum_time;
31 extern unsigned long imi_sum_hit;
32
33
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
35 static BLOCKING_NOTIFIER_HEAD(swap_notifier_list);
36 #endif
37 pid_t gl_nNotifyTgid;
38 EXPORT_SYMBOL_GPL(gl_nNotifyTgid);
39
40 static DECLARE_WAIT_QUEUE_HEAD (notification_waiters_queue);
41 static volatile unsigned notification_count;
42
43 static int device_mmap (struct file *filp, struct vm_area_struct *vma);
44 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
45 static int device_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
46 #else
47 static long device_ioctl (struct file *file, unsigned int cmd, unsigned long arg);
48 #endif
49 static int device_open(struct inode *, struct file *);
50 static int device_release(struct inode *, struct file *);
51 static ssize_t device_read(struct file *, char __user *, size_t, loff_t *);
52 static ssize_t device_write(struct file *, const char __user *, size_t, loff_t *);
53
54 static int gl_nDeviceOpened = 0;
55 static struct file_operations device_fops = {
56         .owner = THIS_MODULE,
57         .mmap = device_mmap,
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
59         .ioctl = device_ioctl,
60 #else
61         .unlocked_ioctl = device_ioctl,
62 #endif
63         .read = device_read,
64         .write = device_write,
65         .open = device_open,
66         .release = device_release
67 };
68
69 typedef void (* dbi_module_callback)(void);
70
71 int device_init (void)
72 {
73         int nReserved = 0;
74         nReserved = register_chrdev(0, device_name, &device_fops);
75         if(nReserved < 0)
76         {
77                 unregister_chrdev(nReserved, device_name);
78                 EPRINTF("Cannot register character device!");
79                 return -1;
80         }
81         EPRINTF("New device node with major number [%d], was created\n", nReserved);
82         device_major = nReserved;
83         return 0;
84 }
85
86 void device_down (void)
87 {
88         unregister_chrdev(device_major, device_name);
89 }
90
91 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
92 void swap_register_notify (struct notifier_block *nb)
93 {
94         blocking_notifier_chain_register(&swap_notifier_list, nb);
95 }
96 EXPORT_SYMBOL_GPL(swap_register_notify);
97
98 void swap_unregister_notify (struct notifier_block *nb)
99 {
100         blocking_notifier_chain_unregister(&swap_notifier_list, nb);
101 }
102 EXPORT_SYMBOL_GPL(swap_unregister_notify);
103 #endif
104
105 void notify_user (event_id_t event_id)
106 {
107         ec_info.events_counters[event_id] += 1;
108
109         if (EVENT_EC_PROBE_RECORD == event_id)
110         {
111                 // EC_PROBE_RECORD events happen to often. To reduce overhead user
112                 // space will be notified only once per each EVENTS_AGGREGATION_USEC
113                 static uint64_t timestamp_usec = 0;
114
115                 uint64_t current_usec;
116                 uint64_t delta_usec;
117
118                 struct timeval tv;
119
120                 do_gettimeofday (&tv);
121                 current_usec = 1000000ULL * (unsigned) tv.tv_sec + (unsigned) tv.tv_usec;
122
123                 if (current_usec < timestamp_usec)
124                 {
125                         // Note: time from do_gettimeofday() may go backward
126                         EPRINTF ("current_usec=%llu timestamp_usec=%llu", current_usec, timestamp_usec);
127                 }
128                 else
129                 {
130                         delta_usec = current_usec - timestamp_usec;
131                         if (EVENTS_AGGREGATION_USEC > delta_usec)
132                         {
133                                 // wait the time left
134 #if defined(__DEBUG)
135                                 unsigned UNUSED left_usec = EVENTS_AGGREGATION_USEC - delta_usec;
136 #endif /* defined(__DEBUG) */
137                                 return; // supress notification
138                         }
139                 }
140                 timestamp_usec = current_usec;  // remember new time for the future use
141         } else if (EVENT_EC_START_CONDITION_SEEN == event_id) {
142                 return;         // supress notification
143         } else if (EVENT_EC_STOP_CONDITION_SEEN == event_id) {
144                 return;         // supress notification
145         }
146
147         ++notification_count;
148         wake_up_interruptible (&notification_waiters_queue);
149 }
150
151 static int device_mmap (struct file *filp UNUSED, struct vm_area_struct *vma)
152 {
153         if(!p_buffer) {
154                 EPRINTF("Null pointer to buffer!");
155                 return -1;
156         }
157         return remap_vmalloc_range (vma, p_buffer, 0);
158 }
159
160 static int device_open(struct inode *inode, struct file *file)
161 {
162         /*if (gl_nDeviceOpened)
163                 return -EBUSY;*/
164         gl_nDeviceOpened++;
165         // TODO
166         try_module_get(THIS_MODULE);
167         return 0;
168 }
169
170 static int device_release(struct inode *inode, struct file *file)
171 {
172         gl_nDeviceOpened--;
173         EPRINTF("++ pre module_put");
174         module_put(THIS_MODULE);
175         EPRINTF("++ aft module_put");
176         return 0;
177 }
178
179 static ssize_t device_read(struct file *filp, char __user *buffer, size_t length, loff_t * offset)
180 {
181         EPRINTF("Operation <<read>> not supported!");
182         return -1;
183 }
184
185 static ssize_t device_write(struct file *filp, const char __user *buff, size_t len, loff_t * off)
186 {
187         EPRINTF("Operation <<write>> not supported!");
188         return -1;
189 }
190
191 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
192 static int device_ioctl (struct inode *inode UNUSED, struct file *file UNUSED, unsigned int cmd, unsigned long arg)
193 #else
194 static long device_ioctl (struct file *file UNUSED, unsigned int cmd, unsigned long arg)
195 #endif
196 {
197         unsigned long spinlock_flags = 0L;
198         int result = -1;
199     void __user * arg_pointer = (void __user *) arg;
200 //      DPRINTF("Command=%d", cmd);
201         switch (cmd)
202         {
203         case EC_IOCTL_SET_EC_MODE:
204                 {
205                         ioctl_general_t param;
206                         unsigned long nIgnoredBytes = 0;
207                         memset(&param, '0', sizeof(ioctl_general_t));
208                         nIgnoredBytes = copy_from_user (&param, arg_pointer, sizeof(ioctl_general_t));
209                         if (nIgnoredBytes > 0) {
210                                 result = -1;
211                                 break;
212                         }
213                         if(SetECMode(param.m_unsignedLong) == -1) {
214                                 result = -1;
215                                 break;
216                         }
217                         result = 0;
218                         DPRINTF("Set EC Mode = %lu", param.m_unsignedLong);
219                         break;
220                 }
221         case EC_IOCTL_GET_EC_MODE:
222                 {
223                         ioctl_general_t param;
224                         unsigned long nIgnoredBytes = 0;
225                         memset(&param, '0', sizeof(ioctl_general_t));
226                         param.m_unsignedLong = GetECMode();
227                         nIgnoredBytes = copy_to_user (arg_pointer, &param, sizeof (ioctl_general_t));
228                         if (nIgnoredBytes > 0) {
229                                 result = -1;
230                                 break;
231                         }
232                         result = 0;
233 //                      DPRINTF("Get EC Mode = %lu", param.m_unsignedLong);  // Frequent call
234                         break;
235                 }
236         case EC_IOCTL_SET_BUFFER_SIZE:
237                 {
238                         ioctl_general_t param;
239                         unsigned long nIgnoredBytes = 0;
240                         memset(&param, '0', sizeof(ioctl_general_t));
241                         nIgnoredBytes = copy_from_user (&param, arg_pointer, sizeof(ioctl_general_t));
242                         if (nIgnoredBytes > 0) {
243                                 result = -1;
244                                 break;
245                         }
246                         if (SetBufferSize(param.m_unsignedLong) == -1) {
247                                 result = -1;
248                                 break;
249                         }
250                         result = 0;
251                         DPRINTF("Set Buffer Size = %lu", param.m_unsignedLong);
252                         break;
253                 }
254         case EC_IOCTL_GET_BUFFER_SIZE:
255                 {
256                         ioctl_general_t param;
257                         unsigned long nIgnoredBytes = 0;
258                         memset(&param, '0', sizeof(ioctl_general_t));
259                         param.m_unsignedLong = GetBufferSize();
260                         nIgnoredBytes = copy_to_user (arg_pointer, &param, sizeof (ioctl_general_t));
261                         if (nIgnoredBytes > 0) {
262                                 result = -1;
263                                 break;
264                         }
265                         result = 0;
266                         DPRINTF("Get Buffer Size = %lu", param.m_unsignedLong);
267                         break;
268                 }
269         case EC_IOCTL_RESET_BUFFER:
270                 {
271                         if (ResetBuffer() == -1) {
272                                 result = -1;
273                                 break;
274                         }
275                         result = 0;
276                         DPRINTF("Reset Buffer");
277                         break;
278                 }
279         case EC_IOCTL_GET_EC_INFO:
280                 {
281                         if (copy_ec_info_to_user_space ((ec_info_t *) arg) != 0) {
282                                 result = -1;
283                                 break;
284                         }
285                         result = 0;
286 //                      DPRINTF("Get Buffer Status"); // Frequent call
287                         break;
288                 }
289         case EC_IOCTL_CONSUME_BUFFER:
290                 {
291                         static ec_info_t ec_info_copy;
292                         int nIgnoredBytes = 0;
293
294                         nIgnoredBytes = copy_from_user (&ec_info_copy, (const void __user *) arg, sizeof (ec_info_t));
295                         if(nIgnoredBytes > 0)
296                         {
297                                 EPRINTF ("copy_from_user(%08X,%08X)=%d", (unsigned) arg, (unsigned) &ec_info_copy, nIgnoredBytes);
298                                 result = -1;
299                                 break;
300                         }
301
302                         spin_lock_irqsave (&ec_spinlock, spinlock_flags);
303
304                         // Original buffer
305                         if(ec_info.after_last > ec_info.first) {
306                                 ec_info.buffer_effect = ec_info.buffer_size;
307                         }
308                         if (ec_info.after_last == ec_info.buffer_effect) {
309                                  ec_info.first = 0;
310                         } else {
311                                  ec_info.first = ec_info_copy.after_last;
312                         }
313                         ec_info.trace_size = ec_info.trace_size - ec_info_copy.trace_size;
314
315                         spin_unlock_irqrestore (&ec_spinlock, spinlock_flags);
316                         result = 0;
317 //                      DPRINTF("Consume Buffer"); // Frequent call
318                         break;
319                 }
320         case EC_IOCTL_ADD_PROBE:
321                 {
322                         unsigned long addr = arg;
323                         result = add_probe(addr);
324
325                         break;
326                 }
327         //@AGv: remove_probe expects probe address instead of name
328         /*case EC_IOCTL_REMOVE_PROBE:
329                 {
330                         char *probe_name = (char *) arg;
331                         result = remove_probe (probe_name);
332
333                         break;
334                 }*/
335         case EC_IOCTL_SET_APPDEPS:
336         {
337                 size_t size;
338                 result = copy_from_user(&size, arg_pointer, sizeof(size_t));
339                 if (result) {
340                         EPRINTF("Cannot copy deps size!");
341                         result = -1;
342                         break;
343                 }
344                 DPRINTF("Deps size has been copied (%d)", size);
345
346                 if (size == 0) {
347                         DPRINTF("Deps are size of 0");
348                         break;
349                 }
350
351                 deps = vmalloc(size);
352                 if (deps == NULL) {
353                         EPRINTF("Cannot alloc mem for deps!");
354                         result = -1;
355                         break;
356                 }
357                 DPRINTF("Mem for deps has been allocated");
358
359                 result = copy_from_user(deps, arg_pointer, size);
360                 if (result) {
361                         EPRINTF("Cannot copy deps!");
362                         result = -1;
363                         break;
364                 }
365                 DPRINTF("Deps has been copied successfully");
366
367                 break;
368         }
369         case EC_IOCTL_SET_PID:
370         {
371                 unsigned int _pid;
372
373                 result = copy_from_user(&_pid, arg_pointer, sizeof(unsigned int));
374                 if (result) {
375                         EPRINTF("Cannot copy pid!");
376                         result = -1;
377                         break;
378                 }
379
380                 inst_pid = _pid;
381
382                 DPRINTF("EC_IOCTL_SET_PID pid:%d", inst_pid);
383
384                 break;
385         }
386         case EC_IOCTL_SET_PROFILEBUNDLE:
387         {
388                 size_t size;
389
390                 result = copy_from_user(&size, arg_pointer, sizeof(size_t));
391                 if (result) {
392                         EPRINTF("Cannot copy bundle size!");
393                         result = -1;
394                         break;
395                 }
396                 DPRINTF("Bundle size has been copied");
397
398                 bundle = vmalloc(size);
399                 if (bundle == NULL) {
400                         EPRINTF("Cannot alloc mem for bundle!");
401                         result = -1;
402                         break;
403                 }
404                 DPRINTF("Mem for bundle has been alloced");
405
406                 result = copy_from_user(bundle, arg_pointer, size);
407                 if (result) {
408                         EPRINTF("Cannot copy bundle!");
409                         result = -1;
410                         break;
411                 }
412                 DPRINTF("Bundle has been copied successfully");
413
414 //              last_error_buffer_initialize();
415
416 //              printk(" --++@@ bef lb\n");
417                 if (link_bundle() == -1 || has_last_error() == -1) {
418                         EPRINTF("Cannot link profile bundle!");
419                         result = -1;
420                         break;
421                 }
422 //              printk(" --++@@ bef has_last_error\n");
423 //              if (has_last_error() == -1) {
424 //                      printk(" --++@@ in if\n");
425 //                      DPRINTF("last_error_buffer != NULL");
426 //                      result = -1;
427 //              }
428 //              printk(" --++@@ aft has_last_error\n");
429
430                 break;
431         }
432         case EC_IOCTL_RESET_PROBES:
433                 {
434                         result = reset_probes();
435
436                         break;
437                 }
438         case EC_IOCTL_UPDATE_CONDS:
439                 {
440                         int args_cnt, i;
441                         struct cond *c, *c_tmp, *p_cond;
442                         unsigned char *p_data;
443                         int err;
444                         result = 0;
445                         err = copy_from_user(&args_cnt, arg_pointer, sizeof(int));
446                         if (err) {
447                                 result = -1;
448                                 break;
449                         }
450                         /* first, delete all the conds */
451                         list_for_each_entry_safe(c, c_tmp, &cond_list.list, list) {
452                                 list_del(&c->list);
453                                 kfree(c);
454                         }
455                         /* second, add new conds */
456                         p_data = (unsigned char *)(arg + sizeof(int));
457                         for (i = 0; i < args_cnt; i++) {
458                                 p_cond = kmalloc(sizeof(struct cond), GFP_KERNEL);
459                                 if (!p_cond) {
460                                         DPRINTF("Cannot alloc cond!");
461                                         result = -1;
462                                         break;
463                                 }
464                                 err = copy_from_user(&p_cond->tmpl, (const void __user *)p_data,
465                                                 sizeof(struct event_tmpl));
466                                 if (err) {
467                                         DPRINTF("Cannot copy cond from user!");
468                                         result = -1;
469                                         break;
470                                 }
471                                 p_cond->applied = 0;
472                                 list_add(&(p_cond->list), &(cond_list.list));
473                                 p_data += sizeof(struct event_tmpl);
474                         }
475                         break;
476                 }
477         case EC_IOCTL_ATTACH:
478                 {
479                         unsigned long dbi_flags;
480                         struct dbi_modules_handlers *local_mh;
481                         struct dbi_modules_handlers_info *local_mhi;
482                         int j;
483                         dbi_module_callback dmc_start;
484
485                         // call "start"-callback for all modules according module priority
486                         local_mh = get_dbi_modules_handlers();
487                         spin_lock_irqsave(&local_mh->lock, dbi_flags);
488                         for (j = 0; j <= MAX_PRIORITY; j++) {
489                                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
490                                         if (local_mhi->dbi_module_priority_start == j) {
491                                                 if (local_mhi->dbi_module_callback_start != NULL) {
492                                                         printk("Started module callback (start) %s\n", local_mhi->dbi_module->name);
493                                                         dmc_start = (dbi_module_callback )local_mhi->dbi_module_callback_start;
494                                                         dmc_start();
495                                                 }
496                                         }
497                                 }
498                         }
499                         spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
500
501                         result = ec_user_attach ();
502 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
503                         DPRINTF("EC_IOCTL_ATTACH calling notification chain");
504                         blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_ATTACH, (void*)NULL);
505 #endif
506                         DPRINTF("Attach Probes");
507                         break;
508                 }
509         case EC_IOCTL_ACTIVATE:
510                 result = ec_user_activate ();
511                 DPRINTF("Activate Probes");
512                 break;
513         case EC_IOCTL_STOP_AND_DETACH:
514         {
515                 unsigned long nIgnoredBytes = 0;
516                 unsigned long dbi_flags;
517                 struct dbi_modules_handlers *local_mh;
518                 struct dbi_modules_handlers_info *local_mhi;
519                 unsigned int local_module_refcount = 0;
520                 int j;
521                 dbi_module_callback dmc_stop;
522
523 #ifdef OVERHEAD_DEBUG
524                 printk("\nswap_sum_time = %ld in kprobe_handler()\n", swap_sum_time);
525                 printk("swap_sum_hit = %ld in kprobe_handler()\n", swap_sum_hit);
526                 swap_sum_time = 0;
527                 swap_sum_hit = 0;
528 #endif
529
530                 printk("\n### imi_sum_time = %ld in install_mapped_ips()\n", imi_sum_time);
531                 printk("### imi_sum_hit = %ld in install_mapped_ips()\n", imi_sum_hit);
532
533                 if (imi_sum_hit != 0) {
534                         printk("### time = %ld in install_mapped_ips()\n", imi_sum_time/imi_sum_hit);
535                 }
536
537                 imi_sum_time = 0;
538                 imi_sum_hit = 0;
539
540                 local_mh = get_dbi_modules_handlers();
541                 if(ec_user_stop() != 0) {
542                         result = -1;
543                         goto sad_cleanup;
544                 }
545                 nIgnoredBytes = copy_ec_info_to_user_space ((ec_info_t*)arg);
546                 if(nIgnoredBytes > 0) {
547                         result = -1;
548                         goto sad_cleanup;
549                 }
550
551                 sspt_procs_free_all();
552
553                 vfree(bundle);
554                 result = 0;
555                 DPRINTF("Stop and Detach Probes");
556 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
557                 DPRINTF("EC_IOCTL_STOP_AND_DETACH calling notification chain");
558                 blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_STOP_AND_DETACH, (void*)&gl_nNotifyTgid);
559 #endif
560                 // call "stop"-callback for all modules according module priority
561                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
562                 for (j = 0; j <= MAX_PRIORITY; j++) {
563                         list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
564                                 if (local_mhi->dbi_module_priority_stop == j) {
565                                         if (local_mhi->dbi_module_callback_stop != NULL) {
566                                                 printk("Started module callback (stop) %s\n", local_mhi->dbi_module->name);
567                                                 dmc_stop = (dbi_module_callback )local_mhi->dbi_module_callback_stop;
568                                                 dmc_stop();
569                                         }
570                                 }
571                         }
572                 }
573                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
574 sad_cleanup:
575                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
576                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
577                         local_module_refcount = module_refcount(local_mhi->dbi_module);
578                         if (local_module_refcount == 1) {
579                                 module_put(local_mhi->dbi_module);
580                         }
581                         else if (local_module_refcount > 1) {
582                                 printk("local_module_refcount too much - force set refcount to zero\n");
583                                 while (local_module_refcount--)
584                                         module_put(local_mhi->dbi_module);
585                         }
586                 }
587                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
588                 break;
589         }
590         case EC_IOCTL_US_EVENT:
591                 {
592                         ioctl_us_event_t ioctl_args;
593                         result = copy_from_user (&ioctl_args, (const void __user *) arg, sizeof (ioctl_args));
594                         if (result)
595                         {
596                                 result = -1;
597                                 EPRINTF ("copy_from_user() failure");
598                         }
599                         else
600                         {
601                                 if(ioctl_args.len == 0){
602                                         result = -EINVAL;
603                                         EPRINTF ("invalid event length!");
604                                 }
605                                 else {
606                                         char *buf = kmalloc(ioctl_args.len, GFP_KERNEL);
607                                         if(!buf){
608                                                 result = -ENOMEM;
609                                                 EPRINTF ("failed to alloc mem for event!");
610                                         }
611                                         else {
612                                                 result = copy_from_user (buf, (const void __user *) ioctl_args.data, ioctl_args.len);
613                                                 if (result){
614                                                         result = -1;
615                                                         EPRINTF ("failed to copy event from user space!");
616                                                 }
617                                                 else
618                                                         result = put_us_event(buf, ioctl_args.len);
619                                                 kfree(buf);
620                                         }
621                                 }
622                         }
623 //                      DPRINTF("User Space Event"); // Frequent call
624                         break;
625                 }
626
627         case EC_IOCTL_SET_EVENT_MASK:
628                 {
629                         int mask;
630                         result = copy_from_user (&mask, arg_pointer, sizeof (mask));
631                         if (result)
632                         {
633                                 result = -EFAULT;
634                                 break;
635                         }
636
637                         result = set_event_mask (mask);
638                         if (result)
639                         {
640                                 break;
641                         }
642                         DPRINTF("Set Event Mask = %d", mask);
643                         break;
644                 }
645
646         case EC_IOCTL_GET_EVENT_MASK:
647                 {
648                         int mask = 0;
649                         result = get_event_mask(&mask);
650                         if (result)
651                         {
652                                 result = -EFAULT;
653                         }
654                         result = copy_to_user (arg_pointer, &mask, sizeof (mask));
655                         if (result)
656                         {
657                                 result = -EFAULT;
658                         }
659                         DPRINTF("Get Event Mask = %d", mask);
660                         break;
661                 }
662
663         case EC_IOCTL_GET_PREDEF_UPROBES:
664                 {
665                         result = get_predef_uprobes((ioctl_predef_uprobes_info_t *)arg);
666                         if (result)
667                         {
668                                 result = -EFAULT;
669                         }
670                         DPRINTF("Get Predefined User Space Probes");
671                         break;
672                 }
673
674         case EC_IOCTL_GET_PREDEF_UPROBES_SIZE:
675                 {
676                         int size = 0;
677                         result = get_predef_uprobes_size(&size);
678                         if (result)
679                         {
680                                 result = -EFAULT;
681                         }
682                         result = copy_to_user (arg_pointer, &size, sizeof (size));
683                         if (result)
684                         {
685                                 result = -EFAULT;
686                         }
687                         DPRINTF("Get Size of Predefined User Space Probes");
688                         break;
689                 }
690         case EC_IOCTL_GET_LAST_ERROR:
691                 {
692                         result = get_last_error((void*)arg);
693                         DPRINTF("Get last error buffer");
694                         break;
695                 }
696         default:
697                 EPRINTF ("Unknown driver command = %u", cmd);
698                 result = -EINVAL;
699                 break;
700         }
701
702         return result;
703 }