dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / kernel / syscall / adjtime.c
blobdc2dde53068792d74c1908b6a20dff1f4d35831f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright 1999,2001-2003 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.78 */
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/sysmacros.h>
36 #include <sys/systm.h>
37 #include <sys/tuneable.h>
38 #include <sys/errno.h>
39 #include <sys/proc.h>
40 #include <sys/time.h>
41 #include <sys/debug.h>
42 #include <sys/model.h>
43 #include <sys/policy.h>
45 int
46 adjtime(struct timeval *delta, struct timeval *olddelta)
48 struct timeval atv, oatv;
49 int64_t ndelta;
50 int64_t old_delta;
51 int s;
52 model_t datamodel = get_udatamodel();
54 if (secpolicy_settime(CRED()) != 0)
55 return (set_errno(EPERM));
57 if (datamodel == DATAMODEL_NATIVE) {
58 if (copyin(delta, &atv, sizeof (atv)))
59 return (set_errno(EFAULT));
60 } else {
61 struct timeval32 atv32;
63 if (copyin(delta, &atv32, sizeof (atv32)))
64 return (set_errno(EFAULT));
65 TIMEVAL32_TO_TIMEVAL(&atv, &atv32);
68 if (atv.tv_usec <= -MICROSEC || atv.tv_usec >= MICROSEC)
69 return (set_errno(EINVAL));
72 * The SVID specifies that if delta is 0, then there is
73 * no effect upon time correction, just return olddelta.
75 ndelta = (int64_t)atv.tv_sec * NANOSEC + atv.tv_usec * 1000;
76 mutex_enter(&tod_lock);
77 s = hr_clock_lock();
78 old_delta = timedelta;
79 if (ndelta)
80 timedelta = ndelta;
82 * Always set tod_needsync on all adjtime() calls, since it implies
83 * someone is watching over us and keeping the local clock in sync.
85 tod_needsync = 1;
86 hr_clock_unlock(s);
87 mutex_exit(&tod_lock);
89 if (olddelta) {
90 oatv.tv_sec = old_delta / NANOSEC;
91 oatv.tv_usec = (old_delta % NANOSEC) / 1000;
92 if (datamodel == DATAMODEL_NATIVE) {
93 if (copyout(&oatv, olddelta, sizeof (oatv)))
94 return (set_errno(EFAULT));
95 } else {
96 struct timeval32 oatv32;
98 if (TIMEVAL_OVERFLOW(&oatv))
99 return (set_errno(EOVERFLOW));
101 TIMEVAL_TO_TIMEVAL32(&oatv32, &oatv);
103 if (copyout(&oatv32, olddelta, sizeof (oatv32)))
104 return (set_errno(EFAULT));
107 return (0);