aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2013-04-30 18:27:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 20:04:03 -0400
commit4a22f16636259f503847b0805e04824171b270fc (patch)
tree764c9b6239416c1b032dd10398b372d84eba8cb8 /kernel
parent1043f65a573b65a5398925551583ea72092e1be2 (diff)
kernel/timer.c: move some non timer related syscalls to kernel/sys.c
Andrew Morton noted: akpm3:/usr/src/25> grep SYSCALL kernel/timer.c SYSCALL_DEFINE1(alarm, unsigned int, seconds) SYSCALL_DEFINE0(getpid) SYSCALL_DEFINE0(getppid) SYSCALL_DEFINE0(getuid) SYSCALL_DEFINE0(geteuid) SYSCALL_DEFINE0(getgid) SYSCALL_DEFINE0(getegid) SYSCALL_DEFINE0(gettid) SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info) COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info) Only one of those should be in kernel/timer.c. Who wrote this thing? [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sys.c211
-rw-r--r--kernel/timer.c208
2 files changed, 212 insertions, 207 deletions
diff --git a/kernel/sys.c b/kernel/sys.c
index 0da73cf73e60..e30eba430b96 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -49,6 +49,11 @@
49#include <linux/user_namespace.h> 49#include <linux/user_namespace.h>
50#include <linux/binfmts.h> 50#include <linux/binfmts.h>
51 51
52#include <linux/sched.h>
53#include <linux/rcupdate.h>
54#include <linux/uidgid.h>
55#include <linux/cred.h>
56
52#include <linux/kmsg_dump.h> 57#include <linux/kmsg_dump.h>
53/* Move somewhere else to avoid recompiling? */ 58/* Move somewhere else to avoid recompiling? */
54#include <generated/utsrelease.h> 59#include <generated/utsrelease.h>
@@ -1044,6 +1049,67 @@ change_okay:
1044 return old_fsgid; 1049 return old_fsgid;
1045} 1050}
1046 1051
1052/**
1053 * sys_getpid - return the thread group id of the current process
1054 *
1055 * Note, despite the name, this returns the tgid not the pid. The tgid and
1056 * the pid are identical unless CLONE_THREAD was specified on clone() in
1057 * which case the tgid is the same in all threads of the same group.
1058 *
1059 * This is SMP safe as current->tgid does not change.
1060 */
1061SYSCALL_DEFINE0(getpid)
1062{
1063 return task_tgid_vnr(current);
1064}
1065
1066/* Thread ID - the internal kernel "pid" */
1067SYSCALL_DEFINE0(gettid)
1068{
1069 return task_pid_vnr(current);
1070}
1071
1072/*
1073 * Accessing ->real_parent is not SMP-safe, it could
1074 * change from under us. However, we can use a stale
1075 * value of ->real_parent under rcu_read_lock(), see
1076 * release_task()->call_rcu(delayed_put_task_struct).
1077 */
1078SYSCALL_DEFINE0(getppid)
1079{
1080 int pid;
1081
1082 rcu_read_lock();
1083 pid = task_tgid_vnr(rcu_dereference(current->real_parent));
1084 rcu_read_unlock();
1085
1086 return pid;
1087}
1088
1089SYSCALL_DEFINE0(getuid)
1090{
1091 /* Only we change this so SMP safe */
1092 return from_kuid_munged(current_user_ns(), current_uid());
1093}
1094
1095SYSCALL_DEFINE0(geteuid)
1096{
1097 /* Only we change this so SMP safe */
1098 return from_kuid_munged(current_user_ns(), current_euid());
1099}
1100
1101SYSCALL_DEFINE0(getgid)
1102{
1103 /* Only we change this so SMP safe */
1104 return from_kgid_munged(current_user_ns(), current_gid());
1105}
1106
1107SYSCALL_DEFINE0(getegid)
1108{
1109 /* Only we change this so SMP safe */
1110 return from_kgid_munged(current_user_ns(), current_egid());
1111}
1112
1047void do_sys_times(struct tms *tms) 1113void do_sys_times(struct tms *tms)
1048{ 1114{
1049 cputime_t tgutime, tgstime, cutime, cstime; 1115 cputime_t tgutime, tgstime, cutime, cstime;
@@ -2245,3 +2311,148 @@ int orderly_poweroff(bool force)
2245 return 0; 2311 return 0;
2246} 2312}
2247EXPORT_SYMBOL_GPL(orderly_poweroff); 2313EXPORT_SYMBOL_GPL(orderly_poweroff);
2314
2315/**
2316 * do_sysinfo - fill in sysinfo struct
2317 * @info: pointer to buffer to fill
2318 */
2319static int do_sysinfo(struct sysinfo *info)
2320{
2321 unsigned long mem_total, sav_total;
2322 unsigned int mem_unit, bitcount;
2323 struct timespec tp;
2324
2325 memset(info, 0, sizeof(struct sysinfo));
2326
2327 ktime_get_ts(&tp);
2328 monotonic_to_bootbased(&tp);
2329 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
2330
2331 get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
2332
2333 info->procs = nr_threads;
2334
2335 si_meminfo(info);
2336 si_swapinfo(info);
2337
2338 /*
2339 * If the sum of all the available memory (i.e. ram + swap)
2340 * is less than can be stored in a 32 bit unsigned long then
2341 * we can be binary compatible with 2.2.x kernels. If not,
2342 * well, in that case 2.2.x was broken anyways...
2343 *
2344 * -Erik Andersen <andersee@debian.org>
2345 */
2346
2347 mem_total = info->totalram + info->totalswap;
2348 if (mem_total < info->totalram || mem_total < info->totalswap)
2349 goto out;
2350 bitcount = 0;
2351 mem_unit = info->mem_unit;
2352 while (mem_unit > 1) {
2353 bitcount++;
2354 mem_unit >>= 1;
2355 sav_total = mem_total;
2356 mem_total <<= 1;
2357 if (mem_total < sav_total)
2358 goto out;
2359 }
2360
2361 /*
2362 * If mem_total did not overflow, multiply all memory values by
2363 * info->mem_unit and set it to 1. This leaves things compatible
2364 * with 2.2.x, and also retains compatibility with earlier 2.4.x
2365 * kernels...
2366 */
2367
2368 info->mem_unit = 1;
2369 info->totalram <<= bitcount;
2370 info->freeram <<= bitcount;
2371 info->sharedram <<= bitcount;
2372 info->bufferram <<= bitcount;
2373 info->totalswap <<= bitcount;
2374 info->freeswap <<= bitcount;
2375 info->totalhigh <<= bitcount;
2376 info->freehigh <<= bitcount;
2377
2378out:
2379 return 0;
2380}
2381
2382SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info)
2383{
2384 struct sysinfo val;
2385
2386 do_sysinfo(&val);
2387
2388 if (copy_to_user(info, &val, sizeof(struct sysinfo)))
2389 return -EFAULT;
2390
2391 return 0;
2392}
2393
2394#ifdef CONFIG_COMPAT
2395struct compat_sysinfo {
2396 s32 uptime;
2397 u32 loads[3];
2398 u32 totalram;
2399 u32 freeram;
2400 u32 sharedram;
2401 u32 bufferram;
2402 u32 totalswap;
2403 u32 freeswap;
2404 u16 procs;
2405 u16 pad;
2406 u32 totalhigh;
2407 u32 freehigh;
2408 u32 mem_unit;
2409 char _f[20-2*sizeof(u32)-sizeof(int)];
2410};
2411
2412COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
2413{
2414 struct sysinfo s;
2415
2416 do_sysinfo(&s);
2417
2418 /* Check to see if any memory value is too large for 32-bit and scale
2419 * down if needed
2420 */
2421 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
2422 int bitcount = 0;
2423
2424 while (s.mem_unit < PAGE_SIZE) {
2425 s.mem_unit <<= 1;
2426 bitcount++;
2427 }
2428
2429 s.totalram >>= bitcount;
2430 s.freeram >>= bitcount;
2431 s.sharedram >>= bitcount;
2432 s.bufferram >>= bitcount;
2433 s.totalswap >>= bitcount;
2434 s.freeswap >>= bitcount;
2435 s.totalhigh >>= bitcount;
2436 s.freehigh >>= bitcount;
2437 }
2438
2439 if (!access_ok(VERIFY_WRITE, info, sizeof(struct compat_sysinfo)) ||
2440 __put_user(s.uptime, &info->uptime) ||
2441 __put_user(s.loads[0], &info->loads[0]) ||
2442 __put_user(s.loads[1], &info->loads[1]) ||
2443 __put_user(s.loads[2], &info->loads[2]) ||
2444 __put_user(s.totalram, &info->totalram) ||
2445 __put_user(s.freeram, &info->freeram) ||
2446 __put_user(s.sharedram, &info->sharedram) ||
2447 __put_user(s.bufferram, &info->bufferram) ||
2448 __put_user(s.totalswap, &info->totalswap) ||
2449 __put_user(s.freeswap, &info->freeswap) ||
2450 __put_user(s.procs, &info->procs) ||
2451 __put_user(s.totalhigh, &info->totalhigh) ||
2452 __put_user(s.freehigh, &info->freehigh) ||
2453 __put_user(s.mem_unit, &info->mem_unit))
2454 return -EFAULT;
2455
2456 return 0;
2457}
2458#endif /* CONFIG_COMPAT */
diff --git a/kernel/timer.c b/kernel/timer.c
index f0e65885b822..09bca8ce9771 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/kernel/timer.c 2 * linux/kernel/timer.c
3 * 3 *
4 * Kernel internal timers, basic process system calls 4 * Kernel internal timers
5 * 5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds 6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * 7 *
@@ -1396,61 +1396,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, seconds)
1396 1396
1397#endif 1397#endif
1398 1398
1399/**
1400 * sys_getpid - return the thread group id of the current process
1401 *
1402 * Note, despite the name, this returns the tgid not the pid. The tgid and
1403 * the pid are identical unless CLONE_THREAD was specified on clone() in
1404 * which case the tgid is the same in all threads of the same group.
1405 *
1406 * This is SMP safe as current->tgid does not change.
1407 */
1408SYSCALL_DEFINE0(getpid)
1409{
1410 return task_tgid_vnr(current);
1411}
1412
1413/*
1414 * Accessing ->real_parent is not SMP-safe, it could
1415 * change from under us. However, we can use a stale
1416 * value of ->real_parent under rcu_read_lock(), see
1417 * release_task()->call_rcu(delayed_put_task_struct).
1418 */
1419SYSCALL_DEFINE0(getppid)
1420{
1421 int pid;
1422
1423 rcu_read_lock();
1424 pid = task_tgid_vnr(rcu_dereference(current->real_parent));
1425 rcu_read_unlock();
1426
1427 return pid;
1428}
1429
1430SYSCALL_DEFINE0(getuid)
1431{
1432 /* Only we change this so SMP safe */
1433 return from_kuid_munged(current_user_ns(), current_uid());
1434}
1435
1436SYSCALL_DEFINE0(geteuid)
1437{
1438 /* Only we change this so SMP safe */
1439 return from_kuid_munged(current_user_ns(), current_euid());
1440}
1441
1442SYSCALL_DEFINE0(getgid)
1443{
1444 /* Only we change this so SMP safe */
1445 return from_kgid_munged(current_user_ns(), current_gid());
1446}
1447
1448SYSCALL_DEFINE0(getegid)
1449{
1450 /* Only we change this so SMP safe */
1451 return from_kgid_munged(current_user_ns(), current_egid());
1452}
1453
1454static void process_timeout(unsigned long __data) 1399static void process_timeout(unsigned long __data)
1455{ 1400{
1456 wake_up_process((struct task_struct *)__data); 1401 wake_up_process((struct task_struct *)__data);
@@ -1558,157 +1503,6 @@ signed long __sched schedule_timeout_uninterruptible(signed long timeout)
1558} 1503}
1559EXPORT_SYMBOL(schedule_timeout_uninterruptible); 1504EXPORT_SYMBOL(schedule_timeout_uninterruptible);
1560 1505
1561/* Thread ID - the internal kernel "pid" */
1562SYSCALL_DEFINE0(gettid)
1563{
1564 return task_pid_vnr(current);
1565}
1566
1567/**
1568 * do_sysinfo - fill in sysinfo struct
1569 * @info: pointer to buffer to fill
1570 */
1571static int do_sysinfo(struct sysinfo *info)
1572{
1573 unsigned long mem_total, sav_total;
1574 unsigned int mem_unit, bitcount;
1575 struct timespec tp;
1576
1577 memset(info, 0, sizeof(struct sysinfo));
1578
1579 ktime_get_ts(&tp);
1580 monotonic_to_bootbased(&tp);
1581 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
1582
1583 get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
1584
1585 info->procs = nr_threads;
1586
1587 si_meminfo(info);
1588 si_swapinfo(info);
1589
1590 /*
1591 * If the sum of all the available memory (i.e. ram + swap)
1592 * is less than can be stored in a 32 bit unsigned long then
1593 * we can be binary compatible with 2.2.x kernels. If not,
1594 * well, in that case 2.2.x was broken anyways...
1595 *
1596 * -Erik Andersen <andersee@debian.org>
1597 */
1598
1599 mem_total = info->totalram + info->totalswap;
1600 if (mem_total < info->totalram || mem_total < info->totalswap)
1601 goto out;
1602 bitcount = 0;
1603 mem_unit = info->mem_unit;
1604 while (mem_unit > 1) {
1605 bitcount++;
1606 mem_unit >>= 1;
1607 sav_total = mem_total;
1608 mem_total <<= 1;
1609 if (mem_total < sav_total)
1610 goto out;
1611 }
1612
1613 /*
1614 * If mem_total did not overflow, multiply all memory values by
1615 * info->mem_unit and set it to 1. This leaves things compatible
1616 * with 2.2.x, and also retains compatibility with earlier 2.4.x
1617 * kernels...
1618 */
1619
1620 info->mem_unit = 1;
1621 info->totalram <<= bitcount;
1622 info->freeram <<= bitcount;
1623 info->sharedram <<= bitcount;
1624 info->bufferram <<= bitcount;
1625 info->totalswap <<= bitcount;
1626 info->freeswap <<= bitcount;
1627 info->totalhigh <<= bitcount;
1628 info->freehigh <<= bitcount;
1629
1630out:
1631 return 0;
1632}
1633
1634SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info)
1635{
1636 struct sysinfo val;
1637
1638 do_sysinfo(&val);
1639
1640 if (copy_to_user(info, &val, sizeof(struct sysinfo)))
1641 return -EFAULT;
1642
1643 return 0;
1644}
1645
1646#ifdef CONFIG_COMPAT
1647struct compat_sysinfo {
1648 s32 uptime;
1649 u32 loads[3];
1650 u32 totalram;
1651 u32 freeram;
1652 u32 sharedram;
1653 u32 bufferram;
1654 u32 totalswap;
1655 u32 freeswap;
1656 u16 procs;
1657 u16 pad;
1658 u32 totalhigh;
1659 u32 freehigh;
1660 u32 mem_unit;
1661 char _f[20-2*sizeof(u32)-sizeof(int)];
1662};
1663
1664COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
1665{
1666 struct sysinfo s;
1667
1668 do_sysinfo(&s);
1669
1670 /* Check to see if any memory value is too large for 32-bit and scale
1671 * down if needed
1672 */
1673 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
1674 int bitcount = 0;
1675
1676 while (s.mem_unit < PAGE_SIZE) {
1677 s.mem_unit <<= 1;
1678 bitcount++;
1679 }
1680
1681 s.totalram >>= bitcount;
1682 s.freeram >>= bitcount;
1683 s.sharedram >>= bitcount;
1684 s.bufferram >>= bitcount;
1685 s.totalswap >>= bitcount;
1686 s.freeswap >>= bitcount;
1687 s.totalhigh >>= bitcount;
1688 s.freehigh >>= bitcount;
1689 }
1690
1691 if (!access_ok(VERIFY_WRITE, info, sizeof(struct compat_sysinfo)) ||
1692 __put_user (s.uptime, &info->uptime) ||
1693 __put_user (s.loads[0], &info->loads[0]) ||
1694 __put_user (s.loads[1], &info->loads[1]) ||
1695 __put_user (s.loads[2], &info->loads[2]) ||
1696 __put_user (s.totalram, &info->totalram) ||
1697 __put_user (s.freeram, &info->freeram) ||
1698 __put_user (s.sharedram, &info->sharedram) ||
1699 __put_user (s.bufferram, &info->bufferram) ||
1700 __put_user (s.totalswap, &info->totalswap) ||
1701 __put_user (s.freeswap, &info->freeswap) ||
1702 __put_user (s.procs, &info->procs) ||
1703 __put_user (s.totalhigh, &info->totalhigh) ||
1704 __put_user (s.freehigh, &info->freehigh) ||
1705 __put_user (s.mem_unit, &info->mem_unit))
1706 return -EFAULT;
1707
1708 return 0;
1709}
1710#endif /* CONFIG_COMPAT */
1711
1712static int __cpuinit init_timers_cpu(int cpu) 1506static int __cpuinit init_timers_cpu(int cpu)
1713{ 1507{
1714 int j; 1508 int j;