Upload folder using huggingface_hub (part 109)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard010/C/0138063_exp2.c +184 -0
- pool/shard010/C/0138064_dev_led_pwm.c +117 -0
- pool/shard010/C/0138065_mpc85xx_ads.c +290 -0
- pool/shard010/C/0138066_gnu_java_awt_peer_gtk_GtkClipboard.c +183 -0
- pool/shard010/C/0138067_string.c +277 -0
- pool/shard010/C/0138068_getValidInteger.c +103 -0
- pool/shard010/C/0138069_H5Tdeprec.c +205 -0
- pool/shard010/C/0138070_syscall.c +68 -0
- pool/shard010/C/0138071_alert.c +217 -0
- pool/shard010/C/0138072_tty.c +86 -0
- pool/shard010/C/0138073_igep0020.c +137 -0
- pool/shard010/C/0138074_machvec.c +70 -0
- pool/shard010/C/0138075_selectionSort.c +55 -0
- pool/shard010/C/0138076_flash.c +254 -0
- pool/shard010/C/0138077_eeze_disk_ls.c +58 -0
- pool/shard010/C/0138078_mod-locale.c +188 -0
- pool/shard010/C/0138079_cam-vertex.c +30 -0
- pool/shard010/C/0138080_ems1Form.c +321 -0
- pool/shard010/C/0138081_sunxi_sram.c +284 -0
- pool/shard010/C/0138082_ping_test.c +229 -0
- pool/shard010/C/0138083_ltt-facility-loader-network.c +66 -0
- pool/shard010/C/0138084_t-sgn.c +64 -0
- pool/shard010/C/0138085_shichif.c +218 -0
- pool/shard010/C/0138086_dirhistory_menu.c +132 -0
- pool/shard010/C/0138087_20090907-1.c +84 -0
- pool/shard010/C/0138088_msgrcv06.c +219 -0
- pool/shard010/C/0138089_CWE134_Uncontrolled_Format_String__char_console_vprintf_34.c +193 -0
- pool/shard010/C/0138090_Descriptors.c +264 -0
- pool/shard010/C/0138091_ipa-pta-14.c +32 -0
- pool/shard010/C/0138092_darken_x11.c +54 -0
- pool/shard010/C/0138093_pseudo_wrappers.c +229 -0
- pool/shard010/C/0138094_restart_7k.c +103 -0
- pool/shard010/C/0138095_phy-exynos-mipi-video.c +175 -0
- pool/shard010/C/0138096_kfd_device_queue_manager_vi.c +64 -0
- pool/shard010/C/0138097_SecPlatformInformation.c +84 -0
- pool/shard010/C/0138098_basic.c +24 -0
- pool/shard010/C/0138099_platsmp.c +177 -0
- pool/shard010/C/0138100_artst.c +91 -0
- pool/shard010/C/0138101_uart.c +219 -0
- pool/shard010/C/0138102_capitalize.c +22 -0
- pool/shard010/C/0138103_pthread_join.c +50 -0
- pool/shard010/C/0138104_mca_dsm.c +346 -0
- pool/shard010/C/0138105_thread_tcache_enabled.c +89 -0
- pool/shard010/C/0138106_watchman.c +82 -0
- pool/shard010/C/0138107_p_verify.c +119 -0
- pool/shard010/C/0138108_i915_random.c +109 -0
- pool/shard010/C/0138109_networkd-netdev-vlan.c +81 -0
- pool/shard010/C/0138110_main.c +298 -0
- pool/shard010/C/0138111_strlcpy.c +64 -0
- pool/shard010/C/0138112_kxsd9-spi.c +68 -0
pool/shard010/C/0138063_exp2.c
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* mpfr_exp2 -- power of 2 function 2^y
|
| 2 |
+
|
| 3 |
+
Copyright 2001-2021 Free Software Foundation, Inc.
|
| 4 |
+
Contributed by the AriC and Caramba projects, INRIA.
|
| 5 |
+
|
| 6 |
+
This file is part of the GNU MPFR Library.
|
| 7 |
+
|
| 8 |
+
The GNU MPFR Library is free software; you can redistribute it and/or modify
|
| 9 |
+
it under the terms of the GNU Lesser General Public License as published by
|
| 10 |
+
the Free Software Foundation; either version 3 of the License, or (at your
|
| 11 |
+
option) any later version.
|
| 12 |
+
|
| 13 |
+
The GNU MPFR Library is distributed in the hope that it will be useful, but
|
| 14 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
| 15 |
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 16 |
+
License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 19 |
+
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
|
| 20 |
+
https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
|
| 21 |
+
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
|
| 22 |
+
|
| 23 |
+
#define MPFR_NEED_LONGLONG_H
|
| 24 |
+
#include "mpfr-impl.h"
|
| 25 |
+
|
| 26 |
+
/* TODO: mpfr_get_exp_t is called 3 times, with 3 different directed
|
| 27 |
+
rounding modes. One could reduce it to only one call thanks to the
|
| 28 |
+
inexact flag, but is it worth? */
|
| 29 |
+
|
| 30 |
+
/* Convert x to an mpfr_eexp_t integer, with saturation at the minimum
|
| 31 |
+
and maximum values. Flags are unchanged. */
|
| 32 |
+
static mpfr_eexp_t
|
| 33 |
+
round_to_eexp_t (mpfr_srcptr x, mpfr_rnd_t rnd_mode)
|
| 34 |
+
{
|
| 35 |
+
mpfr_flags_t flags = __gmpfr_flags;
|
| 36 |
+
mpfr_eexp_t e;
|
| 37 |
+
|
| 38 |
+
e = mpfr_get_exp_t (x, rnd_mode);
|
| 39 |
+
__gmpfr_flags = flags;
|
| 40 |
+
return e;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* The computation of y = 2^z is done by *
|
| 44 |
+
* y = exp(z*log(2)). The result is exact iff z is an integer. */
|
| 45 |
+
|
| 46 |
+
int
|
| 47 |
+
mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
|
| 48 |
+
{
|
| 49 |
+
int inexact;
|
| 50 |
+
mpfr_eexp_t xint; /* note: will fit in mpfr_exp_t */
|
| 51 |
+
mpfr_t xfrac;
|
| 52 |
+
MPFR_SAVE_EXPO_DECL (expo);
|
| 53 |
+
|
| 54 |
+
MPFR_LOG_FUNC
|
| 55 |
+
(("x[%Pu]=%.*Rg rnd=%d", mpfr_get_prec(x), mpfr_log_prec, x, rnd_mode),
|
| 56 |
+
("y[%Pu]=%.*Rg inexact=%d", mpfr_get_prec(y), mpfr_log_prec, y,
|
| 57 |
+
inexact));
|
| 58 |
+
|
| 59 |
+
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
|
| 60 |
+
{
|
| 61 |
+
if (MPFR_IS_NAN (x))
|
| 62 |
+
{
|
| 63 |
+
MPFR_SET_NAN (y);
|
| 64 |
+
MPFR_RET_NAN;
|
| 65 |
+
}
|
| 66 |
+
else if (MPFR_IS_INF (x))
|
| 67 |
+
{
|
| 68 |
+
if (MPFR_IS_POS (x))
|
| 69 |
+
MPFR_SET_INF (y);
|
| 70 |
+
else
|
| 71 |
+
MPFR_SET_ZERO (y);
|
| 72 |
+
MPFR_SET_POS (y);
|
| 73 |
+
MPFR_RET (0);
|
| 74 |
+
}
|
| 75 |
+
else /* 2^0 = 1 */
|
| 76 |
+
{
|
| 77 |
+
MPFR_ASSERTD (MPFR_IS_ZERO(x));
|
| 78 |
+
return mpfr_set_ui (y, 1, rnd_mode);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* Since the smallest representable non-zero float is 1/2 * 2^emin,
|
| 83 |
+
if x <= emin - 2, the result is either 1/2 * 2^emin or 0.
|
| 84 |
+
Warning, for emin - 2 < x < emin - 1, we cannot conclude, since 2^x
|
| 85 |
+
might round to 2^(emin - 1) for rounding away or to nearest, and there
|
| 86 |
+
might be no underflow, since we consider underflow "after rounding". */
|
| 87 |
+
|
| 88 |
+
if (MPFR_UNLIKELY (round_to_eexp_t (x, MPFR_RNDU) <= __gmpfr_emin - 2))
|
| 89 |
+
return mpfr_underflow (y, rnd_mode == MPFR_RNDN ? MPFR_RNDZ : rnd_mode, 1);
|
| 90 |
+
|
| 91 |
+
if (MPFR_UNLIKELY (round_to_eexp_t (x, MPFR_RNDD) >= __gmpfr_emax))
|
| 92 |
+
return mpfr_overflow (y, rnd_mode, 1);
|
| 93 |
+
|
| 94 |
+
/* We now know that emin - 2 < x < emax. Note that an underflow or
|
| 95 |
+
overflow is still possible (we have eliminated only easy cases). */
|
| 96 |
+
|
| 97 |
+
MPFR_SAVE_EXPO_MARK (expo);
|
| 98 |
+
|
| 99 |
+
/* 2^x = 1 + x*log(2) + O(x^2) for x near zero, and for |x| <= 1 we have
|
| 100 |
+
|2^x - 1| <= x < 2^EXP(x). If x > 0 we must round away from 0 (dir=1);
|
| 101 |
+
if x < 0 we must round toward 0 (dir=0). */
|
| 102 |
+
MPFR_SMALL_INPUT_AFTER_SAVE_EXPO (y, __gmpfr_one, - MPFR_GET_EXP (x), 0,
|
| 103 |
+
MPFR_IS_POS (x), rnd_mode, expo, {});
|
| 104 |
+
|
| 105 |
+
xint = mpfr_get_exp_t (x, MPFR_RNDZ);
|
| 106 |
+
MPFR_ASSERTD (__gmpfr_emin - 2 < xint && xint < __gmpfr_emax);
|
| 107 |
+
|
| 108 |
+
mpfr_init2 (xfrac, MPFR_PREC (x));
|
| 109 |
+
MPFR_DBGRES (inexact = mpfr_frac (xfrac, x, MPFR_RNDN));
|
| 110 |
+
MPFR_ASSERTD (inexact == 0);
|
| 111 |
+
|
| 112 |
+
if (MPFR_IS_ZERO (xfrac))
|
| 113 |
+
{
|
| 114 |
+
/* Here, emin - 1 <= x <= emax - 1, so that an underflow or overflow
|
| 115 |
+
will not be possible. */
|
| 116 |
+
mpfr_set_ui (y, 1, MPFR_RNDN);
|
| 117 |
+
inexact = 0;
|
| 118 |
+
}
|
| 119 |
+
else
|
| 120 |
+
{
|
| 121 |
+
/* Declaration of the intermediary variable */
|
| 122 |
+
mpfr_t t;
|
| 123 |
+
|
| 124 |
+
/* Declaration of the size variable */
|
| 125 |
+
mpfr_prec_t Ny = MPFR_PREC(y); /* target precision */
|
| 126 |
+
mpfr_prec_t Nt; /* working precision */
|
| 127 |
+
mpfr_exp_t err; /* error */
|
| 128 |
+
MPFR_ZIV_DECL (loop);
|
| 129 |
+
|
| 130 |
+
/* compute the precision of intermediary variable */
|
| 131 |
+
/* the optimal number of bits : see algorithms.tex */
|
| 132 |
+
Nt = Ny + 5 + MPFR_INT_CEIL_LOG2 (Ny);
|
| 133 |
+
|
| 134 |
+
/* initialize of intermediary variable */
|
| 135 |
+
mpfr_init2 (t, Nt);
|
| 136 |
+
|
| 137 |
+
/* First computation */
|
| 138 |
+
MPFR_ZIV_INIT (loop, Nt);
|
| 139 |
+
for (;;)
|
| 140 |
+
{
|
| 141 |
+
/* compute exp(x*ln(2))*/
|
| 142 |
+
mpfr_const_log2 (t, MPFR_RNDU); /* ln(2) */
|
| 143 |
+
mpfr_mul (t, xfrac, t, MPFR_RNDU); /* xfrac * ln(2) */
|
| 144 |
+
err = Nt - (MPFR_GET_EXP (t) + 2); /* Estimate of the error */
|
| 145 |
+
mpfr_exp (t, t, MPFR_RNDN); /* exp(xfrac * ln(2)) */
|
| 146 |
+
|
| 147 |
+
if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode)))
|
| 148 |
+
break;
|
| 149 |
+
|
| 150 |
+
/* Actualisation of the precision */
|
| 151 |
+
MPFR_ZIV_NEXT (loop, Nt);
|
| 152 |
+
mpfr_set_prec (t, Nt);
|
| 153 |
+
}
|
| 154 |
+
MPFR_ZIV_FREE (loop);
|
| 155 |
+
|
| 156 |
+
inexact = mpfr_set (y, t, rnd_mode);
|
| 157 |
+
|
| 158 |
+
mpfr_clear (t);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
mpfr_clear (xfrac);
|
| 162 |
+
|
| 163 |
+
if (MPFR_UNLIKELY (rnd_mode == MPFR_RNDN && xint == __gmpfr_emin - 1 &&
|
| 164 |
+
MPFR_GET_EXP (y) == 0 && mpfr_powerof2_raw (y)))
|
| 165 |
+
{
|
| 166 |
+
/* y was rounded down to 1/2 and the rounded value with an unbounded
|
| 167 |
+
exponent range would be 2^(emin-2), i.e. the midpoint between 0
|
| 168 |
+
and the smallest positive FP number. This is a double rounding
|
| 169 |
+
problem: we should not round to 0, but to (1/2) * 2^emin. */
|
| 170 |
+
MPFR_SET_EXP (y, __gmpfr_emin);
|
| 171 |
+
inexact = 1;
|
| 172 |
+
MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, MPFR_FLAGS_UNDERFLOW);
|
| 173 |
+
}
|
| 174 |
+
else
|
| 175 |
+
{
|
| 176 |
+
/* The following is OK due to early overflow/underflow checking.
|
| 177 |
+
the exponent may be slightly out-of-range, but this will be
|
| 178 |
+
handled by mpfr_check_range. */
|
| 179 |
+
MPFR_EXP (y) += xint;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
MPFR_SAVE_EXPO_FREE (expo);
|
| 183 |
+
return mpfr_check_range (y, inexact, rnd_mode);
|
| 184 |
+
}
|
pool/shard010/C/0138064_dev_led_pwm.c
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* The MIT License (MIT)
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2016 Nels D. "Chip" Pearson (aka CmdrZin)
|
| 5 |
+
*
|
| 6 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
* in the Software without restriction, including without limitation the rights
|
| 9 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
* furnished to do so, subject to the following conditions:
|
| 12 |
+
*
|
| 13 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
* copies or substantial portions of the Software.
|
| 15 |
+
*
|
| 16 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
* SOFTWARE.
|
| 23 |
+
*
|
| 24 |
+
* dev_led_1.c
|
| 25 |
+
*
|
| 26 |
+
* Created: 2/24/2016 0.01 ndp
|
| 27 |
+
* Author: Chip
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
#include <avr/io.h>
|
| 31 |
+
#include <stdbool.h>
|
| 32 |
+
#include <avr/interrupt.h>
|
| 33 |
+
|
| 34 |
+
#include "sysTimer.h"
|
| 35 |
+
#include "access.h"
|
| 36 |
+
|
| 37 |
+
#include "dev_led_pwm.h"
|
| 38 |
+
|
| 39 |
+
#define DEMO_BOARD 0 // Use for testing. Set to 0 for proto-board set up.
|
| 40 |
+
|
| 41 |
+
bool dlp_state;
|
| 42 |
+
int dlp_rate;
|
| 43 |
+
int dlp_rateAdjust; // Controls how fast the glow cycles.
|
| 44 |
+
|
| 45 |
+
void dev_led_pwm_init()
|
| 46 |
+
{
|
| 47 |
+
dlp_state = false;
|
| 48 |
+
dlp_rate = 0;
|
| 49 |
+
dlp_rateAdjust = 4;
|
| 50 |
+
|
| 51 |
+
DEV_LED_PWM_DDR |= (1<<DEV_LED_PWM_P); // set HIGH for output
|
| 52 |
+
|
| 53 |
+
#if DEMO_BOARD == 1
|
| 54 |
+
// Extras for demo board use.
|
| 55 |
+
DDRD |= (1<<PD1); // use Port D B1 as output
|
| 56 |
+
PORTD &= ~(1<<PD1);
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
// Set up Timer 1
|
| 60 |
+
TCCR1A |= (1<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(1<<WGM11)|(1<<WGM10); // Use OC1A pin for PWM
|
| 61 |
+
TCCR1B |= (0<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(1<<CS10); // WGM = 0111 for 0x03FF as TOP..CPU div 1 = 0.050us
|
| 62 |
+
OCR1A = 0x0200; // 50%
|
| 63 |
+
TIMSK1 |= (1<<TOIE1); // OV bit intr
|
| 64 |
+
|
| 65 |
+
return;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/*
|
| 69 |
+
* Turn LED Glow OFF
|
| 70 |
+
* CMD: F0 DEV 01
|
| 71 |
+
*/
|
| 72 |
+
void dev_led_pwm_off()
|
| 73 |
+
{
|
| 74 |
+
DEV_LED_PWM_DDR &= ~(1<<DEV_LED_PWM_P); // set LOW for input to turn off
|
| 75 |
+
dlp_state = false;
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/*
|
| 80 |
+
* Turn LED Glow ON
|
| 81 |
+
* CMD: F0 DEV 02
|
| 82 |
+
*/
|
| 83 |
+
void dev_led_pwm_on()
|
| 84 |
+
{
|
| 85 |
+
DEV_LED_PWM_DDR |= (1<<DEV_LED_PWM_P); // set HIGH for output to turn on
|
| 86 |
+
dlp_state = true;
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/*
|
| 91 |
+
* Set glow rate
|
| 92 |
+
* CMD: F0 DEV 03 RATE
|
| 93 |
+
*/
|
| 94 |
+
void dev_led_pwm_setRate()
|
| 95 |
+
{
|
| 96 |
+
dlp_rateAdjust = getMsgData(3) & 0x03FF; // Limit to max count of Timer1
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/*
|
| 100 |
+
* Called continuously.
|
| 101 |
+
*/
|
| 102 |
+
void dev_led_pwm_service()
|
| 103 |
+
{
|
| 104 |
+
if( GPIOR0 & (1<<DEV_10MS_TIC) )
|
| 105 |
+
{
|
| 106 |
+
GPIOR0 &= ~(1<<DEV_10MS_TIC);
|
| 107 |
+
|
| 108 |
+
dlp_rate += dlp_rateAdjust;
|
| 109 |
+
if( dlp_rate > 0x03FF )
|
| 110 |
+
dlp_rate = 0;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
ISR( TIMER1_OVF_vect )
|
| 115 |
+
{
|
| 116 |
+
OCR1A = dlp_rate;
|
| 117 |
+
}
|
pool/shard010/C/0138065_mpc85xx_ads.c
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* MPC85xx setup and early boot code plus other random bits.
|
| 3 |
+
*
|
| 4 |
+
* Maintained by Kumar Gala (see MAINTAINERS for contact information)
|
| 5 |
+
*
|
| 6 |
+
* Copyright 2005 Freescale Semiconductor Inc.
|
| 7 |
+
*
|
| 8 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 9 |
+
* under the terms of the GNU General Public License as published by the
|
| 10 |
+
* Free Software Foundation; either version 2 of the License, or (at your
|
| 11 |
+
* option) any later version.
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
#include <linux/stddef.h>
|
| 15 |
+
#include <linux/kernel.h>
|
| 16 |
+
#include <linux/pci.h>
|
| 17 |
+
#include <linux/kdev_t.h>
|
| 18 |
+
#include <linux/delay.h>
|
| 19 |
+
#include <linux/seq_file.h>
|
| 20 |
+
|
| 21 |
+
#include <asm/system.h>
|
| 22 |
+
#include <asm/time.h>
|
| 23 |
+
#include <asm/machdep.h>
|
| 24 |
+
#include <asm/pci-bridge.h>
|
| 25 |
+
#include <asm/mpc85xx.h>
|
| 26 |
+
#include <asm/prom.h>
|
| 27 |
+
#include <asm/mpic.h>
|
| 28 |
+
#include <mm/mmu_decl.h>
|
| 29 |
+
#include <asm/udbg.h>
|
| 30 |
+
|
| 31 |
+
#include <sysdev/fsl_soc.h>
|
| 32 |
+
#include "mpc85xx.h"
|
| 33 |
+
|
| 34 |
+
#ifdef CONFIG_CPM2
|
| 35 |
+
#include <linux/fs_enet_pd.h>
|
| 36 |
+
#include <asm/cpm2.h>
|
| 37 |
+
#include <sysdev/cpm2_pic.h>
|
| 38 |
+
#include <asm/fs_pd.h>
|
| 39 |
+
#endif
|
| 40 |
+
|
| 41 |
+
#ifndef CONFIG_PCI
|
| 42 |
+
unsigned long isa_io_base = 0;
|
| 43 |
+
unsigned long isa_mem_base = 0;
|
| 44 |
+
#endif
|
| 45 |
+
|
| 46 |
+
#ifdef CONFIG_PCI
|
| 47 |
+
static int mpc85xx_exclude_device(u_char bus, u_char devfn)
|
| 48 |
+
{
|
| 49 |
+
if (bus == 0 && PCI_SLOT(devfn) == 0)
|
| 50 |
+
return PCIBIOS_DEVICE_NOT_FOUND;
|
| 51 |
+
else
|
| 52 |
+
return PCIBIOS_SUCCESSFUL;
|
| 53 |
+
}
|
| 54 |
+
#endif /* CONFIG_PCI */
|
| 55 |
+
|
| 56 |
+
#ifdef CONFIG_CPM2
|
| 57 |
+
|
| 58 |
+
static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
|
| 59 |
+
{
|
| 60 |
+
int cascade_irq;
|
| 61 |
+
|
| 62 |
+
while ((cascade_irq = cpm2_get_irq()) >= 0) {
|
| 63 |
+
generic_handle_irq(cascade_irq);
|
| 64 |
+
}
|
| 65 |
+
desc->chip->eoi(irq);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
#endif /* CONFIG_CPM2 */
|
| 69 |
+
|
| 70 |
+
static void __init mpc85xx_ads_pic_init(void)
|
| 71 |
+
{
|
| 72 |
+
struct mpic *mpic;
|
| 73 |
+
struct resource r;
|
| 74 |
+
struct device_node *np = NULL;
|
| 75 |
+
#ifdef CONFIG_CPM2
|
| 76 |
+
int irq;
|
| 77 |
+
#endif
|
| 78 |
+
|
| 79 |
+
np = of_find_node_by_type(np, "open-pic");
|
| 80 |
+
|
| 81 |
+
if (np == NULL) {
|
| 82 |
+
printk(KERN_ERR "Could not find open-pic node\n");
|
| 83 |
+
return;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if(of_address_to_resource(np, 0, &r)) {
|
| 87 |
+
printk(KERN_ERR "Could not map mpic register space\n");
|
| 88 |
+
of_node_put(np);
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
mpic = mpic_alloc(np, r.start,
|
| 93 |
+
MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
|
| 94 |
+
4, 0, " OpenPIC ");
|
| 95 |
+
BUG_ON(mpic == NULL);
|
| 96 |
+
of_node_put(np);
|
| 97 |
+
|
| 98 |
+
mpic_assign_isu(mpic, 0, r.start + 0x10200);
|
| 99 |
+
mpic_assign_isu(mpic, 1, r.start + 0x10280);
|
| 100 |
+
mpic_assign_isu(mpic, 2, r.start + 0x10300);
|
| 101 |
+
mpic_assign_isu(mpic, 3, r.start + 0x10380);
|
| 102 |
+
mpic_assign_isu(mpic, 4, r.start + 0x10400);
|
| 103 |
+
mpic_assign_isu(mpic, 5, r.start + 0x10480);
|
| 104 |
+
mpic_assign_isu(mpic, 6, r.start + 0x10500);
|
| 105 |
+
mpic_assign_isu(mpic, 7, r.start + 0x10580);
|
| 106 |
+
|
| 107 |
+
/* Unused on this platform (leave room for 8548) */
|
| 108 |
+
mpic_assign_isu(mpic, 8, r.start + 0x10600);
|
| 109 |
+
mpic_assign_isu(mpic, 9, r.start + 0x10680);
|
| 110 |
+
mpic_assign_isu(mpic, 10, r.start + 0x10700);
|
| 111 |
+
mpic_assign_isu(mpic, 11, r.start + 0x10780);
|
| 112 |
+
|
| 113 |
+
/* External Interrupts */
|
| 114 |
+
mpic_assign_isu(mpic, 12, r.start + 0x10000);
|
| 115 |
+
mpic_assign_isu(mpic, 13, r.start + 0x10080);
|
| 116 |
+
mpic_assign_isu(mpic, 14, r.start + 0x10100);
|
| 117 |
+
|
| 118 |
+
mpic_init(mpic);
|
| 119 |
+
|
| 120 |
+
#ifdef CONFIG_CPM2
|
| 121 |
+
/* Setup CPM2 PIC */
|
| 122 |
+
np = of_find_node_by_type(NULL, "cpm-pic");
|
| 123 |
+
if (np == NULL) {
|
| 124 |
+
printk(KERN_ERR "PIC init: can not find cpm-pic node\n");
|
| 125 |
+
return;
|
| 126 |
+
}
|
| 127 |
+
irq = irq_of_parse_and_map(np, 0);
|
| 128 |
+
|
| 129 |
+
cpm2_pic_init(np);
|
| 130 |
+
set_irq_chained_handler(irq, cpm2_cascade);
|
| 131 |
+
#endif
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/*
|
| 135 |
+
* Setup the architecture
|
| 136 |
+
*/
|
| 137 |
+
#ifdef CONFIG_CPM2
|
| 138 |
+
void init_fcc_ioports(struct fs_platform_info *fpi)
|
| 139 |
+
{
|
| 140 |
+
struct io_port *io = cpm2_map(im_ioport);
|
| 141 |
+
int fcc_no = fs_get_fcc_index(fpi->fs_no);
|
| 142 |
+
int target;
|
| 143 |
+
u32 tempval;
|
| 144 |
+
|
| 145 |
+
switch(fcc_no) {
|
| 146 |
+
case 1:
|
| 147 |
+
tempval = in_be32(&io->iop_pdirb);
|
| 148 |
+
tempval &= ~PB2_DIRB0;
|
| 149 |
+
tempval |= PB2_DIRB1;
|
| 150 |
+
out_be32(&io->iop_pdirb, tempval);
|
| 151 |
+
|
| 152 |
+
tempval = in_be32(&io->iop_psorb);
|
| 153 |
+
tempval &= ~PB2_PSORB0;
|
| 154 |
+
tempval |= PB2_PSORB1;
|
| 155 |
+
out_be32(&io->iop_psorb, tempval);
|
| 156 |
+
|
| 157 |
+
tempval = in_be32(&io->iop_pparb);
|
| 158 |
+
tempval |= (PB2_DIRB0 | PB2_DIRB1);
|
| 159 |
+
out_be32(&io->iop_pparb, tempval);
|
| 160 |
+
|
| 161 |
+
target = CPM_CLK_FCC2;
|
| 162 |
+
break;
|
| 163 |
+
case 2:
|
| 164 |
+
tempval = in_be32(&io->iop_pdirb);
|
| 165 |
+
tempval &= ~PB3_DIRB0;
|
| 166 |
+
tempval |= PB3_DIRB1;
|
| 167 |
+
out_be32(&io->iop_pdirb, tempval);
|
| 168 |
+
|
| 169 |
+
tempval = in_be32(&io->iop_psorb);
|
| 170 |
+
tempval &= ~PB3_PSORB0;
|
| 171 |
+
tempval |= PB3_PSORB1;
|
| 172 |
+
out_be32(&io->iop_psorb, tempval);
|
| 173 |
+
|
| 174 |
+
tempval = in_be32(&io->iop_pparb);
|
| 175 |
+
tempval |= (PB3_DIRB0 | PB3_DIRB1);
|
| 176 |
+
out_be32(&io->iop_pparb, tempval);
|
| 177 |
+
|
| 178 |
+
tempval = in_be32(&io->iop_pdirc);
|
| 179 |
+
tempval |= PC3_DIRC1;
|
| 180 |
+
out_be32(&io->iop_pdirc, tempval);
|
| 181 |
+
|
| 182 |
+
tempval = in_be32(&io->iop_pparc);
|
| 183 |
+
tempval |= PC3_DIRC1;
|
| 184 |
+
out_be32(&io->iop_pparc, tempval);
|
| 185 |
+
|
| 186 |
+
target = CPM_CLK_FCC3;
|
| 187 |
+
break;
|
| 188 |
+
default:
|
| 189 |
+
printk(KERN_ERR "init_fcc_ioports: invalid FCC number\n");
|
| 190 |
+
return;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/* Port C has clocks...... */
|
| 194 |
+
tempval = in_be32(&io->iop_psorc);
|
| 195 |
+
tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
|
| 196 |
+
out_be32(&io->iop_psorc, tempval);
|
| 197 |
+
|
| 198 |
+
tempval = in_be32(&io->iop_pdirc);
|
| 199 |
+
tempval &= ~(PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
|
| 200 |
+
out_be32(&io->iop_pdirc, tempval);
|
| 201 |
+
tempval = in_be32(&io->iop_pparc);
|
| 202 |
+
tempval |= (PC_CLK(fpi->clk_rx - 8) | PC_CLK(fpi->clk_tx - 8));
|
| 203 |
+
out_be32(&io->iop_pparc, tempval);
|
| 204 |
+
|
| 205 |
+
cpm2_unmap(io);
|
| 206 |
+
|
| 207 |
+
/* Configure Serial Interface clock routing.
|
| 208 |
+
* First, clear FCC bits to zero,
|
| 209 |
+
* then set the ones we want.
|
| 210 |
+
*/
|
| 211 |
+
cpm2_clk_setup(target, fpi->clk_rx, CPM_CLK_RX);
|
| 212 |
+
cpm2_clk_setup(target, fpi->clk_tx, CPM_CLK_TX);
|
| 213 |
+
}
|
| 214 |
+
#endif
|
| 215 |
+
|
| 216 |
+
static void __init mpc85xx_ads_setup_arch(void)
|
| 217 |
+
{
|
| 218 |
+
struct device_node *cpu;
|
| 219 |
+
#ifdef CONFIG_PCI
|
| 220 |
+
struct device_node *np;
|
| 221 |
+
#endif
|
| 222 |
+
|
| 223 |
+
if (ppc_md.progress)
|
| 224 |
+
ppc_md.progress("mpc85xx_ads_setup_arch()", 0);
|
| 225 |
+
|
| 226 |
+
cpu = of_find_node_by_type(NULL, "cpu");
|
| 227 |
+
if (cpu != 0) {
|
| 228 |
+
const unsigned int *fp;
|
| 229 |
+
|
| 230 |
+
fp = get_property(cpu, "clock-frequency", NULL);
|
| 231 |
+
if (fp != 0)
|
| 232 |
+
loops_per_jiffy = *fp / HZ;
|
| 233 |
+
else
|
| 234 |
+
loops_per_jiffy = 50000000 / HZ;
|
| 235 |
+
of_node_put(cpu);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
#ifdef CONFIG_CPM2
|
| 239 |
+
cpm2_reset();
|
| 240 |
+
#endif
|
| 241 |
+
|
| 242 |
+
#ifdef CONFIG_PCI
|
| 243 |
+
for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
|
| 244 |
+
add_bridge(np);
|
| 245 |
+
ppc_md.pci_exclude_device = mpc85xx_exclude_device;
|
| 246 |
+
#endif
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
static void mpc85xx_ads_show_cpuinfo(struct seq_file *m)
|
| 250 |
+
{
|
| 251 |
+
uint pvid, svid, phid1;
|
| 252 |
+
uint memsize = total_memory;
|
| 253 |
+
|
| 254 |
+
pvid = mfspr(SPRN_PVR);
|
| 255 |
+
svid = mfspr(SPRN_SVR);
|
| 256 |
+
|
| 257 |
+
seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
|
| 258 |
+
seq_printf(m, "Machine\t\t: mpc85xx\n");
|
| 259 |
+
seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
|
| 260 |
+
seq_printf(m, "SVR\t\t: 0x%x\n", svid);
|
| 261 |
+
|
| 262 |
+
/* Display cpu Pll setting */
|
| 263 |
+
phid1 = mfspr(SPRN_HID1);
|
| 264 |
+
seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
|
| 265 |
+
|
| 266 |
+
/* Display the amount of memory */
|
| 267 |
+
seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/*
|
| 271 |
+
* Called very early, device-tree isn't unflattened
|
| 272 |
+
*/
|
| 273 |
+
static int __init mpc85xx_ads_probe(void)
|
| 274 |
+
{
|
| 275 |
+
unsigned long root = of_get_flat_dt_root();
|
| 276 |
+
|
| 277 |
+
return of_flat_dt_is_compatible(root, "MPC85xxADS");
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
define_machine(mpc85xx_ads) {
|
| 281 |
+
.name = "MPC85xx ADS",
|
| 282 |
+
.probe = mpc85xx_ads_probe,
|
| 283 |
+
.setup_arch = mpc85xx_ads_setup_arch,
|
| 284 |
+
.init_IRQ = mpc85xx_ads_pic_init,
|
| 285 |
+
.show_cpuinfo = mpc85xx_ads_show_cpuinfo,
|
| 286 |
+
.get_irq = mpic_get_irq,
|
| 287 |
+
.restart = mpc85xx_restart,
|
| 288 |
+
.calibrate_decr = generic_calibrate_decr,
|
| 289 |
+
.progress = udbg_progress,
|
| 290 |
+
};
|
pool/shard010/C/0138066_gnu_java_awt_peer_gtk_GtkClipboard.c
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* gtkclipboard.c
|
| 2 |
+
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
| 3 |
+
|
| 4 |
+
This file is part of GNU Classpath.
|
| 5 |
+
|
| 6 |
+
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU General Public License as published by
|
| 8 |
+
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
+
any later version.
|
| 10 |
+
|
| 11 |
+
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
+
General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU General Public License
|
| 17 |
+
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
| 19 |
+
02111-1307 USA.
|
| 20 |
+
|
| 21 |
+
Linking this library statically or dynamically with other modules is
|
| 22 |
+
making a combined work based on this library. Thus, the terms and
|
| 23 |
+
conditions of the GNU General Public License cover the whole
|
| 24 |
+
combination.
|
| 25 |
+
|
| 26 |
+
As a special exception, the copyright holders of this library give you
|
| 27 |
+
permission to link this library with independent modules to produce an
|
| 28 |
+
executable, regardless of the license terms of these independent
|
| 29 |
+
modules, and to copy and distribute the resulting executable under
|
| 30 |
+
terms of your choice, provided that you also meet, for each linked
|
| 31 |
+
independent module, the terms and conditions of the license of that
|
| 32 |
+
module. An independent module is a module which is not derived from
|
| 33 |
+
or based on this library. If you modify this library, you may extend
|
| 34 |
+
this exception to your version of the library, but you are not
|
| 35 |
+
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
+
exception statement from your version. */
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
#include "gtkpeer.h"
|
| 40 |
+
#include "gnu_java_awt_peer_gtk_GtkClipboard.h"
|
| 41 |
+
|
| 42 |
+
jmethodID stringSelectionReceivedID;
|
| 43 |
+
jmethodID stringSelectionHandlerID;
|
| 44 |
+
jmethodID selectionClearID;
|
| 45 |
+
|
| 46 |
+
void selection_received (GtkWidget *, GtkSelectionData *, guint, gpointer);
|
| 47 |
+
void selection_get (GtkWidget *, GtkSelectionData *, guint, guint, gpointer);
|
| 48 |
+
gint selection_clear (GtkWidget *, GdkEventSelection *);
|
| 49 |
+
|
| 50 |
+
GtkWidget *clipboard;
|
| 51 |
+
jobject cb_obj;
|
| 52 |
+
|
| 53 |
+
JNIEXPORT void JNICALL
|
| 54 |
+
Java_gnu_java_awt_peer_gtk_GtkClipboard_initNativeState (JNIEnv *env,
|
| 55 |
+
jobject obj)
|
| 56 |
+
{
|
| 57 |
+
if (!stringSelectionReceivedID)
|
| 58 |
+
{
|
| 59 |
+
jclass gtkclipboard;
|
| 60 |
+
|
| 61 |
+
gtkclipboard = (*env)->FindClass (env,
|
| 62 |
+
"gnu/java/awt/peer/gtk/GtkClipboard");
|
| 63 |
+
stringSelectionReceivedID = (*env)->GetMethodID (env, gtkclipboard,
|
| 64 |
+
"stringSelectionReceived",
|
| 65 |
+
"(Ljava/lang/String;)V");
|
| 66 |
+
stringSelectionHandlerID = (*env)->GetMethodID (env, gtkclipboard,
|
| 67 |
+
"stringSelectionHandler",
|
| 68 |
+
"()Ljava/lang/String;");
|
| 69 |
+
selectionClearID = (*env)->GetMethodID (env, gtkclipboard,
|
| 70 |
+
"selectionClear", "()V");
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
cb_obj = (*env)->NewGlobalRef (env, obj);
|
| 74 |
+
|
| 75 |
+
gdk_threads_enter ();
|
| 76 |
+
clipboard = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
| 77 |
+
|
| 78 |
+
g_signal_connect (G_OBJECT(clipboard), "selection_received",
|
| 79 |
+
GTK_SIGNAL_FUNC (selection_received), NULL);
|
| 80 |
+
|
| 81 |
+
g_signal_connect (G_OBJECT(clipboard), "selection_clear_event",
|
| 82 |
+
GTK_SIGNAL_FUNC (selection_clear), NULL);
|
| 83 |
+
|
| 84 |
+
gtk_selection_add_target (clipboard, GDK_SELECTION_PRIMARY,
|
| 85 |
+
GDK_TARGET_STRING, 0);
|
| 86 |
+
|
| 87 |
+
g_signal_connect (G_OBJECT(clipboard), "selection_get",
|
| 88 |
+
GTK_SIGNAL_FUNC (selection_get), NULL);
|
| 89 |
+
|
| 90 |
+
gdk_threads_leave ();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
JNIEXPORT void JNICALL
|
| 94 |
+
Java_gnu_java_awt_peer_gtk_GtkClipboard_requestStringConversion
|
| 95 |
+
(JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)))
|
| 96 |
+
{
|
| 97 |
+
gdk_threads_enter ();
|
| 98 |
+
gtk_selection_convert (clipboard, GDK_SELECTION_PRIMARY,
|
| 99 |
+
GDK_TARGET_STRING, GDK_CURRENT_TIME);
|
| 100 |
+
gdk_threads_leave ();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void
|
| 104 |
+
selection_received (GtkWidget *widget __attribute__((unused)),
|
| 105 |
+
GtkSelectionData *selection_data __attribute__((unused)),
|
| 106 |
+
guint time __attribute__((unused)),
|
| 107 |
+
gpointer data __attribute__((unused)))
|
| 108 |
+
{
|
| 109 |
+
/* Check to see if retrieval succeeded */
|
| 110 |
+
if (selection_data->length < 0
|
| 111 |
+
|| selection_data->type != GDK_SELECTION_TYPE_STRING)
|
| 112 |
+
{
|
| 113 |
+
(*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, stringSelectionReceivedID,
|
| 114 |
+
NULL);
|
| 115 |
+
}
|
| 116 |
+
else
|
| 117 |
+
{
|
| 118 |
+
char *str = (char *) selection_data->data;
|
| 119 |
+
|
| 120 |
+
(*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, stringSelectionReceivedID,
|
| 121 |
+
(*gdk_env())->NewStringUTF (gdk_env(), str));
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
void
|
| 128 |
+
selection_get (GtkWidget *widget __attribute__((unused)),
|
| 129 |
+
GtkSelectionData *selection_data,
|
| 130 |
+
guint info __attribute__((unused)),
|
| 131 |
+
guint time __attribute__((unused)),
|
| 132 |
+
gpointer data __attribute__((unused)))
|
| 133 |
+
{
|
| 134 |
+
jstring jstr;
|
| 135 |
+
const char *utf;
|
| 136 |
+
jsize utflen;
|
| 137 |
+
|
| 138 |
+
jstr = (*gdk_env())->CallObjectMethod (gdk_env(), cb_obj,
|
| 139 |
+
stringSelectionHandlerID);
|
| 140 |
+
|
| 141 |
+
if (!jstr)
|
| 142 |
+
{
|
| 143 |
+
gtk_selection_data_set (selection_data,
|
| 144 |
+
GDK_TARGET_STRING, 8, NULL, 0);
|
| 145 |
+
return;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
utflen = (*gdk_env())->GetStringUTFLength (gdk_env(), jstr);
|
| 149 |
+
utf = (*gdk_env())->GetStringUTFChars (gdk_env(), jstr, NULL);
|
| 150 |
+
|
| 151 |
+
gtk_selection_data_set (selection_data, GDK_TARGET_STRING, 8,
|
| 152 |
+
(const unsigned char*)utf, utflen);
|
| 153 |
+
|
| 154 |
+
(*gdk_env())->ReleaseStringUTFChars (gdk_env(), jstr, utf);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
JNIEXPORT void JNICALL
|
| 158 |
+
Java_gnu_java_awt_peer_gtk_GtkClipboard_selectionGet
|
| 159 |
+
(JNIEnv *env, jclass clazz __attribute__((unused)))
|
| 160 |
+
{
|
| 161 |
+
GdkWindow *owner;
|
| 162 |
+
|
| 163 |
+
gdk_threads_enter ();
|
| 164 |
+
|
| 165 |
+
/* if we already own the clipboard, we need to tell the old data object
|
| 166 |
+
that we're no longer going to be using him */
|
| 167 |
+
owner = gdk_selection_owner_get (GDK_SELECTION_PRIMARY);
|
| 168 |
+
if (owner && owner == clipboard->window)
|
| 169 |
+
(*env)->CallVoidMethod (env, cb_obj, selectionClearID);
|
| 170 |
+
|
| 171 |
+
gtk_selection_owner_set (clipboard, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME);
|
| 172 |
+
|
| 173 |
+
gdk_threads_leave ();
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
gint
|
| 177 |
+
selection_clear (GtkWidget *widget __attribute__((unused)),
|
| 178 |
+
GdkEventSelection *event __attribute__((unused)))
|
| 179 |
+
{
|
| 180 |
+
(*gdk_env())->CallVoidMethod (gdk_env(), cb_obj, selectionClearID);
|
| 181 |
+
|
| 182 |
+
return TRUE;
|
| 183 |
+
}
|
pool/shard010/C/0138067_string.c
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdarg.h>
|
| 2 |
+
#include <string.h>
|
| 3 |
+
#include <stdlib.h>
|
| 4 |
+
#include <wchar.h>
|
| 5 |
+
#include <assert.h>
|
| 6 |
+
#include "util/memory.h"
|
| 7 |
+
#include "util/string.h"
|
| 8 |
+
|
| 9 |
+
/* ----------------------------------------------------------------------------
|
| 10 |
+
* Static functions
|
| 11 |
+
* ------------------------------------------------------------------------- */
|
| 12 |
+
static uintptr_t
|
| 13 |
+
safe_strlen(const char* str)
|
| 14 |
+
{
|
| 15 |
+
if(str)
|
| 16 |
+
return strlen(str);
|
| 17 |
+
return 0;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/* ------------------------------------------------------------------------- */
|
| 21 |
+
static void
|
| 22 |
+
safe_strcat(char* target, const char* source)
|
| 23 |
+
{
|
| 24 |
+
assert(target);
|
| 25 |
+
if(source)
|
| 26 |
+
strcat(target, source);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/* ------------------------------------------------------------------------- */
|
| 30 |
+
static uintptr_t
|
| 31 |
+
safe_wcslen(const wchar_t* wcs)
|
| 32 |
+
{
|
| 33 |
+
if(wcs)
|
| 34 |
+
return wcslen(wcs);
|
| 35 |
+
return 0;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* ------------------------------------------------------------------------- */
|
| 39 |
+
static void
|
| 40 |
+
safe_wcscat(wchar_t* target, const wchar_t* source)
|
| 41 |
+
{
|
| 42 |
+
assert(target);
|
| 43 |
+
if(source)
|
| 44 |
+
wcscat(target, source);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* ----------------------------------------------------------------------------
|
| 48 |
+
* Exported functions
|
| 49 |
+
* ------------------------------------------------------------------------- */
|
| 50 |
+
void
|
| 51 |
+
free_string(void* ptr)
|
| 52 |
+
{
|
| 53 |
+
assert(ptr);
|
| 54 |
+
FREE(ptr);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
/* ------------------------------------------------------------------------- */
|
| 58 |
+
char*
|
| 59 |
+
cat_strings(uint32_t num_strs, ...)
|
| 60 |
+
{
|
| 61 |
+
uint32_t total_length = 0;
|
| 62 |
+
uint32_t i;
|
| 63 |
+
char* buffer;
|
| 64 |
+
va_list ap;
|
| 65 |
+
|
| 66 |
+
/* compute total length of all strings combined and allocate a buffer able
|
| 67 |
+
* to contain all strings plus a null terminator */
|
| 68 |
+
va_start(ap, num_strs);
|
| 69 |
+
for(i = 0; i != num_strs; ++i)
|
| 70 |
+
total_length += safe_strlen(va_arg(ap, char*));
|
| 71 |
+
va_end(ap);
|
| 72 |
+
|
| 73 |
+
buffer = (char*)MALLOC((total_length+1) * sizeof(char));
|
| 74 |
+
if(!buffer)
|
| 75 |
+
{
|
| 76 |
+
fprintf(stderr, "malloc() failed in cat_strings() -- not enough memory\n");
|
| 77 |
+
return NULL;
|
| 78 |
+
}
|
| 79 |
+
*buffer = '\0'; /* so strcat works */
|
| 80 |
+
|
| 81 |
+
/* concatenate all strings into the allocated buffer */
|
| 82 |
+
va_start(ap, num_strs);
|
| 83 |
+
for(i = 0; i != num_strs; ++i)
|
| 84 |
+
safe_strcat(buffer, va_arg(ap, char*));
|
| 85 |
+
va_end(ap);
|
| 86 |
+
|
| 87 |
+
return buffer;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* ------------------------------------------------------------------------- */
|
| 91 |
+
char*
|
| 92 |
+
malloc_string(const char* str)
|
| 93 |
+
{
|
| 94 |
+
char* buffer;
|
| 95 |
+
assert(str);
|
| 96 |
+
|
| 97 |
+
buffer = (char*)MALLOC((strlen(str)+1) * sizeof(char));
|
| 98 |
+
if(!buffer)
|
| 99 |
+
{
|
| 100 |
+
fprintf(stderr, "malloc() failed in malloc_string() -- not enough memory\n");
|
| 101 |
+
return NULL;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
strcpy(buffer, str);
|
| 105 |
+
return buffer;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/* ------------------------------------------------------------------------- */
|
| 109 |
+
wchar_t*
|
| 110 |
+
cat_wstrings(uint32_t num_strs, ...)
|
| 111 |
+
{
|
| 112 |
+
uint32_t total_length = 0;
|
| 113 |
+
uint32_t i;
|
| 114 |
+
wchar_t* buffer;
|
| 115 |
+
va_list ap;
|
| 116 |
+
|
| 117 |
+
/* compute total length of all strings combined and allocate a buffer able
|
| 118 |
+
* to contain all strings plus a null terminator */
|
| 119 |
+
va_start(ap, num_strs);
|
| 120 |
+
for(i = 0; i != num_strs; ++i)
|
| 121 |
+
total_length += safe_wcslen(va_arg(ap, wchar_t*));
|
| 122 |
+
va_end(ap);
|
| 123 |
+
|
| 124 |
+
buffer = (wchar_t*)MALLOC((total_length+1) * sizeof(wchar_t));
|
| 125 |
+
if(!buffer)
|
| 126 |
+
{
|
| 127 |
+
fprintf(stderr, "malloc() failed in cat_wstrings() -- not enough memory\n");
|
| 128 |
+
return NULL;
|
| 129 |
+
}
|
| 130 |
+
*buffer = L'\0'; /* so wcscat works */
|
| 131 |
+
|
| 132 |
+
/* concatenate all strings into the allocated buffer */
|
| 133 |
+
va_start(ap, num_strs);
|
| 134 |
+
for(i = 0; i != num_strs; ++i)
|
| 135 |
+
safe_wcscat(buffer, va_arg(ap, wchar_t*));
|
| 136 |
+
va_end(ap);
|
| 137 |
+
|
| 138 |
+
return buffer;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/* ------------------------------------------------------------------------- */
|
| 142 |
+
wchar_t*
|
| 143 |
+
malloc_wstring(const wchar_t* wcs)
|
| 144 |
+
{
|
| 145 |
+
wchar_t* buffer;
|
| 146 |
+
assert(wcs);
|
| 147 |
+
|
| 148 |
+
buffer = (wchar_t*)MALLOC((wcslen(wcs)+1) * sizeof(wchar_t));
|
| 149 |
+
if(!buffer)
|
| 150 |
+
{
|
| 151 |
+
fprintf(stderr, "malloc() failed in malloc_wstring() -- not enough memory\n");
|
| 152 |
+
return NULL;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
wcscpy(buffer, wcs);
|
| 156 |
+
return buffer;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/* ------------------------------------------------------------------------- */
|
| 160 |
+
char*
|
| 161 |
+
strtok_r_portable(char* str, char delimiter, char** saveptr)
|
| 162 |
+
{
|
| 163 |
+
char* begin_ptr;
|
| 164 |
+
char* end_ptr;
|
| 165 |
+
|
| 166 |
+
if(str)
|
| 167 |
+
*saveptr = str - 1;
|
| 168 |
+
|
| 169 |
+
/* no more tokens */
|
| 170 |
+
if(!*saveptr)
|
| 171 |
+
return NULL;
|
| 172 |
+
|
| 173 |
+
/* get first occurrence of token in string */
|
| 174 |
+
begin_ptr = *saveptr + 1;
|
| 175 |
+
end_ptr = (char*)strchr(begin_ptr, delimiter);
|
| 176 |
+
if(!end_ptr)
|
| 177 |
+
*saveptr = NULL; /* last token has been reached */
|
| 178 |
+
else
|
| 179 |
+
{
|
| 180 |
+
/* update saveptr and replace delimiter with null terminator */
|
| 181 |
+
*saveptr = end_ptr;
|
| 182 |
+
**saveptr = '\0';
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/* empty tokens */
|
| 186 |
+
if(*begin_ptr == '\0')
|
| 187 |
+
return NULL;
|
| 188 |
+
return begin_ptr;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/* ------------------------------------------------------------------------- */
|
| 192 |
+
wchar_t*
|
| 193 |
+
strtowcs(const char* str)
|
| 194 |
+
{
|
| 195 |
+
wchar_t* wcs;
|
| 196 |
+
wchar_t* wcs_it;
|
| 197 |
+
uintptr_t len;
|
| 198 |
+
|
| 199 |
+
assert(str);
|
| 200 |
+
|
| 201 |
+
len = strlen(str);
|
| 202 |
+
|
| 203 |
+
wcs = (wchar_t*)MALLOC((len + 1) * sizeof(wchar_t));
|
| 204 |
+
if(!wcs)
|
| 205 |
+
{
|
| 206 |
+
fprintf(stderr, "malloc() failed in strtowcs() -- not enough memory\n");
|
| 207 |
+
return NULL;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
for(wcs_it = wcs; *str; ++str)
|
| 211 |
+
*wcs_it++ = (wchar_t)*str;
|
| 212 |
+
*wcs_it = L'\0';
|
| 213 |
+
return wcs;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/* ------------------------------------------------------------------------- */
|
| 217 |
+
char*
|
| 218 |
+
wcstostr(const wchar_t* wcs)
|
| 219 |
+
{
|
| 220 |
+
char* str;
|
| 221 |
+
char* str_it;
|
| 222 |
+
uintptr_t len;
|
| 223 |
+
|
| 224 |
+
assert(wcs);
|
| 225 |
+
|
| 226 |
+
len = wcslen(wcs);
|
| 227 |
+
|
| 228 |
+
str = (char*)MALLOC((len + 1) * sizeof(char));
|
| 229 |
+
if(!str)
|
| 230 |
+
{
|
| 231 |
+
fprintf(stderr, "malloc() failed in wcstostr() -- not enough memory\n");
|
| 232 |
+
return NULL;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
for(str_it = str; *wcs; ++wcs)
|
| 236 |
+
*str_it++ = (char)*wcs;
|
| 237 |
+
*str_it = '\0';
|
| 238 |
+
return str;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/* ------------------------------------------------------------------------- */
|
| 242 |
+
void
|
| 243 |
+
crlf2lf(char* src)
|
| 244 |
+
{
|
| 245 |
+
char* target;
|
| 246 |
+
|
| 247 |
+
assert(src);
|
| 248 |
+
|
| 249 |
+
target = src;
|
| 250 |
+
while(*src)
|
| 251 |
+
{
|
| 252 |
+
if(*src == '\r') /* skip any CRs */
|
| 253 |
+
++src;
|
| 254 |
+
*target++ = *src++;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/* if at least one CR was skipped, a new null-terminator must be set. */
|
| 258 |
+
if(target != src)
|
| 259 |
+
*target = '\0';
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/* ------------------------------------------------------------------------- */
|
| 263 |
+
void
|
| 264 |
+
string_reverse(char* str)
|
| 265 |
+
{
|
| 266 |
+
char* end;
|
| 267 |
+
|
| 268 |
+
assert(str);
|
| 269 |
+
|
| 270 |
+
end = str + strlen(str) - 1;
|
| 271 |
+
for(; str < end; ++str, --end)
|
| 272 |
+
{
|
| 273 |
+
char tmp = *str;
|
| 274 |
+
*str = *end;
|
| 275 |
+
*end = tmp;
|
| 276 |
+
}
|
| 277 |
+
}
|
pool/shard010/C/0138068_getValidInteger.c
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Filename: getValidInteger.c
|
| 3 |
+
* Author: Andrew Laing
|
| 4 |
+
* Email: parisianconnections@gmail.com
|
| 5 |
+
* Date: 19/08/2017.
|
| 6 |
+
* Description: Input an Integer
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#include <stdio.h>
|
| 10 |
+
#include <stdlib.h>
|
| 11 |
+
#include <ctype.h>
|
| 12 |
+
|
| 13 |
+
#define MAXLEN 9
|
| 14 |
+
|
| 15 |
+
int getLine( char [], int );
|
| 16 |
+
int isValidIntegerString( const char * );
|
| 17 |
+
int getValidInteger();
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
int main()
|
| 21 |
+
{
|
| 22 |
+
int num1;
|
| 23 |
+
|
| 24 |
+
printf("Enter integer string > ");
|
| 25 |
+
num1 = getValidInteger();
|
| 26 |
+
|
| 27 |
+
printf("num1 = %d\n", num1);
|
| 28 |
+
|
| 29 |
+
return 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
/* Read a string into a character array and return the length of the array
|
| 34 |
+
* Note: this produces an error message if the user trys to overflow the
|
| 35 |
+
* the character array, but allows them to retype rather than crashing
|
| 36 |
+
*/
|
| 37 |
+
int getLine( char s[], int maxLength )
|
| 38 |
+
{
|
| 39 |
+
int c, count, i, validLine=0;
|
| 40 |
+
|
| 41 |
+
while(validLine == 0)
|
| 42 |
+
{
|
| 43 |
+
count=0, i=0;
|
| 44 |
+
while( count <= maxLength && ( (c=getchar())!=EOF ) && ( c!='\n' ) )
|
| 45 |
+
{
|
| 46 |
+
s[i++]=c;
|
| 47 |
+
count++;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if( count > maxLength ) {
|
| 51 |
+
printf("Error - max line length is %d characters\n", maxLength );
|
| 52 |
+
printf("Please retype line: ");
|
| 53 |
+
}
|
| 54 |
+
else validLine++;
|
| 55 |
+
|
| 56 |
+
fflush(stdin); /* Clear any overflow*/
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if(c=='\n')
|
| 60 |
+
s[i++]=c;
|
| 61 |
+
s[i] = '\0';
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
fflush(stdin); /* Clear any overflow*/
|
| 65 |
+
|
| 66 |
+
return i;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
/* This method gets the user to input, then returns a valid integer
|
| 72 |
+
* Note: The maximum length of the integer is define as MAXLEN, and
|
| 73 |
+
* at the moment the method does not check that the string
|
| 74 |
+
* is within system integer boundaries.
|
| 75 |
+
|
| 76 |
+
** PROBLEM CAUSED BY SSCANF skipping SPACES
|
| 77 |
+
*/
|
| 78 |
+
int getValidInteger()
|
| 79 |
+
{
|
| 80 |
+
char str[MAXLEN+1];
|
| 81 |
+
int result = 0;
|
| 82 |
+
int validInt = 0;
|
| 83 |
+
|
| 84 |
+
/* Input a string */
|
| 85 |
+
getLine(str, MAXLEN);
|
| 86 |
+
|
| 87 |
+
/* If the string is valid convert and return it */
|
| 88 |
+
while(validInt == 0)
|
| 89 |
+
{
|
| 90 |
+
/* sscanf returns the number of conversions made */
|
| 91 |
+
if( !isspace(str[0]) )
|
| 92 |
+
validInt = sscanf(str, "%d", &result);
|
| 93 |
+
|
| 94 |
+
if( validInt == 0 )
|
| 95 |
+
{
|
| 96 |
+
printf("Error - Please enter a valid number: ");
|
| 97 |
+
getLine(str, MAXLEN);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
return result;
|
| 102 |
+
}
|
| 103 |
+
|
pool/shard010/C/0138069_H5Tdeprec.c
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
| 2 |
+
* Copyright by The HDF Group. *
|
| 3 |
+
* Copyright by the Board of Trustees of the University of Illinois. *
|
| 4 |
+
* All rights reserved. *
|
| 5 |
+
* *
|
| 6 |
+
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
| 7 |
+
* terms governing use, modification, and redistribution, is contained in *
|
| 8 |
+
* the COPYING file, which can be found at the root of the source code *
|
| 9 |
+
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
| 10 |
+
* If you do not have access to either file, you may request a copy from *
|
| 11 |
+
* help@hdfgroup.org. *
|
| 12 |
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
| 13 |
+
|
| 14 |
+
/*-------------------------------------------------------------------------
|
| 15 |
+
*
|
| 16 |
+
* Created: H5Tdeprec.c
|
| 17 |
+
* April 5 2007
|
| 18 |
+
* Quincey Koziol <koziol@hdfgroup.org>
|
| 19 |
+
*
|
| 20 |
+
* Purpose: Deprecated functions from the H5T interface. These
|
| 21 |
+
* functions are here for compatibility purposes and may be
|
| 22 |
+
* removed in the future. Applications should switch to the
|
| 23 |
+
* newer APIs.
|
| 24 |
+
*
|
| 25 |
+
*-------------------------------------------------------------------------
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
/****************/
|
| 29 |
+
/* Module Setup */
|
| 30 |
+
/****************/
|
| 31 |
+
|
| 32 |
+
#include "H5Tmodule.h" /* This source code file is part of the H5T module */
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
/***********/
|
| 36 |
+
/* Headers */
|
| 37 |
+
/***********/
|
| 38 |
+
#include "H5private.h" /* Generic Functions */
|
| 39 |
+
#include "H5ACprivate.h" /* Metadata cache */
|
| 40 |
+
#include "H5Eprivate.h" /* Error handling */
|
| 41 |
+
#include "H5FOprivate.h" /* File objects */
|
| 42 |
+
#include "H5Iprivate.h" /* IDs */
|
| 43 |
+
#include "H5Ppublic.h" /* Property Lists */
|
| 44 |
+
#include "H5Tpkg.h" /* Datatypes */
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
/****************/
|
| 48 |
+
/* Local Macros */
|
| 49 |
+
/****************/
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
/******************/
|
| 53 |
+
/* Local Typedefs */
|
| 54 |
+
/******************/
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
/********************/
|
| 58 |
+
/* Package Typedefs */
|
| 59 |
+
/********************/
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
/********************/
|
| 63 |
+
/* Local Prototypes */
|
| 64 |
+
/********************/
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
/*********************/
|
| 68 |
+
/* Package Variables */
|
| 69 |
+
/*********************/
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
/*****************************/
|
| 73 |
+
/* Library Private Variables */
|
| 74 |
+
/*****************************/
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
/*******************/
|
| 78 |
+
/* Local Variables */
|
| 79 |
+
/*******************/
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
| 83 |
+
|
| 84 |
+
/*-------------------------------------------------------------------------
|
| 85 |
+
* Function: H5Tcommit1
|
| 86 |
+
*
|
| 87 |
+
* Purpose: Save a transient datatype to a file and turn the type handle
|
| 88 |
+
* into a named, immutable type.
|
| 89 |
+
*
|
| 90 |
+
* Note: Deprecated in favor of H5Tcommit2
|
| 91 |
+
*
|
| 92 |
+
* Return: Non-negative on success/Negative on failure
|
| 93 |
+
*
|
| 94 |
+
* Programmer: Robb Matzke
|
| 95 |
+
* Monday, June 1, 1998
|
| 96 |
+
*
|
| 97 |
+
*-------------------------------------------------------------------------
|
| 98 |
+
*/
|
| 99 |
+
herr_t
|
| 100 |
+
H5Tcommit1(hid_t loc_id, const char *name, hid_t type_id)
|
| 101 |
+
{
|
| 102 |
+
H5G_loc_t loc; /* Location to create datatype */
|
| 103 |
+
H5T_t *type; /* Datatype for ID */
|
| 104 |
+
herr_t ret_value = SUCCEED; /* Return value */
|
| 105 |
+
|
| 106 |
+
FUNC_ENTER_API(FAIL)
|
| 107 |
+
H5TRACE3("e", "i*si", loc_id, name, type_id);
|
| 108 |
+
|
| 109 |
+
/* Check arguments */
|
| 110 |
+
if(H5G_loc(loc_id, &loc) < 0)
|
| 111 |
+
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
|
| 112 |
+
if(!name || !*name)
|
| 113 |
+
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
|
| 114 |
+
if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
|
| 115 |
+
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
|
| 116 |
+
|
| 117 |
+
/* Commit the datatype to the file, using default property list values */
|
| 118 |
+
if(H5T__commit_named(&loc, name, type, H5P_LINK_CREATE_DEFAULT,
|
| 119 |
+
H5P_DATATYPE_CREATE_DEFAULT, H5P_DATATYPE_ACCESS_DEFAULT, H5AC_ind_read_dxpl_id) < 0)
|
| 120 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to commit datatype")
|
| 121 |
+
|
| 122 |
+
done:
|
| 123 |
+
FUNC_LEAVE_API(ret_value)
|
| 124 |
+
} /* end H5Tcommit1() */
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
/*-------------------------------------------------------------------------
|
| 128 |
+
* Function: H5Topen1
|
| 129 |
+
*
|
| 130 |
+
* Purpose: Opens a named datatype.
|
| 131 |
+
*
|
| 132 |
+
* Note: Deprecated in favor of H5Topen2
|
| 133 |
+
*
|
| 134 |
+
* Return: Success: Object ID of the named datatype.
|
| 135 |
+
*
|
| 136 |
+
* Failure: Negative
|
| 137 |
+
*
|
| 138 |
+
* Programmer: Robb Matzke
|
| 139 |
+
* Monday, June 1, 1998
|
| 140 |
+
*
|
| 141 |
+
*-------------------------------------------------------------------------
|
| 142 |
+
*/
|
| 143 |
+
hid_t
|
| 144 |
+
H5Topen1(hid_t loc_id, const char *name)
|
| 145 |
+
{
|
| 146 |
+
H5T_t *type = NULL;
|
| 147 |
+
H5G_loc_t loc;
|
| 148 |
+
H5G_name_t path; /* Datatype group hier. path */
|
| 149 |
+
H5O_loc_t oloc; /* Datatype object location */
|
| 150 |
+
H5O_type_t obj_type; /* Type of object at location */
|
| 151 |
+
H5G_loc_t type_loc; /* Group object for datatype */
|
| 152 |
+
hbool_t obj_found = FALSE; /* Object at 'name' found */
|
| 153 |
+
hid_t dxpl_id = H5AC_ind_read_dxpl_id; /* dxpl to use to open datatype */
|
| 154 |
+
hid_t ret_value = FAIL;
|
| 155 |
+
|
| 156 |
+
FUNC_ENTER_API(FAIL)
|
| 157 |
+
H5TRACE2("i", "i*s", loc_id, name);
|
| 158 |
+
|
| 159 |
+
/* Check args */
|
| 160 |
+
if(H5G_loc(loc_id, &loc) < 0)
|
| 161 |
+
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
|
| 162 |
+
if(!name || !*name)
|
| 163 |
+
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
|
| 164 |
+
|
| 165 |
+
/* Set up datatype location to fill in */
|
| 166 |
+
type_loc.oloc = &oloc;
|
| 167 |
+
type_loc.path = &path;
|
| 168 |
+
H5G_loc_reset(&type_loc);
|
| 169 |
+
|
| 170 |
+
/*
|
| 171 |
+
* Find the named datatype object header and read the datatype message
|
| 172 |
+
* from it.
|
| 173 |
+
*/
|
| 174 |
+
if(H5G_loc_find(&loc, name, &type_loc/*out*/, H5P_DEFAULT, dxpl_id) < 0)
|
| 175 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "not found")
|
| 176 |
+
obj_found = TRUE;
|
| 177 |
+
|
| 178 |
+
/* Check that the object found is the correct type */
|
| 179 |
+
if(H5O_obj_type(&oloc, &obj_type, dxpl_id) < 0)
|
| 180 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get object type")
|
| 181 |
+
if(obj_type != H5O_TYPE_NAMED_DATATYPE)
|
| 182 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a named datatype")
|
| 183 |
+
|
| 184 |
+
/* Open it */
|
| 185 |
+
if((type = H5T_open(&type_loc, dxpl_id)) == NULL)
|
| 186 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open named datatype")
|
| 187 |
+
|
| 188 |
+
/* Register the type and return the ID */
|
| 189 |
+
if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0)
|
| 190 |
+
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register named datatype")
|
| 191 |
+
|
| 192 |
+
done:
|
| 193 |
+
if(ret_value < 0) {
|
| 194 |
+
if(type != NULL)
|
| 195 |
+
H5T_close(type);
|
| 196 |
+
else {
|
| 197 |
+
if(obj_found && H5F_addr_defined(type_loc.oloc->addr))
|
| 198 |
+
H5G_loc_free(&type_loc);
|
| 199 |
+
} /* end else */
|
| 200 |
+
} /* end if */
|
| 201 |
+
|
| 202 |
+
FUNC_LEAVE_API(ret_value)
|
| 203 |
+
} /* end H5Topen1() */
|
| 204 |
+
#endif /* H5_NO_DEPRECATED_SYMBOLS */
|
| 205 |
+
|
pool/shard010/C/0138070_syscall.c
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
| 3 |
+
* Licensed under the GPL
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include "linux/file.h"
|
| 7 |
+
#include "linux/fs.h"
|
| 8 |
+
#include "linux/mm.h"
|
| 9 |
+
#include "linux/sched.h"
|
| 10 |
+
#include "linux/utsname.h"
|
| 11 |
+
#include "linux/syscalls.h"
|
| 12 |
+
#include "asm/current.h"
|
| 13 |
+
#include "asm/mman.h"
|
| 14 |
+
#include "asm/uaccess.h"
|
| 15 |
+
#include "asm/unistd.h"
|
| 16 |
+
#include "internal.h"
|
| 17 |
+
|
| 18 |
+
long sys_fork(void)
|
| 19 |
+
{
|
| 20 |
+
return do_fork(SIGCHLD, UPT_SP(¤t->thread.regs.regs),
|
| 21 |
+
¤t->thread.regs, 0, NULL, NULL);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
long sys_vfork(void)
|
| 25 |
+
{
|
| 26 |
+
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
|
| 27 |
+
UPT_SP(¤t->thread.regs.regs),
|
| 28 |
+
¤t->thread.regs, 0, NULL, NULL);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
long sys_clone(unsigned long clone_flags, unsigned long newsp,
|
| 32 |
+
void __user *parent_tid, void __user *child_tid)
|
| 33 |
+
{
|
| 34 |
+
if (!newsp)
|
| 35 |
+
newsp = UPT_SP(¤t->thread.regs.regs);
|
| 36 |
+
|
| 37 |
+
return do_fork(clone_flags, newsp, ¤t->thread.regs, 0, parent_tid,
|
| 38 |
+
child_tid);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
long old_mmap(unsigned long addr, unsigned long len,
|
| 42 |
+
unsigned long prot, unsigned long flags,
|
| 43 |
+
unsigned long fd, unsigned long offset)
|
| 44 |
+
{
|
| 45 |
+
long err = -EINVAL;
|
| 46 |
+
if (offset & ~PAGE_MASK)
|
| 47 |
+
goto out;
|
| 48 |
+
|
| 49 |
+
err = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
|
| 50 |
+
out:
|
| 51 |
+
return err;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
int kernel_execve(const char *filename,
|
| 55 |
+
const char *const argv[],
|
| 56 |
+
const char *const envp[])
|
| 57 |
+
{
|
| 58 |
+
mm_segment_t fs;
|
| 59 |
+
int ret;
|
| 60 |
+
|
| 61 |
+
fs = get_fs();
|
| 62 |
+
set_fs(KERNEL_DS);
|
| 63 |
+
ret = um_execve(filename, (const char __user *const __user *)argv,
|
| 64 |
+
(const char __user *const __user *) envp);
|
| 65 |
+
set_fs(fs);
|
| 66 |
+
|
| 67 |
+
return ret;
|
| 68 |
+
}
|
pool/shard010/C/0138071_alert.c
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) Tildeslash Ltd. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* This program is free software: you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU Affero General Public License version 3.
|
| 6 |
+
*
|
| 7 |
+
* This program is distributed in the hope that it will be useful,
|
| 8 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
* GNU General Public License for more details.
|
| 11 |
+
*
|
| 12 |
+
* You should have received a copy of the GNU Affero General Public License
|
| 13 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 14 |
+
*
|
| 15 |
+
* In addition, as a special exception, the copyright holders give
|
| 16 |
+
* permission to link the code of portions of this program with the
|
| 17 |
+
* OpenSSL library under certain conditions as described in each
|
| 18 |
+
* individual source file, and distribute linked combinations
|
| 19 |
+
* including the two.
|
| 20 |
+
*
|
| 21 |
+
* You must obey the GNU Affero General Public License in all respects
|
| 22 |
+
* for all of the code used other than OpenSSL.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
#include "config.h"
|
| 26 |
+
|
| 27 |
+
#ifdef HAVE_STDIO_H
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
#ifdef HAVE_STDLIB_H
|
| 32 |
+
#include <stdlib.h>
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
#ifdef HAVE_STDARG_H
|
| 36 |
+
#include <stdarg.h>
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
#ifdef HAVE_STRING_H
|
| 40 |
+
#include <string.h>
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
#ifdef HAVE_UNISTD_H
|
| 44 |
+
#include <unistd.h>
|
| 45 |
+
#endif
|
| 46 |
+
|
| 47 |
+
#ifdef HAVE_SIGNAL_H
|
| 48 |
+
#include <signal.h>
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#include "monit.h"
|
| 52 |
+
#include "event.h"
|
| 53 |
+
#include "net.h"
|
| 54 |
+
#include "alert.h"
|
| 55 |
+
|
| 56 |
+
// libmonit
|
| 57 |
+
#include "system/Time.h"
|
| 58 |
+
#include "util/Str.h"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Implementation of the alert module
|
| 63 |
+
*
|
| 64 |
+
* @file
|
| 65 |
+
*/
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
/* -------------------------------------------------------------- Prototypes */
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
static void copy_mail(Mail_T, Mail_T);
|
| 72 |
+
static void escape(Mail_T);
|
| 73 |
+
static void substitute(Mail_T, Event_T);
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
/* ------------------------------------------------------------------ Public */
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Notify registred users about the event
|
| 81 |
+
* @param E An Event object
|
| 82 |
+
* @return If failed, return Handler_Alert flag or Handler_Succeeded if succeeded
|
| 83 |
+
*/
|
| 84 |
+
Handler_Type handle_alert(Event_T E) {
|
| 85 |
+
Handler_Type rv = Handler_Succeeded;
|
| 86 |
+
|
| 87 |
+
ASSERT(E);
|
| 88 |
+
|
| 89 |
+
Service_T s = Event_get_source(E);
|
| 90 |
+
if (! s) {
|
| 91 |
+
LogError("Aborting alert\n");
|
| 92 |
+
return rv;
|
| 93 |
+
}
|
| 94 |
+
if (s->maillist || Run.maillist) {
|
| 95 |
+
Mail_T list = NULL;
|
| 96 |
+
/*
|
| 97 |
+
* Build a mail-list with local recipients that has registered interest
|
| 98 |
+
* for this event.
|
| 99 |
+
*/
|
| 100 |
+
for (Mail_T m = s->maillist; m; m = m->next) {
|
| 101 |
+
if (
|
| 102 |
+
/* particular event notification type is allowed for given recipient */
|
| 103 |
+
IS_EVENT_SET(m->events, Event_get_id(E)) &&
|
| 104 |
+
(
|
| 105 |
+
/* state change notification is sent always */
|
| 106 |
+
E->state_changed ||
|
| 107 |
+
/* in the case that the state is failed for more cycles we check
|
| 108 |
+
* whether we should send the reminder */
|
| 109 |
+
(E->state && m->reminder && E->count % m->reminder == 0)
|
| 110 |
+
)
|
| 111 |
+
)
|
| 112 |
+
{
|
| 113 |
+
Mail_T tmp = NULL;
|
| 114 |
+
NEW(tmp);
|
| 115 |
+
copy_mail(tmp, m);
|
| 116 |
+
substitute(tmp, E);
|
| 117 |
+
escape(tmp);
|
| 118 |
+
tmp->next = list;
|
| 119 |
+
list = tmp;
|
| 120 |
+
DEBUG("%s notification is sent to %s\n", Event_get_description(E), m->to);
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
/*
|
| 124 |
+
* Build a mail-list with global recipients that has registered interest
|
| 125 |
+
* for this event. Recipients which are defined in the service localy
|
| 126 |
+
* overrides the same recipient events which are registered globaly.
|
| 127 |
+
*/
|
| 128 |
+
for (Mail_T m = Run.maillist; m; m = m->next) {
|
| 129 |
+
boolean_t skip = false;
|
| 130 |
+
for (Mail_T n = s->maillist; n; n = n->next) {
|
| 131 |
+
if (IS(m->to, n->to)) {
|
| 132 |
+
skip = true;
|
| 133 |
+
break;
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
if (
|
| 137 |
+
/* the local service alert definition has not overrided the global one */
|
| 138 |
+
! skip &&
|
| 139 |
+
/* particular event notification type is allowed for given recipient */
|
| 140 |
+
IS_EVENT_SET(m->events, Event_get_id(E)) &&
|
| 141 |
+
(
|
| 142 |
+
/* state change notification is sent always */
|
| 143 |
+
E->state_changed ||
|
| 144 |
+
/* in the case that the state is failed for more cycles we check
|
| 145 |
+
* whether we should send the reminder */
|
| 146 |
+
(E->state && m->reminder && E->count % m->reminder == 0)
|
| 147 |
+
)
|
| 148 |
+
)
|
| 149 |
+
{
|
| 150 |
+
Mail_T tmp = NULL;
|
| 151 |
+
NEW(tmp);
|
| 152 |
+
copy_mail(tmp, m);
|
| 153 |
+
substitute(tmp, E);
|
| 154 |
+
escape(tmp);
|
| 155 |
+
tmp->next = list;
|
| 156 |
+
list = tmp;
|
| 157 |
+
DEBUG("%s notification is sent to %s\n", Event_get_description(E), m->to);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
if (list) {
|
| 161 |
+
if (sendmail(list))
|
| 162 |
+
rv = Handler_Alert;
|
| 163 |
+
gc_mail_list(&list);
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
return rv;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
static void substitute(Mail_T m, Event_T e) {
|
| 171 |
+
char timestamp[STRLEN];
|
| 172 |
+
|
| 173 |
+
ASSERT(m && e);
|
| 174 |
+
|
| 175 |
+
Util_replaceString(&m->from, "$HOST", Run.system->name);
|
| 176 |
+
Util_replaceString(&m->subject, "$HOST", Run.system->name);
|
| 177 |
+
Util_replaceString(&m->message, "$HOST", Run.system->name);
|
| 178 |
+
|
| 179 |
+
Time_string(e->collected.tv_sec, timestamp);
|
| 180 |
+
Util_replaceString(&m->subject, "$DATE", timestamp);
|
| 181 |
+
Util_replaceString(&m->message, "$DATE", timestamp);
|
| 182 |
+
|
| 183 |
+
Util_replaceString(&m->subject, "$SERVICE", Event_get_source_name(e));
|
| 184 |
+
Util_replaceString(&m->message, "$SERVICE", Event_get_source_name(e));
|
| 185 |
+
|
| 186 |
+
Util_replaceString(&m->subject, "$EVENT", Event_get_description(e));
|
| 187 |
+
Util_replaceString(&m->message, "$EVENT", Event_get_description(e));
|
| 188 |
+
|
| 189 |
+
Util_replaceString(&m->subject, "$DESCRIPTION", NVLSTR(Event_get_message(e)));
|
| 190 |
+
Util_replaceString(&m->message, "$DESCRIPTION", NVLSTR(Event_get_message(e)));
|
| 191 |
+
|
| 192 |
+
Util_replaceString(&m->subject, "$ACTION", Event_get_action_description(e));
|
| 193 |
+
Util_replaceString(&m->message, "$ACTION", Event_get_action_description(e));
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
static void copy_mail(Mail_T n, Mail_T o) {
|
| 198 |
+
ASSERT(n && o);
|
| 199 |
+
|
| 200 |
+
n->to = Str_dup(o->to);
|
| 201 |
+
n->from = o->from ? Str_dup(o->from) : Run.MailFormat.from ? Str_dup(Run.MailFormat.from) : Str_dup(ALERT_FROM);
|
| 202 |
+
n->replyto = o->replyto ? Str_dup(o->replyto) : Run.MailFormat.replyto ? Str_dup(Run.MailFormat.replyto) : NULL;
|
| 203 |
+
n->subject = o->subject ? Str_dup(o->subject) : Run.MailFormat.subject ? Str_dup(Run.MailFormat.subject) : Str_dup(ALERT_SUBJECT);
|
| 204 |
+
n->message = o->message ? Str_dup(o->message) : Run.MailFormat.message ? Str_dup(Run.MailFormat.message) : Str_dup(ALERT_MESSAGE);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
static void escape(Mail_T m) {
|
| 209 |
+
// replace bare linefeed
|
| 210 |
+
Util_replaceString(&m->message, "\r\n", "\n");
|
| 211 |
+
Util_replaceString(&m->message, "\n", "\r\n");
|
| 212 |
+
// escape ^.
|
| 213 |
+
Util_replaceString(&m->message, "\n.", "\n..");
|
| 214 |
+
// drop any CR|LF from the subject
|
| 215 |
+
Str_chomp(m->subject);
|
| 216 |
+
}
|
| 217 |
+
|
pool/shard010/C/0138072_tty.c
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
|
| 3 |
+
* Licensed under the GPL
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <stdio.h>
|
| 7 |
+
#include <termios.h>
|
| 8 |
+
#include <fcntl.h>
|
| 9 |
+
#include <errno.h>
|
| 10 |
+
#include <unistd.h>
|
| 11 |
+
#include "chan_user.h"
|
| 12 |
+
#include "user_util.h"
|
| 13 |
+
#include "user.h"
|
| 14 |
+
#include "os.h"
|
| 15 |
+
|
| 16 |
+
struct tty_chan {
|
| 17 |
+
char *dev;
|
| 18 |
+
int raw;
|
| 19 |
+
struct termios tt;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
void *tty_chan_init(char *str, int device, struct chan_opts *opts)
|
| 23 |
+
{
|
| 24 |
+
struct tty_chan *data;
|
| 25 |
+
|
| 26 |
+
if(*str != ':'){
|
| 27 |
+
printk("tty_init : channel type 'tty' must specify "
|
| 28 |
+
"a device\n");
|
| 29 |
+
return(NULL);
|
| 30 |
+
}
|
| 31 |
+
str++;
|
| 32 |
+
|
| 33 |
+
if((data = um_kmalloc(sizeof(*data))) == NULL)
|
| 34 |
+
return(NULL);
|
| 35 |
+
*data = ((struct tty_chan) { .dev = str,
|
| 36 |
+
.raw = opts->raw });
|
| 37 |
+
|
| 38 |
+
return(data);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
int tty_open(int input, int output, int primary, void *d, char **dev_out)
|
| 42 |
+
{
|
| 43 |
+
struct tty_chan *data = d;
|
| 44 |
+
int fd;
|
| 45 |
+
|
| 46 |
+
fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
|
| 47 |
+
if(fd < 0) return(fd);
|
| 48 |
+
if(data->raw){
|
| 49 |
+
tcgetattr(fd, &data->tt);
|
| 50 |
+
raw(fd, 0);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
*dev_out = data->dev;
|
| 54 |
+
return(fd);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
int tty_console_write(int fd, const char *buf, int n, void *d)
|
| 58 |
+
{
|
| 59 |
+
struct tty_chan *data = d;
|
| 60 |
+
|
| 61 |
+
return(generic_console_write(fd, buf, n, &data->tt));
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
struct chan_ops tty_ops = {
|
| 65 |
+
.type = "tty",
|
| 66 |
+
.init = tty_chan_init,
|
| 67 |
+
.open = tty_open,
|
| 68 |
+
.close = generic_close,
|
| 69 |
+
.read = generic_read,
|
| 70 |
+
.write = generic_write,
|
| 71 |
+
.console_write = tty_console_write,
|
| 72 |
+
.window_size = generic_window_size,
|
| 73 |
+
.free = generic_free,
|
| 74 |
+
.winch = 0,
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
/*
|
| 78 |
+
* Overrides for Emacs so that we follow Linus's tabbing style.
|
| 79 |
+
* Emacs will notice this stuff at the end of the file and automatically
|
| 80 |
+
* adjust the settings for this buffer only. This must remain at the end
|
| 81 |
+
* of the file.
|
| 82 |
+
* ---------------------------------------------------------------------------
|
| 83 |
+
* Local variables:
|
| 84 |
+
* c-file-style: "linux"
|
| 85 |
+
* End:
|
| 86 |
+
*/
|
pool/shard010/C/0138073_igep0020.c
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* (C) Copyright 2010
|
| 3 |
+
* ISEE 2007 SL, <www.iseebcn.com>
|
| 4 |
+
*
|
| 5 |
+
* See file CREDITS for list of people who contributed to this
|
| 6 |
+
* project.
|
| 7 |
+
*
|
| 8 |
+
* This program is free software; you can redistribute it and/or
|
| 9 |
+
* modify it under the terms of the GNU General Public License as
|
| 10 |
+
* published by the Free Software Foundation; either version 2 of
|
| 11 |
+
* the License, or (at your option) any later version.
|
| 12 |
+
*
|
| 13 |
+
* This program is distributed in the hope that it will be useful,
|
| 14 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
+
* GNU General Public License for more details.
|
| 17 |
+
*
|
| 18 |
+
* You should have received a copy of the GNU General Public License
|
| 19 |
+
* along with this program; if not, write to the Free Software
|
| 20 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
| 21 |
+
* MA 02111-1307 USA
|
| 22 |
+
*/
|
| 23 |
+
#include <common.h>
|
| 24 |
+
#include <netdev.h>
|
| 25 |
+
#include <twl4030.h>
|
| 26 |
+
#include <asm/io.h>
|
| 27 |
+
#include <asm/gpio.h>
|
| 28 |
+
#include <asm/arch/mem.h>
|
| 29 |
+
#include <asm/arch/mmc_host_def.h>
|
| 30 |
+
#include <asm/arch/mux.h>
|
| 31 |
+
#include <asm/arch/sys_proto.h>
|
| 32 |
+
#include <asm/arch/omap_gpmc.h>
|
| 33 |
+
#include <asm/mach-types.h>
|
| 34 |
+
#include "igep0020.h"
|
| 35 |
+
|
| 36 |
+
DECLARE_GLOBAL_DATA_PTR;
|
| 37 |
+
|
| 38 |
+
/* GPMC definitions for LAN9221 chips */
|
| 39 |
+
static const u32 gpmc_lan_config[] = {
|
| 40 |
+
NET_LAN9221_GPMC_CONFIG1,
|
| 41 |
+
NET_LAN9221_GPMC_CONFIG2,
|
| 42 |
+
NET_LAN9221_GPMC_CONFIG3,
|
| 43 |
+
NET_LAN9221_GPMC_CONFIG4,
|
| 44 |
+
NET_LAN9221_GPMC_CONFIG5,
|
| 45 |
+
NET_LAN9221_GPMC_CONFIG6,
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
/*
|
| 49 |
+
* Routine: board_init
|
| 50 |
+
* Description: Early hardware init.
|
| 51 |
+
*/
|
| 52 |
+
int board_init(void)
|
| 53 |
+
{
|
| 54 |
+
gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
|
| 55 |
+
/* boot param addr */
|
| 56 |
+
gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
|
| 57 |
+
|
| 58 |
+
return 0;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/*
|
| 62 |
+
* Routine: setup_net_chip
|
| 63 |
+
* Description: Setting up the configuration GPMC registers specific to the
|
| 64 |
+
* Ethernet hardware.
|
| 65 |
+
*/
|
| 66 |
+
#if defined(CONFIG_CMD_NET)
|
| 67 |
+
static void setup_net_chip(void)
|
| 68 |
+
{
|
| 69 |
+
struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
|
| 70 |
+
|
| 71 |
+
enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
|
| 72 |
+
GPMC_SIZE_16M);
|
| 73 |
+
|
| 74 |
+
/* Enable off mode for NWE in PADCONF_GPMC_NWE register */
|
| 75 |
+
writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
|
| 76 |
+
/* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
|
| 77 |
+
writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
|
| 78 |
+
/* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
|
| 79 |
+
writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
|
| 80 |
+
&ctrl_base->gpmc_nadv_ale);
|
| 81 |
+
|
| 82 |
+
/* Make GPIO 64 as output pin and send a magic pulse through it */
|
| 83 |
+
if (!gpio_request(64, "")) {
|
| 84 |
+
gpio_direction_output(64, 0);
|
| 85 |
+
gpio_set_value(64, 1);
|
| 86 |
+
udelay(1);
|
| 87 |
+
gpio_set_value(64, 0);
|
| 88 |
+
udelay(1);
|
| 89 |
+
gpio_set_value(64, 1);
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
#ifdef CONFIG_GENERIC_MMC
|
| 95 |
+
int board_mmc_init(bd_t *bis)
|
| 96 |
+
{
|
| 97 |
+
omap_mmc_init(0, 0, 0);
|
| 98 |
+
return 0;
|
| 99 |
+
}
|
| 100 |
+
#endif
|
| 101 |
+
|
| 102 |
+
/*
|
| 103 |
+
* Routine: misc_init_r
|
| 104 |
+
* Description: Configure board specific parts
|
| 105 |
+
*/
|
| 106 |
+
int misc_init_r(void)
|
| 107 |
+
{
|
| 108 |
+
twl4030_power_init();
|
| 109 |
+
|
| 110 |
+
#if defined(CONFIG_CMD_NET)
|
| 111 |
+
setup_net_chip();
|
| 112 |
+
#endif
|
| 113 |
+
|
| 114 |
+
dieid_num_r();
|
| 115 |
+
|
| 116 |
+
return 0;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/*
|
| 120 |
+
* Routine: set_muxconf_regs
|
| 121 |
+
* Description: Setting up the configuration Mux registers specific to the
|
| 122 |
+
* hardware. Many pins need to be moved from protect to primary
|
| 123 |
+
* mode.
|
| 124 |
+
*/
|
| 125 |
+
void set_muxconf_regs(void)
|
| 126 |
+
{
|
| 127 |
+
MUX_DEFAULT();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
int board_eth_init(bd_t *bis)
|
| 131 |
+
{
|
| 132 |
+
int rc = 0;
|
| 133 |
+
#ifdef CONFIG_SMC911X
|
| 134 |
+
rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
|
| 135 |
+
#endif
|
| 136 |
+
return rc;
|
| 137 |
+
}
|
pool/shard010/C/0138074_machvec.c
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <linux/config.h>
|
| 2 |
+
#include <linux/module.h>
|
| 3 |
+
|
| 4 |
+
#include <asm/machvec.h>
|
| 5 |
+
#include <asm/system.h>
|
| 6 |
+
|
| 7 |
+
#ifdef CONFIG_IA64_GENERIC
|
| 8 |
+
|
| 9 |
+
#include <linux/kernel.h>
|
| 10 |
+
#include <linux/string.h>
|
| 11 |
+
|
| 12 |
+
#include <asm/page.h>
|
| 13 |
+
|
| 14 |
+
struct ia64_machine_vector ia64_mv;
|
| 15 |
+
EXPORT_SYMBOL(ia64_mv);
|
| 16 |
+
|
| 17 |
+
static struct ia64_machine_vector *
|
| 18 |
+
lookup_machvec (const char *name)
|
| 19 |
+
{
|
| 20 |
+
extern struct ia64_machine_vector machvec_start[];
|
| 21 |
+
extern struct ia64_machine_vector machvec_end[];
|
| 22 |
+
struct ia64_machine_vector *mv;
|
| 23 |
+
|
| 24 |
+
for (mv = machvec_start; mv < machvec_end; ++mv)
|
| 25 |
+
if (strcmp (mv->name, name) == 0)
|
| 26 |
+
return mv;
|
| 27 |
+
|
| 28 |
+
return 0;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
void
|
| 32 |
+
machvec_init (const char *name)
|
| 33 |
+
{
|
| 34 |
+
struct ia64_machine_vector *mv;
|
| 35 |
+
|
| 36 |
+
mv = lookup_machvec(name);
|
| 37 |
+
if (!mv) {
|
| 38 |
+
panic("generic kernel failed to find machine vector for platform %s!", name);
|
| 39 |
+
}
|
| 40 |
+
ia64_mv = *mv;
|
| 41 |
+
printk(KERN_INFO "booting generic kernel on platform %s\n", name);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
#endif /* CONFIG_IA64_GENERIC */
|
| 45 |
+
|
| 46 |
+
void
|
| 47 |
+
machvec_setup (char **arg)
|
| 48 |
+
{
|
| 49 |
+
}
|
| 50 |
+
EXPORT_SYMBOL(machvec_setup);
|
| 51 |
+
|
| 52 |
+
void
|
| 53 |
+
machvec_timer_interrupt (int irq, void *dev_id, struct pt_regs *regs)
|
| 54 |
+
{
|
| 55 |
+
}
|
| 56 |
+
EXPORT_SYMBOL(machvec_timer_interrupt);
|
| 57 |
+
|
| 58 |
+
void
|
| 59 |
+
machvec_dma_sync_single (struct device *hwdev, dma_addr_t dma_handle, size_t size, int dir)
|
| 60 |
+
{
|
| 61 |
+
mb();
|
| 62 |
+
}
|
| 63 |
+
EXPORT_SYMBOL(machvec_dma_sync_single);
|
| 64 |
+
|
| 65 |
+
void
|
| 66 |
+
machvec_dma_sync_sg (struct device *hwdev, struct scatterlist *sg, int n, int dir)
|
| 67 |
+
{
|
| 68 |
+
mb();
|
| 69 |
+
}
|
| 70 |
+
EXPORT_SYMBOL(machvec_dma_sync_sg);
|
pool/shard010/C/0138075_selectionSort.c
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//selection sort using a function
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <stdlib.h>
|
| 4 |
+
#define MAX 10
|
| 5 |
+
|
| 6 |
+
int minimum(int a[],int k,int size) {
|
| 7 |
+
int min=a[k],loc=k,j;
|
| 8 |
+
|
| 9 |
+
for(j=k+1;j<size;j++) {
|
| 10 |
+
if(min>a[j]) {
|
| 11 |
+
min=a[j];
|
| 12 |
+
loc=j;
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
return loc;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void selectionSort(int a[],int size) {
|
| 19 |
+
int i,loc,temp,k;
|
| 20 |
+
|
| 21 |
+
for(i=0;i<size;i++) {
|
| 22 |
+
loc=minimum(a,i,size);
|
| 23 |
+
temp=a[i];
|
| 24 |
+
a[i]=a[loc];
|
| 25 |
+
a[loc]=temp;
|
| 26 |
+
|
| 27 |
+
printf("\nResult after Pass %d -->\n",i+1);
|
| 28 |
+
for(k=0;k<size;k++) {
|
| 29 |
+
printf(" %d",a[k]);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
int main()
|
| 35 |
+
{
|
| 36 |
+
int a[MAX] = {0},n=0,i;
|
| 37 |
+
system("cls");
|
| 38 |
+
|
| 39 |
+
printf("\nEnter the number of elemenets: ");
|
| 40 |
+
scanf("%d",&n);
|
| 41 |
+
|
| 42 |
+
printf("\nEnter the array:\n");
|
| 43 |
+
for(i=0;i<n;i++) {
|
| 44 |
+
scanf("%d",&a[i]);
|
| 45 |
+
}
|
| 46 |
+
selectionSort(a,n);
|
| 47 |
+
|
| 48 |
+
printf("\n\nHere is the sorted array:\n");
|
| 49 |
+
for(i=0;i<n;i++) {
|
| 50 |
+
printf(" %d",a[i]);
|
| 51 |
+
}
|
| 52 |
+
printf("\n\n");
|
| 53 |
+
system("pause");
|
| 54 |
+
return 0;
|
| 55 |
+
}
|
pool/shard010/C/0138076_flash.c
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $Id: flash.c,v 1.1.1.1 2007-05-25 06:50:08 bruce Exp $
|
| 2 |
+
* flash.c: Allow mmap access to the OBP Flash, for OBP updates.
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
#include <linux/module.h>
|
| 8 |
+
#include <linux/types.h>
|
| 9 |
+
#include <linux/errno.h>
|
| 10 |
+
#include <linux/miscdevice.h>
|
| 11 |
+
#include <linux/slab.h>
|
| 12 |
+
#include <linux/fcntl.h>
|
| 13 |
+
#include <linux/poll.h>
|
| 14 |
+
#include <linux/init.h>
|
| 15 |
+
#include <linux/smp_lock.h>
|
| 16 |
+
#include <linux/spinlock.h>
|
| 17 |
+
|
| 18 |
+
#include <asm/system.h>
|
| 19 |
+
#include <asm/uaccess.h>
|
| 20 |
+
#include <asm/pgtable.h>
|
| 21 |
+
#include <asm/io.h>
|
| 22 |
+
#include <asm/sbus.h>
|
| 23 |
+
#include <asm/ebus.h>
|
| 24 |
+
#include <asm/upa.h>
|
| 25 |
+
|
| 26 |
+
static DEFINE_SPINLOCK(flash_lock);
|
| 27 |
+
static struct {
|
| 28 |
+
unsigned long read_base; /* Physical read address */
|
| 29 |
+
unsigned long write_base; /* Physical write address */
|
| 30 |
+
unsigned long read_size; /* Size of read area */
|
| 31 |
+
unsigned long write_size; /* Size of write area */
|
| 32 |
+
unsigned long busy; /* In use? */
|
| 33 |
+
} flash;
|
| 34 |
+
|
| 35 |
+
#define FLASH_MINOR 152
|
| 36 |
+
|
| 37 |
+
static int
|
| 38 |
+
flash_mmap(struct file *file, struct vm_area_struct *vma)
|
| 39 |
+
{
|
| 40 |
+
unsigned long addr;
|
| 41 |
+
unsigned long size;
|
| 42 |
+
|
| 43 |
+
spin_lock(&flash_lock);
|
| 44 |
+
if (flash.read_base == flash.write_base) {
|
| 45 |
+
addr = flash.read_base;
|
| 46 |
+
size = flash.read_size;
|
| 47 |
+
} else {
|
| 48 |
+
if ((vma->vm_flags & VM_READ) &&
|
| 49 |
+
(vma->vm_flags & VM_WRITE)) {
|
| 50 |
+
spin_unlock(&flash_lock);
|
| 51 |
+
return -EINVAL;
|
| 52 |
+
}
|
| 53 |
+
if (vma->vm_flags & VM_READ) {
|
| 54 |
+
addr = flash.read_base;
|
| 55 |
+
size = flash.read_size;
|
| 56 |
+
} else if (vma->vm_flags & VM_WRITE) {
|
| 57 |
+
addr = flash.write_base;
|
| 58 |
+
size = flash.write_size;
|
| 59 |
+
} else {
|
| 60 |
+
spin_unlock(&flash_lock);
|
| 61 |
+
return -ENXIO;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
spin_unlock(&flash_lock);
|
| 65 |
+
|
| 66 |
+
if ((vma->vm_pgoff << PAGE_SHIFT) > size)
|
| 67 |
+
return -ENXIO;
|
| 68 |
+
addr = vma->vm_pgoff + (addr >> PAGE_SHIFT);
|
| 69 |
+
|
| 70 |
+
if (vma->vm_end - (vma->vm_start + (vma->vm_pgoff << PAGE_SHIFT)) > size)
|
| 71 |
+
size = vma->vm_end - (vma->vm_start + (vma->vm_pgoff << PAGE_SHIFT));
|
| 72 |
+
|
| 73 |
+
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
| 74 |
+
|
| 75 |
+
if (io_remap_pfn_range(vma, vma->vm_start, addr, size, vma->vm_page_prot))
|
| 76 |
+
return -EAGAIN;
|
| 77 |
+
|
| 78 |
+
return 0;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
static long long
|
| 82 |
+
flash_llseek(struct file *file, long long offset, int origin)
|
| 83 |
+
{
|
| 84 |
+
lock_kernel();
|
| 85 |
+
switch (origin) {
|
| 86 |
+
case 0:
|
| 87 |
+
file->f_pos = offset;
|
| 88 |
+
break;
|
| 89 |
+
case 1:
|
| 90 |
+
file->f_pos += offset;
|
| 91 |
+
if (file->f_pos > flash.read_size)
|
| 92 |
+
file->f_pos = flash.read_size;
|
| 93 |
+
break;
|
| 94 |
+
case 2:
|
| 95 |
+
file->f_pos = flash.read_size;
|
| 96 |
+
break;
|
| 97 |
+
default:
|
| 98 |
+
unlock_kernel();
|
| 99 |
+
return -EINVAL;
|
| 100 |
+
}
|
| 101 |
+
unlock_kernel();
|
| 102 |
+
return file->f_pos;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
static ssize_t
|
| 106 |
+
flash_read(struct file * file, char __user * buf,
|
| 107 |
+
size_t count, loff_t *ppos)
|
| 108 |
+
{
|
| 109 |
+
unsigned long p = file->f_pos;
|
| 110 |
+
int i;
|
| 111 |
+
|
| 112 |
+
if (count > flash.read_size - p)
|
| 113 |
+
count = flash.read_size - p;
|
| 114 |
+
|
| 115 |
+
for (i = 0; i < count; i++) {
|
| 116 |
+
u8 data = upa_readb(flash.read_base + p + i);
|
| 117 |
+
if (put_user(data, buf))
|
| 118 |
+
return -EFAULT;
|
| 119 |
+
buf++;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
file->f_pos += count;
|
| 123 |
+
return count;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
static int
|
| 127 |
+
flash_open(struct inode *inode, struct file *file)
|
| 128 |
+
{
|
| 129 |
+
if (test_and_set_bit(0, (void *)&flash.busy) != 0)
|
| 130 |
+
return -EBUSY;
|
| 131 |
+
|
| 132 |
+
return 0;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
static int
|
| 136 |
+
flash_release(struct inode *inode, struct file *file)
|
| 137 |
+
{
|
| 138 |
+
spin_lock(&flash_lock);
|
| 139 |
+
flash.busy = 0;
|
| 140 |
+
spin_unlock(&flash_lock);
|
| 141 |
+
|
| 142 |
+
return 0;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
static const struct file_operations flash_fops = {
|
| 146 |
+
/* no write to the Flash, use mmap
|
| 147 |
+
* and play flash dependent tricks.
|
| 148 |
+
*/
|
| 149 |
+
.owner = THIS_MODULE,
|
| 150 |
+
.llseek = flash_llseek,
|
| 151 |
+
.read = flash_read,
|
| 152 |
+
.mmap = flash_mmap,
|
| 153 |
+
.open = flash_open,
|
| 154 |
+
.release = flash_release,
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
static struct miscdevice flash_dev = { FLASH_MINOR, "flash", &flash_fops };
|
| 158 |
+
|
| 159 |
+
static int __init flash_init(void)
|
| 160 |
+
{
|
| 161 |
+
struct sbus_bus *sbus;
|
| 162 |
+
struct sbus_dev *sdev = NULL;
|
| 163 |
+
#ifdef CONFIG_PCI
|
| 164 |
+
struct linux_ebus *ebus;
|
| 165 |
+
struct linux_ebus_device *edev = NULL;
|
| 166 |
+
struct linux_prom_registers regs[2];
|
| 167 |
+
int len, nregs;
|
| 168 |
+
#endif
|
| 169 |
+
int err;
|
| 170 |
+
|
| 171 |
+
for_all_sbusdev(sdev, sbus) {
|
| 172 |
+
if (!strcmp(sdev->prom_name, "flashprom")) {
|
| 173 |
+
if (sdev->reg_addrs[0].phys_addr == sdev->reg_addrs[1].phys_addr) {
|
| 174 |
+
flash.read_base = ((unsigned long)sdev->reg_addrs[0].phys_addr) |
|
| 175 |
+
(((unsigned long)sdev->reg_addrs[0].which_io)<<32UL);
|
| 176 |
+
flash.read_size = sdev->reg_addrs[0].reg_size;
|
| 177 |
+
flash.write_base = flash.read_base;
|
| 178 |
+
flash.write_size = flash.read_size;
|
| 179 |
+
} else {
|
| 180 |
+
flash.read_base = ((unsigned long)sdev->reg_addrs[0].phys_addr) |
|
| 181 |
+
(((unsigned long)sdev->reg_addrs[0].which_io)<<32UL);
|
| 182 |
+
flash.read_size = sdev->reg_addrs[0].reg_size;
|
| 183 |
+
flash.write_base = ((unsigned long)sdev->reg_addrs[1].phys_addr) |
|
| 184 |
+
(((unsigned long)sdev->reg_addrs[1].which_io)<<32UL);
|
| 185 |
+
flash.write_size = sdev->reg_addrs[1].reg_size;
|
| 186 |
+
}
|
| 187 |
+
flash.busy = 0;
|
| 188 |
+
break;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
if (!sdev) {
|
| 192 |
+
#ifdef CONFIG_PCI
|
| 193 |
+
struct linux_prom_registers *ebus_regs;
|
| 194 |
+
|
| 195 |
+
for_each_ebus(ebus) {
|
| 196 |
+
for_each_ebusdev(edev, ebus) {
|
| 197 |
+
if (!strcmp(edev->prom_node->name, "flashprom"))
|
| 198 |
+
goto ebus_done;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
ebus_done:
|
| 202 |
+
if (!edev)
|
| 203 |
+
return -ENODEV;
|
| 204 |
+
|
| 205 |
+
ebus_regs = of_get_property(edev->prom_node, "reg", &len);
|
| 206 |
+
if (!ebus_regs || (len % sizeof(regs[0])) != 0) {
|
| 207 |
+
printk("flash: Strange reg property size %d\n", len);
|
| 208 |
+
return -ENODEV;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
nregs = len / sizeof(ebus_regs[0]);
|
| 212 |
+
|
| 213 |
+
flash.read_base = edev->resource[0].start;
|
| 214 |
+
flash.read_size = ebus_regs[0].reg_size;
|
| 215 |
+
|
| 216 |
+
if (nregs == 1) {
|
| 217 |
+
flash.write_base = edev->resource[0].start;
|
| 218 |
+
flash.write_size = ebus_regs[0].reg_size;
|
| 219 |
+
} else if (nregs == 2) {
|
| 220 |
+
flash.write_base = edev->resource[1].start;
|
| 221 |
+
flash.write_size = ebus_regs[1].reg_size;
|
| 222 |
+
} else {
|
| 223 |
+
printk("flash: Strange number of regs %d\n", nregs);
|
| 224 |
+
return -ENODEV;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
flash.busy = 0;
|
| 228 |
+
|
| 229 |
+
#else
|
| 230 |
+
return -ENODEV;
|
| 231 |
+
#endif
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
printk("OBP Flash: RD %lx[%lx] WR %lx[%lx]\n",
|
| 235 |
+
flash.read_base, flash.read_size,
|
| 236 |
+
flash.write_base, flash.write_size);
|
| 237 |
+
|
| 238 |
+
err = misc_register(&flash_dev);
|
| 239 |
+
if (err) {
|
| 240 |
+
printk(KERN_ERR "flash: unable to get misc minor\n");
|
| 241 |
+
return err;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
return 0;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
static void __exit flash_cleanup(void)
|
| 248 |
+
{
|
| 249 |
+
misc_deregister(&flash_dev);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
module_init(flash_init);
|
| 253 |
+
module_exit(flash_cleanup);
|
| 254 |
+
MODULE_LICENSE("GPL");
|
pool/shard010/C/0138077_eeze_disk_ls.c
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifdef HAVE_CONFIG_H
|
| 2 |
+
# include <config.h>
|
| 3 |
+
#endif
|
| 4 |
+
|
| 5 |
+
#include <stdio.h>
|
| 6 |
+
|
| 7 |
+
#include <Ecore.h>
|
| 8 |
+
#include <Eeze.h>
|
| 9 |
+
#include <Eeze_Disk.h>
|
| 10 |
+
|
| 11 |
+
/* simple app to print disks and their mount points */
|
| 12 |
+
|
| 13 |
+
int
|
| 14 |
+
main(void)
|
| 15 |
+
{
|
| 16 |
+
Eina_List *disks;
|
| 17 |
+
const char *syspath;
|
| 18 |
+
|
| 19 |
+
eeze_init();
|
| 20 |
+
eeze_disk_function();
|
| 21 |
+
|
| 22 |
+
disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
|
| 23 |
+
printf("Found the following mountable disks:\n");
|
| 24 |
+
EINA_LIST_FREE(disks, syspath)
|
| 25 |
+
{
|
| 26 |
+
Eeze_Disk *disk;
|
| 27 |
+
|
| 28 |
+
disk = eeze_disk_new(syspath);
|
| 29 |
+
printf("\t%s - %s:%s\n", syspath, eeze_disk_devpath_get(disk), eeze_disk_mount_point_get(disk));
|
| 30 |
+
eeze_disk_free(disk);
|
| 31 |
+
eina_stringshare_del(syspath);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
|
| 35 |
+
printf("Found the following removable drives:\n");
|
| 36 |
+
EINA_LIST_FREE(disks, syspath)
|
| 37 |
+
{
|
| 38 |
+
Eeze_Disk *disk;
|
| 39 |
+
|
| 40 |
+
disk = eeze_disk_new(syspath);
|
| 41 |
+
printf("\t%s - %s:%s\n", syspath, eeze_disk_devpath_get(disk), eeze_disk_mount_point_get(disk));
|
| 42 |
+
eeze_disk_free(disk);
|
| 43 |
+
eina_stringshare_del(syspath);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
|
| 47 |
+
printf("Found the following internal drives:\n");
|
| 48 |
+
EINA_LIST_FREE(disks, syspath)
|
| 49 |
+
{
|
| 50 |
+
Eeze_Disk *disk;
|
| 51 |
+
|
| 52 |
+
disk = eeze_disk_new(syspath);
|
| 53 |
+
printf("\t%s - %s\n", syspath, eeze_disk_devpath_get(disk));
|
| 54 |
+
eeze_disk_free(disk);
|
| 55 |
+
eina_stringshare_del(syspath);
|
| 56 |
+
}
|
| 57 |
+
return 0;
|
| 58 |
+
}
|
pool/shard010/C/0138078_mod-locale.c
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// File: %mod-locale.c
|
| 3 |
+
// Summary: "Native Functions for spawning and controlling processes"
|
| 4 |
+
// Section: Extension
|
| 5 |
+
// Project: "Rebol 3 Interpreter and Run-time (Ren-C branch)"
|
| 6 |
+
// Homepage: https://github.com/metaeducation/ren-c/
|
| 7 |
+
//
|
| 8 |
+
//=////////////////////////////////////////////////////////////////////////=//
|
| 9 |
+
//
|
| 10 |
+
// Copyright 2012-2017 Rebol Open Source Contributors
|
| 11 |
+
// REBOL is a trademark of REBOL Technologies
|
| 12 |
+
//
|
| 13 |
+
// See README.md and CREDITS.md for more information.
|
| 14 |
+
//
|
| 15 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 16 |
+
// you may not use this file except in compliance with the License.
|
| 17 |
+
// You may obtain a copy of the License at
|
| 18 |
+
//
|
| 19 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 20 |
+
//
|
| 21 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 22 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 23 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 24 |
+
// See the License for the specific language governing permissions and
|
| 25 |
+
// limitations under the License.
|
| 26 |
+
//
|
| 27 |
+
//=////////////////////////////////////////////////////////////////////////=//
|
| 28 |
+
//
|
| 29 |
+
|
| 30 |
+
#ifdef TO_WINDOWS
|
| 31 |
+
#include <windows.h>
|
| 32 |
+
#endif
|
| 33 |
+
#include <locale.h>
|
| 34 |
+
|
| 35 |
+
// IS_ERROR might be defined in winerror.h and reb-types.h
|
| 36 |
+
#ifdef IS_ERROR
|
| 37 |
+
#undef IS_ERROR
|
| 38 |
+
#endif
|
| 39 |
+
|
| 40 |
+
#include "sys-core.h"
|
| 41 |
+
#include "sys-ext.h"
|
| 42 |
+
|
| 43 |
+
#include "tmp-mod-locale-first.h"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
//
|
| 47 |
+
// locale: native/export [
|
| 48 |
+
// "Get locale specific information"
|
| 49 |
+
// category [word!]
|
| 50 |
+
// {Language: English name of the language,
|
| 51 |
+
// Territory: English name of the country/region,
|
| 52 |
+
// Language*: Full localized primary name of the language
|
| 53 |
+
// Territory*: Full localized name of the country/region}
|
| 54 |
+
// ]
|
| 55 |
+
// new-words: [Language Language* Territory Territory*]
|
| 56 |
+
// new-errors: [
|
| 57 |
+
// invalid-category: [{Invalid locale category:} :arg1]
|
| 58 |
+
// ]
|
| 59 |
+
//
|
| 60 |
+
REBNATIVE(locale)
|
| 61 |
+
//
|
| 62 |
+
{
|
| 63 |
+
#ifdef TO_WINDOWS
|
| 64 |
+
LOCALE_INCLUDE_PARAMS_OF_LOCALE;
|
| 65 |
+
|
| 66 |
+
REBSTR *cat = VAL_WORD_CANON(ARG(category));
|
| 67 |
+
|
| 68 |
+
LCTYPE type;
|
| 69 |
+
if (cat == LOCALE_WORD_LANGUAGE)
|
| 70 |
+
type = LOCALE_SENGLANGUAGE;
|
| 71 |
+
else if (cat == LOCALE_WORD_LANGUAGE_P)
|
| 72 |
+
type = LOCALE_SNATIVELANGNAME;
|
| 73 |
+
else if (cat == LOCALE_WORD_TERRITORY)
|
| 74 |
+
type = LOCALE_SENGCOUNTRY;
|
| 75 |
+
else if (cat == LOCALE_WORD_TERRITORY_P)
|
| 76 |
+
type = LOCALE_SCOUNTRY;
|
| 77 |
+
else
|
| 78 |
+
fail (Error(RE_EXT_LOCALE_INVALID_CATEGORY, ARG(category), END));
|
| 79 |
+
|
| 80 |
+
int len_plus_term = GetLocaleInfo(0, type, 0, 0); // fetch needed length
|
| 81 |
+
|
| 82 |
+
WCHAR *buffer = OS_ALLOC_N(WCHAR, len_plus_term);
|
| 83 |
+
|
| 84 |
+
int len_check = GetLocaleInfo(0, type, buffer, len_plus_term);
|
| 85 |
+
assert(len_check == len_plus_term);
|
| 86 |
+
UNUSED(len_check);
|
| 87 |
+
|
| 88 |
+
REBVAL *str = rebSizedStringW(buffer, len_plus_term - 1);
|
| 89 |
+
Move_Value(D_OUT, str);
|
| 90 |
+
rebRelease(str);
|
| 91 |
+
|
| 92 |
+
return R_OUT;
|
| 93 |
+
#else
|
| 94 |
+
UNUSED(frame_);
|
| 95 |
+
fail ("Locale not implemented for non-windows");
|
| 96 |
+
#endif
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
//
|
| 101 |
+
// setlocale: native/export [
|
| 102 |
+
// {Set/Get current locale, just a simple wrapper around C version}
|
| 103 |
+
// return: [string! blank!]
|
| 104 |
+
// category [word!]
|
| 105 |
+
// value [string!]
|
| 106 |
+
// ]
|
| 107 |
+
// new-words: [
|
| 108 |
+
// all
|
| 109 |
+
// address
|
| 110 |
+
// collate
|
| 111 |
+
// ctype
|
| 112 |
+
// identification
|
| 113 |
+
// measurement
|
| 114 |
+
// messages
|
| 115 |
+
// monetary
|
| 116 |
+
// name
|
| 117 |
+
// numeric
|
| 118 |
+
// paper
|
| 119 |
+
// telephone
|
| 120 |
+
// time
|
| 121 |
+
// ]
|
| 122 |
+
// new-errors: [
|
| 123 |
+
// ]
|
| 124 |
+
//
|
| 125 |
+
REBNATIVE(setlocale)
|
| 126 |
+
{
|
| 127 |
+
LOCALE_INCLUDE_PARAMS_OF_SETLOCALE;
|
| 128 |
+
|
| 129 |
+
struct cat_pair {
|
| 130 |
+
REBSTR *word;
|
| 131 |
+
int cat;
|
| 132 |
+
} ctypes [] = {
|
| 133 |
+
{LOCALE_WORD_ALL, LC_ALL},
|
| 134 |
+
#if defined(LC_ADDRESS) // GNU extension
|
| 135 |
+
{LOCALE_WORD_ADDRESS, LC_ADDRESS},
|
| 136 |
+
#endif
|
| 137 |
+
{LOCALE_WORD_COLLATE, LC_COLLATE},
|
| 138 |
+
{LOCALE_WORD_CTYPE, LC_CTYPE},
|
| 139 |
+
#if defined(LC_IDENTIFICATION) // GNU extension
|
| 140 |
+
{LOCALE_WORD_IDENTIFICATION, LC_IDENTIFICATION},
|
| 141 |
+
#endif
|
| 142 |
+
#if defined(LC_MEASUREMENT) // GNU extension
|
| 143 |
+
{LOCALE_WORD_MEASUREMENT, LC_MEASUREMENT},
|
| 144 |
+
#endif
|
| 145 |
+
#if defined(LC_MESSAGES) // GNU extension
|
| 146 |
+
{LOCALE_WORD_MESSAGES, LC_MESSAGES},
|
| 147 |
+
#endif
|
| 148 |
+
{LOCALE_WORD_MONETARY, LC_MONETARY},
|
| 149 |
+
#if defined(LC_NAME) // GNU extension
|
| 150 |
+
{LOCALE_WORD_NAME, LC_NAME},
|
| 151 |
+
#endif
|
| 152 |
+
{LOCALE_WORD_NUMERIC, LC_NUMERIC},
|
| 153 |
+
#if defined(LC_TELEPHONE) // GNU extension
|
| 154 |
+
{LOCALE_WORD_TELEPHONE, LC_TELEPHONE},
|
| 155 |
+
#endif
|
| 156 |
+
#if defined(LC_PAPER) // GNU extension
|
| 157 |
+
{LOCALE_WORD_PAPER, LC_PAPER},
|
| 158 |
+
#endif
|
| 159 |
+
{LOCALE_WORD_TIME, LC_TIME}
|
| 160 |
+
};
|
| 161 |
+
|
| 162 |
+
REBSTR *w_cat = VAL_WORD_CANON(ARG(category));
|
| 163 |
+
|
| 164 |
+
int cat = -1; // avoid possibly uninitialized warning
|
| 165 |
+
REBCNT i = 0;
|
| 166 |
+
for (; i < sizeof (ctypes) / sizeof (ctypes[0]); ++i) {
|
| 167 |
+
if (ctypes[i].word == w_cat) {
|
| 168 |
+
cat = ctypes[i].cat;
|
| 169 |
+
break;
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
if (i == sizeof (ctypes) / sizeof (ctypes[0]))
|
| 173 |
+
fail (Error(RE_EXT_LOCALE_INVALID_CATEGORY, ARG(category), END));
|
| 174 |
+
|
| 175 |
+
const char *ret = setlocale(cat, cs_cast(VAL_BIN_AT(ARG(value))));
|
| 176 |
+
if (ret == NULL) {
|
| 177 |
+
Init_Blank(D_OUT);
|
| 178 |
+
} else {
|
| 179 |
+
REBCNT len = strlen(ret);
|
| 180 |
+
REBSER *ser = Make_Binary(len);
|
| 181 |
+
Append_Series(ser, cb_cast(ret), len);
|
| 182 |
+
Init_String(D_OUT, ser);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return R_OUT;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
#include "tmp-mod-locale-last.h"
|
pool/shard010/C/0138079_cam-vertex.c
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
in vec4 position;
|
| 2 |
+
out vec2 Texcoord;
|
| 3 |
+
uniform float angle;
|
| 4 |
+
|
| 5 |
+
void main()
|
| 6 |
+
{
|
| 7 |
+
const mat4 m_projection = mat4(
|
| 8 |
+
vec4(3.0 / 4.0, 0.0, 0.0, 0.0),
|
| 9 |
+
vec4( 0.0, 1.0, 0.0, 0.0),
|
| 10 |
+
vec4( 0.0, 0.0, 0.5, 0.5),
|
| 11 |
+
vec4( 0.0, 0.0, 0.0, 1.0)
|
| 12 |
+
);
|
| 13 |
+
|
| 14 |
+
mat4 m_rotation = mat4(
|
| 15 |
+
vec4(1.0, 0.0, 0.0, 0.0),
|
| 16 |
+
vec4(0.0, cos(radians(angle)), sin(radians(angle)), 0.0),
|
| 17 |
+
vec4(0.0, -sin(radians(angle)), cos(radians(angle)), 0.0),
|
| 18 |
+
vec4(0.0, 0.0, 0.0, 1.0)
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
mat4 m_scale = mat4(
|
| 22 |
+
vec4(4.0 / 3.0, 0.0, 0.0, 0.0),
|
| 23 |
+
vec4( 0.0, 1.0, 0.0, 0.0),
|
| 24 |
+
vec4( 0.0, 0.0, 1.0, 0.0),
|
| 25 |
+
vec4( 0.0, 0.0, 0.0, 1.0)
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
gl_Position = m_projection * m_rotation * m_scale * position;
|
| 29 |
+
Texcoord = position.xy * vec2(0.5) + vec2(0.5);
|
| 30 |
+
}
|
pool/shard010/C/0138080_ems1Form.c
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*+
|
| 3 |
+
* Name:
|
| 4 |
+
* ems1Form
|
| 5 |
+
|
| 6 |
+
* Purpose:
|
| 7 |
+
* Form an error message from its text and components.
|
| 8 |
+
|
| 9 |
+
* Language:
|
| 10 |
+
* Starlink ANSI
|
| 11 |
+
|
| 12 |
+
* Invocation:
|
| 13 |
+
* ems1Form( text, maxlen, esctokval, clean, opstr, oplen, status )
|
| 14 |
+
|
| 15 |
+
* Description:
|
| 16 |
+
* Construct the final text, OPSTR( 1 : OPLEN ), of a message
|
| 17 |
+
* using the text in TEXT, and available message tokens only.
|
| 18 |
+
|
| 19 |
+
* Arguments:
|
| 20 |
+
* text = char* (Given)
|
| 21 |
+
* The input message text, with any tokens.
|
| 22 |
+
* maxlen = const int (Given)
|
| 23 |
+
* Maximum length of output string
|
| 24 |
+
* esctokval = Logical (Given)
|
| 25 |
+
* if true, token values containing % will be escaped into %%
|
| 26 |
+
* to enable sprintf processing to be performed on the expanded
|
| 27 |
+
* string subsequently.
|
| 28 |
+
* clean = logical (Given)
|
| 29 |
+
* if the string is to be 'cleaned'
|
| 30 |
+
* opstr = char* (Returned)
|
| 31 |
+
* Resultant message text, with parsed tokens.
|
| 32 |
+
* oplen = int* (Returned)
|
| 33 |
+
* The filled length of OPSTR.
|
| 34 |
+
* status = int* (Returned)
|
| 35 |
+
* The global status.
|
| 36 |
+
|
| 37 |
+
* Algorithm:
|
| 38 |
+
* - Parse the message text, TEXT, and copy it into OPSTR, making
|
| 39 |
+
* translations for token escapes.
|
| 40 |
+
* - The message length is returned in OPLEN.
|
| 41 |
+
|
| 42 |
+
* Notes:
|
| 43 |
+
* The code assumes "%" is the escape character to be doubled up in
|
| 44 |
+
* token values. This is done for simplicity and can easily be made
|
| 45 |
+
* generic by changing esctokval to be a const char *.
|
| 46 |
+
|
| 47 |
+
* Copyright:
|
| 48 |
+
* Copyright (C) 1982 Science & Engineering Research Council.
|
| 49 |
+
* Copyright (C) 2001 Central Laboratory of the Research Councils.
|
| 50 |
+
* Copyright (C) 2006 Particle Physics & Astronomy Research Council.
|
| 51 |
+
* Copyright (C) 2008 Science and Technology Facilities Council.
|
| 52 |
+
* All Rights Reserved.
|
| 53 |
+
|
| 54 |
+
* Licence:
|
| 55 |
+
* This program is free software; you can redistribute it and/or
|
| 56 |
+
* modify it under the terms of the GNU General Public License as
|
| 57 |
+
* published by the Free Software Foundation; either version 2 of
|
| 58 |
+
* the License, or (at your option) any later version.
|
| 59 |
+
*
|
| 60 |
+
* This program is distributed in the hope that it will be
|
| 61 |
+
* useful,but WITHOUT ANY WARRANTY; without even the implied
|
| 62 |
+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
| 63 |
+
* PURPOSE. See the GNU General Public License for more details.
|
| 64 |
+
*
|
| 65 |
+
* You should have received a copy of the GNU General Public License
|
| 66 |
+
* along with this program; if not, write to the Free Software
|
| 67 |
+
* Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA
|
| 68 |
+
* 02110-1301, USA
|
| 69 |
+
|
| 70 |
+
* Authors:
|
| 71 |
+
* JRG: Jack Giddings (UCL)
|
| 72 |
+
* BDK: Dennis Kelly (ROE)
|
| 73 |
+
* AJC: Alan Chipperfield (STARLINK)
|
| 74 |
+
* PCTR: P.C.T. Rees (STARLINK)
|
| 75 |
+
* RTP: R.T. Platon (STARLINK)
|
| 76 |
+
* TIMJ: Tim Jenness (JAC, Hawaii)
|
| 77 |
+
* PWD: Peter W. Draper (JAC, Durham University)
|
| 78 |
+
* {enter_new_authors_here}
|
| 79 |
+
|
| 80 |
+
* History:
|
| 81 |
+
* 3-JAN-1982 (JRG):
|
| 82 |
+
* Original FORTRAN version.
|
| 83 |
+
* 14-FEB-2001 (RTP)
|
| 84 |
+
* Rewritten in C based on the Fortran routine EMS1_PFORM
|
| 85 |
+
* 5-MAR-2001 (AJC):
|
| 86 |
+
* Set returned value OPLEN
|
| 87 |
+
* Use a temporary buffer for text amnipulation
|
| 88 |
+
* Use ems1Putc to append to string
|
| 89 |
+
* Add 'maxlen' argument
|
| 90 |
+
* Remove 'param' argument
|
| 91 |
+
* 13-AUG-2001 (AJC):
|
| 92 |
+
* #include stdlib.h and ems1.h
|
| 93 |
+
* 23-FEB-2006 (TIMJ):
|
| 94 |
+
* Use starMem
|
| 95 |
+
* 15-MAY-2008 (PWD):
|
| 96 |
+
* Remove ems_msgtb.h include, not needed.
|
| 97 |
+
* 23-DEC-2008 (TIMJ):
|
| 98 |
+
* use isprint() to filter out non-printable characters. Rather
|
| 99 |
+
* than checking for char < 32. Add argument to enable escaping
|
| 100 |
+
* of % characters in token values. Required for safe sprintf processing.
|
| 101 |
+
* {enter_further_changes_here}
|
| 102 |
+
|
| 103 |
+
* Bugs:
|
| 104 |
+
* {note_any_bugs_here}
|
| 105 |
+
*/
|
| 106 |
+
|
| 107 |
+
#include <stdlib.h>
|
| 108 |
+
#include <string.h>
|
| 109 |
+
#include <stdio.h>
|
| 110 |
+
#include <ctype.h>
|
| 111 |
+
|
| 112 |
+
#include "sae_par.h" /* Standard SAE constants */
|
| 113 |
+
#include "ems_par.h" /* EMS_ public constants */
|
| 114 |
+
#include "ems_sys.h" /* EMS_ private constants */
|
| 115 |
+
#include "ems1.h" /* EMS1 function prototypes */
|
| 116 |
+
#include "ems.h"
|
| 117 |
+
#include "star/mem.h"
|
| 118 |
+
|
| 119 |
+
void ems1Form( const char *text, const int maxlen, Logical esctokval,
|
| 120 |
+
Logical clean, char *opstr, int *oplen,
|
| 121 |
+
int *status __attribute__((unused)) )
|
| 122 |
+
{
|
| 123 |
+
Logical literl; /* Whether a literal token escape */
|
| 124 |
+
|
| 125 |
+
int curpos; /* Current character pointer */
|
| 126 |
+
int lstat; /* Local status */
|
| 127 |
+
int lstpos; /* Previous value of CURPOS */
|
| 128 |
+
int oppos; /* Position in OP string */
|
| 129 |
+
int namlen; /* Token name length */
|
| 130 |
+
int pstat; /* Local status */
|
| 131 |
+
int texlen; /* TEXSTR length */
|
| 132 |
+
int tkvlen; /* TOKVAL length */
|
| 133 |
+
int j;
|
| 134 |
+
int i;
|
| 135 |
+
|
| 136 |
+
char namstr[ EMS__SZMSG + 1 ] = ""; /* Token name string */
|
| 137 |
+
char tokval[ EMS__SZTOK + 1 ] = ""; /* Token value string */
|
| 138 |
+
char tstr[EMS__SZTOK + 1 ]; /* Escaped token value temp string buffer */
|
| 139 |
+
const char tokescval = '%'; /* Escape value to look for in token values */
|
| 140 |
+
char *texbuf; /* Ptr to temporary text buffer */
|
| 141 |
+
|
| 142 |
+
TRACE("ems1Form");
|
| 143 |
+
|
| 144 |
+
/* Initialise the returned message. */
|
| 145 |
+
opstr[0] = '\0';
|
| 146 |
+
*oplen = 0;
|
| 147 |
+
|
| 148 |
+
/* Get the length of the given string. */
|
| 149 |
+
if (!text) {
|
| 150 |
+
strcpy( opstr, "Internal malloc failure. Abort!" );
|
| 151 |
+
*oplen = strlen( opstr );
|
| 152 |
+
/* Clear the message token table. */
|
| 153 |
+
ems1Ktok();
|
| 154 |
+
return;
|
| 155 |
+
}
|
| 156 |
+
texlen = strlen( text );
|
| 157 |
+
|
| 158 |
+
/* Check for an empty string. */
|
| 159 |
+
if ( texlen > 0 ) {
|
| 160 |
+
|
| 161 |
+
/* Use a temporary text buffer which can be modified */
|
| 162 |
+
texbuf = starMalloc( texlen + 1 );
|
| 163 |
+
if (!texbuf) {
|
| 164 |
+
strcpy( opstr, "Internal malloc failure. Abort!" );
|
| 165 |
+
*oplen = strlen( opstr );
|
| 166 |
+
/* Clear the message token table. */
|
| 167 |
+
ems1Ktok();
|
| 168 |
+
return;
|
| 169 |
+
}
|
| 170 |
+
strcpy( texbuf, text );
|
| 171 |
+
|
| 172 |
+
/* Initialise the text pointers and local status. */
|
| 173 |
+
literl = FALSE;
|
| 174 |
+
curpos = -1;
|
| 175 |
+
lstpos = -1;
|
| 176 |
+
oppos = -1;
|
| 177 |
+
lstat = SAI__OK;
|
| 178 |
+
pstat = SAI__OK;
|
| 179 |
+
|
| 180 |
+
/* Parse and expand the message text.
|
| 181 |
+
* DO WHILE loop.
|
| 182 |
+
*/
|
| 183 |
+
while ( pstat == SAI__OK && curpos < texlen ) {
|
| 184 |
+
|
| 185 |
+
/* Find the next occurrence of an escape character. */
|
| 186 |
+
ems1Gesc( EMS__TOKEC, texbuf, &curpos );
|
| 187 |
+
|
| 188 |
+
if ( curpos == -1 ) {
|
| 189 |
+
|
| 190 |
+
/* No more escape characters have been found, so append all
|
| 191 |
+
* the text that remains to the returned message text and
|
| 192 |
+
* exit the loop.
|
| 193 |
+
*/
|
| 194 |
+
ems1Putc( &texbuf[ lstpos+1 ], maxlen, opstr, &oppos, &pstat );
|
| 195 |
+
break;
|
| 196 |
+
|
| 197 |
+
} else {
|
| 198 |
+
/* A token escape has been found, so check if it is a double
|
| 199 |
+
* token escape.
|
| 200 |
+
*/
|
| 201 |
+
if ( literl && curpos == lstpos + 1 ) {
|
| 202 |
+
/* A double token escape, so do nothing except update
|
| 203 |
+
* CURPOS and reset the literal token escape flag.
|
| 204 |
+
*/
|
| 205 |
+
literl = FALSE;
|
| 206 |
+
|
| 207 |
+
} else {
|
| 208 |
+
|
| 209 |
+
/* Reset the literal token escape flag. */
|
| 210 |
+
literl = FALSE;
|
| 211 |
+
|
| 212 |
+
/* Append any text prior to the escape character. */
|
| 213 |
+
/* Terminate the string to be copied at the escape */
|
| 214 |
+
if ( curpos - lstpos > 0 ) {
|
| 215 |
+
texbuf[ curpos ] = '\0';
|
| 216 |
+
(void)ems1Putc( &texbuf[ lstpos+1 ], maxlen, opstr,
|
| 217 |
+
&oppos, &pstat );
|
| 218 |
+
|
| 219 |
+
/* Overwrite the terminator - actual character
|
| 220 |
+
* doesn't matter */
|
| 221 |
+
texbuf[ curpos ] = '^';
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/* Find the token name. */
|
| 225 |
+
ems1Gnam( texbuf, &curpos, namstr, &namlen, &lstat );
|
| 226 |
+
|
| 227 |
+
/* Check that a token name exists. */
|
| 228 |
+
if ( lstat != SAI__OK ) {
|
| 229 |
+
|
| 230 |
+
/* The name string has been over-run, so indicate
|
| 231 |
+
* this in the message text. */
|
| 232 |
+
ems1Putc( EMS__TOKEC, maxlen, opstr, &oppos, &pstat );
|
| 233 |
+
ems1Putc( "<", maxlen, opstr, &oppos, &pstat );
|
| 234 |
+
ems1Putc( namstr, maxlen, opstr, &oppos, &pstat );
|
| 235 |
+
ems1Putc( ">", maxlen, opstr, &oppos, &pstat );
|
| 236 |
+
|
| 237 |
+
/* Reset the local status. */
|
| 238 |
+
lstat = SAI__OK;
|
| 239 |
+
|
| 240 |
+
} else if ( namlen > 0 ) {
|
| 241 |
+
|
| 242 |
+
/* There is a name, so get the token value. */
|
| 243 |
+
if ( ems1Gtok( namstr, tokval, &tkvlen ) ) {
|
| 244 |
+
|
| 245 |
+
/* if there is an escape character in the token
|
| 246 |
+
itself we need to double it up. This is used
|
| 247 |
+
to enable a % in the token to be retained
|
| 248 |
+
after sprintf processing */
|
| 249 |
+
if ( esctokval ) {
|
| 250 |
+
j=0;
|
| 251 |
+
for ( i = 0; i < tkvlen; i++) {
|
| 252 |
+
/* if we have found the escape char we
|
| 253 |
+
insert an additional one */
|
| 254 |
+
if (tokval[i] == tokescval) {
|
| 255 |
+
tstr[j] = tokescval;
|
| 256 |
+
j++;
|
| 257 |
+
}
|
| 258 |
+
/* copy the character that was tested */
|
| 259 |
+
tstr[j] = tokval[i];
|
| 260 |
+
j++;
|
| 261 |
+
}
|
| 262 |
+
tkvlen = j;
|
| 263 |
+
tstr[j] = '\0';
|
| 264 |
+
} else {
|
| 265 |
+
strncpy( tstr, tokval, sizeof(tstr));
|
| 266 |
+
tstr[tkvlen] = '\0';
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
/* Append the token value to the expanded message
|
| 270 |
+
* text. */
|
| 271 |
+
ems1Putc( tstr, maxlen, opstr, &oppos, &pstat );
|
| 272 |
+
|
| 273 |
+
} else {
|
| 274 |
+
/* The message token is not defined, so indicate
|
| 275 |
+
* this in the message text. */
|
| 276 |
+
ems1Putc( EMS__TOKEC, maxlen, opstr, &oppos,
|
| 277 |
+
&pstat );
|
| 278 |
+
ems1Putc( "<", maxlen, opstr, &oppos, &pstat );
|
| 279 |
+
ems1Putc( namstr, maxlen, opstr, &oppos, &pstat );
|
| 280 |
+
ems1Putc( ">", maxlen, opstr, &oppos, &pstat );
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
} else {
|
| 284 |
+
|
| 285 |
+
/* There is an isolated token escape character in the
|
| 286 |
+
* string, so set the literal token escape flag and
|
| 287 |
+
* append the character. */
|
| 288 |
+
literl = TRUE;
|
| 289 |
+
ems1Putc( EMS__TOKEC, maxlen, opstr, &oppos, &pstat );
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/* Update LSTPOS. */
|
| 294 |
+
lstpos = curpos;
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
starFree( texbuf );
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
/* Get the length of the string and, if CLEAN is TRUE, ensure the
|
| 301 |
+
* returned message string contains no unprintable characters.
|
| 302 |
+
*/
|
| 303 |
+
*oplen = strlen( opstr );
|
| 304 |
+
if ( clean ) {
|
| 305 |
+
int i;
|
| 306 |
+
for ( i = 0; i < *oplen; i++ ) {
|
| 307 |
+
if ( !isprint(opstr[ i ]) ) opstr[ i ] = ' ';
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
DEBUG( "ems1Form", "Error Message: '%s'\n", opstr );
|
| 312 |
+
#if PRINT_ERRMESS
|
| 313 |
+
fprintf( OP_STREAM, "! %s\n", opstr );
|
| 314 |
+
fflush( OP_STREAM );
|
| 315 |
+
#endif
|
| 316 |
+
|
| 317 |
+
/* Clear the message token table. */
|
| 318 |
+
ems1Ktok();
|
| 319 |
+
|
| 320 |
+
return;
|
| 321 |
+
}
|
pool/shard010/C/0138081_sunxi_sram.c
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Allwinner SoCs SRAM Controller Driver
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2015 Maxime Ripard
|
| 5 |
+
*
|
| 6 |
+
* Author: Maxime Ripard <maxime.ripard@free-electrons.com>
|
| 7 |
+
*
|
| 8 |
+
* This file is licensed under the terms of the GNU General Public
|
| 9 |
+
* License version 2. This program is licensed "as is" without any
|
| 10 |
+
* warranty of any kind, whether express or implied.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
#include <linux/debugfs.h>
|
| 14 |
+
#include <linux/io.h>
|
| 15 |
+
#include <linux/module.h>
|
| 16 |
+
#include <linux/of.h>
|
| 17 |
+
#include <linux/of_address.h>
|
| 18 |
+
#include <linux/of_device.h>
|
| 19 |
+
#include <linux/platform_device.h>
|
| 20 |
+
|
| 21 |
+
#include <linux/soc/sunxi/sunxi_sram.h>
|
| 22 |
+
|
| 23 |
+
struct sunxi_sram_func {
|
| 24 |
+
char *func;
|
| 25 |
+
u8 val;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct sunxi_sram_data {
|
| 29 |
+
char *name;
|
| 30 |
+
u8 reg;
|
| 31 |
+
u8 offset;
|
| 32 |
+
u8 width;
|
| 33 |
+
struct sunxi_sram_func *func;
|
| 34 |
+
struct list_head list;
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
struct sunxi_sram_desc {
|
| 38 |
+
struct sunxi_sram_data data;
|
| 39 |
+
bool claimed;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
#define SUNXI_SRAM_MAP(_val, _func) \
|
| 43 |
+
{ \
|
| 44 |
+
.func = _func, \
|
| 45 |
+
.val = _val, \
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
#define SUNXI_SRAM_DATA(_name, _reg, _off, _width, ...) \
|
| 49 |
+
{ \
|
| 50 |
+
.name = _name, \
|
| 51 |
+
.reg = _reg, \
|
| 52 |
+
.offset = _off, \
|
| 53 |
+
.width = _width, \
|
| 54 |
+
.func = (struct sunxi_sram_func[]){ \
|
| 55 |
+
__VA_ARGS__, { } }, \
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
static struct sunxi_sram_desc sun4i_a10_sram_a3_a4 = {
|
| 59 |
+
.data = SUNXI_SRAM_DATA("A3-A4", 0x4, 0x4, 2,
|
| 60 |
+
SUNXI_SRAM_MAP(0, "cpu"),
|
| 61 |
+
SUNXI_SRAM_MAP(1, "emac")),
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
static struct sunxi_sram_desc sun4i_a10_sram_d = {
|
| 65 |
+
.data = SUNXI_SRAM_DATA("D", 0x4, 0x0, 1,
|
| 66 |
+
SUNXI_SRAM_MAP(0, "cpu"),
|
| 67 |
+
SUNXI_SRAM_MAP(1, "usb-otg")),
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
static const struct of_device_id sunxi_sram_dt_ids[] = {
|
| 71 |
+
{
|
| 72 |
+
.compatible = "allwinner,sun4i-a10-sram-a3-a4",
|
| 73 |
+
.data = &sun4i_a10_sram_a3_a4.data,
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
.compatible = "allwinner,sun4i-a10-sram-d",
|
| 77 |
+
.data = &sun4i_a10_sram_d.data,
|
| 78 |
+
},
|
| 79 |
+
{}
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
static struct device *sram_dev;
|
| 83 |
+
static LIST_HEAD(claimed_sram);
|
| 84 |
+
static DEFINE_SPINLOCK(sram_lock);
|
| 85 |
+
static void __iomem *base;
|
| 86 |
+
|
| 87 |
+
static int sunxi_sram_show(struct seq_file *s, void *data)
|
| 88 |
+
{
|
| 89 |
+
struct device_node *sram_node, *section_node;
|
| 90 |
+
const struct sunxi_sram_data *sram_data;
|
| 91 |
+
const struct of_device_id *match;
|
| 92 |
+
struct sunxi_sram_func *func;
|
| 93 |
+
const __be32 *sram_addr_p, *section_addr_p;
|
| 94 |
+
u32 val;
|
| 95 |
+
|
| 96 |
+
seq_puts(s, "Allwinner sunXi SRAM\n");
|
| 97 |
+
seq_puts(s, "--------------------\n\n");
|
| 98 |
+
|
| 99 |
+
for_each_child_of_node(sram_dev->of_node, sram_node) {
|
| 100 |
+
sram_addr_p = of_get_address(sram_node, 0, NULL, NULL);
|
| 101 |
+
|
| 102 |
+
seq_printf(s, "sram@%08x\n",
|
| 103 |
+
be32_to_cpu(*sram_addr_p));
|
| 104 |
+
|
| 105 |
+
for_each_child_of_node(sram_node, section_node) {
|
| 106 |
+
match = of_match_node(sunxi_sram_dt_ids, section_node);
|
| 107 |
+
if (!match)
|
| 108 |
+
continue;
|
| 109 |
+
sram_data = match->data;
|
| 110 |
+
|
| 111 |
+
section_addr_p = of_get_address(section_node, 0,
|
| 112 |
+
NULL, NULL);
|
| 113 |
+
|
| 114 |
+
seq_printf(s, "\tsection@%04x\t(%s)\n",
|
| 115 |
+
be32_to_cpu(*section_addr_p),
|
| 116 |
+
sram_data->name);
|
| 117 |
+
|
| 118 |
+
val = readl(base + sram_data->reg);
|
| 119 |
+
val >>= sram_data->offset;
|
| 120 |
+
val &= sram_data->width;
|
| 121 |
+
|
| 122 |
+
for (func = sram_data->func; func->func; func++) {
|
| 123 |
+
seq_printf(s, "\t\t%s%c\n", func->func,
|
| 124 |
+
func->val == val ? '*' : ' ');
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
seq_puts(s, "\n");
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return 0;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
static int sunxi_sram_open(struct inode *inode, struct file *file)
|
| 135 |
+
{
|
| 136 |
+
return single_open(file, sunxi_sram_show, inode->i_private);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
static const struct file_operations sunxi_sram_fops = {
|
| 140 |
+
.open = sunxi_sram_open,
|
| 141 |
+
.read = seq_read,
|
| 142 |
+
.llseek = seq_lseek,
|
| 143 |
+
.release = single_release,
|
| 144 |
+
};
|
| 145 |
+
|
| 146 |
+
static inline struct sunxi_sram_desc *to_sram_desc(const struct sunxi_sram_data *data)
|
| 147 |
+
{
|
| 148 |
+
return container_of(data, struct sunxi_sram_desc, data);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
static const struct sunxi_sram_data *sunxi_sram_of_parse(struct device_node *node,
|
| 152 |
+
unsigned int *value)
|
| 153 |
+
{
|
| 154 |
+
const struct of_device_id *match;
|
| 155 |
+
struct of_phandle_args args;
|
| 156 |
+
int ret;
|
| 157 |
+
|
| 158 |
+
ret = of_parse_phandle_with_fixed_args(node, "allwinner,sram", 1, 0,
|
| 159 |
+
&args);
|
| 160 |
+
if (ret)
|
| 161 |
+
return ERR_PTR(ret);
|
| 162 |
+
|
| 163 |
+
if (!of_device_is_available(args.np)) {
|
| 164 |
+
ret = -EBUSY;
|
| 165 |
+
goto err;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
if (value)
|
| 169 |
+
*value = args.args[0];
|
| 170 |
+
|
| 171 |
+
match = of_match_node(sunxi_sram_dt_ids, args.np);
|
| 172 |
+
if (!match) {
|
| 173 |
+
ret = -EINVAL;
|
| 174 |
+
goto err;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
of_node_put(args.np);
|
| 178 |
+
return match->data;
|
| 179 |
+
|
| 180 |
+
err:
|
| 181 |
+
of_node_put(args.np);
|
| 182 |
+
return ERR_PTR(ret);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
int sunxi_sram_claim(struct device *dev)
|
| 186 |
+
{
|
| 187 |
+
const struct sunxi_sram_data *sram_data;
|
| 188 |
+
struct sunxi_sram_desc *sram_desc;
|
| 189 |
+
unsigned int device;
|
| 190 |
+
u32 val, mask;
|
| 191 |
+
|
| 192 |
+
if (IS_ERR(base))
|
| 193 |
+
return -EPROBE_DEFER;
|
| 194 |
+
|
| 195 |
+
if (!dev || !dev->of_node)
|
| 196 |
+
return -EINVAL;
|
| 197 |
+
|
| 198 |
+
sram_data = sunxi_sram_of_parse(dev->of_node, &device);
|
| 199 |
+
if (IS_ERR(sram_data))
|
| 200 |
+
return PTR_ERR(sram_data);
|
| 201 |
+
|
| 202 |
+
sram_desc = to_sram_desc(sram_data);
|
| 203 |
+
|
| 204 |
+
spin_lock(&sram_lock);
|
| 205 |
+
|
| 206 |
+
if (sram_desc->claimed) {
|
| 207 |
+
spin_unlock(&sram_lock);
|
| 208 |
+
return -EBUSY;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
mask = GENMASK(sram_data->offset + sram_data->width, sram_data->offset);
|
| 212 |
+
val = readl(base + sram_data->reg);
|
| 213 |
+
val &= ~mask;
|
| 214 |
+
writel(val | ((device << sram_data->offset) & mask),
|
| 215 |
+
base + sram_data->reg);
|
| 216 |
+
|
| 217 |
+
spin_unlock(&sram_lock);
|
| 218 |
+
|
| 219 |
+
return 0;
|
| 220 |
+
}
|
| 221 |
+
EXPORT_SYMBOL(sunxi_sram_claim);
|
| 222 |
+
|
| 223 |
+
int sunxi_sram_release(struct device *dev)
|
| 224 |
+
{
|
| 225 |
+
const struct sunxi_sram_data *sram_data;
|
| 226 |
+
struct sunxi_sram_desc *sram_desc;
|
| 227 |
+
|
| 228 |
+
if (!dev || !dev->of_node)
|
| 229 |
+
return -EINVAL;
|
| 230 |
+
|
| 231 |
+
sram_data = sunxi_sram_of_parse(dev->of_node, NULL);
|
| 232 |
+
if (IS_ERR(sram_data))
|
| 233 |
+
return -EINVAL;
|
| 234 |
+
|
| 235 |
+
sram_desc = to_sram_desc(sram_data);
|
| 236 |
+
|
| 237 |
+
spin_lock(&sram_lock);
|
| 238 |
+
sram_desc->claimed = false;
|
| 239 |
+
spin_unlock(&sram_lock);
|
| 240 |
+
|
| 241 |
+
return 0;
|
| 242 |
+
}
|
| 243 |
+
EXPORT_SYMBOL(sunxi_sram_release);
|
| 244 |
+
|
| 245 |
+
static int sunxi_sram_probe(struct platform_device *pdev)
|
| 246 |
+
{
|
| 247 |
+
struct resource *res;
|
| 248 |
+
struct dentry *d;
|
| 249 |
+
|
| 250 |
+
sram_dev = &pdev->dev;
|
| 251 |
+
|
| 252 |
+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
| 253 |
+
base = devm_ioremap_resource(&pdev->dev, res);
|
| 254 |
+
if (IS_ERR(base))
|
| 255 |
+
return PTR_ERR(base);
|
| 256 |
+
|
| 257 |
+
of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
|
| 258 |
+
|
| 259 |
+
d = debugfs_create_file("sram", S_IRUGO, NULL, NULL,
|
| 260 |
+
&sunxi_sram_fops);
|
| 261 |
+
if (!d)
|
| 262 |
+
return -ENOMEM;
|
| 263 |
+
|
| 264 |
+
return 0;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
static const struct of_device_id sunxi_sram_dt_match[] = {
|
| 268 |
+
{ .compatible = "allwinner,sun4i-a10-sram-controller" },
|
| 269 |
+
{ },
|
| 270 |
+
};
|
| 271 |
+
MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match);
|
| 272 |
+
|
| 273 |
+
static struct platform_driver sunxi_sram_driver = {
|
| 274 |
+
.driver = {
|
| 275 |
+
.name = "sunxi-sram",
|
| 276 |
+
.of_match_table = sunxi_sram_dt_match,
|
| 277 |
+
},
|
| 278 |
+
.probe = sunxi_sram_probe,
|
| 279 |
+
};
|
| 280 |
+
module_platform_driver(sunxi_sram_driver);
|
| 281 |
+
|
| 282 |
+
MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
|
| 283 |
+
MODULE_DESCRIPTION("Allwinner sunXi SRAM Controller Driver");
|
| 284 |
+
MODULE_LICENSE("GPL");
|
pool/shard010/C/0138082_ping_test.c
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* GPL HEADER START
|
| 3 |
+
*
|
| 4 |
+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License version 2 only,
|
| 8 |
+
* as published by the Free Software Foundation.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful, but
|
| 11 |
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
* General Public License version 2 for more details (a copy is included
|
| 14 |
+
* in the LICENSE file that accompanied this code).
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* version 2 along with this program; If not, see
|
| 18 |
+
* http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
|
| 19 |
+
*
|
| 20 |
+
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
| 21 |
+
* CA 95054 USA or visit www.sun.com if you need additional information or
|
| 22 |
+
* have any questions.
|
| 23 |
+
*
|
| 24 |
+
* GPL HEADER END
|
| 25 |
+
*/
|
| 26 |
+
/*
|
| 27 |
+
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
|
| 28 |
+
* Use is subject to license terms.
|
| 29 |
+
*
|
| 30 |
+
* Copyright (c) 2012, Intel Corporation.
|
| 31 |
+
*/
|
| 32 |
+
/*
|
| 33 |
+
* This file is part of Lustre, http://www.lustre.org/
|
| 34 |
+
* Lustre is a trademark of Sun Microsystems, Inc.
|
| 35 |
+
*
|
| 36 |
+
* lnet/selftest/conctl.c
|
| 37 |
+
*
|
| 38 |
+
* Test client & Server
|
| 39 |
+
*
|
| 40 |
+
* Author: Liang Zhen <liangzhen@clusterfs.com>
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
#include "selftest.h"
|
| 44 |
+
|
| 45 |
+
#define LST_PING_TEST_MAGIC 0xbabeface
|
| 46 |
+
|
| 47 |
+
int ping_srv_workitems = SFW_TEST_WI_MAX;
|
| 48 |
+
CFS_MODULE_PARM(ping_srv_workitems, "i", int, 0644, "# PING server workitems");
|
| 49 |
+
|
| 50 |
+
typedef struct {
|
| 51 |
+
spinlock_t pnd_lock; /* serialize */
|
| 52 |
+
int pnd_counter; /* sequence counter */
|
| 53 |
+
} lst_ping_data_t;
|
| 54 |
+
|
| 55 |
+
static lst_ping_data_t lst_ping_data;
|
| 56 |
+
|
| 57 |
+
static int
|
| 58 |
+
ping_client_init(sfw_test_instance_t *tsi)
|
| 59 |
+
{
|
| 60 |
+
sfw_session_t *sn = tsi->tsi_batch->bat_session;
|
| 61 |
+
|
| 62 |
+
LASSERT(tsi->tsi_is_client);
|
| 63 |
+
LASSERT(sn != NULL && (sn->sn_features & ~LST_FEATS_MASK) == 0);
|
| 64 |
+
|
| 65 |
+
spin_lock_init(&lst_ping_data.pnd_lock);
|
| 66 |
+
lst_ping_data.pnd_counter = 0;
|
| 67 |
+
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
static void
|
| 72 |
+
ping_client_fini (sfw_test_instance_t *tsi)
|
| 73 |
+
{
|
| 74 |
+
sfw_session_t *sn = tsi->tsi_batch->bat_session;
|
| 75 |
+
int errors;
|
| 76 |
+
|
| 77 |
+
LASSERT (sn != NULL);
|
| 78 |
+
LASSERT (tsi->tsi_is_client);
|
| 79 |
+
|
| 80 |
+
errors = atomic_read(&sn->sn_ping_errors);
|
| 81 |
+
if (errors)
|
| 82 |
+
CWARN ("%d pings have failed.\n", errors);
|
| 83 |
+
else
|
| 84 |
+
CDEBUG (D_NET, "Ping test finished OK.\n");
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
static int
|
| 88 |
+
ping_client_prep_rpc(sfw_test_unit_t *tsu,
|
| 89 |
+
lnet_process_id_t dest, srpc_client_rpc_t **rpc)
|
| 90 |
+
{
|
| 91 |
+
srpc_ping_reqst_t *req;
|
| 92 |
+
sfw_test_instance_t *tsi = tsu->tsu_instance;
|
| 93 |
+
sfw_session_t *sn = tsi->tsi_batch->bat_session;
|
| 94 |
+
struct timeval tv;
|
| 95 |
+
int rc;
|
| 96 |
+
|
| 97 |
+
LASSERT(sn != NULL);
|
| 98 |
+
LASSERT((sn->sn_features & ~LST_FEATS_MASK) == 0);
|
| 99 |
+
|
| 100 |
+
rc = sfw_create_test_rpc(tsu, dest, sn->sn_features, 0, 0, rpc);
|
| 101 |
+
if (rc != 0)
|
| 102 |
+
return rc;
|
| 103 |
+
|
| 104 |
+
req = &(*rpc)->crpc_reqstmsg.msg_body.ping_reqst;
|
| 105 |
+
|
| 106 |
+
req->pnr_magic = LST_PING_TEST_MAGIC;
|
| 107 |
+
|
| 108 |
+
spin_lock(&lst_ping_data.pnd_lock);
|
| 109 |
+
req->pnr_seq = lst_ping_data.pnd_counter++;
|
| 110 |
+
spin_unlock(&lst_ping_data.pnd_lock);
|
| 111 |
+
|
| 112 |
+
cfs_fs_timeval(&tv);
|
| 113 |
+
req->pnr_time_sec = tv.tv_sec;
|
| 114 |
+
req->pnr_time_usec = tv.tv_usec;
|
| 115 |
+
|
| 116 |
+
return rc;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
static void
|
| 120 |
+
ping_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
|
| 121 |
+
{
|
| 122 |
+
sfw_test_instance_t *tsi = tsu->tsu_instance;
|
| 123 |
+
sfw_session_t *sn = tsi->tsi_batch->bat_session;
|
| 124 |
+
srpc_ping_reqst_t *reqst = &rpc->crpc_reqstmsg.msg_body.ping_reqst;
|
| 125 |
+
srpc_ping_reply_t *reply = &rpc->crpc_replymsg.msg_body.ping_reply;
|
| 126 |
+
struct timeval tv;
|
| 127 |
+
|
| 128 |
+
LASSERT (sn != NULL);
|
| 129 |
+
|
| 130 |
+
if (rpc->crpc_status != 0) {
|
| 131 |
+
if (!tsi->tsi_stopping) /* rpc could have been aborted */
|
| 132 |
+
atomic_inc(&sn->sn_ping_errors);
|
| 133 |
+
CERROR ("Unable to ping %s (%d): %d\n",
|
| 134 |
+
libcfs_id2str(rpc->crpc_dest),
|
| 135 |
+
reqst->pnr_seq, rpc->crpc_status);
|
| 136 |
+
return;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
if (rpc->crpc_replymsg.msg_magic != SRPC_MSG_MAGIC) {
|
| 140 |
+
__swab32s(&reply->pnr_seq);
|
| 141 |
+
__swab32s(&reply->pnr_magic);
|
| 142 |
+
__swab32s(&reply->pnr_status);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
if (reply->pnr_magic != LST_PING_TEST_MAGIC) {
|
| 146 |
+
rpc->crpc_status = -EBADMSG;
|
| 147 |
+
atomic_inc(&sn->sn_ping_errors);
|
| 148 |
+
CERROR ("Bad magic %u from %s, %u expected.\n",
|
| 149 |
+
reply->pnr_magic, libcfs_id2str(rpc->crpc_dest),
|
| 150 |
+
LST_PING_TEST_MAGIC);
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
if (reply->pnr_seq != reqst->pnr_seq) {
|
| 155 |
+
rpc->crpc_status = -EBADMSG;
|
| 156 |
+
atomic_inc(&sn->sn_ping_errors);
|
| 157 |
+
CERROR ("Bad seq %u from %s, %u expected.\n",
|
| 158 |
+
reply->pnr_seq, libcfs_id2str(rpc->crpc_dest),
|
| 159 |
+
reqst->pnr_seq);
|
| 160 |
+
return;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
cfs_fs_timeval(&tv);
|
| 164 |
+
CDEBUG (D_NET, "%d reply in %u usec\n", reply->pnr_seq,
|
| 165 |
+
(unsigned)((tv.tv_sec - (unsigned)reqst->pnr_time_sec) * 1000000
|
| 166 |
+
+ (tv.tv_usec - reqst->pnr_time_usec)));
|
| 167 |
+
return;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
static int
|
| 171 |
+
ping_server_handle(struct srpc_server_rpc *rpc)
|
| 172 |
+
{
|
| 173 |
+
struct srpc_service *sv = rpc->srpc_scd->scd_svc;
|
| 174 |
+
srpc_msg_t *reqstmsg = &rpc->srpc_reqstbuf->buf_msg;
|
| 175 |
+
srpc_msg_t *replymsg = &rpc->srpc_replymsg;
|
| 176 |
+
srpc_ping_reqst_t *req = &reqstmsg->msg_body.ping_reqst;
|
| 177 |
+
srpc_ping_reply_t *rep = &rpc->srpc_replymsg.msg_body.ping_reply;
|
| 178 |
+
|
| 179 |
+
LASSERT (sv->sv_id == SRPC_SERVICE_PING);
|
| 180 |
+
|
| 181 |
+
if (reqstmsg->msg_magic != SRPC_MSG_MAGIC) {
|
| 182 |
+
LASSERT (reqstmsg->msg_magic == __swab32(SRPC_MSG_MAGIC));
|
| 183 |
+
|
| 184 |
+
__swab32s(&req->pnr_seq);
|
| 185 |
+
__swab32s(&req->pnr_magic);
|
| 186 |
+
__swab64s(&req->pnr_time_sec);
|
| 187 |
+
__swab64s(&req->pnr_time_usec);
|
| 188 |
+
}
|
| 189 |
+
LASSERT (reqstmsg->msg_type == srpc_service2request(sv->sv_id));
|
| 190 |
+
|
| 191 |
+
if (req->pnr_magic != LST_PING_TEST_MAGIC) {
|
| 192 |
+
CERROR ("Unexpect magic %08x from %s\n",
|
| 193 |
+
req->pnr_magic, libcfs_id2str(rpc->srpc_peer));
|
| 194 |
+
return -EINVAL;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
rep->pnr_seq = req->pnr_seq;
|
| 198 |
+
rep->pnr_magic = LST_PING_TEST_MAGIC;
|
| 199 |
+
|
| 200 |
+
if ((reqstmsg->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
|
| 201 |
+
replymsg->msg_ses_feats = LST_FEATS_MASK;
|
| 202 |
+
rep->pnr_status = EPROTO;
|
| 203 |
+
return 0;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
replymsg->msg_ses_feats = reqstmsg->msg_ses_feats;
|
| 207 |
+
|
| 208 |
+
CDEBUG(D_NET, "Get ping %d from %s\n",
|
| 209 |
+
req->pnr_seq, libcfs_id2str(rpc->srpc_peer));
|
| 210 |
+
return 0;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
sfw_test_client_ops_t ping_test_client;
|
| 214 |
+
void ping_init_test_client(void)
|
| 215 |
+
{
|
| 216 |
+
ping_test_client.tso_init = ping_client_init;
|
| 217 |
+
ping_test_client.tso_fini = ping_client_fini;
|
| 218 |
+
ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
|
| 219 |
+
ping_test_client.tso_done_rpc = ping_client_done_rpc;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
srpc_service_t ping_test_service;
|
| 223 |
+
void ping_init_test_service(void)
|
| 224 |
+
{
|
| 225 |
+
ping_test_service.sv_id = SRPC_SERVICE_PING;
|
| 226 |
+
ping_test_service.sv_name = "ping_test";
|
| 227 |
+
ping_test_service.sv_handler = ping_server_handle;
|
| 228 |
+
ping_test_service.sv_wi_total = ping_srv_workitems;
|
| 229 |
+
}
|
pool/shard010/C/0138083_ltt-facility-loader-network.c
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* ltt-facility-loader-network.c
|
| 3 |
+
*
|
| 4 |
+
* (C) Copyright 2005 -
|
| 5 |
+
* Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
|
| 6 |
+
*
|
| 7 |
+
* Contains the LTT facility loader.
|
| 8 |
+
*
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
#include <linux/ltt-facilities.h>
|
| 13 |
+
#include <linux/module.h>
|
| 14 |
+
#include <linux/init.h>
|
| 15 |
+
#include <linux/config.h>
|
| 16 |
+
#include "ltt-facility-loader-network.h"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
#ifdef CONFIG_LTT
|
| 20 |
+
|
| 21 |
+
EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);
|
| 22 |
+
EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);
|
| 23 |
+
|
| 24 |
+
static const char ltt_facility_name[] = LTT_FACILITY_NAME;
|
| 25 |
+
|
| 26 |
+
#define SYMBOL_STRING(sym) #sym
|
| 27 |
+
|
| 28 |
+
static struct ltt_facility facility = {
|
| 29 |
+
.name = ltt_facility_name,
|
| 30 |
+
.num_events = LTT_FACILITY_NUM_EVENTS,
|
| 31 |
+
.checksum = LTT_FACILITY_CHECKSUM,
|
| 32 |
+
.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
static int __init facility_init(void)
|
| 36 |
+
{
|
| 37 |
+
printk(KERN_INFO "LTT : ltt-facility-network init in kernel\n");
|
| 38 |
+
|
| 39 |
+
LTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);
|
| 40 |
+
LTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;
|
| 41 |
+
|
| 42 |
+
return LTT_FACILITY_SYMBOL;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
#ifndef MODULE
|
| 46 |
+
__initcall(facility_init);
|
| 47 |
+
#else
|
| 48 |
+
module_init(facility_init);
|
| 49 |
+
static void __exit facility_exit(void)
|
| 50 |
+
{
|
| 51 |
+
int err;
|
| 52 |
+
|
| 53 |
+
err = ltt_facility_unregister(LTT_FACILITY_SYMBOL);
|
| 54 |
+
if(err != 0)
|
| 55 |
+
printk(KERN_ERR "LTT : Error in unregistering facility.\n");
|
| 56 |
+
|
| 57 |
+
}
|
| 58 |
+
module_exit(facility_exit)
|
| 59 |
+
|
| 60 |
+
MODULE_LICENSE("GPL");
|
| 61 |
+
MODULE_AUTHOR("Mathieu Desnoyers");
|
| 62 |
+
MODULE_DESCRIPTION("Linux Trace Toolkit Facility");
|
| 63 |
+
|
| 64 |
+
#endif //MODULE
|
| 65 |
+
|
| 66 |
+
#endif //CONFIG_LTT
|
pool/shard010/C/0138084_t-sgn.c
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2009 William Hart
|
| 3 |
+
|
| 4 |
+
This file is part of FLINT.
|
| 5 |
+
|
| 6 |
+
FLINT is free software: you can redistribute it and/or modify it under
|
| 7 |
+
the terms of the GNU Lesser General Public License (LGPL) as published
|
| 8 |
+
by the Free Software Foundation; either version 2.1 of the License, or
|
| 9 |
+
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stdlib.h>
|
| 14 |
+
#include <gmp.h>
|
| 15 |
+
#include "flint.h"
|
| 16 |
+
#include "ulong_extras.h"
|
| 17 |
+
#include "fmpz.h"
|
| 18 |
+
|
| 19 |
+
int
|
| 20 |
+
main(void)
|
| 21 |
+
{
|
| 22 |
+
int i, result;
|
| 23 |
+
FLINT_TEST_INIT(state);
|
| 24 |
+
|
| 25 |
+
flint_printf("sgn....");
|
| 26 |
+
fflush(stdout);
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
for (i = 0; i < 10000 * flint_test_multiplier(); i++)
|
| 31 |
+
{
|
| 32 |
+
fmpz_t a;
|
| 33 |
+
mpz_t b;
|
| 34 |
+
mp_size_t r1, r2;
|
| 35 |
+
|
| 36 |
+
fmpz_init(a);
|
| 37 |
+
|
| 38 |
+
mpz_init(b);
|
| 39 |
+
|
| 40 |
+
fmpz_randtest(a, state, 200);
|
| 41 |
+
|
| 42 |
+
fmpz_get_mpz(b, a);
|
| 43 |
+
|
| 44 |
+
r1 = fmpz_sgn(a);
|
| 45 |
+
r2 = mpz_sgn(b);
|
| 46 |
+
result = (r1 == r2);
|
| 47 |
+
|
| 48 |
+
if (!result)
|
| 49 |
+
{
|
| 50 |
+
flint_printf("FAIL:\n");
|
| 51 |
+
gmp_printf("b = %Zd\n", b);
|
| 52 |
+
abort();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
fmpz_clear(a);
|
| 56 |
+
|
| 57 |
+
mpz_clear(b);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
FLINT_TEST_CLEANUP(state);
|
| 61 |
+
|
| 62 |
+
flint_printf("PASS\n");
|
| 63 |
+
return 0;
|
| 64 |
+
}
|
pool/shard010/C/0138085_shichif.c
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* shichif.c
|
| 2 |
+
*
|
| 3 |
+
* Hyperbolic sine and cosine integrals
|
| 4 |
+
*
|
| 5 |
+
*
|
| 6 |
+
*
|
| 7 |
+
* SYNOPSIS:
|
| 8 |
+
*
|
| 9 |
+
* float x, Chi, Shi;
|
| 10 |
+
*
|
| 11 |
+
* shichi( x, &Chi, &Shi );
|
| 12 |
+
*
|
| 13 |
+
*
|
| 14 |
+
* DESCRIPTION:
|
| 15 |
+
*
|
| 16 |
+
* Approximates the integrals
|
| 17 |
+
*
|
| 18 |
+
* x
|
| 19 |
+
* -
|
| 20 |
+
* | | cosh t - 1
|
| 21 |
+
* Chi(x) = eul + ln x + | ----------- dt,
|
| 22 |
+
* | | t
|
| 23 |
+
* -
|
| 24 |
+
* 0
|
| 25 |
+
*
|
| 26 |
+
* x
|
| 27 |
+
* -
|
| 28 |
+
* | | sinh t
|
| 29 |
+
* Shi(x) = | ------ dt
|
| 30 |
+
* | | t
|
| 31 |
+
* -
|
| 32 |
+
* 0
|
| 33 |
+
*
|
| 34 |
+
* where eul = 0.57721566490153286061 is Euler's constant.
|
| 35 |
+
* The integrals are evaluated by power series for x < 8
|
| 36 |
+
* and by Chebyshev expansions for x between 8 and 88.
|
| 37 |
+
* For large x, both functions approach exp(x)/2x.
|
| 38 |
+
* Arguments greater than 88 in magnitude return MAXNUM.
|
| 39 |
+
*
|
| 40 |
+
*
|
| 41 |
+
* ACCURACY:
|
| 42 |
+
*
|
| 43 |
+
* Test interval 0 to 88.
|
| 44 |
+
* Relative error:
|
| 45 |
+
* arithmetic function # trials peak rms
|
| 46 |
+
* IEEE Shi 20000 3.5e-7 7.0e-8
|
| 47 |
+
* Absolute error, except relative when |Chi| > 1:
|
| 48 |
+
* IEEE Chi 20000 3.8e-7 7.6e-8
|
| 49 |
+
*/
|
| 50 |
+
|
| 51 |
+
/*
|
| 52 |
+
Cephes Math Library Release 2.2: July, 1992
|
| 53 |
+
Copyright 1984, 1987, 1992 by Stephen L. Moshier
|
| 54 |
+
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
| 55 |
+
*/
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
#include "mconf.h"
|
| 59 |
+
|
| 60 |
+
/* x exp(-x) shi(x), inverted interval 8 to 18 */
|
| 61 |
+
static float S1[] = {
|
| 62 |
+
-3.56699611114982536845E-8,
|
| 63 |
+
1.44818877384267342057E-7,
|
| 64 |
+
7.82018215184051295296E-7,
|
| 65 |
+
-5.39919118403805073710E-6,
|
| 66 |
+
-3.12458202168959833422E-5,
|
| 67 |
+
8.90136741950727517826E-5,
|
| 68 |
+
2.02558474743846862168E-3,
|
| 69 |
+
2.96064440855633256972E-2,
|
| 70 |
+
1.11847751047257036625E0
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
/* x exp(-x) shi(x), inverted interval 18 to 88 */
|
| 74 |
+
static float S2[] = {
|
| 75 |
+
1.69050228879421288846E-8,
|
| 76 |
+
1.25391771228487041649E-7,
|
| 77 |
+
1.16229947068677338732E-6,
|
| 78 |
+
1.61038260117376323993E-5,
|
| 79 |
+
3.49810375601053973070E-4,
|
| 80 |
+
1.28478065259647610779E-2,
|
| 81 |
+
1.03665722588798326712E0
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
/* x exp(-x) chin(x), inverted interval 8 to 18 */
|
| 86 |
+
static float C1[] = {
|
| 87 |
+
1.31458150989474594064E-8,
|
| 88 |
+
-4.75513930924765465590E-8,
|
| 89 |
+
-2.21775018801848880741E-7,
|
| 90 |
+
1.94635531373272490962E-6,
|
| 91 |
+
4.33505889257316408893E-6,
|
| 92 |
+
-6.13387001076494349496E-5,
|
| 93 |
+
-3.13085477492997465138E-4,
|
| 94 |
+
4.97164789823116062801E-4,
|
| 95 |
+
2.64347496031374526641E-2,
|
| 96 |
+
1.11446150876699213025E0
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
/* x exp(-x) chin(x), inverted interval 18 to 88 */
|
| 100 |
+
static float C2[] = {
|
| 101 |
+
-3.00095178028681682282E-9,
|
| 102 |
+
7.79387474390914922337E-8,
|
| 103 |
+
1.06942765566401507066E-6,
|
| 104 |
+
1.59503164802313196374E-5,
|
| 105 |
+
3.49592575153777996871E-4,
|
| 106 |
+
1.28475387530065247392E-2,
|
| 107 |
+
1.03665693917934275131E0
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
/* Sine and cosine integrals */
|
| 113 |
+
|
| 114 |
+
#define EUL 0.57721566490153286061
|
| 115 |
+
extern float MACHEPF, MAXNUMF;
|
| 116 |
+
|
| 117 |
+
#define fabsf(x) ( (x) < 0 ? -(x) : (x) )
|
| 118 |
+
|
| 119 |
+
#ifdef ANSIC
|
| 120 |
+
float logf(float ), expf(float), chbevlf(float, float *, int);
|
| 121 |
+
#else
|
| 122 |
+
float logf(), expf(), chbevlf();
|
| 123 |
+
#endif
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
#ifdef ANSIC
|
| 128 |
+
int shichif( float xx, float *si, float *ci )
|
| 129 |
+
#else
|
| 130 |
+
int shichif( xx, si, ci )
|
| 131 |
+
double xx;
|
| 132 |
+
float *si, *ci;
|
| 133 |
+
#endif
|
| 134 |
+
{
|
| 135 |
+
float x, k, z, c, s, a;
|
| 136 |
+
short sign;
|
| 137 |
+
|
| 138 |
+
x = xx;
|
| 139 |
+
if( x < 0.0 )
|
| 140 |
+
{
|
| 141 |
+
sign = -1;
|
| 142 |
+
x = -x;
|
| 143 |
+
}
|
| 144 |
+
else
|
| 145 |
+
sign = 0;
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if( x == 0.0 )
|
| 149 |
+
{
|
| 150 |
+
*si = 0.0;
|
| 151 |
+
*ci = -MAXNUMF;
|
| 152 |
+
return( 0 );
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
if( x >= 8.0 )
|
| 156 |
+
goto chb;
|
| 157 |
+
|
| 158 |
+
z = x * x;
|
| 159 |
+
|
| 160 |
+
/* Direct power series expansion */
|
| 161 |
+
|
| 162 |
+
a = 1.0;
|
| 163 |
+
s = 1.0;
|
| 164 |
+
c = 0.0;
|
| 165 |
+
k = 2.0;
|
| 166 |
+
|
| 167 |
+
do
|
| 168 |
+
{
|
| 169 |
+
a *= z/k;
|
| 170 |
+
c += a/k;
|
| 171 |
+
k += 1.0;
|
| 172 |
+
a /= k;
|
| 173 |
+
s += a/k;
|
| 174 |
+
k += 1.0;
|
| 175 |
+
}
|
| 176 |
+
while( fabsf(a/s) > MACHEPF );
|
| 177 |
+
|
| 178 |
+
s *= x;
|
| 179 |
+
goto done;
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
chb:
|
| 183 |
+
|
| 184 |
+
if( x < 18.0 )
|
| 185 |
+
{
|
| 186 |
+
a = (576.0/x - 52.0)/10.0;
|
| 187 |
+
k = expf(x) / x;
|
| 188 |
+
s = k * chbevlf( a, S1, 9 );
|
| 189 |
+
c = k * chbevlf( a, C1, 10 );
|
| 190 |
+
goto done;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
if( x <= 88.0 )
|
| 194 |
+
{
|
| 195 |
+
a = (6336.0/x - 212.0)/70.0;
|
| 196 |
+
k = expf(x) / x;
|
| 197 |
+
s = k * chbevlf( a, S2, 7 );
|
| 198 |
+
c = k * chbevlf( a, C2, 7 );
|
| 199 |
+
goto done;
|
| 200 |
+
}
|
| 201 |
+
else
|
| 202 |
+
{
|
| 203 |
+
if( sign )
|
| 204 |
+
*si = -MAXNUMF;
|
| 205 |
+
else
|
| 206 |
+
*si = MAXNUMF;
|
| 207 |
+
*ci = MAXNUMF;
|
| 208 |
+
return(0);
|
| 209 |
+
}
|
| 210 |
+
done:
|
| 211 |
+
if( sign )
|
| 212 |
+
s = -s;
|
| 213 |
+
|
| 214 |
+
*si = s;
|
| 215 |
+
|
| 216 |
+
*ci = EUL + logf(x) + c;
|
| 217 |
+
return(0);
|
| 218 |
+
}
|
pool/shard010/C/0138086_dirhistory_menu.c
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* vifm
|
| 2 |
+
* Copyright (C) 2001 Ken Steen.
|
| 3 |
+
* Copyright (C) 2011 xaizek.
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "dirhistory_menu.h"
|
| 21 |
+
|
| 22 |
+
#include <stddef.h> /* NULL */
|
| 23 |
+
#include <string.h> /* strdup() */
|
| 24 |
+
|
| 25 |
+
#include "../cfg/config.h"
|
| 26 |
+
#include "../ui/ui.h"
|
| 27 |
+
#include "../utils/fs.h"
|
| 28 |
+
#include "../utils/str.h"
|
| 29 |
+
#include "../utils/string_array.h"
|
| 30 |
+
#include "../filelist.h"
|
| 31 |
+
#include "menus.h"
|
| 32 |
+
|
| 33 |
+
static int execute_dirhistory_cb(FileView *view, menu_info *m);
|
| 34 |
+
|
| 35 |
+
int
|
| 36 |
+
show_history_menu(FileView *view)
|
| 37 |
+
{
|
| 38 |
+
int i;
|
| 39 |
+
int need_cleanup;
|
| 40 |
+
|
| 41 |
+
static menu_info m;
|
| 42 |
+
init_menu_info(&m, strdup("Directory History"),
|
| 43 |
+
strdup("History disabled or empty"));
|
| 44 |
+
|
| 45 |
+
m.execute_handler = &execute_dirhistory_cb;
|
| 46 |
+
|
| 47 |
+
need_cleanup = 0;
|
| 48 |
+
for(i = 0; i < view->history_num && i < cfg.history_len; i++)
|
| 49 |
+
{
|
| 50 |
+
int j;
|
| 51 |
+
if(view->history[i].dir[0] == '\0')
|
| 52 |
+
break;
|
| 53 |
+
for(j = i + 1; j < view->history_num && j < cfg.history_len; j++)
|
| 54 |
+
if(stroscmp(view->history[i].dir, view->history[j].dir) == 0)
|
| 55 |
+
break;
|
| 56 |
+
if(j < view->history_num && j < cfg.history_len)
|
| 57 |
+
continue;
|
| 58 |
+
if(!is_valid_dir(view->history[i].dir))
|
| 59 |
+
{
|
| 60 |
+
/* "Mark" directory as non-existent. */
|
| 61 |
+
free(view->history[i].dir);
|
| 62 |
+
view->history[i].dir = NULL;
|
| 63 |
+
need_cleanup = 1;
|
| 64 |
+
continue;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* Change the current dir to reflect the current file. */
|
| 68 |
+
if(stroscmp(view->history[i].dir, view->curr_dir) == 0)
|
| 69 |
+
{
|
| 70 |
+
(void)replace_string(&view->history[i].file, get_current_file_name(view));
|
| 71 |
+
m.pos = m.len;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
m.len = add_to_string_array(&m.items, m.len, 1, view->history[i].dir);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
if(need_cleanup)
|
| 78 |
+
{
|
| 79 |
+
int i, j;
|
| 80 |
+
|
| 81 |
+
/* Erase non existing directories from history. */
|
| 82 |
+
j = 0;
|
| 83 |
+
for(i = 0; i < view->history_num && i < cfg.history_len; ++i)
|
| 84 |
+
{
|
| 85 |
+
if(view->history[i].dir == NULL)
|
| 86 |
+
{
|
| 87 |
+
free(view->history[i].file);
|
| 88 |
+
continue;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if(j != i)
|
| 92 |
+
{
|
| 93 |
+
view->history[j] = view->history[i];
|
| 94 |
+
|
| 95 |
+
view->history[i].dir = NULL;
|
| 96 |
+
view->history[i].file = NULL;
|
| 97 |
+
view->history[i].rel_pos = -1;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
if(view->history_pos == i)
|
| 101 |
+
{
|
| 102 |
+
view->history_pos = j;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
++j;
|
| 106 |
+
}
|
| 107 |
+
view->history_num = j;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/* Reverse order in which items appear. */
|
| 111 |
+
for(i = 0; i < m.len/2; i++)
|
| 112 |
+
{
|
| 113 |
+
char *t = m.items[i];
|
| 114 |
+
m.items[i] = m.items[m.len - 1 - i];
|
| 115 |
+
m.items[m.len - 1 - i] = t;
|
| 116 |
+
}
|
| 117 |
+
m.pos = m.len - 1 - m.pos;
|
| 118 |
+
|
| 119 |
+
return display_menu(&m, view);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/* Callback that is called when menu item is selected. Should return non-zero
|
| 123 |
+
* to stay in menu mode. */
|
| 124 |
+
static int
|
| 125 |
+
execute_dirhistory_cb(FileView *view, menu_info *m)
|
| 126 |
+
{
|
| 127 |
+
goto_selected_directory(view, m->items[m->pos]);
|
| 128 |
+
return 0;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
|
| 132 |
+
/* vim: set cinoptions+=t0 filetype=c : */
|
pool/shard010/C/0138087_20090907-1.c
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
struct platform_device;
|
| 2 |
+
typedef unsigned long __kernel_size_t;
|
| 3 |
+
typedef unsigned short __u16;
|
| 4 |
+
typedef unsigned int __u32;
|
| 5 |
+
typedef unsigned char u8;
|
| 6 |
+
typedef unsigned short u16;
|
| 7 |
+
typedef __kernel_size_t size_t;
|
| 8 |
+
typedef __u32 uint32_t;
|
| 9 |
+
static inline __attribute__ ((always_inline))
|
| 10 |
+
uint32_t __attribute__ ((pure)) bfin_dspid (void)
|
| 11 |
+
{
|
| 12 |
+
return ( {
|
| 13 |
+
uint32_t __v; __v;}
|
| 14 |
+
);
|
| 15 |
+
}
|
| 16 |
+
struct list_head {
|
| 17 |
+
struct list_head *next, *prev;
|
| 18 |
+
};
|
| 19 |
+
struct page {
|
| 20 |
+
union {
|
| 21 |
+
};
|
| 22 |
+
struct list_head lru;
|
| 23 |
+
};
|
| 24 |
+
struct device_driver {
|
| 25 |
+
const char *name;
|
| 26 |
+
struct module *owner;
|
| 27 |
+
};
|
| 28 |
+
struct fb_info {
|
| 29 |
+
struct device *dev;
|
| 30 |
+
};
|
| 31 |
+
struct platform_driver {
|
| 32 |
+
int (*probe) (struct platform_device *);
|
| 33 |
+
int (*remove) (struct platform_device *);
|
| 34 |
+
struct device_driver driver;
|
| 35 |
+
};
|
| 36 |
+
struct firmware {
|
| 37 |
+
size_t size;
|
| 38 |
+
const u8 *data;
|
| 39 |
+
};
|
| 40 |
+
struct metronomefb_par {
|
| 41 |
+
struct fb_info *info;
|
| 42 |
+
};
|
| 43 |
+
struct waveform_hdr {
|
| 44 |
+
u8 trc;
|
| 45 |
+
};
|
| 46 |
+
static u8 calc_cksum (int start, int end, u8 * mem)
|
| 47 |
+
{
|
| 48 |
+
u8 tmp = 0;
|
| 49 |
+
int i;
|
| 50 |
+
for (i = start; i < end; i++)
|
| 51 |
+
tmp += mem[i];
|
| 52 |
+
return tmp;
|
| 53 |
+
}
|
| 54 |
+
extern struct waveform_hdr *wfm_hdr;
|
| 55 |
+
extern int wmta;
|
| 56 |
+
|
| 57 |
+
static int
|
| 58 |
+
load_waveform (u8 * mem, size_t size, int m, int t, struct metronomefb_par *par)
|
| 59 |
+
{
|
| 60 |
+
int tta;
|
| 61 |
+
int trn = 0;
|
| 62 |
+
int i;
|
| 63 |
+
u8 cksum;
|
| 64 |
+
int cksum_idx;
|
| 65 |
+
struct device *dev = par->info->dev;
|
| 66 |
+
for (i = 0; i <= sizeof (*wfm_hdr) + wfm_hdr->trc; i++) {
|
| 67 |
+
if (mem[i] > t) {
|
| 68 |
+
trn = i - sizeof (*wfm_hdr) - 1;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
tta = * (mem + wmta + m * 4) & 0x00FFFFFF;
|
| 72 |
+
cksum_idx = tta + trn * 4 + 3;
|
| 73 |
+
cksum = calc_cksum (cksum_idx - 3, cksum_idx, mem);
|
| 74 |
+
if (cksum != mem[cksum_idx]) {
|
| 75 |
+
abort();
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
extern struct firmware *fw_entry;
|
| 79 |
+
extern struct metronomefb_par *par;
|
| 80 |
+
|
| 81 |
+
int metronomefb_probe (struct platform_device *dev)
|
| 82 |
+
{
|
| 83 |
+
return load_waveform ((u8 *) fw_entry->data, fw_entry->size, 3, 31, par);
|
| 84 |
+
}
|
pool/shard010/C/0138088_msgrcv06.c
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*
|
| 3 |
+
* Copyright (c) International Business Machines Corp., 2001
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
| 13 |
+
* the GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
/*
|
| 21 |
+
* NAME
|
| 22 |
+
* msgrcv06.c
|
| 23 |
+
*
|
| 24 |
+
* DESCRIPTION
|
| 25 |
+
* msgrcv06 - test for EIDRM error
|
| 26 |
+
*
|
| 27 |
+
* ALGORITHM
|
| 28 |
+
* loop if that option was specified
|
| 29 |
+
* create a message queue with read/write permissions
|
| 30 |
+
* fork a child who sleeps on an attempted read with msgrcv()
|
| 31 |
+
* parent removes the queue then waits for child to complete
|
| 32 |
+
* check the errno value
|
| 33 |
+
* issue a PASS message if we get EIDRM
|
| 34 |
+
* otherwise, the tests fails
|
| 35 |
+
* issue a FAIL message
|
| 36 |
+
* child removes message queue if required
|
| 37 |
+
* parent callc cleanup
|
| 38 |
+
*
|
| 39 |
+
* USAGE: <for command-line>
|
| 40 |
+
* msgrcv06 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
|
| 41 |
+
* where, -c n : Run n copies concurrently.
|
| 42 |
+
* -e : Turn on errno logging.
|
| 43 |
+
* -i n : Execute test n times.
|
| 44 |
+
* -I x : Execute test for x seconds.
|
| 45 |
+
* -P x : Pause for x seconds between iterations.
|
| 46 |
+
* -t : Turn on syscall timing.
|
| 47 |
+
*
|
| 48 |
+
* HISTORY
|
| 49 |
+
* 03/2001 - Written by Wayne Boyer
|
| 50 |
+
* 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
|
| 51 |
+
* - Fix concurrency issue. Due to the use of usleep function to
|
| 52 |
+
* synchronize processes, synchronization issues can occur on a loaded
|
| 53 |
+
* system. Fix this by using pipes to synchronize processes.
|
| 54 |
+
*
|
| 55 |
+
*
|
| 56 |
+
* RESTRICTIONS
|
| 57 |
+
* none
|
| 58 |
+
*/
|
| 59 |
+
|
| 60 |
+
#include "test.h"
|
| 61 |
+
|
| 62 |
+
#include "ipcmsg.h"
|
| 63 |
+
|
| 64 |
+
#include <sys/types.h>
|
| 65 |
+
#include <sys/wait.h>
|
| 66 |
+
|
| 67 |
+
void do_child(void);
|
| 68 |
+
void cleanup(void);
|
| 69 |
+
void setup(void);
|
| 70 |
+
#ifdef UCLINUX
|
| 71 |
+
#define PIPE_NAME "msgrcv06"
|
| 72 |
+
void do_child_uclinux(void);
|
| 73 |
+
#endif
|
| 74 |
+
|
| 75 |
+
char *TCID = "msgrcv06";
|
| 76 |
+
int TST_TOTAL = 1;
|
| 77 |
+
|
| 78 |
+
int msg_q_1 = -1; /* The message queue id created in setup */
|
| 79 |
+
|
| 80 |
+
MSGBUF rcv_buf;
|
| 81 |
+
pid_t c_pid;
|
| 82 |
+
|
| 83 |
+
int main(int ac, char **av)
|
| 84 |
+
{
|
| 85 |
+
int lc;
|
| 86 |
+
|
| 87 |
+
tst_parse_opts(ac, av, NULL, NULL);
|
| 88 |
+
|
| 89 |
+
#ifdef UCLINUX
|
| 90 |
+
maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
|
| 91 |
+
#endif
|
| 92 |
+
|
| 93 |
+
setup(); /* global setup */
|
| 94 |
+
|
| 95 |
+
/* The following loop checks looping state if -i option given */
|
| 96 |
+
|
| 97 |
+
for (lc = 0; TEST_LOOPING(lc); lc++) {
|
| 98 |
+
/* reset tst_count in case we are looping */
|
| 99 |
+
tst_count = 0;
|
| 100 |
+
|
| 101 |
+
/*
|
| 102 |
+
* set up the queue here so that multiple test iterations
|
| 103 |
+
* will work.
|
| 104 |
+
*/
|
| 105 |
+
msgkey = getipckey();
|
| 106 |
+
|
| 107 |
+
/* create a message queue with read/write permission */
|
| 108 |
+
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
|
| 109 |
+
== -1) {
|
| 110 |
+
tst_brkm(TBROK, cleanup, "Can't create message queue");
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/*
|
| 114 |
+
* fork a child that will attempt to read a non-existent
|
| 115 |
+
* message from the queue
|
| 116 |
+
*/
|
| 117 |
+
if ((c_pid = FORK_OR_VFORK()) == -1) {
|
| 118 |
+
tst_brkm(TBROK, cleanup, "could not fork");
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (c_pid == 0) { /* child */
|
| 122 |
+
/*
|
| 123 |
+
* Attempt to read a message without IPC_NOWAIT.
|
| 124 |
+
* With no message to read, the child sleeps.
|
| 125 |
+
*/
|
| 126 |
+
|
| 127 |
+
#ifdef UCLINUX
|
| 128 |
+
if (self_exec(av[0], "d", msg_q_1) < 0) {
|
| 129 |
+
tst_brkm(TBROK, cleanup, "could not self_exec");
|
| 130 |
+
}
|
| 131 |
+
#else
|
| 132 |
+
do_child();
|
| 133 |
+
#endif
|
| 134 |
+
} else {
|
| 135 |
+
TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
|
| 136 |
+
|
| 137 |
+
/* remove the queue */
|
| 138 |
+
rm_queue(msg_q_1);
|
| 139 |
+
|
| 140 |
+
waitpid(c_pid, NULL, 0);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
tst_exit();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/*
|
| 148 |
+
* do_child()
|
| 149 |
+
*/
|
| 150 |
+
void do_child(void)
|
| 151 |
+
{
|
| 152 |
+
TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));
|
| 153 |
+
|
| 154 |
+
if (TEST_RETURN != -1) {
|
| 155 |
+
tst_resm(TFAIL, "call succeeded when error expected");
|
| 156 |
+
exit(-1);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
switch (TEST_ERRNO) {
|
| 160 |
+
case EIDRM:
|
| 161 |
+
tst_resm(TPASS, "expected failure - errno = %d : %s",
|
| 162 |
+
TEST_ERRNO, strerror(TEST_ERRNO));
|
| 163 |
+
|
| 164 |
+
/* mark the queue as invalid as it was removed */
|
| 165 |
+
msg_q_1 = -1;
|
| 166 |
+
break;
|
| 167 |
+
default:
|
| 168 |
+
tst_resm(TFAIL,
|
| 169 |
+
"call failed with an unexpected error - %d : %s",
|
| 170 |
+
TEST_ERRNO, strerror(TEST_ERRNO));
|
| 171 |
+
break;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* if it exists, remove the message queue that was created */
|
| 175 |
+
rm_queue(msg_q_1);
|
| 176 |
+
|
| 177 |
+
exit(0);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
#ifdef UCLINUX
|
| 181 |
+
/*
|
| 182 |
+
* do_child_uclinux() - capture signals again, then run do_child()
|
| 183 |
+
*/
|
| 184 |
+
void do_child_uclinux(void)
|
| 185 |
+
{
|
| 186 |
+
tst_sig(FORK, SIG_IGN, cleanup);
|
| 187 |
+
|
| 188 |
+
do_child();
|
| 189 |
+
}
|
| 190 |
+
#endif
|
| 191 |
+
|
| 192 |
+
/*
|
| 193 |
+
* setup() - performs all the ONE TIME setup for this test.
|
| 194 |
+
*/
|
| 195 |
+
void setup(void)
|
| 196 |
+
{
|
| 197 |
+
|
| 198 |
+
tst_sig(FORK, SIG_IGN, cleanup);
|
| 199 |
+
|
| 200 |
+
TEST_PAUSE;
|
| 201 |
+
|
| 202 |
+
/*
|
| 203 |
+
* Create a temporary directory and cd into it.
|
| 204 |
+
* This helps to ensure that a unique msgkey is created.
|
| 205 |
+
* See libs/libltpipc/libipc.c for more information.
|
| 206 |
+
*/
|
| 207 |
+
tst_tmpdir();
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/*
|
| 211 |
+
* cleanup() - performs all the ONE TIME cleanup for this test at completion
|
| 212 |
+
* or premature exit.
|
| 213 |
+
*/
|
| 214 |
+
void cleanup(void)
|
| 215 |
+
{
|
| 216 |
+
|
| 217 |
+
tst_rmdir();
|
| 218 |
+
|
| 219 |
+
}
|
pool/shard010/C/0138089_CWE134_Uncontrolled_Format_String__char_console_vprintf_34.c
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE134_Uncontrolled_Format_String__char_console_vprintf_34.c
|
| 3 |
+
Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
|
| 4 |
+
Template File: sources-vasinks-34.tmpl.c
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 134 Uncontrolled Format String
|
| 9 |
+
* BadSource: console Read input from the console
|
| 10 |
+
* GoodSource: Copy a fixed string into data
|
| 11 |
+
* Sinks: vprintf
|
| 12 |
+
* GoodSink: vprintf with a format string
|
| 13 |
+
* BadSink : vprintf without a format string
|
| 14 |
+
* Flow Variant: 34 Data flow: use of a union containing two methods of accessing the same data (within the same function)
|
| 15 |
+
*
|
| 16 |
+
* */
|
| 17 |
+
|
| 18 |
+
#include <stdarg.h>
|
| 19 |
+
#include "std_testcase.h"
|
| 20 |
+
|
| 21 |
+
#ifndef _WIN32
|
| 22 |
+
#include <wchar.h>
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
typedef union
|
| 26 |
+
{
|
| 27 |
+
char * unionFirst;
|
| 28 |
+
char * unionSecond;
|
| 29 |
+
} CWE134_Uncontrolled_Format_String__char_console_vprintf_34_unionType;
|
| 30 |
+
|
| 31 |
+
#ifndef OMITBAD
|
| 32 |
+
|
| 33 |
+
static void badVaSink(char * data, ...)
|
| 34 |
+
{
|
| 35 |
+
{
|
| 36 |
+
va_list args;
|
| 37 |
+
va_start(args, data);
|
| 38 |
+
/* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
|
| 39 |
+
vprintf(data, args);
|
| 40 |
+
va_end(args);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void CWE134_Uncontrolled_Format_String__char_console_vprintf_34_bad()
|
| 45 |
+
{
|
| 46 |
+
char * data;
|
| 47 |
+
char dataBuffer[100] = "";
|
| 48 |
+
data = dataBuffer;
|
| 49 |
+
{
|
| 50 |
+
/* Read input from the console */
|
| 51 |
+
size_t dataLen = strlen(data);
|
| 52 |
+
/* if there is room in data, read into it from the console */
|
| 53 |
+
if (100-dataLen > 1)
|
| 54 |
+
{
|
| 55 |
+
/* POTENTIAL FLAW: Read data from the console */
|
| 56 |
+
if (fgets(data+dataLen, (int)(100-dataLen), stdin) != NULL)
|
| 57 |
+
{
|
| 58 |
+
/* The next few lines remove the carriage return from the string that is
|
| 59 |
+
* inserted by fgets() */
|
| 60 |
+
dataLen = strlen(data);
|
| 61 |
+
if (dataLen > 0 && data[dataLen-1] == '\n')
|
| 62 |
+
{
|
| 63 |
+
data[dataLen-1] = '\0';
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
else
|
| 67 |
+
{
|
| 68 |
+
printLine("fgets() failed");
|
| 69 |
+
/* Restore NUL terminator if fgets fails */
|
| 70 |
+
data[dataLen] = '\0';
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
{
|
| 75 |
+
char * dataCopy = data;
|
| 76 |
+
char * data = dataCopy;
|
| 77 |
+
badVaSink(data, data);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
#endif /* OMITBAD */
|
| 82 |
+
|
| 83 |
+
#ifndef OMITGOOD
|
| 84 |
+
|
| 85 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 86 |
+
static void goodG2BVaSink(char * data, ...)
|
| 87 |
+
{
|
| 88 |
+
{
|
| 89 |
+
va_list args;
|
| 90 |
+
va_start(args, data);
|
| 91 |
+
/* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
|
| 92 |
+
vprintf(data, args);
|
| 93 |
+
va_end(args);
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
static void goodG2B()
|
| 98 |
+
{
|
| 99 |
+
char * data;
|
| 100 |
+
CWE134_Uncontrolled_Format_String__char_console_vprintf_34_unionType myUnion;
|
| 101 |
+
char dataBuffer[100] = "";
|
| 102 |
+
data = dataBuffer;
|
| 103 |
+
/* FIX: Use a fixed string that does not contain a format specifier */
|
| 104 |
+
strcpy(data, "fixedstringtest");
|
| 105 |
+
myUnion.unionFirst = data;
|
| 106 |
+
{
|
| 107 |
+
char * data = myUnion.unionSecond;
|
| 108 |
+
goodG2BVaSink(data, data);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* goodB2G uses the BadSource with the GoodSink */
|
| 113 |
+
static void goodB2GVaSink(char * data, ...)
|
| 114 |
+
{
|
| 115 |
+
{
|
| 116 |
+
va_list args;
|
| 117 |
+
va_start(args, data);
|
| 118 |
+
/* FIX: Specify the format disallowing a format string vulnerability */
|
| 119 |
+
vprintf("%s", args);
|
| 120 |
+
va_end(args);
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
static void goodB2G()
|
| 125 |
+
{
|
| 126 |
+
char * data;
|
| 127 |
+
CWE134_Uncontrolled_Format_String__char_console_vprintf_34_unionType myUnion;
|
| 128 |
+
char dataBuffer[100] = "";
|
| 129 |
+
data = dataBuffer;
|
| 130 |
+
{
|
| 131 |
+
/* Read input from the console */
|
| 132 |
+
size_t dataLen = strlen(data);
|
| 133 |
+
/* if there is room in data, read into it from the console */
|
| 134 |
+
if (100-dataLen > 1)
|
| 135 |
+
{
|
| 136 |
+
/* POTENTIAL FLAW: Read data from the console */
|
| 137 |
+
if (fgets(data+dataLen, (int)(100-dataLen), stdin) != NULL)
|
| 138 |
+
{
|
| 139 |
+
/* The next few lines remove the carriage return from the string that is
|
| 140 |
+
* inserted by fgets() */
|
| 141 |
+
dataLen = strlen(data);
|
| 142 |
+
if (dataLen > 0 && data[dataLen-1] == '\n')
|
| 143 |
+
{
|
| 144 |
+
data[dataLen-1] = '\0';
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
else
|
| 148 |
+
{
|
| 149 |
+
printLine("fgets() failed");
|
| 150 |
+
/* Restore NUL terminator if fgets fails */
|
| 151 |
+
data[dataLen] = '\0';
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
myUnion.unionFirst = data;
|
| 156 |
+
{
|
| 157 |
+
char * data = myUnion.unionSecond;
|
| 158 |
+
goodB2GVaSink(data, data);
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
void CWE134_Uncontrolled_Format_String__char_console_vprintf_34_good()
|
| 163 |
+
{
|
| 164 |
+
goodG2B();
|
| 165 |
+
goodB2G();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
#endif /* OMITGOOD */
|
| 169 |
+
|
| 170 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 171 |
+
its own for testing or for building a binary to use in testing binary
|
| 172 |
+
analysis tools. It is not used when compiling all the testcases as one
|
| 173 |
+
application, which is how source code analysis tools are tested. */
|
| 174 |
+
#ifdef INCLUDEMAIN
|
| 175 |
+
|
| 176 |
+
int main(int argc, char * argv[])
|
| 177 |
+
{
|
| 178 |
+
/* seed randomness */
|
| 179 |
+
srand( (unsigned)time(NULL) );
|
| 180 |
+
#ifndef OMITGOOD
|
| 181 |
+
printLine("Calling good()...");
|
| 182 |
+
CWE134_Uncontrolled_Format_String__char_console_vprintf_34_good();
|
| 183 |
+
printLine("Finished good()");
|
| 184 |
+
#endif /* OMITGOOD */
|
| 185 |
+
#ifndef OMITBAD
|
| 186 |
+
printLine("Calling bad()...");
|
| 187 |
+
CWE134_Uncontrolled_Format_String__char_console_vprintf_34_bad();
|
| 188 |
+
printLine("Finished bad()");
|
| 189 |
+
#endif /* OMITBAD */
|
| 190 |
+
return 0;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
#endif
|
pool/shard010/C/0138090_Descriptors.c
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
LUFA Library
|
| 3 |
+
Copyright (C) Dean Camera, 2011.
|
| 4 |
+
|
| 5 |
+
dean [at] fourwalledcubicle [dot] com
|
| 6 |
+
www.lufa-lib.org
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/*
|
| 10 |
+
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
| 11 |
+
|
| 12 |
+
Permission to use, copy, modify, distribute, and sell this
|
| 13 |
+
software and its documentation for any purpose is hereby granted
|
| 14 |
+
without fee, provided that the above copyright notice appear in
|
| 15 |
+
all copies and that both that the copyright notice and this
|
| 16 |
+
permission notice and warranty disclaimer appear in supporting
|
| 17 |
+
documentation, and that the name of the author not be used in
|
| 18 |
+
advertising or publicity pertaining to distribution of the
|
| 19 |
+
software without specific, written prior permission.
|
| 20 |
+
|
| 21 |
+
The author disclaim all warranties with regard to this
|
| 22 |
+
software, including all implied warranties of merchantability
|
| 23 |
+
and fitness. In no event shall the author be liable for any
|
| 24 |
+
special, indirect or consequential damages or any damages
|
| 25 |
+
whatsoever resulting from loss of use, data or profits, whether
|
| 26 |
+
in an action of contract, negligence or other tortious action,
|
| 27 |
+
arising out of or in connection with the use or performance of
|
| 28 |
+
this software.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
/** \file
|
| 32 |
+
*
|
| 33 |
+
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
| 34 |
+
* computer-readable structures which the host requests upon device enumeration, to determine
|
| 35 |
+
* the device's capabilities and functions.
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
#include "Descriptors.h"
|
| 39 |
+
|
| 40 |
+
/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
|
| 41 |
+
* device characteristics, including the supported USB version, control endpoint size and the
|
| 42 |
+
* number of device configurations. The descriptor is read out by the USB host when the enumeration
|
| 43 |
+
* process begins.
|
| 44 |
+
*/
|
| 45 |
+
const USB_Descriptor_Device_t DeviceDescriptor =
|
| 46 |
+
{
|
| 47 |
+
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
|
| 48 |
+
|
| 49 |
+
.USBSpecification = VERSION_BCD(01.10),
|
| 50 |
+
.Class = CDC_CSCP_CDCClass,
|
| 51 |
+
.SubClass = CDC_CSCP_NoSpecificSubclass,
|
| 52 |
+
.Protocol = CDC_CSCP_NoSpecificProtocol,
|
| 53 |
+
|
| 54 |
+
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
| 55 |
+
|
| 56 |
+
.VendorID = DEVICE_VID,
|
| 57 |
+
.ProductID = DEVICE_PID,
|
| 58 |
+
.ReleaseNumber = VERSION_BCD(00.01),
|
| 59 |
+
|
| 60 |
+
.ManufacturerStrIndex = 0x02,
|
| 61 |
+
.ProductStrIndex = 0x01,
|
| 62 |
+
.SerialNumStrIndex = NO_DESCRIPTOR,
|
| 63 |
+
|
| 64 |
+
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
/** Configuration descriptor structure. This descriptor, located in SRAM memory, describes the usage
|
| 68 |
+
* of the device in one of its supported configurations, including information about any device interfaces
|
| 69 |
+
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
|
| 70 |
+
* a configuration so that the host may correctly communicate with the USB device.
|
| 71 |
+
*/
|
| 72 |
+
const USB_Descriptor_Configuration_t ConfigurationDescriptor =
|
| 73 |
+
{
|
| 74 |
+
.Config =
|
| 75 |
+
{
|
| 76 |
+
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
|
| 77 |
+
|
| 78 |
+
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
|
| 79 |
+
.TotalInterfaces = 2,
|
| 80 |
+
|
| 81 |
+
.ConfigurationNumber = 1,
|
| 82 |
+
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
| 83 |
+
|
| 84 |
+
.ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
|
| 85 |
+
|
| 86 |
+
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
| 87 |
+
},
|
| 88 |
+
|
| 89 |
+
.CDC_CCI_Interface =
|
| 90 |
+
{
|
| 91 |
+
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
| 92 |
+
|
| 93 |
+
.InterfaceNumber = 0,
|
| 94 |
+
.AlternateSetting = 0,
|
| 95 |
+
|
| 96 |
+
.TotalEndpoints = 1,
|
| 97 |
+
|
| 98 |
+
.Class = CDC_CSCP_CDCClass,
|
| 99 |
+
.SubClass = CDC_CSCP_ACMSubclass,
|
| 100 |
+
.Protocol = CDC_CSCP_ATCommandProtocol,
|
| 101 |
+
|
| 102 |
+
.InterfaceStrIndex = NO_DESCRIPTOR
|
| 103 |
+
},
|
| 104 |
+
|
| 105 |
+
.CDC_Functional_Header =
|
| 106 |
+
{
|
| 107 |
+
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
|
| 108 |
+
.Subtype = 0x00,
|
| 109 |
+
|
| 110 |
+
.CDCSpecification = VERSION_BCD(01.10),
|
| 111 |
+
},
|
| 112 |
+
|
| 113 |
+
.CDC_Functional_ACM =
|
| 114 |
+
{
|
| 115 |
+
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
|
| 116 |
+
.Subtype = 0x02,
|
| 117 |
+
|
| 118 |
+
.Capabilities = 0x04,
|
| 119 |
+
},
|
| 120 |
+
|
| 121 |
+
.CDC_Functional_Union =
|
| 122 |
+
{
|
| 123 |
+
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
|
| 124 |
+
.Subtype = 0x06,
|
| 125 |
+
|
| 126 |
+
.MasterInterfaceNumber = 0,
|
| 127 |
+
.SlaveInterfaceNumber = 1,
|
| 128 |
+
},
|
| 129 |
+
|
| 130 |
+
.CDC_NotificationEndpoint =
|
| 131 |
+
{
|
| 132 |
+
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
| 133 |
+
|
| 134 |
+
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
|
| 135 |
+
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
| 136 |
+
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
|
| 137 |
+
.PollingIntervalMS = 0xFF
|
| 138 |
+
},
|
| 139 |
+
|
| 140 |
+
.CDC_DCI_Interface =
|
| 141 |
+
{
|
| 142 |
+
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
| 143 |
+
|
| 144 |
+
.InterfaceNumber = 1,
|
| 145 |
+
.AlternateSetting = 0,
|
| 146 |
+
|
| 147 |
+
.TotalEndpoints = 2,
|
| 148 |
+
|
| 149 |
+
.Class = CDC_CSCP_CDCDataClass,
|
| 150 |
+
.SubClass = CDC_CSCP_NoDataSubclass,
|
| 151 |
+
.Protocol = CDC_CSCP_NoDataProtocol,
|
| 152 |
+
|
| 153 |
+
.InterfaceStrIndex = NO_DESCRIPTOR
|
| 154 |
+
},
|
| 155 |
+
|
| 156 |
+
.CDC_DataOutEndpoint =
|
| 157 |
+
{
|
| 158 |
+
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
| 159 |
+
|
| 160 |
+
.EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM),
|
| 161 |
+
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
| 162 |
+
.EndpointSize = CDC_TXRX_EPSIZE,
|
| 163 |
+
.PollingIntervalMS = 0x01
|
| 164 |
+
},
|
| 165 |
+
|
| 166 |
+
.CDC_DataInEndpoint =
|
| 167 |
+
{
|
| 168 |
+
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
| 169 |
+
|
| 170 |
+
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM),
|
| 171 |
+
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
| 172 |
+
.EndpointSize = CDC_TXRX_EPSIZE,
|
| 173 |
+
.PollingIntervalMS = 0x01
|
| 174 |
+
}
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
/** Language descriptor structure. This descriptor, located in SRAM memory, is returned when the host requests
|
| 178 |
+
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
|
| 179 |
+
* via the language ID table available at USB.org what languages the device supports for its string descriptors.
|
| 180 |
+
*/
|
| 181 |
+
const USB_Descriptor_String_t LanguageString =
|
| 182 |
+
{
|
| 183 |
+
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
|
| 184 |
+
|
| 185 |
+
.UnicodeString = {LANGUAGE_ID_ENG}
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
|
| 189 |
+
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
|
| 190 |
+
* Descriptor.
|
| 191 |
+
*/
|
| 192 |
+
const USB_Descriptor_String_t ProductString =
|
| 193 |
+
{
|
| 194 |
+
.Header = {.Size = USB_STRING_LEN(16), .Type = DTYPE_String},
|
| 195 |
+
|
| 196 |
+
#if DEVICE_PID == 0x0036
|
| 197 |
+
//.UnicodeString = L"Arduino Leonardo"
|
| 198 |
+
.UnicodeString = L"Helios Gadget"
|
| 199 |
+
#else
|
| 200 |
+
.UnicodeString = L"USB IO board "
|
| 201 |
+
#endif
|
| 202 |
+
};
|
| 203 |
+
|
| 204 |
+
const USB_Descriptor_String_t ManufNameString =
|
| 205 |
+
{
|
| 206 |
+
.Header = {.Size = USB_STRING_LEN(16), .Type = DTYPE_String},
|
| 207 |
+
|
| 208 |
+
#if DEVICE_VID == 0x2341
|
| 209 |
+
//.UnicodeString = L"Arduino LLC"
|
| 210 |
+
.UnicodeString = L"KITT Engineering"
|
| 211 |
+
#else
|
| 212 |
+
.UnicodeString = L"Unknown "
|
| 213 |
+
#endif
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
/** This function is called by the library when in device mode, and must be overridden (see LUFA library "USB Descriptors"
|
| 217 |
+
* documentation) by the application code so that the address and size of a requested descriptor can be given
|
| 218 |
+
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
| 219 |
+
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
|
| 220 |
+
* USB host.
|
| 221 |
+
*/
|
| 222 |
+
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
| 223 |
+
const uint8_t wIndex,
|
| 224 |
+
const void** const DescriptorAddress)
|
| 225 |
+
{
|
| 226 |
+
const uint8_t DescriptorType = (wValue >> 8);
|
| 227 |
+
const uint8_t DescriptorNumber = (wValue & 0xFF);
|
| 228 |
+
|
| 229 |
+
const void* Address = NULL;
|
| 230 |
+
uint16_t Size = NO_DESCRIPTOR;
|
| 231 |
+
|
| 232 |
+
switch (DescriptorType)
|
| 233 |
+
{
|
| 234 |
+
case DTYPE_Device:
|
| 235 |
+
Address = &DeviceDescriptor;
|
| 236 |
+
Size = sizeof(USB_Descriptor_Device_t);
|
| 237 |
+
break;
|
| 238 |
+
case DTYPE_Configuration:
|
| 239 |
+
Address = &ConfigurationDescriptor;
|
| 240 |
+
Size = sizeof(USB_Descriptor_Configuration_t);
|
| 241 |
+
break;
|
| 242 |
+
case DTYPE_String:
|
| 243 |
+
if (!(DescriptorNumber))
|
| 244 |
+
{
|
| 245 |
+
Address = &LanguageString;
|
| 246 |
+
Size = LanguageString.Header.Size;
|
| 247 |
+
}
|
| 248 |
+
else if (DescriptorNumber == DeviceDescriptor.ProductStrIndex)
|
| 249 |
+
{
|
| 250 |
+
Address = &ProductString;
|
| 251 |
+
Size = ProductString.Header.Size;
|
| 252 |
+
} else if (DescriptorNumber == DeviceDescriptor.ManufacturerStrIndex)
|
| 253 |
+
{
|
| 254 |
+
Address = &ManufNameString;
|
| 255 |
+
Size = ManufNameString.Header.Size;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
break;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
*DescriptorAddress = Address;
|
| 262 |
+
return Size;
|
| 263 |
+
}
|
| 264 |
+
|
pool/shard010/C/0138091_ipa-pta-14.c
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* { dg-do run } */
|
| 2 |
+
/* { dg-options "-O2 -fipa-pta -fno-tree-fre -fno-tree-sra -fdump-ipa-pta-details" } */
|
| 3 |
+
|
| 4 |
+
struct X {
|
| 5 |
+
int i;
|
| 6 |
+
void *p;
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
+
static void * __attribute__((noinline,noclone))
|
| 10 |
+
foo(struct X *q, void *p)
|
| 11 |
+
{
|
| 12 |
+
struct X b;
|
| 13 |
+
b.p = p;
|
| 14 |
+
*q = b;
|
| 15 |
+
return q->p;
|
| 16 |
+
}
|
| 17 |
+
extern void abort (void);
|
| 18 |
+
int main()
|
| 19 |
+
{
|
| 20 |
+
struct X a, c;
|
| 21 |
+
void *p;
|
| 22 |
+
a.p = (void *)&c;
|
| 23 |
+
p = foo(&a, &a);
|
| 24 |
+
/* { dg-final { scan-ipa-dump "foo.result = { NULL a\[^ \]* c\[^ \]* }" "pta" { target { ! keeps_null_pointer_checks } } } } */
|
| 25 |
+
/* { dg-final { scan-ipa-dump "foo.result = { NONLOCAL a\[^ \]* c\[^ \]* }" "pta" { target { keeps_null_pointer_checks } } } } */
|
| 26 |
+
((struct X *)p)->p = (void *)0;
|
| 27 |
+
if (a.p != (void *)0)
|
| 28 |
+
abort ();
|
| 29 |
+
return 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/* { dg-final { cleanup-ipa-dump "pta" } } */
|
pool/shard010/C/0138092_darken_x11.c
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2013, Lukas Holecek <hluk@email.cz>
|
| 3 |
+
|
| 4 |
+
This file is part of TheRed.
|
| 5 |
+
|
| 6 |
+
TheRed is free software: you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU General Public License as published by
|
| 8 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
(at your option) any later version.
|
| 10 |
+
|
| 11 |
+
TheRed is distributed in the hope that it will be useful,
|
| 12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
GNU General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU General Public License
|
| 17 |
+
along with TheRed. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "darken.h"
|
| 21 |
+
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
#include <X11/Xlib.h>
|
| 24 |
+
#include <X11/extensions/xf86vmode.h>
|
| 25 |
+
|
| 26 |
+
int darken(int r, int g, int b)
|
| 27 |
+
{
|
| 28 |
+
int retval = -1;
|
| 29 |
+
int sz, i;
|
| 30 |
+
unsigned short *red, *green, *blue;
|
| 31 |
+
|
| 32 |
+
Display *dpy = XOpenDisplay(NULL);
|
| 33 |
+
if (dpy == NULL)
|
| 34 |
+
return -1;
|
| 35 |
+
|
| 36 |
+
XF86VidModeGetGammaRampSize(dpy, 0, &sz);
|
| 37 |
+
|
| 38 |
+
red = malloc(sz * sizeof(unsigned short));
|
| 39 |
+
green = malloc(sz * sizeof(unsigned short));
|
| 40 |
+
blue = malloc(sz * sizeof(unsigned short));
|
| 41 |
+
|
| 42 |
+
XF86VidModeGetGammaRamp(dpy, 0, sz, red, green, blue);
|
| 43 |
+
|
| 44 |
+
retval = change_colors(red, green, blue, sz, r, g, b);
|
| 45 |
+
|
| 46 |
+
XF86VidModeSetGammaRamp(dpy, 0, sz, red, green, blue);
|
| 47 |
+
|
| 48 |
+
free(red);
|
| 49 |
+
free(green);
|
| 50 |
+
free(blue);
|
| 51 |
+
XCloseDisplay(dpy);
|
| 52 |
+
|
| 53 |
+
return retval;
|
| 54 |
+
}
|
pool/shard010/C/0138093_pseudo_wrappers.c
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* shared functionality for the xattr code */
|
| 2 |
+
/* Each of these functions is expecting to get an optional name, and
|
| 3 |
+
* a populated statbuf to use for sending messages to the server.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/* to avoid namespace pollution and such, we now duplicate the
|
| 7 |
+
* basic functionality of a POSIX ACL list, as used by libacl or
|
| 8 |
+
* the kernel. Documentation was obtained from the headers of libacl
|
| 9 |
+
* and from a page or two of _The Linux Programming Interface_, by
|
| 10 |
+
* Michael Kerrisk.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
typedef struct {
|
| 14 |
+
uint16_t tag;
|
| 15 |
+
uint16_t perm;
|
| 16 |
+
uint32_t id;
|
| 17 |
+
} acl_entry;
|
| 18 |
+
|
| 19 |
+
typedef struct {
|
| 20 |
+
uint32_t version;
|
| 21 |
+
acl_entry entries[];
|
| 22 |
+
} acl_header;
|
| 23 |
+
|
| 24 |
+
enum acl_tags {
|
| 25 |
+
ACL_UNDEFINED = 0x0,
|
| 26 |
+
ACL_USER_OBJ = 0x1,
|
| 27 |
+
ACL_USER = 0x2,
|
| 28 |
+
ACL_GROUP_OBJ = 0x4,
|
| 29 |
+
ACL_GROUP = 0x8,
|
| 30 |
+
ACL_MASK = 0x10,
|
| 31 |
+
ACL_OTHER = 0x20,
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
static const int endian_test = 1;
|
| 35 |
+
static const char *endian_tester = (char *) &endian_test;
|
| 36 |
+
|
| 37 |
+
static inline int
|
| 38 |
+
le16(int x16) {
|
| 39 |
+
if (*endian_tester) {
|
| 40 |
+
return x16;
|
| 41 |
+
} else {
|
| 42 |
+
return ((x16 & 0xff) << 8) | ((x16 & 0xff00) >> 8);
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
static inline int
|
| 47 |
+
le32(int x32) {
|
| 48 |
+
if (*endian_tester) {
|
| 49 |
+
return x32;
|
| 50 |
+
} else {
|
| 51 |
+
return ((x32 & 0xff) << 24) | ((x32 & 0xff00) << 8) |
|
| 52 |
+
((x32 & 0xff0000) >> 8) | ((x32 & 0xff000000) >> 24);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* set mode to match the contents of header. Return non-zero on error.
|
| 57 |
+
* On a zero return, mode is a valid posix mode, and *extra is set to
|
| 58 |
+
* 1 if any of the entries are not reflected by that mode. On a non-zero
|
| 59 |
+
* return, no promises are made about *extra or *mode.
|
| 60 |
+
*/
|
| 61 |
+
static int
|
| 62 |
+
posix_permissions(const acl_header *header, int entries, int *extra, int *mode) {
|
| 63 |
+
int acl_seen = 0;
|
| 64 |
+
if (le32(header->version) != 2) {
|
| 65 |
+
pseudo_diag("Fatal: ACL support no available for header version %d.\n",
|
| 66 |
+
le32(header->version));
|
| 67 |
+
return 1;
|
| 68 |
+
}
|
| 69 |
+
*mode = 0;
|
| 70 |
+
*extra = 0;
|
| 71 |
+
for (int i = 0; i < entries; ++i) {
|
| 72 |
+
const acl_entry *e = &header->entries[i];
|
| 73 |
+
int tag = le16(e->tag);
|
| 74 |
+
int perm = le16(e->perm);
|
| 75 |
+
acl_seen |= tag;
|
| 76 |
+
switch (tag) {
|
| 77 |
+
case ACL_USER_OBJ:
|
| 78 |
+
*mode = *mode | (perm << 6);
|
| 79 |
+
break;
|
| 80 |
+
case ACL_GROUP_OBJ:
|
| 81 |
+
*mode = *mode | (perm << 3);
|
| 82 |
+
break;
|
| 83 |
+
case ACL_OTHER:
|
| 84 |
+
*mode = *mode | perm;
|
| 85 |
+
break;
|
| 86 |
+
case ACL_USER:
|
| 87 |
+
case ACL_GROUP:
|
| 88 |
+
case ACL_MASK:
|
| 89 |
+
*extra = *extra + 1;
|
| 90 |
+
break;
|
| 91 |
+
default:
|
| 92 |
+
pseudo_debug(PDBGF_XATTR, "Unknown tag in ACL: 0x%x.\n",
|
| 93 |
+
tag);
|
| 94 |
+
return 1;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
return 0;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
#define RC_AND_BUF \
|
| 101 |
+
int rc; \
|
| 102 |
+
PSEUDO_STATBUF buf; \
|
| 103 |
+
if (path) { \
|
| 104 |
+
rc = base_lstat(path, &buf); \
|
| 105 |
+
} else { \
|
| 106 |
+
rc = base_fstat(fd, &buf); \
|
| 107 |
+
} \
|
| 108 |
+
if (rc == -1) { \
|
| 109 |
+
return rc; \
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
static ssize_t shared_getxattr(const char *path, int fd, const char *name, void *value, size_t size) {
|
| 113 |
+
RC_AND_BUF
|
| 114 |
+
|
| 115 |
+
pseudo_debug(PDBGF_XATTR, "getxattr(%s [fd %d], %s)\n",
|
| 116 |
+
path ? path : "<no path>", fd, name);
|
| 117 |
+
pseudo_msg_t *result = pseudo_client_op(OP_GET_XATTR, 0, fd, -1, path, &buf, name);
|
| 118 |
+
if (result->result != RESULT_SUCCEED) {
|
| 119 |
+
errno = ENOATTR;
|
| 120 |
+
return -1;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if (value) {
|
| 124 |
+
pseudo_debug(PDBGF_XATTR, "returned attributes: '%s' (%d bytes)\n",
|
| 125 |
+
result->path, result->pathlen);
|
| 126 |
+
if (size >= result->pathlen) {
|
| 127 |
+
memcpy(value, result->path, result->pathlen);
|
| 128 |
+
} else {
|
| 129 |
+
memcpy(value, result->path, size);
|
| 130 |
+
errno = ERANGE;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
return result->pathlen;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
static int shared_setxattr(const char *path, int fd, const char *name, const void *value, size_t size, int flags) {
|
| 137 |
+
RC_AND_BUF
|
| 138 |
+
pseudo_op_t op;
|
| 139 |
+
|
| 140 |
+
pseudo_debug(PDBGF_XATTR, "setxattr(%s [fd %d], %s => '%.*s')\n",
|
| 141 |
+
path ? path : "<no path>", fd, name, (int) size, (char *) value);
|
| 142 |
+
|
| 143 |
+
/* this may be a plain chmod */
|
| 144 |
+
if (!strcmp(name, "system.posix_acl_access")) {
|
| 145 |
+
int extra;
|
| 146 |
+
int mode;
|
| 147 |
+
int entries = (size - sizeof(acl_header)) / sizeof(acl_entry);
|
| 148 |
+
if (!posix_permissions(value, entries, &extra, &mode)) {
|
| 149 |
+
pseudo_debug(PDBGF_XATTR, "posix_acl_access translated to mode %04o. Remaining attribute(s): %d.\n",
|
| 150 |
+
mode, extra);
|
| 151 |
+
buf.st_mode = mode;
|
| 152 |
+
/* we want to actually issue a corresponding chmod,
|
| 153 |
+
* as well, or else the file ends up 0600 on the
|
| 154 |
+
* host. Using the slightly-less-efficient wrap_chmod
|
| 155 |
+
* avoids possible misalignment.
|
| 156 |
+
*/
|
| 157 |
+
if (path) {
|
| 158 |
+
wrap_chmod(path, mode);
|
| 159 |
+
} else {
|
| 160 |
+
wrap_fchmod(fd, mode);
|
| 161 |
+
}
|
| 162 |
+
/* we are sneaky, and do not actually record this using
|
| 163 |
+
* extended attributes. */
|
| 164 |
+
if (!extra) {
|
| 165 |
+
return 0;
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
switch (flags) {
|
| 171 |
+
case XATTR_CREATE:
|
| 172 |
+
op = OP_CREATE_XATTR;
|
| 173 |
+
break;
|
| 174 |
+
case XATTR_REPLACE:
|
| 175 |
+
op = OP_REPLACE_XATTR;
|
| 176 |
+
break;
|
| 177 |
+
default:
|
| 178 |
+
op = OP_SET_XATTR;
|
| 179 |
+
break;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
pseudo_msg_t *result = pseudo_client_op(op, 0, fd, -1, path, &buf, name, value, size);
|
| 183 |
+
|
| 184 |
+
/* we automatically assume success */
|
| 185 |
+
if (op == OP_SET_XATTR) {
|
| 186 |
+
return 0;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* CREATE/REPLACE operations can report failure */
|
| 190 |
+
if (!result || result->result == RESULT_FAIL) {
|
| 191 |
+
return -1;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
return 0;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
static ssize_t shared_listxattr(const char *path, int fd, char *list, size_t size) {
|
| 198 |
+
RC_AND_BUF
|
| 199 |
+
pseudo_msg_t *result = pseudo_client_op(OP_LIST_XATTR, 0, fd, -1, path, &buf);
|
| 200 |
+
if (result->result != RESULT_SUCCEED) {
|
| 201 |
+
pseudo_debug(PDBGF_XATTR, "listxattr: no success.\n");
|
| 202 |
+
errno = ENOATTR;
|
| 203 |
+
return -1;
|
| 204 |
+
}
|
| 205 |
+
if (list) {
|
| 206 |
+
pseudo_debug(PDBGF_XATTR, "listxattr: %d bytes of names, starting '%.*s'\n",
|
| 207 |
+
(int) result->pathlen, (int) result->pathlen, result->path);
|
| 208 |
+
if (size >= result->pathlen) {
|
| 209 |
+
memcpy(list, result->path, result->pathlen);
|
| 210 |
+
} else {
|
| 211 |
+
memcpy(list, result->path, size);
|
| 212 |
+
errno = ERANGE;
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
return result->pathlen;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
static int shared_removexattr(const char *path, int fd, const char *name) {
|
| 219 |
+
RC_AND_BUF
|
| 220 |
+
pseudo_msg_t *result = pseudo_client_op(OP_REMOVE_XATTR, 0, fd, -1, path, &buf, name);
|
| 221 |
+
|
| 222 |
+
if (result->result != RESULT_SUCCEED) {
|
| 223 |
+
/* docs say ENOATTR, but I don't have one */
|
| 224 |
+
errno = ENOENT;
|
| 225 |
+
return -1;
|
| 226 |
+
}
|
| 227 |
+
return 0;
|
| 228 |
+
}
|
| 229 |
+
|
pool/shard010/C/0138094_restart_7k.c
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
|
| 2 |
+
*
|
| 3 |
+
* This program is free software; you can redistribute it and/or modify
|
| 4 |
+
* it under the terms of the GNU General Public License version 2 and
|
| 5 |
+
* only version 2 as published by the Free Software Foundation.
|
| 6 |
+
*
|
| 7 |
+
* This program is distributed in the hope that it will be useful,
|
| 8 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
* GNU General Public License for more details.
|
| 11 |
+
*
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
#include <linux/module.h>
|
| 15 |
+
#include <linux/moduleparam.h>
|
| 16 |
+
#include <linux/kernel.h>
|
| 17 |
+
#include <linux/init.h>
|
| 18 |
+
#include <linux/reboot.h>
|
| 19 |
+
#include <linux/pm.h>
|
| 20 |
+
#include <asm/system_misc.h>
|
| 21 |
+
#include <mach/proc_comm.h>
|
| 22 |
+
|
| 23 |
+
#include "devices-msm7x2xa.h"
|
| 24 |
+
|
| 25 |
+
static uint32_t restart_reason = 0x776655AA;
|
| 26 |
+
|
| 27 |
+
static void msm_pm_power_off(void)
|
| 28 |
+
{
|
| 29 |
+
msm_proc_comm(PCOM_POWER_DOWN, 0, 0);
|
| 30 |
+
for (;;)
|
| 31 |
+
;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
static void msm_pm_restart(char str, const char *cmd)
|
| 35 |
+
{
|
| 36 |
+
pr_debug("The reset reason is %x\n", restart_reason);
|
| 37 |
+
|
| 38 |
+
/* Disable interrupts */
|
| 39 |
+
local_irq_disable();
|
| 40 |
+
local_fiq_disable();
|
| 41 |
+
|
| 42 |
+
/*
|
| 43 |
+
* Take out a flat memory mapping and will
|
| 44 |
+
* insert a 1:1 mapping in place of
|
| 45 |
+
* the user-mode pages to ensure predictable results
|
| 46 |
+
* This function takes care of flushing the caches
|
| 47 |
+
* and flushing the TLB.
|
| 48 |
+
*/
|
| 49 |
+
setup_mm_for_reboot();
|
| 50 |
+
|
| 51 |
+
msm_proc_comm(PCOM_RESET_CHIP, &restart_reason, 0);
|
| 52 |
+
|
| 53 |
+
for (;;)
|
| 54 |
+
;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static int msm_reboot_call
|
| 58 |
+
(struct notifier_block *this, unsigned long code, void *_cmd)
|
| 59 |
+
{
|
| 60 |
+
if ((code == SYS_RESTART) && _cmd) {
|
| 61 |
+
char *cmd = _cmd;
|
| 62 |
+
if (!strncmp(cmd, "bootloader", 10)) {
|
| 63 |
+
restart_reason = 0x77665500;
|
| 64 |
+
} else if (!strncmp(cmd, "recovery", 8)) {
|
| 65 |
+
restart_reason = 0x77665502;
|
| 66 |
+
} else if (!strncmp(cmd, "eraseflash", 10)) {
|
| 67 |
+
restart_reason = 0x776655EF;
|
| 68 |
+
} else if (!strncmp(cmd, "oem-", 4)) {
|
| 69 |
+
unsigned long code;
|
| 70 |
+
int res;
|
| 71 |
+
res = kstrtoul(cmd + 4, 16, &code);
|
| 72 |
+
code &= 0xff;
|
| 73 |
+
restart_reason = 0x6f656d00 | code;
|
| 74 |
+
#ifdef CONFIG_HUAWEI_KERNEL
|
| 75 |
+
} else if (!strcmp(cmd, "mtkupdate")) {
|
| 76 |
+
#define MTK_DOWNLOAD_EN 0x6d74646c
|
| 77 |
+
restart_reason = MTK_DOWNLOAD_EN;
|
| 78 |
+
#endif
|
| 79 |
+
} else {
|
| 80 |
+
restart_reason = 0x77665501;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
return NOTIFY_DONE;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
static struct notifier_block msm_reboot_notifier = {
|
| 87 |
+
.notifier_call = msm_reboot_call,
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
static int __init msm_pm_restart_init(void)
|
| 91 |
+
{
|
| 92 |
+
int ret;
|
| 93 |
+
|
| 94 |
+
pm_power_off = msm_pm_power_off;
|
| 95 |
+
arm_pm_restart = msm_pm_restart;
|
| 96 |
+
|
| 97 |
+
ret = register_reboot_notifier(&msm_reboot_notifier);
|
| 98 |
+
if (ret)
|
| 99 |
+
pr_err("Failed to register reboot notifier\n");
|
| 100 |
+
|
| 101 |
+
return ret;
|
| 102 |
+
}
|
| 103 |
+
late_initcall(msm_pm_restart_init);
|
pool/shard010/C/0138095_phy-exynos-mipi-video.c
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
|
| 5 |
+
* Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
|
| 6 |
+
*
|
| 7 |
+
* This program is free software; you can redistribute it and/or modify
|
| 8 |
+
* it under the terms of the GNU General Public License version 2 as
|
| 9 |
+
* published by the Free Software Foundation.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include <linux/err.h>
|
| 13 |
+
#include <linux/io.h>
|
| 14 |
+
#include <linux/kernel.h>
|
| 15 |
+
#include <linux/module.h>
|
| 16 |
+
#include <linux/of.h>
|
| 17 |
+
#include <linux/of_address.h>
|
| 18 |
+
#include <linux/phy/phy.h>
|
| 19 |
+
#include <linux/platform_device.h>
|
| 20 |
+
#include <linux/spinlock.h>
|
| 21 |
+
|
| 22 |
+
/* MIPI_PHYn_CONTROL register offset: n = 0..1 */
|
| 23 |
+
#define EXYNOS_MIPI_PHY_CONTROL(n) ((n) * 4)
|
| 24 |
+
#define EXYNOS_MIPI_PHY_ENABLE (1 << 0)
|
| 25 |
+
#define EXYNOS_MIPI_PHY_SRESETN (1 << 1)
|
| 26 |
+
#define EXYNOS_MIPI_PHY_MRESETN (1 << 2)
|
| 27 |
+
#define EXYNOS_MIPI_PHY_RESET_MASK (3 << 1)
|
| 28 |
+
|
| 29 |
+
enum exynos_mipi_phy_id {
|
| 30 |
+
EXYNOS_MIPI_PHY_ID_CSIS0,
|
| 31 |
+
EXYNOS_MIPI_PHY_ID_DSIM0,
|
| 32 |
+
EXYNOS_MIPI_PHY_ID_CSIS1,
|
| 33 |
+
EXYNOS_MIPI_PHY_ID_DSIM1,
|
| 34 |
+
EXYNOS_MIPI_PHYS_NUM
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
#define is_mipi_dsim_phy_id(id) \
|
| 38 |
+
((id) == EXYNOS_MIPI_PHY_ID_DSIM0 || (id) == EXYNOS_MIPI_PHY_ID_DSIM1)
|
| 39 |
+
|
| 40 |
+
struct exynos_mipi_video_phy {
|
| 41 |
+
spinlock_t slock;
|
| 42 |
+
struct video_phy_desc {
|
| 43 |
+
struct phy *phy;
|
| 44 |
+
unsigned int index;
|
| 45 |
+
} phys[EXYNOS_MIPI_PHYS_NUM];
|
| 46 |
+
void __iomem *regs;
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
static int __set_phy_state(struct exynos_mipi_video_phy *state,
|
| 50 |
+
enum exynos_mipi_phy_id id, unsigned int on)
|
| 51 |
+
{
|
| 52 |
+
void __iomem *addr;
|
| 53 |
+
u32 reg, reset;
|
| 54 |
+
|
| 55 |
+
addr = state->regs + EXYNOS_MIPI_PHY_CONTROL(id / 2);
|
| 56 |
+
|
| 57 |
+
if (is_mipi_dsim_phy_id(id))
|
| 58 |
+
reset = EXYNOS_MIPI_PHY_MRESETN;
|
| 59 |
+
else
|
| 60 |
+
reset = EXYNOS_MIPI_PHY_SRESETN;
|
| 61 |
+
|
| 62 |
+
spin_lock(&state->slock);
|
| 63 |
+
reg = readl(addr);
|
| 64 |
+
if (on)
|
| 65 |
+
reg |= reset;
|
| 66 |
+
else
|
| 67 |
+
reg &= ~reset;
|
| 68 |
+
writel(reg, addr);
|
| 69 |
+
|
| 70 |
+
/* Clear ENABLE bit only if MRESETN, SRESETN bits are not set. */
|
| 71 |
+
if (on)
|
| 72 |
+
reg |= EXYNOS_MIPI_PHY_ENABLE;
|
| 73 |
+
else if (!(reg & EXYNOS_MIPI_PHY_RESET_MASK))
|
| 74 |
+
reg &= ~EXYNOS_MIPI_PHY_ENABLE;
|
| 75 |
+
|
| 76 |
+
writel(reg, addr);
|
| 77 |
+
spin_unlock(&state->slock);
|
| 78 |
+
return 0;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
#define to_mipi_video_phy(desc) \
|
| 82 |
+
container_of((desc), struct exynos_mipi_video_phy, phys[(desc)->index]);
|
| 83 |
+
|
| 84 |
+
static int exynos_mipi_video_phy_power_on(struct phy *phy)
|
| 85 |
+
{
|
| 86 |
+
struct video_phy_desc *phy_desc = phy_get_drvdata(phy);
|
| 87 |
+
struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc);
|
| 88 |
+
|
| 89 |
+
return __set_phy_state(state, phy_desc->index, 1);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
static int exynos_mipi_video_phy_power_off(struct phy *phy)
|
| 93 |
+
{
|
| 94 |
+
struct video_phy_desc *phy_desc = phy_get_drvdata(phy);
|
| 95 |
+
struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc);
|
| 96 |
+
|
| 97 |
+
return __set_phy_state(state, phy_desc->index, 0);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
static struct phy *exynos_mipi_video_phy_xlate(struct device *dev,
|
| 101 |
+
struct of_phandle_args *args)
|
| 102 |
+
{
|
| 103 |
+
struct exynos_mipi_video_phy *state = dev_get_drvdata(dev);
|
| 104 |
+
|
| 105 |
+
if (WARN_ON(args->args[0] >= EXYNOS_MIPI_PHYS_NUM))
|
| 106 |
+
return ERR_PTR(-ENODEV);
|
| 107 |
+
|
| 108 |
+
return state->phys[args->args[0]].phy;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static struct phy_ops exynos_mipi_video_phy_ops = {
|
| 112 |
+
.power_on = exynos_mipi_video_phy_power_on,
|
| 113 |
+
.power_off = exynos_mipi_video_phy_power_off,
|
| 114 |
+
.owner = THIS_MODULE,
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
static int exynos_mipi_video_phy_probe(struct platform_device *pdev)
|
| 118 |
+
{
|
| 119 |
+
struct exynos_mipi_video_phy *state;
|
| 120 |
+
struct device *dev = &pdev->dev;
|
| 121 |
+
struct resource *res;
|
| 122 |
+
struct phy_provider *phy_provider;
|
| 123 |
+
unsigned int i;
|
| 124 |
+
|
| 125 |
+
state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
|
| 126 |
+
if (!state)
|
| 127 |
+
return -ENOMEM;
|
| 128 |
+
|
| 129 |
+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
| 130 |
+
|
| 131 |
+
state->regs = devm_ioremap_resource(dev, res);
|
| 132 |
+
if (IS_ERR(state->regs))
|
| 133 |
+
return PTR_ERR(state->regs);
|
| 134 |
+
|
| 135 |
+
dev_set_drvdata(dev, state);
|
| 136 |
+
spin_lock_init(&state->slock);
|
| 137 |
+
|
| 138 |
+
for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) {
|
| 139 |
+
struct phy *phy = devm_phy_create(dev, NULL,
|
| 140 |
+
&exynos_mipi_video_phy_ops, NULL);
|
| 141 |
+
if (IS_ERR(phy)) {
|
| 142 |
+
dev_err(dev, "failed to create PHY %d\n", i);
|
| 143 |
+
return PTR_ERR(phy);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
state->phys[i].phy = phy;
|
| 147 |
+
state->phys[i].index = i;
|
| 148 |
+
phy_set_drvdata(phy, &state->phys[i]);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
phy_provider = devm_of_phy_provider_register(dev,
|
| 152 |
+
exynos_mipi_video_phy_xlate);
|
| 153 |
+
|
| 154 |
+
return PTR_ERR_OR_ZERO(phy_provider);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
static const struct of_device_id exynos_mipi_video_phy_of_match[] = {
|
| 158 |
+
{ .compatible = "samsung,s5pv210-mipi-video-phy" },
|
| 159 |
+
{ },
|
| 160 |
+
};
|
| 161 |
+
MODULE_DEVICE_TABLE(of, exynos_mipi_video_phy_of_match);
|
| 162 |
+
|
| 163 |
+
static struct platform_driver exynos_mipi_video_phy_driver = {
|
| 164 |
+
.probe = exynos_mipi_video_phy_probe,
|
| 165 |
+
.driver = {
|
| 166 |
+
.of_match_table = exynos_mipi_video_phy_of_match,
|
| 167 |
+
.name = "exynos-mipi-video-phy",
|
| 168 |
+
.owner = THIS_MODULE,
|
| 169 |
+
}
|
| 170 |
+
};
|
| 171 |
+
module_platform_driver(exynos_mipi_video_phy_driver);
|
| 172 |
+
|
| 173 |
+
MODULE_DESCRIPTION("Samsung S5P/EXYNOS SoC MIPI CSI-2/DSI PHY driver");
|
| 174 |
+
MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
|
| 175 |
+
MODULE_LICENSE("GPL v2");
|
pool/shard010/C/0138096_kfd_device_queue_manager_vi.c
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2014 Advanced Micro Devices, Inc.
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
| 5 |
+
* copy of this software and associated documentation files (the "Software"),
|
| 6 |
+
* to deal in the Software without restriction, including without limitation
|
| 7 |
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 8 |
+
* and/or sell copies of the Software, and to permit persons to whom the
|
| 9 |
+
* Software is furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| 17 |
+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
| 18 |
+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
| 19 |
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 20 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include "kfd_device_queue_manager.h"
|
| 25 |
+
|
| 26 |
+
static bool set_cache_memory_policy_vi(struct device_queue_manager *dqm,
|
| 27 |
+
struct qcm_process_device *qpd,
|
| 28 |
+
enum cache_policy default_policy,
|
| 29 |
+
enum cache_policy alternate_policy,
|
| 30 |
+
void __user *alternate_aperture_base,
|
| 31 |
+
uint64_t alternate_aperture_size);
|
| 32 |
+
static int register_process_vi(struct device_queue_manager *dqm,
|
| 33 |
+
struct qcm_process_device *qpd);
|
| 34 |
+
static int initialize_cpsch_vi(struct device_queue_manager *dqm);
|
| 35 |
+
|
| 36 |
+
void device_queue_manager_init_vi(struct device_queue_manager_ops *ops)
|
| 37 |
+
{
|
| 38 |
+
pr_warn("amdkfd: VI DQM is not currently supported\n");
|
| 39 |
+
|
| 40 |
+
ops->set_cache_memory_policy = set_cache_memory_policy_vi;
|
| 41 |
+
ops->register_process = register_process_vi;
|
| 42 |
+
ops->initialize = initialize_cpsch_vi;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
static bool set_cache_memory_policy_vi(struct device_queue_manager *dqm,
|
| 46 |
+
struct qcm_process_device *qpd,
|
| 47 |
+
enum cache_policy default_policy,
|
| 48 |
+
enum cache_policy alternate_policy,
|
| 49 |
+
void __user *alternate_aperture_base,
|
| 50 |
+
uint64_t alternate_aperture_size)
|
| 51 |
+
{
|
| 52 |
+
return false;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static int register_process_vi(struct device_queue_manager *dqm,
|
| 56 |
+
struct qcm_process_device *qpd)
|
| 57 |
+
{
|
| 58 |
+
return -1;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
static int initialize_cpsch_vi(struct device_queue_manager *dqm)
|
| 62 |
+
{
|
| 63 |
+
return 0;
|
| 64 |
+
}
|
pool/shard010/C/0138097_SecPlatformInformation.c
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @file
|
| 2 |
+
Sample to provide SecPlatformInformation function.
|
| 3 |
+
|
| 4 |
+
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
|
| 5 |
+
This program and the accompanying materials
|
| 6 |
+
are licensed and made available under the terms and conditions of the BSD License
|
| 7 |
+
which accompanies this distribution. The full text of the license may be found at
|
| 8 |
+
http://opensource.org/licenses/bsd-license.php.
|
| 9 |
+
|
| 10 |
+
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 11 |
+
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 12 |
+
|
| 13 |
+
**/
|
| 14 |
+
|
| 15 |
+
#include <PiPei.h>
|
| 16 |
+
|
| 17 |
+
#include <Ppi/SecPlatformInformation.h>
|
| 18 |
+
#include <Ppi/TopOfTemporaryRam.h>
|
| 19 |
+
|
| 20 |
+
#include <Library/BaseMemoryLib.h>
|
| 21 |
+
#include <Library/DebugLib.h>
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
This interface conveys state information out of the Security (SEC) phase into PEI.
|
| 25 |
+
|
| 26 |
+
@param[in] PeiServices Pointer to the PEI Services Table.
|
| 27 |
+
@param[in,out] StructureSize Pointer to the variable describing size of the input buffer.
|
| 28 |
+
@param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
|
| 29 |
+
|
| 30 |
+
@retval EFI_SUCCESS The data was successfully returned.
|
| 31 |
+
@retval EFI_BUFFER_TOO_SMALL The buffer was too small.
|
| 32 |
+
|
| 33 |
+
**/
|
| 34 |
+
EFI_STATUS
|
| 35 |
+
EFIAPI
|
| 36 |
+
SecPlatformInformation (
|
| 37 |
+
IN CONST EFI_PEI_SERVICES **PeiServices,
|
| 38 |
+
IN OUT UINT64 *StructureSize,
|
| 39 |
+
OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
|
| 40 |
+
)
|
| 41 |
+
{
|
| 42 |
+
UINT32 *Bist;
|
| 43 |
+
UINT32 Size;
|
| 44 |
+
UINT32 Count;
|
| 45 |
+
UINT32 TopOfTemporaryRam;
|
| 46 |
+
VOID *TopOfTemporaryRamPpi;
|
| 47 |
+
EFI_STATUS Status;
|
| 48 |
+
|
| 49 |
+
DEBUG ((DEBUG_INFO, "SecPlatformInformation\n"));
|
| 50 |
+
|
| 51 |
+
Status = (*PeiServices)->LocatePpi (
|
| 52 |
+
PeiServices,
|
| 53 |
+
&gTopOfTemporaryRamPpiGuid,
|
| 54 |
+
0,
|
| 55 |
+
NULL,
|
| 56 |
+
(VOID **) &TopOfTemporaryRamPpi
|
| 57 |
+
);
|
| 58 |
+
if (EFI_ERROR (Status)) {
|
| 59 |
+
return EFI_NOT_FOUND;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
//
|
| 63 |
+
// The entries of BIST information, together with the number of them,
|
| 64 |
+
// reside in the bottom of stack, left untouched by normal stack operation.
|
| 65 |
+
// This routine copies the BIST information to the buffer pointed by
|
| 66 |
+
// PlatformInformationRecord for output.
|
| 67 |
+
//
|
| 68 |
+
TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof (UINT32);
|
| 69 |
+
TopOfTemporaryRam -= sizeof(UINT32) * 2;
|
| 70 |
+
Count = *((UINT32 *)(UINTN) (TopOfTemporaryRam - sizeof (UINT32)));
|
| 71 |
+
Size = Count * sizeof (IA32_HANDOFF_STATUS);
|
| 72 |
+
|
| 73 |
+
if ((*StructureSize) < (UINT64) Size) {
|
| 74 |
+
*StructureSize = Size;
|
| 75 |
+
return EFI_BUFFER_TOO_SMALL;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
*StructureSize = Size;
|
| 79 |
+
Bist = (UINT32 *) (TopOfTemporaryRam - sizeof (UINT32) - Size);
|
| 80 |
+
|
| 81 |
+
CopyMem (PlatformInformationRecord, Bist, Size);
|
| 82 |
+
|
| 83 |
+
return EFI_SUCCESS;
|
| 84 |
+
}
|
pool/shard010/C/0138098_basic.c
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <state.h>
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
|
| 4 |
+
int a(void *p){
|
| 5 |
+
static int counter=0;
|
| 6 |
+
counter+=1;
|
| 7 |
+
printf("a: %d\n",counter);
|
| 8 |
+
return counter;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
int b(void *p){
|
| 12 |
+
printf("b\n");
|
| 13 |
+
return 0;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
int main(){
|
| 17 |
+
struct StateMachine *machine;
|
| 18 |
+
machine=state_newmachine();
|
| 19 |
+
state_add_transition(machine,a,1,b);
|
| 20 |
+
state_add_transition(machine,b,0,a);
|
| 21 |
+
state_add_transition(machine,a,2,NULL);
|
| 22 |
+
state_start(machine,a,NULL);
|
| 23 |
+
state_free(machine);
|
| 24 |
+
}
|
pool/shard010/C/0138099_platsmp.c
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2002 ARM Ltd.
|
| 3 |
+
* Copyright (C) 2008 STMicroelctronics.
|
| 4 |
+
* Copyright (C) 2009 ST-Ericsson.
|
| 5 |
+
* Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
|
| 6 |
+
*
|
| 7 |
+
* This file is based on arm realview platform
|
| 8 |
+
*
|
| 9 |
+
* This program is free software; you can redistribute it and/or modify
|
| 10 |
+
* it under the terms of the GNU General Public License version 2 as
|
| 11 |
+
* published by the Free Software Foundation.
|
| 12 |
+
*/
|
| 13 |
+
#include <linux/init.h>
|
| 14 |
+
#include <linux/errno.h>
|
| 15 |
+
#include <linux/delay.h>
|
| 16 |
+
#include <linux/device.h>
|
| 17 |
+
#include <linux/smp.h>
|
| 18 |
+
#include <linux/io.h>
|
| 19 |
+
|
| 20 |
+
#include <asm/cacheflush.h>
|
| 21 |
+
#include <asm/hardware/gic.h>
|
| 22 |
+
#include <asm/smp_plat.h>
|
| 23 |
+
#include <asm/smp_scu.h>
|
| 24 |
+
#include <mach/hardware.h>
|
| 25 |
+
#include <mach/setup.h>
|
| 26 |
+
|
| 27 |
+
/* This is called from headsmp.S to wakeup the secondary core */
|
| 28 |
+
extern void u8500_secondary_startup(void);
|
| 29 |
+
|
| 30 |
+
/*
|
| 31 |
+
* Write pen_release in a way that is guaranteed to be visible to all
|
| 32 |
+
* observers, irrespective of whether they're taking part in coherency
|
| 33 |
+
* or not. This is necessary for the hotplug code to work reliably.
|
| 34 |
+
*/
|
| 35 |
+
static void write_pen_release(int val)
|
| 36 |
+
{
|
| 37 |
+
pen_release = val;
|
| 38 |
+
smp_wmb();
|
| 39 |
+
__cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
|
| 40 |
+
outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
static void __iomem *scu_base_addr(void)
|
| 44 |
+
{
|
| 45 |
+
if (cpu_is_u8500_family() || cpu_is_ux540_family())
|
| 46 |
+
return __io_address(U8500_SCU_BASE);
|
| 47 |
+
else
|
| 48 |
+
ux500_unknown_soc();
|
| 49 |
+
|
| 50 |
+
return NULL;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
static DEFINE_SPINLOCK(boot_lock);
|
| 54 |
+
|
| 55 |
+
static void __cpuinit ux500_secondary_init(unsigned int cpu)
|
| 56 |
+
{
|
| 57 |
+
/*
|
| 58 |
+
* if any interrupts are already enabled for the primary
|
| 59 |
+
* core (e.g. timer irq), then they will not have been enabled
|
| 60 |
+
* for us: do so
|
| 61 |
+
*/
|
| 62 |
+
gic_secondary_init(0);
|
| 63 |
+
|
| 64 |
+
/*
|
| 65 |
+
* let the primary processor know we're out of the
|
| 66 |
+
* pen, then head off into the C entry point
|
| 67 |
+
*/
|
| 68 |
+
write_pen_release(-1);
|
| 69 |
+
|
| 70 |
+
/*
|
| 71 |
+
* Synchronise with the boot thread.
|
| 72 |
+
*/
|
| 73 |
+
spin_lock(&boot_lock);
|
| 74 |
+
spin_unlock(&boot_lock);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
static int __cpuinit ux500_boot_secondary(unsigned int cpu, struct task_struct *idle)
|
| 78 |
+
{
|
| 79 |
+
unsigned long timeout;
|
| 80 |
+
|
| 81 |
+
/*
|
| 82 |
+
* set synchronisation state between this boot processor
|
| 83 |
+
* and the secondary one
|
| 84 |
+
*/
|
| 85 |
+
spin_lock(&boot_lock);
|
| 86 |
+
|
| 87 |
+
/*
|
| 88 |
+
* The secondary processor is waiting to be released from
|
| 89 |
+
* the holding pen - release it, then wait for it to flag
|
| 90 |
+
* that it has been released by resetting pen_release.
|
| 91 |
+
*/
|
| 92 |
+
write_pen_release(cpu_logical_map(cpu));
|
| 93 |
+
|
| 94 |
+
smp_send_reschedule(cpu);
|
| 95 |
+
|
| 96 |
+
timeout = jiffies + (1 * HZ);
|
| 97 |
+
while (time_before(jiffies, timeout)) {
|
| 98 |
+
if (pen_release == -1)
|
| 99 |
+
break;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/*
|
| 103 |
+
* now the secondary core is starting up let it run its
|
| 104 |
+
* calibrations, then wait for it to finish
|
| 105 |
+
*/
|
| 106 |
+
spin_unlock(&boot_lock);
|
| 107 |
+
|
| 108 |
+
return pen_release != -1 ? -ENOSYS : 0;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static void __init wakeup_secondary(void)
|
| 112 |
+
{
|
| 113 |
+
void __iomem *backupram;
|
| 114 |
+
|
| 115 |
+
if (cpu_is_u8500_family() || cpu_is_ux540_family())
|
| 116 |
+
backupram = __io_address(U8500_BACKUPRAM0_BASE);
|
| 117 |
+
else
|
| 118 |
+
ux500_unknown_soc();
|
| 119 |
+
|
| 120 |
+
/*
|
| 121 |
+
* write the address of secondary startup into the backup ram register
|
| 122 |
+
* at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
|
| 123 |
+
* backup ram register at offset 0x1FF0, which is what boot rom code
|
| 124 |
+
* is waiting for. This would wake up the secondary core from WFE
|
| 125 |
+
*/
|
| 126 |
+
#define UX500_CPU1_JUMPADDR_OFFSET 0x1FF4
|
| 127 |
+
__raw_writel(virt_to_phys(u8500_secondary_startup),
|
| 128 |
+
backupram + UX500_CPU1_JUMPADDR_OFFSET);
|
| 129 |
+
|
| 130 |
+
#define UX500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
|
| 131 |
+
__raw_writel(0xA1FEED01,
|
| 132 |
+
backupram + UX500_CPU1_WAKEMAGIC_OFFSET);
|
| 133 |
+
|
| 134 |
+
/* make sure write buffer is drained */
|
| 135 |
+
mb();
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/*
|
| 139 |
+
* Initialise the CPU possible map early - this describes the CPUs
|
| 140 |
+
* which may be present or become present in the system.
|
| 141 |
+
*/
|
| 142 |
+
static void __init ux500_smp_init_cpus(void)
|
| 143 |
+
{
|
| 144 |
+
void __iomem *scu_base = scu_base_addr();
|
| 145 |
+
unsigned int i, ncores;
|
| 146 |
+
|
| 147 |
+
ncores = scu_base ? scu_get_core_count(scu_base) : 1;
|
| 148 |
+
|
| 149 |
+
/* sanity check */
|
| 150 |
+
if (ncores > nr_cpu_ids) {
|
| 151 |
+
pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
|
| 152 |
+
ncores, nr_cpu_ids);
|
| 153 |
+
ncores = nr_cpu_ids;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
for (i = 0; i < ncores; i++)
|
| 157 |
+
set_cpu_possible(i, true);
|
| 158 |
+
|
| 159 |
+
set_smp_cross_call(gic_raise_softirq);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
static void __init ux500_smp_prepare_cpus(unsigned int max_cpus)
|
| 163 |
+
{
|
| 164 |
+
|
| 165 |
+
scu_enable(scu_base_addr());
|
| 166 |
+
wakeup_secondary();
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
struct smp_operations ux500_smp_ops __initdata = {
|
| 170 |
+
.smp_init_cpus = ux500_smp_init_cpus,
|
| 171 |
+
.smp_prepare_cpus = ux500_smp_prepare_cpus,
|
| 172 |
+
.smp_secondary_init = ux500_secondary_init,
|
| 173 |
+
.smp_boot_secondary = ux500_boot_secondary,
|
| 174 |
+
#ifdef CONFIG_HOTPLUG_CPU
|
| 175 |
+
.cpu_die = ux500_cpu_die,
|
| 176 |
+
#endif
|
| 177 |
+
};
|
pool/shard010/C/0138100_artst.c
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Quick hack to test input of non aligned data */
|
| 2 |
+
/* Quickly hacked from atst */
|
| 3 |
+
/* PAB 1/8/92 */
|
| 4 |
+
|
| 5 |
+
#include <helios.h>
|
| 6 |
+
|
| 7 |
+
#if 1 /* posix version */
|
| 8 |
+
|
| 9 |
+
#include <stdio.h>
|
| 10 |
+
#include <stdlib.h>
|
| 11 |
+
#include <posix.h>
|
| 12 |
+
#include <fcntl.h>
|
| 13 |
+
|
| 14 |
+
int main(int argc, char **argv)
|
| 15 |
+
{
|
| 16 |
+
int sz;
|
| 17 |
+
char *fred = "abcdefghijklmnopqrstuvwxyz"
|
| 18 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 19 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 20 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 21 |
+
|
| 22 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 23 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 24 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 25 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 26 |
+
|
| 27 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 28 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 29 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 30 |
+
"abcdefghijklmnopqrstuvwxyz";
|
| 31 |
+
|
| 32 |
+
/* 012345678901234567890123456789 */
|
| 33 |
+
|
| 34 |
+
int fd = open("/helios/lib/nucleus", O_RDONLY);
|
| 35 |
+
|
| 36 |
+
for (sz = 1 ;sz <= 20; sz++) {
|
| 37 |
+
fprintf(stderr, "Read sz %d\n", sz);
|
| 38 |
+
read(fd, &fred[0], sz);
|
| 39 |
+
#if 1
|
| 40 |
+
read(fd, &fred[1], sz);
|
| 41 |
+
read(fd, &fred[2], sz);
|
| 42 |
+
read(fd, &fred[3], sz);
|
| 43 |
+
#endif
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
#else /* syslib version */
|
| 48 |
+
|
| 49 |
+
#include <stdio.h>
|
| 50 |
+
#include <stdlib.h>
|
| 51 |
+
#include <posix.h>
|
| 52 |
+
#include <fcntl.h>
|
| 53 |
+
#include <syslib.h>
|
| 54 |
+
|
| 55 |
+
int main(int argc, char **argv)
|
| 56 |
+
{
|
| 57 |
+
int sz;
|
| 58 |
+
char *fred = "abcdefghijklmnopqrstuvwxyz"
|
| 59 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 60 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 61 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 62 |
+
|
| 63 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 64 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 65 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 66 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 67 |
+
|
| 68 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 69 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 70 |
+
"abcdefghijklmnopqrstuvwxyz"
|
| 71 |
+
"abcdefghijklmnopqrstuvwxyz";
|
| 72 |
+
|
| 73 |
+
/* 012345678901234567890123456789 */
|
| 74 |
+
|
| 75 |
+
Object *ob = Locate(NULL, "/helios/lib/nucleus");
|
| 76 |
+
Stream *fd = Open(ob, NULL, O_ReadOnly);
|
| 77 |
+
|
| 78 |
+
for (sz = 1 ;sz <= 20; sz++) {
|
| 79 |
+
fprintf(stderr, "Read sz %d\n", sz);
|
| 80 |
+
Read(fd, &fred[0], sz, -1);
|
| 81 |
+
#if 1
|
| 82 |
+
Read(fd, &fred[1], sz, -1);
|
| 83 |
+
Read(fd, &fred[2], sz, -1);
|
| 84 |
+
Read(fd, &fred[3], sz, -1);
|
| 85 |
+
#endif
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
#endif
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
/* end of align test */
|
pool/shard010/C/0138101_uart.c
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Include processor definitions.
|
| 3 |
+
*/
|
| 4 |
+
#include "pic32mz.h"
|
| 5 |
+
|
| 6 |
+
#define MHZ 200 /* CPU clock. */
|
| 7 |
+
|
| 8 |
+
/*
|
| 9 |
+
* Chip configuration.
|
| 10 |
+
*/
|
| 11 |
+
PIC32_DEVCFG (
|
| 12 |
+
DEVCFG0_JTAG_DISABLE | /* Disable JTAG port */
|
| 13 |
+
DEVCFG0_TRC_DISABLE, /* Disable trace port */
|
| 14 |
+
#if 0
|
| 15 |
+
/* Case #1: using internal fast RC oscillator.
|
| 16 |
+
* The frequency is around 8 MHz.
|
| 17 |
+
* PLL multiplies it to 200 MHz. */
|
| 18 |
+
DEVCFG1_FNOSC_SPLL | /* System clock supplied by SPLL */
|
| 19 |
+
DEVCFG1_POSCMOD_DISABLE | /* Primary oscillator disabled */
|
| 20 |
+
DEVCFG1_CLKO_DISABLE, /* CLKO output disable */
|
| 21 |
+
|
| 22 |
+
DEVCFG2_FPLLIDIV_1 | /* PLL input divider = 1 */
|
| 23 |
+
DEVCFG2_FPLLRNG_5_10 | /* PLL input range is 5-10 MHz */
|
| 24 |
+
DEVCFG2_FPLLICLK_FRC | /* Select FRC as input to PLL */
|
| 25 |
+
DEVCFG2_FPLLMULT(50) | /* PLL multiplier = 50x */
|
| 26 |
+
DEVCFG2_FPLLODIV_2, /* PLL postscaler = 1/2 */
|
| 27 |
+
#endif
|
| 28 |
+
#if 1
|
| 29 |
+
/* Case #2: using primary oscillator with external crystal 24 MHz.
|
| 30 |
+
* PLL multiplies it to 200 MHz. */
|
| 31 |
+
DEVCFG1_FNOSC_SPLL | /* System clock supplied by SPLL */
|
| 32 |
+
DEVCFG1_POSCMOD_EXT | /* External generator */
|
| 33 |
+
DEVCFG1_FCKS_ENABLE | /* Enable clock switching */
|
| 34 |
+
DEVCFG1_FCKM_ENABLE | /* Enable fail-safe clock monitoring */
|
| 35 |
+
DEVCFG1_IESO | /* Internal-external switch over enable */
|
| 36 |
+
DEVCFG1_CLKO_DISABLE, /* CLKO output disable */
|
| 37 |
+
|
| 38 |
+
DEVCFG2_FPLLIDIV_3 | /* PLL input divider = 3 */
|
| 39 |
+
DEVCFG2_FPLLRNG_5_10 | /* PLL input range is 5-10 MHz */
|
| 40 |
+
DEVCFG2_FPLLMULT(50) | /* PLL multiplier = 50x */
|
| 41 |
+
DEVCFG2_FPLLODIV_2, /* PLL postscaler = 1/2 */
|
| 42 |
+
#endif
|
| 43 |
+
DEVCFG3_FETHIO | /* Default Ethernet pins */
|
| 44 |
+
DEVCFG3_USERID(0xffff)); /* User-defined ID */
|
| 45 |
+
|
| 46 |
+
/*
|
| 47 |
+
* Boot code at bfc00000.
|
| 48 |
+
* Setup stack pointer and $gp registers, and jump to main().
|
| 49 |
+
*/
|
| 50 |
+
asm (" .section .exception");
|
| 51 |
+
asm (" .globl _start");
|
| 52 |
+
asm (" .type _start, function");
|
| 53 |
+
asm ("_start: la $sp, _estack");
|
| 54 |
+
asm (" la $ra, main");
|
| 55 |
+
asm (" la $gp, _gp");
|
| 56 |
+
asm (" jr $ra");
|
| 57 |
+
asm (" .text");
|
| 58 |
+
asm ("_estack = _end + 0x1000");
|
| 59 |
+
|
| 60 |
+
volatile unsigned loop;
|
| 61 |
+
|
| 62 |
+
/*
|
| 63 |
+
* Delay for a given number of microseconds.
|
| 64 |
+
* The processor has a 32-bit hardware Count register,
|
| 65 |
+
* which increments at half CPU rate.
|
| 66 |
+
* We use it to get a precise delay.
|
| 67 |
+
*/
|
| 68 |
+
void udelay (unsigned usec)
|
| 69 |
+
{
|
| 70 |
+
unsigned now = mfc0 (C0_COUNT, 0);
|
| 71 |
+
unsigned final = now + usec * MHZ / 2;
|
| 72 |
+
|
| 73 |
+
for (;;) {
|
| 74 |
+
now = mfc0 (C0_COUNT, 0);
|
| 75 |
+
|
| 76 |
+
/* This comparison is valid only when using a signed type. */
|
| 77 |
+
if ((int) (now - final) >= 0)
|
| 78 |
+
break;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/*
|
| 83 |
+
* Send a byte to the UART transmitter, with interrupts disabled.
|
| 84 |
+
*/
|
| 85 |
+
void putch (unsigned char c)
|
| 86 |
+
{
|
| 87 |
+
/* Wait for transmitter shift register empty. */
|
| 88 |
+
while (! (U1STA & PIC32_USTA_TRMT))
|
| 89 |
+
continue;
|
| 90 |
+
|
| 91 |
+
again:
|
| 92 |
+
/* Send byte. */
|
| 93 |
+
U1TXREG = c;
|
| 94 |
+
|
| 95 |
+
/* Wait for transmitter shift register empty. */
|
| 96 |
+
while (! (U1STA & PIC32_USTA_TRMT))
|
| 97 |
+
continue;
|
| 98 |
+
|
| 99 |
+
if (c == '\n') {
|
| 100 |
+
c = '\r';
|
| 101 |
+
goto again;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/*
|
| 106 |
+
* Wait for the byte to be received and return it.
|
| 107 |
+
*/
|
| 108 |
+
unsigned getch (void)
|
| 109 |
+
{
|
| 110 |
+
unsigned c;
|
| 111 |
+
|
| 112 |
+
for (;;) {
|
| 113 |
+
/* Wait until receive data available. */
|
| 114 |
+
if (U1STA & PIC32_USTA_URXDA) {
|
| 115 |
+
c = (unsigned char) U1RXREG;
|
| 116 |
+
break;
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
return c;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
int hexchar (unsigned val)
|
| 123 |
+
{
|
| 124 |
+
return "0123456789abcdef" [val & 0xf];
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
void printreg (const char *p, unsigned val)
|
| 128 |
+
{
|
| 129 |
+
for (; *p; ++p)
|
| 130 |
+
putch (*p);
|
| 131 |
+
|
| 132 |
+
putch ('=');
|
| 133 |
+
putch (' ');
|
| 134 |
+
putch (hexchar (val >> 28));
|
| 135 |
+
putch (hexchar (val >> 24));
|
| 136 |
+
putch (hexchar (val >> 20));
|
| 137 |
+
putch (hexchar (val >> 16));
|
| 138 |
+
putch (hexchar (val >> 12));
|
| 139 |
+
putch (hexchar (val >> 8));
|
| 140 |
+
putch (hexchar (val >> 4));
|
| 141 |
+
putch (hexchar (val));
|
| 142 |
+
putch ('\n');
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
int main()
|
| 146 |
+
{
|
| 147 |
+
/* Initialize coprocessor 0. */
|
| 148 |
+
mtc0 (C0_COUNT, 0, 0);
|
| 149 |
+
mtc0 (C0_COMPARE, 0, -1);
|
| 150 |
+
//mtc0 (C0_EBASE, 1, 0x9fc00000); /* Vector base */
|
| 151 |
+
//mtc0 (C0_INTCTL, 1, 1 << 5); /* Vector spacing 32 bytes */
|
| 152 |
+
//mtc0 (C0_CAUSE, 0, 1 << 23); /* Set IV */
|
| 153 |
+
//mtc0 (C0_STATUS, 0, 0); /* Clear BEV */
|
| 154 |
+
|
| 155 |
+
/* Use pins PA0-PA3, PF13, PF12, PA6-PA7 as output: LED control. */
|
| 156 |
+
LATACLR = 0xCF;
|
| 157 |
+
TRISACLR = 0xCF;
|
| 158 |
+
LATFCLR = 0x3000;
|
| 159 |
+
TRISFCLR = 0x3000;
|
| 160 |
+
|
| 161 |
+
/* Initialize UART. */
|
| 162 |
+
U1RXR = 2; /* assign UART1 receive to pin RPF4 */
|
| 163 |
+
RPF5R = 1; /* assign pin RPF5 to UART1 transmit */
|
| 164 |
+
|
| 165 |
+
U1BRG = PIC32_BRG_BAUD (MHZ * 500000, 115200);
|
| 166 |
+
U1STA = 0;
|
| 167 |
+
U1MODE = PIC32_UMODE_PDSEL_8NPAR | /* 8-bit data, no parity */
|
| 168 |
+
PIC32_UMODE_ON; /* UART Enable */
|
| 169 |
+
U1STASET = PIC32_USTA_URXEN | /* Receiver Enable */
|
| 170 |
+
PIC32_USTA_UTXEN; /* Transmit Enable */
|
| 171 |
+
|
| 172 |
+
/*
|
| 173 |
+
* Print initial state of control registers.
|
| 174 |
+
*/
|
| 175 |
+
putch ('-');
|
| 176 |
+
putch ('\n');
|
| 177 |
+
printreg ("Status ", mfc0(12, 0));
|
| 178 |
+
printreg ("IntCtl ", mfc0(12, 1));
|
| 179 |
+
printreg ("SRSCtl ", mfc0(12, 2));
|
| 180 |
+
printreg ("Cause ", mfc0(13, 0));
|
| 181 |
+
printreg ("PRId ", mfc0(15, 0));
|
| 182 |
+
printreg ("EBase ", mfc0(15, 1));
|
| 183 |
+
printreg ("CDMMBase", mfc0(15, 2));
|
| 184 |
+
printreg ("Config ", mfc0(16, 0));
|
| 185 |
+
printreg ("Config1 ", mfc0(16, 1));
|
| 186 |
+
printreg ("Config2 ", mfc0(16, 2));
|
| 187 |
+
printreg ("Config3 ", mfc0(16, 3));
|
| 188 |
+
printreg ("Config4 ", mfc0(16, 4));
|
| 189 |
+
printreg ("Config5 ", mfc0(16, 5));
|
| 190 |
+
printreg ("Config7 ", mfc0(16, 7));
|
| 191 |
+
printreg ("WatchHi ", mfc0(19, 0));
|
| 192 |
+
printreg ("WatchHi1", mfc0(19, 1));
|
| 193 |
+
printreg ("WatchHi2", mfc0(19, 2));
|
| 194 |
+
printreg ("WatchHi3", mfc0(19, 3));
|
| 195 |
+
printreg ("Debug ", mfc0(23, 0));
|
| 196 |
+
printreg ("PerfCtl0", mfc0(25, 0));
|
| 197 |
+
printreg ("PerfCtl1", mfc0(25, 2));
|
| 198 |
+
printreg ("DEVID ", DEVID);
|
| 199 |
+
printreg ("OSCCON ", OSCCON);
|
| 200 |
+
printreg ("DEVCFG0 ", DEVCFG0);
|
| 201 |
+
printreg ("DEVCFG1 ", DEVCFG1);
|
| 202 |
+
printreg ("DEVCFG2 ", DEVCFG2);
|
| 203 |
+
printreg ("DEVCFG3 ", DEVCFG3);
|
| 204 |
+
|
| 205 |
+
while (1) {
|
| 206 |
+
/* Invert pins PA7-PA0. */
|
| 207 |
+
LATAINV = 1 << 0; udelay (100000);
|
| 208 |
+
LATAINV = 1 << 1; udelay (100000);
|
| 209 |
+
LATAINV = 1 << 2; udelay (100000);
|
| 210 |
+
LATAINV = 1 << 3; udelay (100000);
|
| 211 |
+
LATFINV = 1 << 13; udelay (100000);
|
| 212 |
+
LATFINV = 1 << 12; udelay (100000);
|
| 213 |
+
LATAINV = 1 << 6; udelay (100000);
|
| 214 |
+
LATAINV = 1 << 7; udelay (100000);
|
| 215 |
+
|
| 216 |
+
loop++;
|
| 217 |
+
putch ('.');
|
| 218 |
+
}
|
| 219 |
+
}
|
pool/shard010/C/0138102_capitalize.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <cs50.h>
|
| 3 |
+
|
| 4 |
+
int main(void)
|
| 5 |
+
{
|
| 6 |
+
string s = GetString();
|
| 7 |
+
|
| 8 |
+
for (int i = 0, n = strlen(s); i < n; i++)
|
| 9 |
+
{
|
| 10 |
+
if (s[i] >= "a" && s[i] <= "z")
|
| 11 |
+
{
|
| 12 |
+
printf("%c", s[i] - ("a" - "A"));
|
| 13 |
+
}
|
| 14 |
+
else
|
| 15 |
+
{
|
| 16 |
+
printf("%c",s[i]);
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
printf("\n");
|
| 20 |
+
return 0;
|
| 21 |
+
}
|
| 22 |
+
|
pool/shard010/C/0138103_pthread_join.c
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <string.h>
|
| 3 |
+
#include <pthread.h>
|
| 4 |
+
|
| 5 |
+
pthread_t threads[5];
|
| 6 |
+
int done[5];
|
| 7 |
+
|
| 8 |
+
void *thread_main(void *);
|
| 9 |
+
|
| 10 |
+
int main(void)
|
| 11 |
+
{
|
| 12 |
+
int i;
|
| 13 |
+
int rc;
|
| 14 |
+
// int status; pthread_join() need to get void pointer's addr
|
| 15 |
+
void *status;
|
| 16 |
+
|
| 17 |
+
for (i = 0; i < 5; i++)
|
| 18 |
+
{
|
| 19 |
+
done[i] = 0;
|
| 20 |
+
pthread_create(&threads[i], NULL, &thread_main, (void *)&i);
|
| 21 |
+
printf("thread[%d] create, %ld\n", i, threads[i]);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
for (i = 4; i >= 0; i--)
|
| 25 |
+
{
|
| 26 |
+
done[i] = 1;
|
| 27 |
+
rc = pthread_join(threads[i], status);
|
| 28 |
+
printf("%p\n", status);
|
| 29 |
+
if (rc == 0)
|
| 30 |
+
{
|
| 31 |
+
printf("Completed join with thread %d status= %p\n",i, status);
|
| 32 |
+
}
|
| 33 |
+
else
|
| 34 |
+
{
|
| 35 |
+
printf("ERROR; return code from pthread_join() is %d, thread %d\n", rc, i);
|
| 36 |
+
return -1;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void *thread_main(void *arg)
|
| 44 |
+
{
|
| 45 |
+
int i;
|
| 46 |
+
double result=0.0;
|
| 47 |
+
|
| 48 |
+
printf("thread: %d\n", *((int *)arg));
|
| 49 |
+
}
|
| 50 |
+
|
pool/shard010/C/0138104_mca_dsm.c
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* Copyright (C) 2009-2012 Broadcom Corporation
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
* you may not use this file except in compliance with the License.
|
| 7 |
+
* You may obtain a copy of the License at:
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*
|
| 17 |
+
******************************************************************************/
|
| 18 |
+
|
| 19 |
+
/******************************************************************************
|
| 20 |
+
*
|
| 21 |
+
* This is the implementation file for the MCAP Data chahnel state machine.
|
| 22 |
+
*
|
| 23 |
+
******************************************************************************/
|
| 24 |
+
#include <string.h>
|
| 25 |
+
|
| 26 |
+
#include "bt_target.h"
|
| 27 |
+
#include "mca_api.h"
|
| 28 |
+
#include "mca_defs.h"
|
| 29 |
+
#include "mca_int.h"
|
| 30 |
+
|
| 31 |
+
/*****************************************************************************
|
| 32 |
+
** data channel state machine constants and types
|
| 33 |
+
*****************************************************************************/
|
| 34 |
+
enum
|
| 35 |
+
{
|
| 36 |
+
MCA_DCB_TC_OPEN,
|
| 37 |
+
MCA_DCB_CONG,
|
| 38 |
+
MCA_DCB_FREE_DATA,
|
| 39 |
+
MCA_DCB_DEALLOC,
|
| 40 |
+
MCA_DCB_DO_DISCONN,
|
| 41 |
+
MCA_DCB_SND_DATA,
|
| 42 |
+
MCA_DCB_HDL_DATA,
|
| 43 |
+
MCA_DCB_NUM_ACTIONS
|
| 44 |
+
};
|
| 45 |
+
#define MCA_DCB_IGNORE MCA_DCB_NUM_ACTIONS
|
| 46 |
+
|
| 47 |
+
/* action function list */
|
| 48 |
+
const tMCA_DCB_ACTION mca_dcb_action[] = {
|
| 49 |
+
mca_dcb_tc_open,
|
| 50 |
+
mca_dcb_cong,
|
| 51 |
+
mca_dcb_free_data,
|
| 52 |
+
mca_dcb_dealloc,
|
| 53 |
+
mca_dcb_do_disconn,
|
| 54 |
+
mca_dcb_snd_data,
|
| 55 |
+
mca_dcb_hdl_data
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
/* state table information */
|
| 59 |
+
#define MCA_DCB_ACTIONS 1 /* number of actions */
|
| 60 |
+
#define MCA_DCB_ACT_COL 0 /* position of action function */
|
| 61 |
+
#define MCA_DCB_NEXT_STATE 1 /* position of next state */
|
| 62 |
+
#define MCA_DCB_NUM_COLS 2 /* number of columns in state tables */
|
| 63 |
+
|
| 64 |
+
/* state table for opening state */
|
| 65 |
+
const UINT8 mca_dcb_st_opening[][MCA_DCB_NUM_COLS] = {
|
| 66 |
+
/* Event Action Next State */
|
| 67 |
+
/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST},
|
| 68 |
+
/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPENING_ST},
|
| 69 |
+
/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST},
|
| 70 |
+
/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST},
|
| 71 |
+
/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPENING_ST},
|
| 72 |
+
/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_OPENING_ST}
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
/* state table for open state */
|
| 76 |
+
const UINT8 mca_dcb_st_open[][MCA_DCB_NUM_COLS] = {
|
| 77 |
+
/* Event Action Next State */
|
| 78 |
+
/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST},
|
| 79 |
+
/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_SND_DATA, MCA_DCB_OPEN_ST},
|
| 80 |
+
/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPEN_ST},
|
| 81 |
+
/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST},
|
| 82 |
+
/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPEN_ST},
|
| 83 |
+
/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_HDL_DATA, MCA_DCB_OPEN_ST}
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
/* state table for closing state */
|
| 87 |
+
const UINT8 mca_dcb_st_closing[][MCA_DCB_NUM_COLS] = {
|
| 88 |
+
/* Event Action Next State */
|
| 89 |
+
/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST},
|
| 90 |
+
/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST},
|
| 91 |
+
/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST},
|
| 92 |
+
/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST},
|
| 93 |
+
/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST},
|
| 94 |
+
/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_CLOSING_ST}
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
/* type for state table */
|
| 98 |
+
typedef const UINT8 (*tMCA_DCB_ST_TBL)[MCA_DCB_NUM_COLS];
|
| 99 |
+
|
| 100 |
+
/* state table */
|
| 101 |
+
const tMCA_DCB_ST_TBL mca_dcb_st_tbl[] = {
|
| 102 |
+
mca_dcb_st_opening,
|
| 103 |
+
mca_dcb_st_open,
|
| 104 |
+
mca_dcb_st_closing
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
#if (BT_TRACE_VERBOSE == TRUE)
|
| 108 |
+
/* verbose event strings for trace */
|
| 109 |
+
const char * const mca_dcb_evt_str[] = {
|
| 110 |
+
"API_CLOSE_EVT",
|
| 111 |
+
"API_WRITE_EVT",
|
| 112 |
+
"TC_OPEN_EVT",
|
| 113 |
+
"TC_CLOSE_EVT",
|
| 114 |
+
"TC_CONG_EVT",
|
| 115 |
+
"TC_DATA_EVT"
|
| 116 |
+
};
|
| 117 |
+
/* verbose state strings for trace */
|
| 118 |
+
const char * const mca_dcb_st_str[] = {
|
| 119 |
+
"NULL_ST",
|
| 120 |
+
"OPENING_ST",
|
| 121 |
+
"OPEN_ST",
|
| 122 |
+
"CLOSING_ST"
|
| 123 |
+
};
|
| 124 |
+
#endif
|
| 125 |
+
|
| 126 |
+
/*******************************************************************************
|
| 127 |
+
**
|
| 128 |
+
** Function mca_dcb_event
|
| 129 |
+
**
|
| 130 |
+
** Description This function is the DCB state machine main function.
|
| 131 |
+
** It uses the state and action function tables to execute
|
| 132 |
+
** action functions.
|
| 133 |
+
**
|
| 134 |
+
** Returns void.
|
| 135 |
+
**
|
| 136 |
+
*******************************************************************************/
|
| 137 |
+
void mca_dcb_event(tMCA_DCB *p_dcb, UINT8 event, tMCA_DCB_EVT *p_data)
|
| 138 |
+
{
|
| 139 |
+
tMCA_DCB_ST_TBL state_table;
|
| 140 |
+
UINT8 action;
|
| 141 |
+
|
| 142 |
+
if (p_dcb == NULL)
|
| 143 |
+
return;
|
| 144 |
+
#if (BT_TRACE_VERBOSE == TRUE)
|
| 145 |
+
MCA_TRACE_EVENT("DCB dcb=%d event=%s state=%s", mca_dcb_to_hdl(p_dcb), mca_dcb_evt_str[event], mca_dcb_st_str[p_dcb->state]);
|
| 146 |
+
#else
|
| 147 |
+
MCA_TRACE_EVENT("DCB dcb=%d event=%d state=%d", mca_dcb_to_hdl(p_dcb), event, p_dcb->state);
|
| 148 |
+
#endif
|
| 149 |
+
|
| 150 |
+
/* look up the state table for the current state */
|
| 151 |
+
state_table = mca_dcb_st_tbl[p_dcb->state - 1];
|
| 152 |
+
|
| 153 |
+
/* set next state */
|
| 154 |
+
p_dcb->state = state_table[event][MCA_DCB_NEXT_STATE];
|
| 155 |
+
|
| 156 |
+
/* execute action functions */
|
| 157 |
+
if ((action = state_table[event][MCA_DCB_ACT_COL]) != MCA_DCB_IGNORE)
|
| 158 |
+
{
|
| 159 |
+
(*mca_dcb_action[action])(p_dcb, p_data);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/*******************************************************************************
|
| 164 |
+
**
|
| 165 |
+
** Function mca_dcb_alloc
|
| 166 |
+
**
|
| 167 |
+
** Description This function is called to allocate an DCB.
|
| 168 |
+
** It initializes the DCB with the data passed to the function.
|
| 169 |
+
**
|
| 170 |
+
** Returns tMCA_DCB *
|
| 171 |
+
**
|
| 172 |
+
*******************************************************************************/
|
| 173 |
+
tMCA_DCB *mca_dcb_alloc(tMCA_CCB*p_ccb, tMCA_DEP dep)
|
| 174 |
+
{
|
| 175 |
+
tMCA_DCB *p_dcb = NULL, *p_dcb_tmp;
|
| 176 |
+
tMCA_RCB *p_rcb = p_ccb->p_rcb;
|
| 177 |
+
tMCA_CS *p_cs;
|
| 178 |
+
int i, max;
|
| 179 |
+
|
| 180 |
+
if (dep < MCA_NUM_DEPS)
|
| 181 |
+
{
|
| 182 |
+
p_cs = &p_rcb->dep[dep];
|
| 183 |
+
i = mca_ccb_to_hdl(p_ccb)-1;
|
| 184 |
+
p_dcb_tmp = &mca_cb.dcb[i*MCA_NUM_MDLS];
|
| 185 |
+
/* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */
|
| 186 |
+
max = p_cs->max_mdl;
|
| 187 |
+
for (i=0; i<max; i++, p_dcb_tmp++)
|
| 188 |
+
{
|
| 189 |
+
if (p_dcb_tmp->state == MCA_DCB_NULL_ST)
|
| 190 |
+
{
|
| 191 |
+
p_dcb_tmp->p_ccb = p_ccb;
|
| 192 |
+
p_dcb_tmp->state = MCA_DCB_OPENING_ST;
|
| 193 |
+
p_dcb_tmp->cong = TRUE;
|
| 194 |
+
p_dcb_tmp->p_cs = p_cs;
|
| 195 |
+
p_dcb = p_dcb_tmp;
|
| 196 |
+
break;
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
return p_dcb;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/*******************************************************************************
|
| 204 |
+
**
|
| 205 |
+
** Function mca_dep_free_mdl
|
| 206 |
+
**
|
| 207 |
+
** Description This function is called to check the number of free mdl for
|
| 208 |
+
** the given dep.
|
| 209 |
+
**
|
| 210 |
+
** Returns the number of free mdl for the given dep
|
| 211 |
+
**
|
| 212 |
+
*******************************************************************************/
|
| 213 |
+
UINT8 mca_dep_free_mdl(tMCA_CCB *p_ccb, tMCA_DEP dep)
|
| 214 |
+
{
|
| 215 |
+
tMCA_DCB *p_dcb;
|
| 216 |
+
tMCA_RCB *p_rcb = p_ccb->p_rcb;
|
| 217 |
+
tMCA_CS *p_cs;
|
| 218 |
+
int i, max;
|
| 219 |
+
UINT8 count = 0;
|
| 220 |
+
UINT8 left;
|
| 221 |
+
|
| 222 |
+
if (dep < MCA_NUM_DEPS)
|
| 223 |
+
{
|
| 224 |
+
p_cs = &p_rcb->dep[dep];
|
| 225 |
+
i = mca_ccb_to_hdl(p_ccb)-1;
|
| 226 |
+
p_dcb = &mca_cb.dcb[i * MCA_NUM_MDLS];
|
| 227 |
+
/* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */
|
| 228 |
+
max = p_cs->max_mdl;
|
| 229 |
+
for (i=0; i<max; i++, p_dcb++)
|
| 230 |
+
{
|
| 231 |
+
if ((p_dcb->state != MCA_DCB_NULL_ST) && (p_dcb->p_cs == p_cs))
|
| 232 |
+
{
|
| 233 |
+
count++;
|
| 234 |
+
break;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
else
|
| 239 |
+
{
|
| 240 |
+
max = 0;
|
| 241 |
+
MCA_TRACE_WARNING("Invalid Dep ID");
|
| 242 |
+
}
|
| 243 |
+
left = max - count;
|
| 244 |
+
return left;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
/*******************************************************************************
|
| 248 |
+
**
|
| 249 |
+
** Function mca_dcb_dealloc
|
| 250 |
+
**
|
| 251 |
+
** Description This function deallocates an DCB.
|
| 252 |
+
**
|
| 253 |
+
** Returns void.
|
| 254 |
+
**
|
| 255 |
+
*******************************************************************************/
|
| 256 |
+
void mca_dcb_dealloc(tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
|
| 257 |
+
{
|
| 258 |
+
tMCA_CCB *p_ccb = p_dcb->p_ccb;
|
| 259 |
+
UINT8 event = MCA_CLOSE_IND_EVT;
|
| 260 |
+
tMCA_CTRL evt_data;
|
| 261 |
+
|
| 262 |
+
MCA_TRACE_DEBUG("mca_dcb_dealloc");
|
| 263 |
+
mca_free_buf ((void **)&p_dcb->p_data);
|
| 264 |
+
if (p_data)
|
| 265 |
+
{
|
| 266 |
+
/* non-NULL -> an action function -> report disconnect event */
|
| 267 |
+
evt_data.close_cfm.mdl = mca_dcb_to_hdl(p_dcb);
|
| 268 |
+
evt_data.close_cfm.reason = p_data->close.reason;
|
| 269 |
+
evt_data.close_cfm.mdl_id = p_dcb->mdl_id;
|
| 270 |
+
if (p_data->close.param == MCA_INT)
|
| 271 |
+
event = MCA_CLOSE_CFM_EVT;
|
| 272 |
+
if (p_data->close.lcid)
|
| 273 |
+
mca_ccb_report_event(p_ccb, event, &evt_data);
|
| 274 |
+
}
|
| 275 |
+
mca_free_tc_tbl_by_lcid (p_dcb->lcid);
|
| 276 |
+
memset (p_dcb, 0, sizeof (tMCA_DCB));
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
/*******************************************************************************
|
| 280 |
+
**
|
| 281 |
+
** Function mca_dcb_to_hdl
|
| 282 |
+
**
|
| 283 |
+
** Description This function converts a pointer to an DCB to a handle (tMCA_DL).
|
| 284 |
+
** It returns the handle.
|
| 285 |
+
**
|
| 286 |
+
** Returns tMCA_DL.
|
| 287 |
+
**
|
| 288 |
+
*******************************************************************************/
|
| 289 |
+
tMCA_DL mca_dcb_to_hdl(tMCA_DCB *p_dcb)
|
| 290 |
+
{
|
| 291 |
+
return (UINT8) (p_dcb - mca_cb.dcb + 1);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/*******************************************************************************
|
| 295 |
+
**
|
| 296 |
+
** Function mca_dcb_by_hdl
|
| 297 |
+
**
|
| 298 |
+
** Description This function finds the DCB for a handle (tMCA_DL).
|
| 299 |
+
** It returns a pointer to the DCB.
|
| 300 |
+
** If no DCB matches the handle it returns NULL.
|
| 301 |
+
**
|
| 302 |
+
** Returns tMCA_DCB *
|
| 303 |
+
**
|
| 304 |
+
*******************************************************************************/
|
| 305 |
+
tMCA_DCB *mca_dcb_by_hdl(tMCA_DL hdl)
|
| 306 |
+
{
|
| 307 |
+
tMCA_DCB * p_dcb = NULL;
|
| 308 |
+
if (hdl && hdl <= MCA_NUM_DCBS && mca_cb.dcb[hdl-1].state)
|
| 309 |
+
p_dcb = &mca_cb.dcb[hdl-1];
|
| 310 |
+
return p_dcb;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
/*******************************************************************************
|
| 314 |
+
**
|
| 315 |
+
** Function mca_dcb_close_by_mdl_id
|
| 316 |
+
**
|
| 317 |
+
** Description This function finds the DCB for a mdl_id and
|
| 318 |
+
** disconnect the mdl
|
| 319 |
+
**
|
| 320 |
+
** Returns void
|
| 321 |
+
**
|
| 322 |
+
*******************************************************************************/
|
| 323 |
+
void mca_dcb_close_by_mdl_id(tMCA_CCB*p_ccb, UINT16 mdl_id)
|
| 324 |
+
{
|
| 325 |
+
tMCA_DCB *p_dcb;
|
| 326 |
+
int i;
|
| 327 |
+
|
| 328 |
+
MCA_TRACE_DEBUG("mca_dcb_close_by_mdl_id mdl_id=%d", mdl_id);
|
| 329 |
+
i = mca_ccb_to_hdl(p_ccb)-1;
|
| 330 |
+
p_dcb = &mca_cb.dcb[i*MCA_NUM_MDLS];
|
| 331 |
+
for (i=0; i<MCA_NUM_MDLS; i++, p_dcb++)
|
| 332 |
+
{
|
| 333 |
+
if (p_dcb->state)
|
| 334 |
+
{
|
| 335 |
+
if (p_dcb->mdl_id == mdl_id)
|
| 336 |
+
{
|
| 337 |
+
mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL);
|
| 338 |
+
break;
|
| 339 |
+
}
|
| 340 |
+
else if (mdl_id == MCA_ALL_MDL_ID)
|
| 341 |
+
{
|
| 342 |
+
mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL);
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
pool/shard010/C/0138105_thread_tcache_enabled.c
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "test/jemalloc_test.h"
|
| 2 |
+
|
| 3 |
+
void *
|
| 4 |
+
thd_start(void *arg) {
|
| 5 |
+
bool e0, e1;
|
| 6 |
+
size_t sz = sizeof(bool);
|
| 7 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL,
|
| 8 |
+
0), 0, "Unexpected mallctl failure");
|
| 9 |
+
|
| 10 |
+
if (e0) {
|
| 11 |
+
e1 = false;
|
| 12 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 13 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 14 |
+
assert_true(e0, "tcache should be enabled");
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
e1 = true;
|
| 18 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 19 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 20 |
+
assert_false(e0, "tcache should be disabled");
|
| 21 |
+
|
| 22 |
+
e1 = true;
|
| 23 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 24 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 25 |
+
assert_true(e0, "tcache should be enabled");
|
| 26 |
+
|
| 27 |
+
e1 = false;
|
| 28 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 29 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 30 |
+
assert_true(e0, "tcache should be enabled");
|
| 31 |
+
|
| 32 |
+
e1 = false;
|
| 33 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 34 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 35 |
+
assert_false(e0, "tcache should be disabled");
|
| 36 |
+
|
| 37 |
+
free(malloc(1));
|
| 38 |
+
e1 = true;
|
| 39 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 40 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 41 |
+
assert_false(e0, "tcache should be disabled");
|
| 42 |
+
|
| 43 |
+
free(malloc(1));
|
| 44 |
+
e1 = true;
|
| 45 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 46 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 47 |
+
assert_true(e0, "tcache should be enabled");
|
| 48 |
+
|
| 49 |
+
free(malloc(1));
|
| 50 |
+
e1 = false;
|
| 51 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 52 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 53 |
+
assert_true(e0, "tcache should be enabled");
|
| 54 |
+
|
| 55 |
+
free(malloc(1));
|
| 56 |
+
e1 = false;
|
| 57 |
+
assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
| 58 |
+
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
| 59 |
+
assert_false(e0, "tcache should be disabled");
|
| 60 |
+
|
| 61 |
+
free(malloc(1));
|
| 62 |
+
return NULL;
|
| 63 |
+
test_skip("\"thread.tcache.enabled\" mallctl not available");
|
| 64 |
+
return NULL;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
TEST_BEGIN(test_main_thread) {
|
| 68 |
+
thd_start(NULL);
|
| 69 |
+
}
|
| 70 |
+
TEST_END
|
| 71 |
+
|
| 72 |
+
TEST_BEGIN(test_subthread) {
|
| 73 |
+
thd_t thd;
|
| 74 |
+
|
| 75 |
+
thd_create(&thd, thd_start, NULL);
|
| 76 |
+
thd_join(thd, NULL);
|
| 77 |
+
}
|
| 78 |
+
TEST_END
|
| 79 |
+
|
| 80 |
+
int
|
| 81 |
+
main(void) {
|
| 82 |
+
/* Run tests multiple times to check for bad interactions. */
|
| 83 |
+
return test(
|
| 84 |
+
test_main_thread,
|
| 85 |
+
test_subthread,
|
| 86 |
+
test_main_thread,
|
| 87 |
+
test_subthread,
|
| 88 |
+
test_main_thread);
|
| 89 |
+
}
|
pool/shard010/C/0138106_watchman.c
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "bbs.h"
|
| 2 |
+
|
| 3 |
+
#define DEFAULT_ADD 600
|
| 4 |
+
#define CONT MY_BBS_HOME "/help/watchmanhelp"
|
| 5 |
+
|
| 6 |
+
struct bbsinfo bbsinfo;
|
| 7 |
+
|
| 8 |
+
void
|
| 9 |
+
usage(char *name)
|
| 10 |
+
{
|
| 11 |
+
printf("%s userid userpasswd [minutes_to_delay]\n", name);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
int
|
| 15 |
+
main(int argc, char *argv[])
|
| 16 |
+
{
|
| 17 |
+
struct UTMPFILE *shm_utmp;
|
| 18 |
+
int time_add = 0;
|
| 19 |
+
int i;
|
| 20 |
+
FILE *fp, *fr;
|
| 21 |
+
time_t now_t;
|
| 22 |
+
char buf[256];
|
| 23 |
+
if (argc < 3) {
|
| 24 |
+
usage(argv[0]);
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
| 27 |
+
//errlog("argc:%d",argc);
|
| 28 |
+
if (argc > 3){
|
| 29 |
+
time_add = atoi(argv[3]) * 60;
|
| 30 |
+
// errlog("argv[3]: %s",argv[3]);
|
| 31 |
+
}
|
| 32 |
+
if (!time_add)
|
| 33 |
+
time_add = DEFAULT_ADD;
|
| 34 |
+
for (i = 0; i < 10; i++) {
|
| 35 |
+
initbbsinfo(&bbsinfo);
|
| 36 |
+
shm_utmp = bbsinfo.utmpshm;
|
| 37 |
+
if (shm_utmp)
|
| 38 |
+
break;
|
| 39 |
+
sleep(10);
|
| 40 |
+
}
|
| 41 |
+
if (!shm_utmp) {
|
| 42 |
+
errlog("can't attach ushm!");
|
| 43 |
+
return -1;
|
| 44 |
+
}
|
| 45 |
+
now_t = time(NULL);
|
| 46 |
+
if (shm_utmp->watchman) {
|
| 47 |
+
strcpy(buf,
|
| 48 |
+
"¡ï¡ï¡ï¡ï¡ï¾¯±¨¡ï¡ï¡ï¡ï¡ïÕþÖÎÐÔ°æÃæËø×¡ÁË¡ï¡ï¡ï¡ï¡ï");
|
| 49 |
+
} else {
|
| 50 |
+
shm_utmp->watchman = now_t + time_add;
|
| 51 |
+
getrandomint(&(shm_utmp->unlock));
|
| 52 |
+
snprintf(buf, sizeof (buf), "À´À´À´,µãîÁË!ÏÖÔÚÊÇ %s",
|
| 53 |
+
Ctime(now_t));
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
fp = popen("/usr/bin/mail bbs", "w");
|
| 57 |
+
if (!fp) {
|
| 58 |
+
errlog("can't open mail!");
|
| 59 |
+
return -2;
|
| 60 |
+
}
|
| 61 |
+
fr = fopen(CONT, "r");
|
| 62 |
+
fprintf(fp, "#name: %s\n", argv[1]);
|
| 63 |
+
fprintf(fp, "#pass: %s\n", argv[2]);
|
| 64 |
+
fprintf(fp, "#board: deleterequest\n");
|
| 65 |
+
fprintf(fp, "#title: %s\n", buf);
|
| 66 |
+
fprintf(fp, "#localpost:\n\n");
|
| 67 |
+
if (!strncmp(buf, "À´", 2)) {
|
| 68 |
+
fprintf(fp,
|
| 69 |
+
"ÇëÔÚ%d·ÖÖÓÄÚ½øÐнâËø²Ù×÷,·ñÔò±¾BBSËùÓкÍÕþÖÎÏà¹ØµÄ°æÃ潫±»·â°æ\n"
|
| 70 |
+
"Ö±ÖÁÓÐÈ˽øÐÐÁ˽âËø²Ù×÷.\n" "½âËøÃÜÂë: %u\n",
|
| 71 |
+
time_add / 60, shm_utmp->unlock % 10000);
|
| 72 |
+
}
|
| 73 |
+
fprintf(fp, "ÒÔÏÂÊǹØÓÚ½âËø²Ù×÷µÄ˵Ã÷:\n");
|
| 74 |
+
fr = fopen(CONT, "r");
|
| 75 |
+
if (fr) {
|
| 76 |
+
while (fgets(buf, sizeof (buf), fr))
|
| 77 |
+
fputs(buf, fp);
|
| 78 |
+
fclose(fr);
|
| 79 |
+
}
|
| 80 |
+
pclose(fp);
|
| 81 |
+
return 0;
|
| 82 |
+
}
|
pool/shard010/C/0138107_p_verify.c
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* crypto/evp/p_verify.c */
|
| 2 |
+
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This package is an SSL implementation written
|
| 6 |
+
* by Eric Young (eay@cryptsoft.com).
|
| 7 |
+
* The implementation was written so as to conform with Netscapes SSL.
|
| 8 |
+
*
|
| 9 |
+
* This library is free for commercial and non-commercial use as long as
|
| 10 |
+
* the following conditions are aheared to. The following conditions
|
| 11 |
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
| 12 |
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
| 13 |
+
* included with this distribution is covered by the same copyright terms
|
| 14 |
+
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
| 15 |
+
*
|
| 16 |
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
| 17 |
+
* the code are not to be removed.
|
| 18 |
+
* If this package is used in a product, Eric Young should be given attribution
|
| 19 |
+
* as the author of the parts of the library used.
|
| 20 |
+
* This can be in the form of a textual message at program startup or
|
| 21 |
+
* in documentation (online or textual) provided with the package.
|
| 22 |
+
*
|
| 23 |
+
* Redistribution and use in source and binary forms, with or without
|
| 24 |
+
* modification, are permitted provided that the following conditions
|
| 25 |
+
* are met:
|
| 26 |
+
* 1. Redistributions of source code must retain the copyright
|
| 27 |
+
* notice, this list of conditions and the following disclaimer.
|
| 28 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 29 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 30 |
+
* documentation and/or other materials provided with the distribution.
|
| 31 |
+
* 3. All advertising materials mentioning features or use of this software
|
| 32 |
+
* must display the following acknowledgement:
|
| 33 |
+
* "This product includes cryptographic software written by
|
| 34 |
+
* Eric Young (eay@cryptsoft.com)"
|
| 35 |
+
* The word 'cryptographic' can be left out if the rouines from the library
|
| 36 |
+
* being used are not cryptographic related :-).
|
| 37 |
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
| 38 |
+
* the apps directory (application code) you must include an acknowledgement:
|
| 39 |
+
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
| 40 |
+
*
|
| 41 |
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
| 42 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 43 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 44 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 45 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 46 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 47 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 48 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 49 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 50 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 51 |
+
* SUCH DAMAGE.
|
| 52 |
+
*
|
| 53 |
+
* The licence and distribution terms for any publically available version or
|
| 54 |
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
| 55 |
+
* copied and put under another distribution licence
|
| 56 |
+
* [including the GNU Public Licence.]
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
#include <stdio.h>
|
| 60 |
+
#include "cryptlib.h"
|
| 61 |
+
#include <openssl/evp.h>
|
| 62 |
+
#include <openssl/objects.h>
|
| 63 |
+
#include <openssl/x509.h>
|
| 64 |
+
|
| 65 |
+
int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
|
| 66 |
+
unsigned int siglen, EVP_PKEY *pkey)
|
| 67 |
+
{
|
| 68 |
+
unsigned char m[EVP_MAX_MD_SIZE];
|
| 69 |
+
unsigned int m_len;
|
| 70 |
+
int i,ok=0,v;
|
| 71 |
+
MS_STATIC EVP_MD_CTX tmp_ctx;
|
| 72 |
+
|
| 73 |
+
EVP_MD_CTX_init(&tmp_ctx);
|
| 74 |
+
EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
|
| 75 |
+
EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
|
| 76 |
+
EVP_MD_CTX_cleanup(&tmp_ctx);
|
| 77 |
+
|
| 78 |
+
if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
|
| 79 |
+
{
|
| 80 |
+
EVP_PKEY_CTX *pkctx = NULL;
|
| 81 |
+
i = -1;
|
| 82 |
+
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
|
| 83 |
+
if (!pkctx)
|
| 84 |
+
goto err;
|
| 85 |
+
if (EVP_PKEY_verify_init(pkctx) <= 0)
|
| 86 |
+
goto err;
|
| 87 |
+
if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
|
| 88 |
+
goto err;
|
| 89 |
+
i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);
|
| 90 |
+
err:
|
| 91 |
+
EVP_PKEY_CTX_free(pkctx);
|
| 92 |
+
return i;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
for (i=0; i<4; i++)
|
| 96 |
+
{
|
| 97 |
+
v=ctx->digest->required_pkey_type[i];
|
| 98 |
+
if (v == 0) break;
|
| 99 |
+
if (pkey->type == v)
|
| 100 |
+
{
|
| 101 |
+
ok=1;
|
| 102 |
+
break;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
if (!ok)
|
| 106 |
+
{
|
| 107 |
+
EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
|
| 108 |
+
return(-1);
|
| 109 |
+
}
|
| 110 |
+
if (ctx->digest->verify == NULL)
|
| 111 |
+
{
|
| 112 |
+
EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
|
| 113 |
+
return(0);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return(ctx->digest->verify(ctx->digest->type,m,m_len,
|
| 117 |
+
sigbuf,siglen,pkey->pkey.ptr));
|
| 118 |
+
}
|
| 119 |
+
|
pool/shard010/C/0138108_i915_random.c
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright © 2016 Intel Corporation
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
| 5 |
+
* copy of this software and associated documentation files (the "Software"),
|
| 6 |
+
* to deal in the Software without restriction, including without limitation
|
| 7 |
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 8 |
+
* and/or sell copies of the Software, and to permit persons to whom the
|
| 9 |
+
* Software is furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice (including the next
|
| 12 |
+
* paragraph) shall be included in all copies or substantial portions of the
|
| 13 |
+
* Software.
|
| 14 |
+
*
|
| 15 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| 18 |
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 20 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 21 |
+
* IN THE SOFTWARE.
|
| 22 |
+
*
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
#include <linux/bitops.h>
|
| 26 |
+
#include <linux/kernel.h>
|
| 27 |
+
#include <linux/random.h>
|
| 28 |
+
#include <linux/slab.h>
|
| 29 |
+
#include <linux/types.h>
|
| 30 |
+
|
| 31 |
+
#include "i915_random.h"
|
| 32 |
+
#include "i915_utils.h"
|
| 33 |
+
|
| 34 |
+
u64 i915_prandom_u64_state(struct rnd_state *rnd)
|
| 35 |
+
{
|
| 36 |
+
u64 x;
|
| 37 |
+
|
| 38 |
+
x = prandom_u32_state(rnd);
|
| 39 |
+
x <<= 32;
|
| 40 |
+
x |= prandom_u32_state(rnd);
|
| 41 |
+
|
| 42 |
+
return x;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void i915_prandom_shuffle(void *arr, size_t elsz, size_t count,
|
| 46 |
+
struct rnd_state *state)
|
| 47 |
+
{
|
| 48 |
+
char stack[128];
|
| 49 |
+
|
| 50 |
+
if (WARN_ON(elsz > sizeof(stack) || count > U32_MAX))
|
| 51 |
+
return;
|
| 52 |
+
|
| 53 |
+
if (!elsz || !count)
|
| 54 |
+
return;
|
| 55 |
+
|
| 56 |
+
/* Fisher-Yates shuffle courtesy of Knuth */
|
| 57 |
+
while (--count) {
|
| 58 |
+
size_t swp;
|
| 59 |
+
|
| 60 |
+
swp = i915_prandom_u32_max_state(count + 1, state);
|
| 61 |
+
if (swp == count)
|
| 62 |
+
continue;
|
| 63 |
+
|
| 64 |
+
memcpy(stack, arr + count * elsz, elsz);
|
| 65 |
+
memcpy(arr + count * elsz, arr + swp * elsz, elsz);
|
| 66 |
+
memcpy(arr + swp * elsz, stack, elsz);
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void i915_random_reorder(unsigned int *order, unsigned int count,
|
| 71 |
+
struct rnd_state *state)
|
| 72 |
+
{
|
| 73 |
+
i915_prandom_shuffle(order, sizeof(*order), count, state);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
unsigned int *i915_random_order(unsigned int count, struct rnd_state *state)
|
| 77 |
+
{
|
| 78 |
+
unsigned int *order, i;
|
| 79 |
+
|
| 80 |
+
order = kmalloc_array(count, sizeof(*order),
|
| 81 |
+
GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
|
| 82 |
+
if (!order)
|
| 83 |
+
return order;
|
| 84 |
+
|
| 85 |
+
for (i = 0; i < count; i++)
|
| 86 |
+
order[i] = i;
|
| 87 |
+
|
| 88 |
+
i915_random_reorder(order, count, state);
|
| 89 |
+
return order;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
u64 igt_random_offset(struct rnd_state *state,
|
| 93 |
+
u64 start, u64 end,
|
| 94 |
+
u64 len, u64 align)
|
| 95 |
+
{
|
| 96 |
+
u64 range, addr;
|
| 97 |
+
|
| 98 |
+
BUG_ON(range_overflows(start, len, end));
|
| 99 |
+
BUG_ON(round_up(start, align) > round_down(end - len, align));
|
| 100 |
+
|
| 101 |
+
range = round_down(end - len, align) - round_up(start, align);
|
| 102 |
+
if (range) {
|
| 103 |
+
addr = i915_prandom_u64_state(state);
|
| 104 |
+
div64_u64_rem(addr, range, &addr);
|
| 105 |
+
start += addr;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return round_up(start, align);
|
| 109 |
+
}
|
pool/shard010/C/0138109_networkd-netdev-vlan.c
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
| 2 |
+
|
| 3 |
+
/***
|
| 4 |
+
This file is part of systemd.
|
| 5 |
+
|
| 6 |
+
Copyright 2013 Tom Gundersen <teg@jklm.no>
|
| 7 |
+
|
| 8 |
+
systemd is free software; you can redistribute it and/or modify it
|
| 9 |
+
under the terms of the GNU Lesser General Public License as published by
|
| 10 |
+
the Free Software Foundation; either version 2.1 of the License, or
|
| 11 |
+
(at your option) any later version.
|
| 12 |
+
|
| 13 |
+
systemd is distributed in the hope that it will be useful, but
|
| 14 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 19 |
+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
+
***/
|
| 21 |
+
|
| 22 |
+
#include <net/if.h>
|
| 23 |
+
|
| 24 |
+
#include "networkd-netdev-vlan.h"
|
| 25 |
+
#include "network-internal.h"
|
| 26 |
+
#include "list.h"
|
| 27 |
+
|
| 28 |
+
static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *req) {
|
| 29 |
+
VLan *v = VLAN(netdev);
|
| 30 |
+
int r;
|
| 31 |
+
|
| 32 |
+
assert(netdev);
|
| 33 |
+
assert(v);
|
| 34 |
+
assert(link);
|
| 35 |
+
assert(req);
|
| 36 |
+
|
| 37 |
+
if (v->id <= VLANID_MAX) {
|
| 38 |
+
r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, v->id);
|
| 39 |
+
if (r < 0) {
|
| 40 |
+
log_error_netdev(netdev,
|
| 41 |
+
"Could not append IFLA_VLAN_ID attribute: %s",
|
| 42 |
+
strerror(-r));
|
| 43 |
+
return r;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return 0;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
|
| 51 |
+
VLan *v = VLAN(netdev);
|
| 52 |
+
|
| 53 |
+
assert(netdev);
|
| 54 |
+
assert(v);
|
| 55 |
+
assert(filename);
|
| 56 |
+
|
| 57 |
+
if (v->id > VLANID_MAX) {
|
| 58 |
+
log_warning("VLAN without valid Id (%"PRIu64") configured in %s. Ignoring", v->id, filename);
|
| 59 |
+
return -EINVAL;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
return 0;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
static void vlan_init(NetDev *netdev) {
|
| 66 |
+
VLan *v = VLAN(netdev);
|
| 67 |
+
|
| 68 |
+
assert(netdev);
|
| 69 |
+
assert(v);
|
| 70 |
+
|
| 71 |
+
v->id = VLANID_MAX + 1;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
const NetDevVTable vlan_vtable = {
|
| 75 |
+
.object_size = sizeof(VLan),
|
| 76 |
+
.init = vlan_init,
|
| 77 |
+
.sections = "Match\0NetDev\0VLAN\0",
|
| 78 |
+
.fill_message_create = netdev_vlan_fill_message_create,
|
| 79 |
+
.create_type = NETDEV_CREATE_STACKED,
|
| 80 |
+
.config_verify = netdev_vlan_verify,
|
| 81 |
+
};
|
pool/shard010/C/0138110_main.c
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
******************************************************************************
|
| 3 |
+
* @file ADC/ADC_TriggerMode/Src/main.c
|
| 4 |
+
* @author MCD Application Team
|
| 5 |
+
* @brief This example describes how to use Timer to trig ADC conversion.
|
| 6 |
+
******************************************************************************
|
| 7 |
+
* @attention
|
| 8 |
+
*
|
| 9 |
+
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
| 10 |
+
*
|
| 11 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
| 12 |
+
* are permitted provided that the following conditions are met:
|
| 13 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
| 14 |
+
* this list of conditions and the following disclaimer.
|
| 15 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 16 |
+
* this list of conditions and the following disclaimer in the documentation
|
| 17 |
+
* and/or other materials provided with the distribution.
|
| 18 |
+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
| 19 |
+
* may be used to endorse or promote products derived from this software
|
| 20 |
+
* without specific prior written permission.
|
| 21 |
+
*
|
| 22 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 23 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 24 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 25 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 26 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 27 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 28 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 29 |
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 30 |
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 31 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 32 |
+
*
|
| 33 |
+
******************************************************************************
|
| 34 |
+
*/
|
| 35 |
+
|
| 36 |
+
/* Includes ------------------------------------------------------------------*/
|
| 37 |
+
#include "main.h"
|
| 38 |
+
|
| 39 |
+
/** @addtogroup STM32F0xx_HAL_Examples
|
| 40 |
+
* @{
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
/** @addtogroup ADC_TriggerMode
|
| 44 |
+
* @{
|
| 45 |
+
*/
|
| 46 |
+
|
| 47 |
+
/* Private typedef -----------------------------------------------------------*/
|
| 48 |
+
/* Private define ------------------------------------------------------------*/
|
| 49 |
+
/* Private macro -------------------------------------------------------------*/
|
| 50 |
+
/* Private variables ---------------------------------------------------------*/
|
| 51 |
+
/* ADC handler declaration */
|
| 52 |
+
ADC_HandleTypeDef AdcHandle;
|
| 53 |
+
|
| 54 |
+
/* TIM handler declaration */
|
| 55 |
+
static TIM_HandleTypeDef htim;
|
| 56 |
+
|
| 57 |
+
/* Variable used to get converted value */
|
| 58 |
+
__IO uint16_t uhADCxConvertedValue = 0;
|
| 59 |
+
|
| 60 |
+
/* Private function prototypes -----------------------------------------------*/
|
| 61 |
+
static void SystemClock_Config(void);
|
| 62 |
+
static void Error_Handler(void);
|
| 63 |
+
static void ADC_Config(void);
|
| 64 |
+
static void TIM_Config(void);
|
| 65 |
+
|
| 66 |
+
/* Private functions ---------------------------------------------------------*/
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* @brief Main program.
|
| 70 |
+
* @param None
|
| 71 |
+
* @retval None
|
| 72 |
+
*/
|
| 73 |
+
int main(void)
|
| 74 |
+
{
|
| 75 |
+
/* STM32F0xx HAL library initialization:
|
| 76 |
+
- Configure the Flash prefetch
|
| 77 |
+
- Systick timer is configured by default as source of time base, but user
|
| 78 |
+
can eventually implement his proper time base source (a general purpose
|
| 79 |
+
timer for example or other time source), keeping in mind that Time base
|
| 80 |
+
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
|
| 81 |
+
handled in milliseconds basis.
|
| 82 |
+
- Low Level Initialization
|
| 83 |
+
*/
|
| 84 |
+
HAL_Init();
|
| 85 |
+
|
| 86 |
+
/* Configure LED3 */
|
| 87 |
+
BSP_LED_Init(LED3);
|
| 88 |
+
|
| 89 |
+
/* Configure the system clock to 48 MHz */
|
| 90 |
+
SystemClock_Config();
|
| 91 |
+
|
| 92 |
+
/*##-1- TIM Peripheral Configuration ######################################*/
|
| 93 |
+
TIM_Config();
|
| 94 |
+
|
| 95 |
+
/*##-2- Configure the ADC peripheral ######################################*/
|
| 96 |
+
ADC_Config();
|
| 97 |
+
|
| 98 |
+
/*##-4- Start the conversion process and enable interrupt ##################*/
|
| 99 |
+
if (HAL_ADC_Start_IT(&AdcHandle) != HAL_OK)
|
| 100 |
+
{
|
| 101 |
+
/* Start Conversation Error */
|
| 102 |
+
Error_Handler();
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/*##-3- TIM counter enable ################################################*/
|
| 106 |
+
if (HAL_TIM_Base_Start(&htim) != HAL_OK)
|
| 107 |
+
{
|
| 108 |
+
/* Counter Enable Error */
|
| 109 |
+
Error_Handler();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* Infinite loop */
|
| 113 |
+
while (1)
|
| 114 |
+
{
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/**
|
| 119 |
+
* @brief System Clock Configuration
|
| 120 |
+
* The system Clock is configured as follow :
|
| 121 |
+
* System Clock source = PLL (HSE)
|
| 122 |
+
* SYSCLK(Hz) = 48000000
|
| 123 |
+
* HCLK(Hz) = 48000000
|
| 124 |
+
* AHB Prescaler = 1
|
| 125 |
+
* APB1 Prescaler = 1
|
| 126 |
+
* HSE Frequency(Hz) = 8000000
|
| 127 |
+
* PREDIV = 1
|
| 128 |
+
* PLLMUL = 6
|
| 129 |
+
* Flash Latency(WS) = 1
|
| 130 |
+
* @param None
|
| 131 |
+
* @retval None
|
| 132 |
+
*/
|
| 133 |
+
static void SystemClock_Config(void)
|
| 134 |
+
{
|
| 135 |
+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
| 136 |
+
RCC_OscInitTypeDef RCC_OscInitStruct;
|
| 137 |
+
|
| 138 |
+
/* Enable HSE Oscillator and Activate PLL with HSE as source */
|
| 139 |
+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
| 140 |
+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
| 141 |
+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
| 142 |
+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
| 143 |
+
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
|
| 144 |
+
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
| 145 |
+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
|
| 146 |
+
{
|
| 147 |
+
Error_Handler();
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/* Select PLL as system clock source and configure the HCLK, PCLK1 clocks dividers */
|
| 151 |
+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
|
| 152 |
+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
| 153 |
+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
| 154 |
+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
| 155 |
+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1)!= HAL_OK)
|
| 156 |
+
{
|
| 157 |
+
Error_Handler();
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* @brief This function is executed in case of error occurrence.
|
| 163 |
+
* @param None
|
| 164 |
+
* @retval None
|
| 165 |
+
*/
|
| 166 |
+
static void Error_Handler(void)
|
| 167 |
+
{
|
| 168 |
+
/* Turn LED3 on */
|
| 169 |
+
BSP_LED_On(LED3);
|
| 170 |
+
while (1)
|
| 171 |
+
{
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* @brief ADC configuration
|
| 177 |
+
* @param None
|
| 178 |
+
* @retval None
|
| 179 |
+
*/
|
| 180 |
+
static void ADC_Config(void)
|
| 181 |
+
{
|
| 182 |
+
ADC_ChannelConfTypeDef sConfig;
|
| 183 |
+
|
| 184 |
+
/* ADC Initialization */
|
| 185 |
+
AdcHandle.Instance = ADCx;
|
| 186 |
+
|
| 187 |
+
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
|
| 188 |
+
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
|
| 189 |
+
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
| 190 |
+
AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
|
| 191 |
+
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
| 192 |
+
AdcHandle.Init.LowPowerAutoWait = DISABLE;
|
| 193 |
+
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE;
|
| 194 |
+
AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
|
| 195 |
+
AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
|
| 196 |
+
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO; /* Conversion start trigged at each external event */
|
| 197 |
+
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
|
| 198 |
+
AdcHandle.Init.DMAContinuousRequests = ENABLE;
|
| 199 |
+
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
|
| 200 |
+
|
| 201 |
+
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
|
| 202 |
+
{
|
| 203 |
+
/* ADC initiliazation Error */
|
| 204 |
+
Error_Handler();
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/* Configure ADC regular channel */
|
| 208 |
+
sConfig.Channel = ADCx_CHANNEL;
|
| 209 |
+
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
|
| 210 |
+
sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5;
|
| 211 |
+
|
| 212 |
+
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
|
| 213 |
+
{
|
| 214 |
+
/* Channel Configuration Error */
|
| 215 |
+
Error_Handler();
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* @brief TIM configuration
|
| 221 |
+
* @param None
|
| 222 |
+
* @retval None
|
| 223 |
+
*/
|
| 224 |
+
static void TIM_Config(void)
|
| 225 |
+
{
|
| 226 |
+
TIM_MasterConfigTypeDef sMasterConfig;
|
| 227 |
+
|
| 228 |
+
/* Time Base configuration */
|
| 229 |
+
htim.Instance = TIMx;
|
| 230 |
+
|
| 231 |
+
htim.Init.Period = 2400;
|
| 232 |
+
htim.Init.Prescaler = 0;
|
| 233 |
+
htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
| 234 |
+
htim.Init.CounterMode = TIM_COUNTERMODE_UP;
|
| 235 |
+
htim.Init.RepetitionCounter = 0x0;
|
| 236 |
+
htim.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
| 237 |
+
|
| 238 |
+
if (HAL_TIM_Base_Init(&htim) != HAL_OK)
|
| 239 |
+
{
|
| 240 |
+
/* Timer Initiliazation Error */
|
| 241 |
+
Error_Handler();
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* Timer TRGO selection */
|
| 245 |
+
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
|
| 246 |
+
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
| 247 |
+
|
| 248 |
+
if (HAL_TIMEx_MasterConfigSynchronization(&htim, &sMasterConfig) != HAL_OK)
|
| 249 |
+
{
|
| 250 |
+
/* Timer TRGO selection Error */
|
| 251 |
+
Error_Handler();
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* @brief Conversion complete callback in non blocking mode
|
| 257 |
+
* @param AdcHandle : AdcHandle handle
|
| 258 |
+
* @note This example shows a simple way to report end of conversion, and
|
| 259 |
+
* you can add your own implementation.
|
| 260 |
+
* @retval None
|
| 261 |
+
*/
|
| 262 |
+
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *AdcHandle)
|
| 263 |
+
{
|
| 264 |
+
/* Get the converted value of regular channel */
|
| 265 |
+
uhADCxConvertedValue = HAL_ADC_GetValue(AdcHandle);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
#ifdef USE_FULL_ASSERT
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* @brief Reports the name of the source file and the source line number
|
| 272 |
+
* where the assert_param error has occurred.
|
| 273 |
+
* @param file: pointer to the source file name
|
| 274 |
+
* @param line: assert_param error line source number
|
| 275 |
+
* @retval None
|
| 276 |
+
*/
|
| 277 |
+
void assert_failed(uint8_t *file, uint32_t line)
|
| 278 |
+
{
|
| 279 |
+
/* User can add his own implementation to report the file name and line number,
|
| 280 |
+
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
| 281 |
+
|
| 282 |
+
/* Infinite loop */
|
| 283 |
+
while (1)
|
| 284 |
+
{
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
#endif
|
| 289 |
+
|
| 290 |
+
/**
|
| 291 |
+
* @}
|
| 292 |
+
*/
|
| 293 |
+
|
| 294 |
+
/**
|
| 295 |
+
* @}
|
| 296 |
+
*/
|
| 297 |
+
|
| 298 |
+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
pool/shard010/C/0138111_strlcpy.c
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $Id: strlcpy.c,v 1.1 2002/04/11 16:39:59 provos Exp $ */
|
| 2 |
+
/* $OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $ */
|
| 3 |
+
|
| 4 |
+
/*
|
| 5 |
+
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
| 6 |
+
* All rights reserved.
|
| 7 |
+
*
|
| 8 |
+
* Redistribution and use in source and binary forms, with or without
|
| 9 |
+
* modification, are permitted provided that the following conditions
|
| 10 |
+
* are met:
|
| 11 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 12 |
+
* notice, this list of conditions and the following disclaimer.
|
| 13 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 14 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 15 |
+
* documentation and/or other materials provided with the distribution.
|
| 16 |
+
* 3. The name of the author may not be used to endorse or promote products
|
| 17 |
+
* derived from this software without specific prior written permission.
|
| 18 |
+
*
|
| 19 |
+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
| 20 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
| 21 |
+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
| 22 |
+
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 23 |
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 24 |
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
| 25 |
+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
| 26 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
| 27 |
+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
| 28 |
+
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
#if defined(LIBC_SCCS) && !defined(lint)
|
| 32 |
+
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $";
|
| 33 |
+
#endif /* LIBC_SCCS and not lint */
|
| 34 |
+
|
| 35 |
+
#include <sys/types.h>
|
| 36 |
+
#include <string.h>
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
* Copy src to string dst of size siz. At most siz-1 characters
|
| 40 |
+
* will be copied. Always NUL terminates (unless siz == 0).
|
| 41 |
+
* Returns strlen(src); if retval >= siz, truncation occurred.
|
| 42 |
+
*/
|
| 43 |
+
size_t strlcpy(dst, src, siz)
|
| 44 |
+
char *dst;
|
| 45 |
+
const char *src;
|
| 46 |
+
size_t siz;
|
| 47 |
+
{
|
| 48 |
+
register char *d = dst;
|
| 49 |
+
register const char *s = src;
|
| 50 |
+
register size_t n = siz;
|
| 51 |
+
|
| 52 |
+
if (n == 0)
|
| 53 |
+
return(strlen(s));
|
| 54 |
+
while (*s != '\0') {
|
| 55 |
+
if (n != 1) {
|
| 56 |
+
*d++ = *s;
|
| 57 |
+
n--;
|
| 58 |
+
}
|
| 59 |
+
s++;
|
| 60 |
+
}
|
| 61 |
+
*d = '\0';
|
| 62 |
+
|
| 63 |
+
return(s - src); /* count does not include NUL */
|
| 64 |
+
}
|
pool/shard010/C/0138112_kxsd9-spi.c
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: GPL-2.0-only
|
| 2 |
+
#include <linux/device.h>
|
| 3 |
+
#include <linux/kernel.h>
|
| 4 |
+
#include <linux/of.h>
|
| 5 |
+
#include <linux/of_device.h>
|
| 6 |
+
#include <linux/spi/spi.h>
|
| 7 |
+
#include <linux/module.h>
|
| 8 |
+
#include <linux/slab.h>
|
| 9 |
+
#include <linux/regmap.h>
|
| 10 |
+
|
| 11 |
+
#include "kxsd9.h"
|
| 12 |
+
|
| 13 |
+
static int kxsd9_spi_probe(struct spi_device *spi)
|
| 14 |
+
{
|
| 15 |
+
static const struct regmap_config config = {
|
| 16 |
+
.reg_bits = 8,
|
| 17 |
+
.val_bits = 8,
|
| 18 |
+
.max_register = 0x0e,
|
| 19 |
+
};
|
| 20 |
+
struct regmap *regmap;
|
| 21 |
+
|
| 22 |
+
spi->mode = SPI_MODE_0;
|
| 23 |
+
regmap = devm_regmap_init_spi(spi, &config);
|
| 24 |
+
if (IS_ERR(regmap)) {
|
| 25 |
+
dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
|
| 26 |
+
__func__, PTR_ERR(regmap));
|
| 27 |
+
return PTR_ERR(regmap);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return kxsd9_common_probe(&spi->dev,
|
| 31 |
+
regmap,
|
| 32 |
+
spi_get_device_id(spi)->name);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
static int kxsd9_spi_remove(struct spi_device *spi)
|
| 36 |
+
{
|
| 37 |
+
kxsd9_common_remove(&spi->dev);
|
| 38 |
+
|
| 39 |
+
return 0;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
static const struct spi_device_id kxsd9_spi_id[] = {
|
| 43 |
+
{"kxsd9", 0},
|
| 44 |
+
{ },
|
| 45 |
+
};
|
| 46 |
+
MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
|
| 47 |
+
|
| 48 |
+
static const struct of_device_id kxsd9_of_match[] = {
|
| 49 |
+
{ .compatible = "kionix,kxsd9" },
|
| 50 |
+
{ },
|
| 51 |
+
};
|
| 52 |
+
MODULE_DEVICE_TABLE(of, kxsd9_of_match);
|
| 53 |
+
|
| 54 |
+
static struct spi_driver kxsd9_spi_driver = {
|
| 55 |
+
.driver = {
|
| 56 |
+
.name = "kxsd9",
|
| 57 |
+
.pm = &kxsd9_dev_pm_ops,
|
| 58 |
+
.of_match_table = kxsd9_of_match,
|
| 59 |
+
},
|
| 60 |
+
.probe = kxsd9_spi_probe,
|
| 61 |
+
.remove = kxsd9_spi_remove,
|
| 62 |
+
.id_table = kxsd9_spi_id,
|
| 63 |
+
};
|
| 64 |
+
module_spi_driver(kxsd9_spi_driver);
|
| 65 |
+
|
| 66 |
+
MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
|
| 67 |
+
MODULE_DESCRIPTION("Kionix KXSD9 SPI driver");
|
| 68 |
+
MODULE_LICENSE("GPL v2");
|