4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* #pragma ident "@(#)profile.c 1.6 06/03/24 SMI" */
28 #if !defined(__APPLE__)
29 #include <sys/errno.h>
31 #include <sys/modctl.h>
33 #include <sys/systm.h>
35 #include <sys/sunddi.h>
36 #include <sys/cpuvar.h>
38 #include <sys/strsubr.h>
39 #include <sys/dtrace.h>
40 #include <sys/cyclic.h>
41 #include <sys/atomic.h>
45 #define _KERNEL /* Solaris vs. Darwin */
49 #define MACH__POSIX_C_SOURCE_PRIVATE 1 /* pulls in suitable savearea from mach/ppc/thread_status.h */
50 #include <kern/cpu_data.h>
51 #include <kern/thread.h>
52 #include <mach/thread_status.h>
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/errno.h>
58 #include <sys/ioctl.h>
60 #include <sys/fcntl.h>
61 #include <miscfs/devfs/devfs.h>
63 #include <sys/dtrace.h>
64 #include <sys/dtrace_impl.h>
66 #include <sys/dtrace_glue.h>
68 #if defined(__ppc__) || defined(__ppc64__)
69 extern struct savearea
*find_kern_regs(thread_t
);
70 #elif defined(__i386__) || defined(__x86_64__)
71 extern x86_saved_state32_t
*find_kern_regs(thread_t
);
72 #elif defined (__arm__)
73 extern struct arm_saved_state
*find_kern_regs(thread_t
);
75 #error Unknown architecture
79 #define ASSERT(x) do {} while(0)
81 extern void profile_init(void);
82 #endif /* __APPLE__ */
84 static dev_info_t
*profile_devi
;
85 static dtrace_provider_id_t profile_id
;
88 * Regardless of platform, there are five artificial frames in the case of the
97 * On amd64, there are two frames associated with locore: one in locore, and
98 * another in common interrupt dispatch code. (i386 has not been modified to
99 * use this common layer.) Further, on i386, the interrupted instruction
100 * appears as its own stack frame. All of this means that we need to add one
101 * frame for amd64, and then take one away for both amd64 and i386.
103 * On SPARC, the picture is further complicated because the compiler
104 * optimizes away tail-calls -- so the following frames are optimized away:
109 * This gives three frames. However, on DEBUG kernels, the cyclic_expire
110 * frame cannot be tail-call eliminated, yielding four frames in this case.
112 * All of the above constraints lead to the mess below. Yes, the profile
113 * provider should ideally figure this out on-the-fly by hiting one of its own
114 * probes and then walking its own stack trace. This is complicated, however,
115 * and the static definition doesn't seem to be overly brittle. Still, we
116 * allow for a manual override in case we get it completely wrong.
118 #if !defined(__APPLE__)
121 #define PROF_ARTIFICIAL_FRAMES 7
124 #define PROF_ARTIFICIAL_FRAMES 6
128 #define PROF_ARTIFICIAL_FRAMES 4
130 #define PROF_ARTIFICIAL_FRAMES 3
136 #else /* is Mac OS X */
138 #if defined(__ppc__) || defined(__ppc64__)
139 #define PROF_ARTIFICIAL_FRAMES 8
140 #elif defined(__i386__) || defined(__x86_64__)
141 #define PROF_ARTIFICIAL_FRAMES 9
142 #elif defined(__arm__)
143 #define PROF_ARTIFICIAL_FRAMES 3 /* XXX BOGUS ARMTODO */
145 #error Unknown architecture
148 #endif /* __APPLE__ */
150 #define PROF_NAMELEN 15
152 #define PROF_PROFILE 0
154 #define PROF_PREFIX_PROFILE "profile-"
155 #define PROF_PREFIX_TICK "tick-"
157 typedef struct profile_probe
{
158 char prof_name
[PROF_NAMELEN
];
161 hrtime_t prof_interval
;
162 cyclic_id_t prof_cyclic
;
165 typedef struct profile_probe_percpu
{
166 hrtime_t profc_expected
;
167 hrtime_t profc_interval
;
168 profile_probe_t
*profc_probe
;
169 } profile_probe_percpu_t
;
171 hrtime_t profile_interval_min
= NANOSEC
/ 5000; /* 5000 hz */
172 int profile_aframes
= 0; /* override */
174 static int profile_rates
[] = {
175 97, 199, 499, 997, 1999,
181 static int profile_ticks
[] = {
182 1, 10, 100, 500, 1000,
188 * profile_max defines the upper bound on the number of profile probes that
189 * can exist (this is to prevent malicious or clumsy users from exhausing
190 * system resources by creating a slew of profile probes). At mod load time,
191 * this gets its value from PROFILE_MAX_DEFAULT or profile-max-probes if it's
192 * present in the profile.conf file.
194 #define PROFILE_MAX_DEFAULT 1000 /* default max. number of probes */
195 static uint32_t profile_max
; /* maximum number of profile probes */
196 static uint32_t profile_total
; /* current number of profile probes */
199 profile_fire(void *arg
)
201 profile_probe_percpu_t
*pcpu
= arg
;
202 profile_probe_t
*prof
= pcpu
->profc_probe
;
205 late
= dtrace_gethrtime() - pcpu
->profc_expected
;
206 pcpu
->profc_expected
+= pcpu
->profc_interval
;
208 #if !defined(__APPLE__)
209 dtrace_probe(prof
->prof_id
, CPU
->cpu_profile_pc
,
210 CPU
->cpu_profile_upc
, late
, 0, 0);
212 #if defined(__ppc__) || defined(__ppc64__)
213 struct savearea
*sv
= find_kern_regs(current_thread());
216 if (USERMODE(sv
->save_srr1
)) {
217 dtrace_probe(prof
->prof_id
, 0x0, sv
->save_srr0
, late
, 0, 0);
219 dtrace_probe(prof
->prof_id
, sv
->save_srr0
, 0x0, late
, 0, 0);
222 dtrace_probe(prof
->prof_id
, 0xcafebabe,
223 0x0, late
, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */
225 #elif defined(__i386__) || defined(__x86_64__)
226 x86_saved_state32_t
*kern_regs
= find_kern_regs(current_thread());
228 if (NULL
!= kern_regs
) {
229 /* Kernel was interrupted. */
230 dtrace_probe(prof
->prof_id
, kern_regs
->eip
, 0x0, 0, 0, 0);
232 /* Possibly a user interrupt */
233 x86_saved_state_t
*tagged_regs
= (x86_saved_state_t
*)find_user_regs(current_thread());
235 if (NULL
== tagged_regs
) {
236 /* Too bad, so sad, no useful interrupt state. */
237 dtrace_probe(prof
->prof_id
, 0xcafebabe,
238 0x0, 0, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */
239 } else if (is_saved_state64(tagged_regs
)) {
240 x86_saved_state64_t
*regs
= saved_state64(tagged_regs
);
242 dtrace_probe(prof
->prof_id
, 0x0, regs
->isf
.rip
, 0, 0, 0);
244 x86_saved_state32_t
*regs
= saved_state32(tagged_regs
);
246 dtrace_probe(prof
->prof_id
, 0x0, regs
->eip
, 0, 0, 0);
250 #error Unknown architecture
252 #endif /* __APPLE__ */
256 profile_tick(void *arg
)
258 profile_probe_t
*prof
= arg
;
260 #if !defined(__APPLE__)
261 dtrace_probe(prof
->prof_id
, CPU
->cpu_profile_pc
,
262 CPU
->cpu_profile_upc
, 0, 0, 0);
264 #if defined(__ppc__) || defined(__ppc64__)
265 struct savearea
*sv
= find_kern_regs(current_thread());
268 if (USERMODE(sv
->save_srr1
)) {
269 dtrace_probe(prof
->prof_id
, 0x0, sv
->save_srr0
, 0, 0, 0);
271 dtrace_probe(prof
->prof_id
, sv
->save_srr0
, 0x0, 0, 0, 0);
274 dtrace_probe(prof
->prof_id
, 0xcafebabe,
275 0x0, 0, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */
277 #elif defined(__i386__) || defined(__x86_64__)
278 x86_saved_state32_t
*kern_regs
= find_kern_regs(current_thread());
280 if (NULL
!= kern_regs
) {
281 /* Kernel was interrupted. */
282 dtrace_probe(prof
->prof_id
, kern_regs
->eip
, 0x0, 0, 0, 0);
284 /* Possibly a user interrupt */
285 x86_saved_state_t
*tagged_regs
= (x86_saved_state_t
*)find_user_regs(current_thread());
287 if (NULL
== tagged_regs
) {
288 /* Too bad, so sad, no useful interrupt state. */
289 dtrace_probe(prof
->prof_id
, 0xcafebabe,
290 0x0, 0, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */
291 } else if (is_saved_state64(tagged_regs
)) {
292 x86_saved_state64_t
*regs
= saved_state64(tagged_regs
);
294 dtrace_probe(prof
->prof_id
, 0x0, regs
->isf
.rip
, 0, 0, 0);
296 x86_saved_state32_t
*regs
= saved_state32(tagged_regs
);
298 dtrace_probe(prof
->prof_id
, 0x0, regs
->eip
, 0, 0, 0);
302 #error Unknown architecture
304 #endif /* __APPLE__ */
308 profile_create(hrtime_t interval
, const char *name
, int kind
)
310 profile_probe_t
*prof
;
312 if (interval
< profile_interval_min
)
315 if (dtrace_probe_lookup(profile_id
, NULL
, NULL
, name
) != 0)
318 atomic_add_32(&profile_total
, 1);
319 if (profile_total
> profile_max
) {
320 atomic_add_32(&profile_total
, -1);
324 #if !defined(__APPLE__)
325 prof
= kmem_zalloc(sizeof (profile_probe_t
), KM_SLEEP
);
327 if (PROF_TICK
== kind
)
328 prof
= kmem_zalloc(sizeof (profile_probe_t
), KM_SLEEP
);
330 prof
= kmem_zalloc(sizeof (profile_probe_t
) + NCPU
*sizeof(profile_probe_percpu_t
), KM_SLEEP
);
331 #endif /* __APPLE__ */
332 (void) strlcpy(prof
->prof_name
, name
, sizeof(prof
->prof_name
));
333 prof
->prof_interval
= interval
;
334 prof
->prof_cyclic
= CYCLIC_NONE
;
335 prof
->prof_kind
= kind
;
336 prof
->prof_id
= dtrace_probe_create(profile_id
,
338 profile_aframes
? profile_aframes
: PROF_ARTIFICIAL_FRAMES
, prof
);
343 profile_provide(void *arg
, const dtrace_probedesc_t
*desc
)
345 int i
, j
, rate
, kind
;
346 hrtime_t val
= 0, mult
= 1, len
;
347 const char *name
, *suffix
= NULL
;
353 { PROF_PREFIX_PROFILE
, PROF_PROFILE
},
354 { PROF_PREFIX_TICK
, PROF_TICK
},
362 { "ns", NANOSEC
/ NANOSEC
},
363 { "nsec", NANOSEC
/ NANOSEC
},
364 { "us", NANOSEC
/ MICROSEC
},
365 { "usec", NANOSEC
/ MICROSEC
},
366 { "ms", NANOSEC
/ MILLISEC
},
367 { "msec", NANOSEC
/ MILLISEC
},
368 { "s", NANOSEC
/ SEC
},
369 { "sec", NANOSEC
/ SEC
},
370 { "m", NANOSEC
* (hrtime_t
)60 },
371 { "min", NANOSEC
* (hrtime_t
)60 },
372 { "h", NANOSEC
* (hrtime_t
)(60 * 60) },
373 { "hour", NANOSEC
* (hrtime_t
)(60 * 60) },
374 { "d", NANOSEC
* (hrtime_t
)(24 * 60 * 60) },
375 { "day", NANOSEC
* (hrtime_t
)(24 * 60 * 60) },
377 #if !defined(__APPLE__)
381 #endif /* __APPLE__ */
385 char n
[PROF_NAMELEN
];
388 * If no description was provided, provide all of our probes.
390 for (i
= 0; i
< sizeof (profile_rates
) / sizeof (int); i
++) {
391 if ((rate
= profile_rates
[i
]) == 0)
394 (void) snprintf(n
, PROF_NAMELEN
, "%s%d",
395 PROF_PREFIX_PROFILE
, rate
);
396 profile_create(NANOSEC
/ rate
, n
, PROF_PROFILE
);
399 for (i
= 0; i
< sizeof (profile_ticks
) / sizeof (int); i
++) {
400 if ((rate
= profile_ticks
[i
]) == 0)
403 (void) snprintf(n
, PROF_NAMELEN
, "%s%d",
404 PROF_PREFIX_TICK
, rate
);
405 profile_create(NANOSEC
/ rate
, n
, PROF_TICK
);
411 name
= desc
->dtpd_name
;
413 for (i
= 0; types
[i
].prefix
!= NULL
; i
++) {
414 len
= strlen(types
[i
].prefix
);
416 if (strncmp(name
, types
[i
].prefix
, len
) != 0)
421 if (types
[i
].prefix
== NULL
)
424 kind
= types
[i
].kind
;
425 j
= strlen(name
) - len
;
428 * We need to start before any time suffix.
430 for (j
= strlen(name
); j
>= len
; j
--) {
431 if (name
[j
] >= '0' && name
[j
] <= '9')
436 ASSERT(suffix
!= NULL
);
439 * Now determine the numerical value present in the probe name.
441 for (; j
>= len
; j
--) {
442 if (name
[j
] < '0' || name
[j
] > '9')
445 val
+= (name
[j
] - '0') * mult
;
446 mult
*= (hrtime_t
)10;
453 * Look-up the suffix to determine the multiplier.
455 for (i
= 0, mult
= 0; suffixes
[i
].name
!= NULL
; i
++) {
456 if (strcasecmp(suffixes
[i
].name
, suffix
) == 0) {
457 mult
= suffixes
[i
].mult
;
462 if (suffixes
[i
].name
== NULL
&& *suffix
!= '\0')
467 * The default is frequency-per-second.
474 profile_create(val
, name
, kind
);
479 profile_destroy(void *arg
, dtrace_id_t id
, void *parg
)
481 profile_probe_t
*prof
= parg
;
483 ASSERT(prof
->prof_cyclic
== CYCLIC_NONE
);
484 #if !defined(__APPLE__)
485 kmem_free(prof
, sizeof (profile_probe_t
));
487 if (prof
->prof_kind
== PROF_TICK
)
488 kmem_free(prof
, sizeof (profile_probe_t
));
490 kmem_free(prof
, sizeof (profile_probe_t
) + NCPU
*sizeof(profile_probe_percpu_t
));
491 #endif /* __APPLE__ */
493 ASSERT(profile_total
>= 1);
494 atomic_add_32(&profile_total
, -1);
499 profile_online(void *arg
, cpu_t
*cpu
, cyc_handler_t
*hdlr
, cyc_time_t
*when
)
501 profile_probe_t
*prof
= arg
;
502 profile_probe_percpu_t
*pcpu
;
504 #if !defined(__APPLE__)
505 pcpu
= kmem_zalloc(sizeof (profile_probe_percpu_t
), KM_SLEEP
);
507 pcpu
= ((profile_probe_percpu_t
*)(&(prof
[1]))) + cpu_number();
508 #endif /* __APPLE__ */
509 pcpu
->profc_probe
= prof
;
511 hdlr
->cyh_func
= profile_fire
;
512 hdlr
->cyh_arg
= pcpu
;
513 hdlr
->cyh_level
= CY_HIGH_LEVEL
;
515 when
->cyt_interval
= prof
->prof_interval
;
516 #if !defined(__APPLE__)
517 when
->cyt_when
= dtrace_gethrtime() + when
->cyt_interval
;
520 #endif /* __APPLE__ */
522 pcpu
->profc_expected
= when
->cyt_when
;
523 pcpu
->profc_interval
= when
->cyt_interval
;
528 profile_offline(void *arg
, cpu_t
*cpu
, void *oarg
)
530 profile_probe_percpu_t
*pcpu
= oarg
;
532 ASSERT(pcpu
->profc_probe
== arg
);
533 #if !defined(__APPLE__)
534 kmem_free(pcpu
, sizeof (profile_probe_percpu_t
));
535 #endif /* __APPLE__ */
540 profile_enable(void *arg
, dtrace_id_t id
, void *parg
)
542 profile_probe_t
*prof
= parg
;
543 cyc_omni_handler_t omni
;
547 ASSERT(prof
->prof_interval
!= 0);
548 ASSERT(MUTEX_HELD(&cpu_lock
));
550 if (prof
->prof_kind
== PROF_TICK
) {
551 hdlr
.cyh_func
= profile_tick
;
553 hdlr
.cyh_level
= CY_HIGH_LEVEL
;
555 when
.cyt_interval
= prof
->prof_interval
;
556 #if !defined(__APPLE__)
557 when
.cyt_when
= dtrace_gethrtime() + when
.cyt_interval
;
560 #endif /* __APPLE__ */
562 ASSERT(prof
->prof_kind
== PROF_PROFILE
);
563 omni
.cyo_online
= profile_online
;
564 omni
.cyo_offline
= profile_offline
;
568 #if !defined(__APPLE__)
569 if (prof
->prof_kind
== PROF_TICK
) {
570 prof
->prof_cyclic
= cyclic_add(&hdlr
, &when
);
572 prof
->prof_cyclic
= cyclic_add_omni(&omni
);
575 if (prof
->prof_kind
== PROF_TICK
) {
576 prof
->prof_cyclic
= cyclic_timer_add(&hdlr
, &when
);
578 prof
->prof_cyclic
= (cyclic_id_t
)cyclic_add_omni(&omni
); /* cast puns cyclic_id_list_t with cyclic_id_t */
580 #endif /* __APPLE__ */
585 profile_disable(void *arg
, dtrace_id_t id
, void *parg
)
587 profile_probe_t
*prof
= parg
;
589 ASSERT(prof
->prof_cyclic
!= CYCLIC_NONE
);
590 ASSERT(MUTEX_HELD(&cpu_lock
));
592 #if !defined(__APPLE__)
593 cyclic_remove(prof
->prof_cyclic
);
595 if (prof
->prof_kind
== PROF_TICK
) {
596 cyclic_timer_remove(prof
->prof_cyclic
);
598 cyclic_remove_omni((cyclic_id_list_t
)prof
->prof_cyclic
); /* cast puns cyclic_id_list_t with cyclic_id_t */
600 #endif /* __APPLE__ */
601 prof
->prof_cyclic
= CYCLIC_NONE
;
604 #if !defined(__APPLE__)
607 profile_usermode(void *arg
, dtrace_id_t id
, void *parg
)
609 return (CPU
->cpu_profile_pc
== 0);
613 profile_usermode(void *arg
, dtrace_id_t id
, void *parg
)
615 #pragma unused(arg,id,parg)
616 return 1; /* XXX_BOGUS */
618 #endif /* __APPLE__ */
620 static dtrace_pattr_t profile_attr
= {
621 { DTRACE_STABILITY_EVOLVING
, DTRACE_STABILITY_EVOLVING
, DTRACE_CLASS_COMMON
},
622 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_UNKNOWN
},
623 { DTRACE_STABILITY_PRIVATE
, DTRACE_STABILITY_PRIVATE
, DTRACE_CLASS_UNKNOWN
},
624 { DTRACE_STABILITY_EVOLVING
, DTRACE_STABILITY_EVOLVING
, DTRACE_CLASS_COMMON
},
625 { DTRACE_STABILITY_EVOLVING
, DTRACE_STABILITY_EVOLVING
, DTRACE_CLASS_COMMON
},
628 static dtrace_pops_t profile_pops
= {
642 profile_attach(dev_info_t
*devi
, ddi_attach_cmd_t cmd
)
648 return (DDI_SUCCESS
);
650 return (DDI_FAILURE
);
653 if (ddi_create_minor_node(devi
, "profile", S_IFCHR
, 0,
654 DDI_PSEUDO
, NULL
) == DDI_FAILURE
||
655 dtrace_register("profile", &profile_attr
,
656 DTRACE_PRIV_KERNEL
| DTRACE_PRIV_USER
, NULL
,
657 &profile_pops
, NULL
, &profile_id
) != 0) {
658 ddi_remove_minor_node(devi
, NULL
);
659 return (DDI_FAILURE
);
662 #if !defined(__APPLE__)
663 profile_max
= ddi_getprop(DDI_DEV_T_ANY
, devi
, DDI_PROP_DONTPASS
,
664 "profile-max-probes", PROFILE_MAX_DEFAULT
);
666 profile_max
= PROFILE_MAX_DEFAULT
;
667 #endif /* __APPLE__ */
669 ddi_report_dev(devi
);
671 return (DDI_SUCCESS
);
674 #if !defined(__APPLE__)
676 profile_detach(dev_info_t
*devi
, ddi_detach_cmd_t cmd
)
682 return (DDI_SUCCESS
);
684 return (DDI_FAILURE
);
687 if (dtrace_unregister(profile_id
) != 0)
688 return (DDI_FAILURE
);
690 ddi_remove_minor_node(devi
, NULL
);
691 return (DDI_SUCCESS
);
696 profile_info(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
701 case DDI_INFO_DEVT2DEVINFO
:
702 *result
= (void *)profile_devi
;
705 case DDI_INFO_DEVT2INSTANCE
:
717 profile_open(dev_t
*devp
, int flag
, int otyp
, cred_t
*cred_p
)
722 static struct cb_ops profile_cb_ops
= {
723 profile_open
, /* open */
725 nulldev
, /* strategy */
735 ddi_prop_op
, /* cb_prop_op */
737 D_NEW
| D_MP
/* Driver compatibility flag */
740 static struct dev_ops profile_ops
= {
741 DEVO_REV
, /* devo_rev, */
743 profile_info
, /* get_dev_info */
744 nulldev
, /* identify */
746 profile_attach
, /* attach */
747 profile_detach
, /* detach */
749 &profile_cb_ops
, /* driver operations */
750 NULL
, /* bus operations */
751 nodev
/* dev power */
755 * Module linkage information for the kernel.
757 static struct modldrv modldrv
= {
758 &mod_driverops
, /* module type (this is a pseudo driver) */
759 "Profile Interrupt Tracing", /* name of module */
760 &profile_ops
, /* driver ops */
763 static struct modlinkage modlinkage
= {
772 return (mod_install(&modlinkage
));
776 _info(struct modinfo
*modinfop
)
778 return (mod_info(&modlinkage
, modinfop
));
784 return (mod_remove(&modlinkage
));
787 d_open_t _profile_open
;
789 int _profile_open(dev_t dev
, int flags
, int devtype
, struct proc
*p
)
791 #pragma unused(dev,flags,devtype,p)
795 #define PROFILE_MAJOR -24 /* let the kernel pick the device number */
798 * A struct describing which functions will get invoked for certain
801 static struct cdevsw profile_cdevsw
=
803 _profile_open
, /* open */
804 eno_opcl
, /* close */
805 eno_rdwrt
, /* read */
806 eno_rdwrt
, /* write */
807 eno_ioctl
, /* ioctl */
808 (stop_fcn_t
*)nulldev
, /* stop */
809 (reset_fcn_t
*)nulldev
, /* reset */
811 eno_select
, /* select */
813 eno_strat
, /* strategy */
819 static int gProfileInited
= 0;
821 void profile_init( void )
823 if (0 == gProfileInited
)
825 int majdevno
= cdevsw_add(PROFILE_MAJOR
, &profile_cdevsw
);
828 printf("profile_init: failed to allocate a major number!\n");
833 profile_attach( (dev_info_t
*)majdevno
, DDI_ATTACH
);
837 panic("profile_init: called twice!\n");
840 #endif /* __APPLE__ */