diff options
Diffstat (limited to 'mm')
-rw-r--r-- | mm/util.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -413,6 +413,54 @@ unsigned long vm_commit_limit(void) | |||
413 | * sysctl_overcommit_ratio / 100) + total_swap_pages; | 413 | * sysctl_overcommit_ratio / 100) + total_swap_pages; |
414 | } | 414 | } |
415 | 415 | ||
416 | /** | ||
417 | * get_cmdline() - copy the cmdline value to a buffer. | ||
418 | * @task: the task whose cmdline value to copy. | ||
419 | * @buffer: the buffer to copy to. | ||
420 | * @buflen: the length of the buffer. Larger cmdline values are truncated | ||
421 | * to this length. | ||
422 | * Returns the size of the cmdline field copied. Note that the copy does | ||
423 | * not guarantee an ending NULL byte. | ||
424 | */ | ||
425 | int get_cmdline(struct task_struct *task, char *buffer, int buflen) | ||
426 | { | ||
427 | int res = 0; | ||
428 | unsigned int len; | ||
429 | struct mm_struct *mm = get_task_mm(task); | ||
430 | if (!mm) | ||
431 | goto out; | ||
432 | if (!mm->arg_end) | ||
433 | goto out_mm; /* Shh! No looking before we're done */ | ||
434 | |||
435 | len = mm->arg_end - mm->arg_start; | ||
436 | |||
437 | if (len > buflen) | ||
438 | len = buflen; | ||
439 | |||
440 | res = access_process_vm(task, mm->arg_start, buffer, len, 0); | ||
441 | |||
442 | /* | ||
443 | * If the nul at the end of args has been overwritten, then | ||
444 | * assume application is using setproctitle(3). | ||
445 | */ | ||
446 | if (res > 0 && buffer[res-1] != '\0' && len < buflen) { | ||
447 | len = strnlen(buffer, res); | ||
448 | if (len < res) { | ||
449 | res = len; | ||
450 | } else { | ||
451 | len = mm->env_end - mm->env_start; | ||
452 | if (len > buflen - res) | ||
453 | len = buflen - res; | ||
454 | res += access_process_vm(task, mm->env_start, | ||
455 | buffer+res, len, 0); | ||
456 | res = strnlen(buffer, res); | ||
457 | } | ||
458 | } | ||
459 | out_mm: | ||
460 | mmput(mm); | ||
461 | out: | ||
462 | return res; | ||
463 | } | ||
416 | 464 | ||
417 | /* Tracepoints definitions. */ | 465 | /* Tracepoints definitions. */ |
418 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); | 466 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); |