Upload folder using huggingface_hub (part 69)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard006/C/0117045_if_tr_isa.c +264 -0
- pool/shard006/C/0117046_ooaofooa_ACT_RU_class.c +234 -0
- pool/shard006/C/0117050_kern_condvar.c +242 -0
- pool/shard006/C/0117055_sysschevt.c +129 -0
- pool/shard006/C/0117061_find_missing.c +62 -0
- pool/shard006/C/0117064_filesys.c +266 -0
- pool/shard006/C/0117068_print-mobile.c +109 -0
- pool/shard006/C/0117072_util.c +147 -0
- pool/shard006/C/0117080_uws_datatype.c +27 -0
- pool/shard006/C/0117089_hashHelper.c +113 -0
- pool/shard006/C/0117090_rotlet_direct.c +65 -0
- pool/shard006/C/0117104_macronix.c +106 -0
- pool/shard006/C/0117111_boo.c +45 -0
- pool/shard006/C/0117113_stm32f4xx_rng.c +399 -0
- pool/shard006/C/0117118_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52a.c +94 -0
- pool/shard006/C/0117122_dht22.c +210 -0
- pool/shard006/C/0117136_pthread_exit.c +34 -0
- pool/shard006/C/0117143_pr67790.c +41 -0
- pool/shard006/C/0117153_mkdepend.c +122 -0
- pool/shard006/C/0117158_gl_hwdec_vdpau.c +209 -0
- pool/shard006/C/0117160_sendcommit-proc.c +262 -0
- pool/shard006/C/0117164_ged_base.c +126 -0
- pool/shard006/C/0117166_empty-Seed4-RandomFuns-Type_int-ControlStructures_12-BB1-ForBound_boundedInput-Operators_PlusA_MinusA_Lt_Gt_Le_Ge_Eq_Ne.c +102 -0
- pool/shard006/C/0117167_lab7.c +137 -0
- pool/shard006/C/0117169_waitqueue.c +308 -0
- pool/shard006/C/0117173_sorter.c +111 -0
- pool/shard006/C/0117174_clock_config.c +302 -0
- pool/shard006/C/0117193_netdev.c +239 -0
- pool/shard006/C/0117201_iwl-rx.c +281 -0
- pool/shard006/C/0117203_yaffs_ramdisk.c +229 -0
- pool/shard006/C/0117206_dpll44xx.c +153 -0
- pool/shard006/C/0117220_gsl_sf_exp.c +14 -0
- pool/shard006/C/0117227_edges.c +47 -0
- pool/shard006/C/0117253_gb-terminal-application-addin.c +84 -0
- pool/shard006/C/0117260_list_test.c +79 -0
- pool/shard006/C/0117271_max77803_haptic.c +169 -0
- pool/shard006/C/0117275_Ex1.c +12 -0
- pool/shard006/C/0117280_CWE401_Memory_Leak__twoIntsStruct_calloc_44.c +123 -0
- pool/shard006/C/0117283_reaper.c +134 -0
- pool/shard006/C/0117287_strfunc.c +33 -0
- pool/shard006/C/0117293_hdmi_tx_hdcp.c +76 -0
- pool/shard006/C/0117296_dqawst.c +40 -0
- pool/shard006/C/0117298_idmap.c +162 -0
- pool/shard006/C/0117299_spy.c +186 -0
- pool/shard006/C/0117302_xmalloc.c +141 -0
- pool/shard006/C/0117305_pool.c +74 -0
- pool/shard006/C/0117309_main.c +218 -0
- pool/shard006/C/0117311_utent.c +109 -0
- pool/shard006/C/0117315_tclLoadDld.c +163 -0
- pool/shard006/C/0117317_div.c +214 -0
pool/shard006/C/0117045_if_tr_isa.c
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $NetBSD: if_tr_isa.c,v 1.24 2012/10/27 17:18:24 chs Exp $ */
|
| 2 |
+
|
| 3 |
+
/* XXXJRT changes isa_attach_args too early!! */
|
| 4 |
+
|
| 5 |
+
/*
|
| 6 |
+
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
| 7 |
+
* All rights reserved.
|
| 8 |
+
*
|
| 9 |
+
* This code is derived from software contributed to The NetBSD Foundation
|
| 10 |
+
* by Onno van der Linden.
|
| 11 |
+
*
|
| 12 |
+
* Redistribution and use in source and binary forms, with or without
|
| 13 |
+
* modification, are permitted provided that the following conditions
|
| 14 |
+
* are met:
|
| 15 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 16 |
+
* notice, this list of conditions and the following disclaimer.
|
| 17 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 18 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 19 |
+
* documentation and/or other materials provided with the distribution.
|
| 20 |
+
*
|
| 21 |
+
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
| 22 |
+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
| 23 |
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 24 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
| 25 |
+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 26 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 27 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 28 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 29 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 30 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 31 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
#include <sys/cdefs.h>
|
| 35 |
+
__KERNEL_RCSID(0, "$NetBSD: if_tr_isa.c,v 1.24 2012/10/27 17:18:24 chs Exp $");
|
| 36 |
+
|
| 37 |
+
#undef TRISADEBUG
|
| 38 |
+
|
| 39 |
+
#include <sys/param.h>
|
| 40 |
+
#include <sys/systm.h>
|
| 41 |
+
#include <sys/socket.h>
|
| 42 |
+
#include <sys/device.h>
|
| 43 |
+
|
| 44 |
+
#include <net/if.h>
|
| 45 |
+
#include <net/if_ether.h>
|
| 46 |
+
#include <net/if_media.h>
|
| 47 |
+
|
| 48 |
+
#include <sys/cpu.h>
|
| 49 |
+
#include <sys/bus.h>
|
| 50 |
+
#include <sys/intr.h>
|
| 51 |
+
|
| 52 |
+
#include <dev/isa/isavar.h>
|
| 53 |
+
|
| 54 |
+
#include <dev/ic/tropicreg.h>
|
| 55 |
+
#include <dev/ic/tropicvar.h>
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
int tr_isa_probe(device_t, cfdata_t, void *);
|
| 59 |
+
int trtcm_isa_probe(device_t, cfdata_t, void *);
|
| 60 |
+
int tribm_isa_probe(device_t, cfdata_t, void *);
|
| 61 |
+
void tr_isa_attach(device_t, device_t, void *);
|
| 62 |
+
int tr_isa_map_io(struct isa_attach_args *, bus_space_handle_t *,
|
| 63 |
+
bus_space_handle_t *);
|
| 64 |
+
void tr_isa_unmap_io(struct isa_attach_args *, bus_space_handle_t,
|
| 65 |
+
bus_space_handle_t);
|
| 66 |
+
int trtcm_isa_mediachange(struct tr_softc *);
|
| 67 |
+
void trtcm_isa_mediastatus(struct tr_softc *, struct ifmediareq *);
|
| 68 |
+
#ifdef TRISADEBUG
|
| 69 |
+
void tr_isa_dumpaip(bus_space_tag_t, bus_space_handle_t);
|
| 70 |
+
#endif
|
| 71 |
+
|
| 72 |
+
/*
|
| 73 |
+
* List of manufacturer specific probe routines. Order is important.
|
| 74 |
+
*/
|
| 75 |
+
int (*tr_isa_probe_list[])(device_t, cfdata_t, void *) = {
|
| 76 |
+
trtcm_isa_probe,
|
| 77 |
+
tribm_isa_probe,
|
| 78 |
+
0
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
CFATTACH_DECL_NEW(tr_isa, sizeof(struct tr_softc),
|
| 82 |
+
tr_isa_probe, tr_isa_attach, NULL, NULL);
|
| 83 |
+
|
| 84 |
+
int
|
| 85 |
+
tr_isa_map_io(struct isa_attach_args *ia, bus_space_handle_t *pioh, bus_space_handle_t *mmioh)
|
| 86 |
+
{
|
| 87 |
+
bus_size_t mmio;
|
| 88 |
+
u_int8_t s;
|
| 89 |
+
|
| 90 |
+
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
|
| 91 |
+
ia->ia_io[0].ir_size, 0, pioh)) {
|
| 92 |
+
printf("tr_isa_map_io: can't map PIO ports\n");
|
| 93 |
+
return 1;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/* Read adapter switches and calculate addresses of MMIO. */
|
| 97 |
+
s = bus_space_read_1(ia->ia_iot, *pioh, TR_SWITCH);
|
| 98 |
+
|
| 99 |
+
if ((s & 0xfc) < ((TR_MMIO_MINADDR - TR_MMIO_OFFSET) >> 11) ||
|
| 100 |
+
(s & 0xfc) > ((TR_MMIO_MAXADDR - TR_MMIO_OFFSET) >> 11)) {
|
| 101 |
+
bus_space_unmap(ia->ia_iot, *pioh, ia->ia_io[0].ir_size);
|
| 102 |
+
return 1;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
mmio = ((s & 0xfc) << 11) + TR_MMIO_OFFSET;
|
| 106 |
+
if (bus_space_map(ia->ia_memt, mmio, TR_MMIO_SIZE, 0, mmioh)) {
|
| 107 |
+
printf("tr_isa_map_io: can't map MMIO region 0x%05lx/%d\n",
|
| 108 |
+
(u_long)mmio, TR_MMIO_SIZE);
|
| 109 |
+
bus_space_unmap(ia->ia_iot, *pioh, ia->ia_io[0].ir_size);
|
| 110 |
+
return 1;
|
| 111 |
+
}
|
| 112 |
+
return 0;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
void
|
| 116 |
+
tr_isa_unmap_io(struct isa_attach_args *ia, bus_space_handle_t pioh, bus_space_handle_t mmioh)
|
| 117 |
+
{
|
| 118 |
+
bus_space_unmap(ia->ia_memt, mmioh, TR_MMIO_SIZE);
|
| 119 |
+
bus_space_unmap(ia->ia_iot, pioh, ia->ia_io[0].ir_size);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
static u_char tr_isa_id[] = {
|
| 123 |
+
5, 0, 4, 9, 4, 3, 4, 15, 3, 6, 3, 1, 3, 1, 3, 0, 3, 9, 3, 9, 3, 0, 2, 0
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
/*
|
| 127 |
+
* XXX handle multiple IBM TR cards (sram mapping !!)
|
| 128 |
+
*/
|
| 129 |
+
|
| 130 |
+
int
|
| 131 |
+
tr_isa_probe(device_t parent, cfdata_t match, void *aux)
|
| 132 |
+
{
|
| 133 |
+
struct isa_attach_args *ia = aux;
|
| 134 |
+
int i;
|
| 135 |
+
bus_size_t tr_id;
|
| 136 |
+
bus_space_handle_t sramh, pioh, mmioh;
|
| 137 |
+
int probecode;
|
| 138 |
+
int matched = 0;
|
| 139 |
+
|
| 140 |
+
if (ia->ia_nio < 1)
|
| 141 |
+
return (0);
|
| 142 |
+
if (ia->ia_niomem < 1)
|
| 143 |
+
return (0);
|
| 144 |
+
if (ia->ia_nirq < 1)
|
| 145 |
+
return (0);
|
| 146 |
+
|
| 147 |
+
if (ISA_DIRECT_CONFIG(ia))
|
| 148 |
+
return (0);
|
| 149 |
+
|
| 150 |
+
for (i = 0; tr_isa_probe_list[i] != 0; i++) {
|
| 151 |
+
probecode = tr_isa_probe_list[i](parent, match, aux);
|
| 152 |
+
if (probecode < 0)
|
| 153 |
+
return 0; /* Fail instantly. */
|
| 154 |
+
if (probecode > 0)
|
| 155 |
+
break; /* We have a match. */
|
| 156 |
+
}
|
| 157 |
+
if (tr_isa_probe_list[i] == 0)
|
| 158 |
+
return 0; /* Nothing matched. */
|
| 159 |
+
if (tr_isa_map_io(ia, &pioh, &mmioh))
|
| 160 |
+
return 0;
|
| 161 |
+
tr_id = TR_ID_OFFSET;
|
| 162 |
+
matched = 1;
|
| 163 |
+
for (i = 0; i < sizeof(tr_isa_id); i++) {
|
| 164 |
+
if (bus_space_read_1(ia->ia_memt, mmioh, tr_id) !=
|
| 165 |
+
tr_isa_id[i])
|
| 166 |
+
matched = 0;
|
| 167 |
+
tr_id += 2;
|
| 168 |
+
}
|
| 169 |
+
#ifdef TRISADEBUG
|
| 170 |
+
tr_isa_dumpaip(ia->ia_memt, mmioh);
|
| 171 |
+
#endif
|
| 172 |
+
tr_isa_unmap_io(ia, pioh, mmioh);
|
| 173 |
+
if (!matched) {
|
| 174 |
+
return 0;
|
| 175 |
+
}
|
| 176 |
+
if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
|
| 177 |
+
ia->ia_iomem[0].ir_size, 0, &sramh)) {
|
| 178 |
+
printf("tr_isa_probe: can't map shared ram\n");
|
| 179 |
+
return 0;
|
| 180 |
+
}
|
| 181 |
+
bus_space_unmap(ia->ia_memt, sramh, ia->ia_iomem[0].ir_size);
|
| 182 |
+
|
| 183 |
+
ia->ia_nio = 1;
|
| 184 |
+
ia->ia_niomem = 1;
|
| 185 |
+
ia->ia_nirq = 1;
|
| 186 |
+
|
| 187 |
+
ia->ia_ndrq = 0;
|
| 188 |
+
|
| 189 |
+
return 1;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
int trtcm_setspeed(struct tr_softc *, int);
|
| 193 |
+
|
| 194 |
+
void
|
| 195 |
+
tr_isa_attach(device_t parent, device_t self, void *aux)
|
| 196 |
+
{
|
| 197 |
+
struct tr_softc *sc = device_private(self);
|
| 198 |
+
struct isa_attach_args *ia = aux;
|
| 199 |
+
|
| 200 |
+
printf("\n");
|
| 201 |
+
|
| 202 |
+
sc->sc_dev = self;
|
| 203 |
+
sc->sc_piot = ia->ia_iot;
|
| 204 |
+
sc->sc_memt = ia->ia_memt;
|
| 205 |
+
if (tr_isa_map_io(ia, &sc->sc_pioh, &sc->sc_mmioh)) {
|
| 206 |
+
printf("tr_isa_attach: IO space vanished\n");
|
| 207 |
+
return;
|
| 208 |
+
}
|
| 209 |
+
if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr,
|
| 210 |
+
ia->ia_iomem[0].ir_size, 0, &sc->sc_sramh)) {
|
| 211 |
+
printf("tr_isa_attach: shared ram space vanished\n");
|
| 212 |
+
return;
|
| 213 |
+
}
|
| 214 |
+
/* set ACA offset */
|
| 215 |
+
sc->sc_aca = TR_ACA_OFFSET;
|
| 216 |
+
sc->sc_memwinsz = ia->ia_iomem[0].ir_size;
|
| 217 |
+
sc->sc_maddr = ia->ia_iomem[0].ir_addr;
|
| 218 |
+
/*
|
| 219 |
+
* Determine total RAM on adapter and decide how much to use.
|
| 220 |
+
* XXX Since we don't use RAM paging, use sc_memwinsz for now.
|
| 221 |
+
*/
|
| 222 |
+
sc->sc_memsize = sc->sc_memwinsz;
|
| 223 |
+
sc->sc_memreserved = 0;
|
| 224 |
+
|
| 225 |
+
if (tr_reset(sc) != 0)
|
| 226 |
+
return;
|
| 227 |
+
|
| 228 |
+
if (ia->ia_aux != NULL) {
|
| 229 |
+
sc->sc_mediastatus = trtcm_isa_mediastatus;
|
| 230 |
+
sc->sc_mediachange = trtcm_isa_mediachange;
|
| 231 |
+
}
|
| 232 |
+
else {
|
| 233 |
+
sc->sc_mediastatus = NULL;
|
| 234 |
+
sc->sc_mediachange = NULL;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
if (tr_attach(sc) != 0)
|
| 238 |
+
return;
|
| 239 |
+
|
| 240 |
+
/*
|
| 241 |
+
* XXX 3Com 619 can use LEVEL intr
|
| 242 |
+
*/
|
| 243 |
+
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
|
| 244 |
+
IST_EDGE, IPL_NET, tr_intr, sc);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
#ifdef TRISADEBUG
|
| 248 |
+
/*
|
| 249 |
+
* Dump the adapters AIP
|
| 250 |
+
*/
|
| 251 |
+
void
|
| 252 |
+
tr_isa_dumpaip(bus_space_tag_t memt, bus_space_handle_t mmioh)
|
| 253 |
+
{
|
| 254 |
+
unsigned int off, val;
|
| 255 |
+
printf("AIP contents:");
|
| 256 |
+
for (off=0; off < 256; off++) {
|
| 257 |
+
val = bus_space_read_1(memt, mmioh, TR_MAC_OFFSET + off);
|
| 258 |
+
if ((off % 16) == 0)
|
| 259 |
+
printf("\n");
|
| 260 |
+
printf("%02x ", val);
|
| 261 |
+
}
|
| 262 |
+
printf("\n");
|
| 263 |
+
}
|
| 264 |
+
#endif
|
pool/shard006/C/0117046_ooaofooa_ACT_RU_class.c
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*----------------------------------------------------------------------------
|
| 2 |
+
* File: ooaofooa_ACT_RU_class.c
|
| 3 |
+
*
|
| 4 |
+
* Class: Relate Using (ACT_RU)
|
| 5 |
+
* Component: ooaofooa
|
| 6 |
+
*
|
| 7 |
+
* your copyright statement can go here (from te_copyright.body)
|
| 8 |
+
*--------------------------------------------------------------------------*/
|
| 9 |
+
|
| 10 |
+
#include "sys_sys_types.h"
|
| 11 |
+
#include "LOG_bridge.h"
|
| 12 |
+
#include "POP_bridge.h"
|
| 13 |
+
#include "T_bridge.h"
|
| 14 |
+
#include "ooaofooa_classes.h"
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
* Instance Loader (from string data).
|
| 18 |
+
*/
|
| 19 |
+
Escher_iHandle_t
|
| 20 |
+
ooaofooa_ACT_RU_instanceloader( Escher_iHandle_t instance, const c_t * avlstring[] )
|
| 21 |
+
{
|
| 22 |
+
Escher_iHandle_t return_identifier = 0;
|
| 23 |
+
ooaofooa_ACT_RU * self = (ooaofooa_ACT_RU *) instance;
|
| 24 |
+
/* Initialize application analysis class attributes. */
|
| 25 |
+
self->Statement_ID = (Escher_iHandle_t) Escher_atoi( avlstring[ 1 ] );
|
| 26 |
+
self->One_Side_Var_ID = (Escher_iHandle_t) Escher_atoi( avlstring[ 2 ] );
|
| 27 |
+
self->Other_Side_Var_ID = (Escher_iHandle_t) Escher_atoi( avlstring[ 3 ] );
|
| 28 |
+
self->Associative_Var_ID = (Escher_iHandle_t) Escher_atoi( avlstring[ 4 ] );
|
| 29 |
+
self->relationship_phrase = Escher_strcpy( self->relationship_phrase, avlstring[ 5 ] );
|
| 30 |
+
self->Rel_ID = (Escher_iHandle_t) Escher_atoi( avlstring[ 6 ] );
|
| 31 |
+
self->associationNumberLineNumber = Escher_atoi( avlstring[ 7 ] );
|
| 32 |
+
self->associationNumberColumn = Escher_atoi( avlstring[ 8 ] );
|
| 33 |
+
self->associationPhraseLineNumber = Escher_atoi( avlstring[ 9 ] );
|
| 34 |
+
self->associationPhraseColumn = Escher_atoi( avlstring[ 10 ] );
|
| 35 |
+
return return_identifier;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
* Select any where using referential/identifying attribute set.
|
| 40 |
+
* If not_empty, relate this instance to the selected instance.
|
| 41 |
+
*/
|
| 42 |
+
void ooaofooa_ACT_RU_batch_relate( Escher_iHandle_t instance )
|
| 43 |
+
{
|
| 44 |
+
ooaofooa_ACT_RU * ooaofooa_ACT_RU_instance = (ooaofooa_ACT_RU *) instance;
|
| 45 |
+
ooaofooa_V_VAR * ooaofooa_V_VARrelated_instance1 = (ooaofooa_V_VAR *) Escher_instance_cache[ (intptr_t) ooaofooa_ACT_RU_instance->One_Side_Var_ID ];
|
| 46 |
+
if ( ooaofooa_V_VARrelated_instance1 ) {
|
| 47 |
+
ooaofooa_ACT_RU_R617_Link_is_one_variable( ooaofooa_V_VARrelated_instance1, ooaofooa_ACT_RU_instance );
|
| 48 |
+
}
|
| 49 |
+
{
|
| 50 |
+
ooaofooa_V_VAR * ooaofooa_V_VARrelated_instance1 = (ooaofooa_V_VAR *) Escher_instance_cache[ (intptr_t) ooaofooa_ACT_RU_instance->Other_Side_Var_ID ];
|
| 51 |
+
if ( ooaofooa_V_VARrelated_instance1 ) {
|
| 52 |
+
ooaofooa_ACT_RU_R618_Link_is_other_variable( ooaofooa_V_VARrelated_instance1, ooaofooa_ACT_RU_instance );
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
{
|
| 56 |
+
ooaofooa_V_VAR * ooaofooa_V_VARrelated_instance1 = (ooaofooa_V_VAR *) Escher_instance_cache[ (intptr_t) ooaofooa_ACT_RU_instance->Associative_Var_ID ];
|
| 57 |
+
if ( ooaofooa_V_VARrelated_instance1 ) {
|
| 58 |
+
ooaofooa_ACT_RU_R619_Link_is_using_variable( ooaofooa_V_VARrelated_instance1, ooaofooa_ACT_RU_instance );
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
{
|
| 62 |
+
ooaofooa_ACT_SMT * ooaofooa_ACT_SMTrelated_instance1 = (ooaofooa_ACT_SMT *) Escher_instance_cache[ (intptr_t) ooaofooa_ACT_RU_instance->Statement_ID ];
|
| 63 |
+
if ( ooaofooa_ACT_SMTrelated_instance1 ) {
|
| 64 |
+
ooaofooa_ACT_RU_R603_Link( ooaofooa_ACT_SMTrelated_instance1, ooaofooa_ACT_RU_instance );
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
{
|
| 68 |
+
ooaofooa_R_REL * ooaofooa_R_RELrelated_instance1 = ooaofooa_R_REL_AnyWhere1( ooaofooa_ACT_RU_instance->Rel_ID );
|
| 69 |
+
if ( ooaofooa_R_RELrelated_instance1 ) {
|
| 70 |
+
ooaofooa_ACT_RU_R654_Link( ooaofooa_R_RELrelated_instance1, ooaofooa_ACT_RU_instance );
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
* RELATE ACT_SMT TO ACT_RU ACROSS R603
|
| 78 |
+
*/
|
| 79 |
+
void
|
| 80 |
+
ooaofooa_ACT_RU_R603_Link( ooaofooa_ACT_SMT * supertype, ooaofooa_ACT_RU * subtype )
|
| 81 |
+
{
|
| 82 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 83 |
+
subtype->Statement_ID = supertype->Statement_ID;
|
| 84 |
+
/* Optimized linkage for ACT_RU->ACT_SMT[R603] */
|
| 85 |
+
subtype->ACT_SMT_R603 = supertype;
|
| 86 |
+
/* Optimized linkage for ACT_SMT->ACT_RU[R603] */
|
| 87 |
+
supertype->R603_subtype = subtype;
|
| 88 |
+
supertype->R603_object_id = ooaofooa_ACT_RU_CLASS_NUMBER;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
/*
|
| 93 |
+
* UNRELATE ACT_SMT FROM ACT_RU ACROSS R603
|
| 94 |
+
*/
|
| 95 |
+
void
|
| 96 |
+
ooaofooa_ACT_RU_R603_Unlink( ooaofooa_ACT_SMT * supertype, ooaofooa_ACT_RU * subtype )
|
| 97 |
+
{
|
| 98 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 99 |
+
subtype->ACT_SMT_R603 = 0;
|
| 100 |
+
supertype->R603_subtype = 0;
|
| 101 |
+
supertype->R603_object_id = 0;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
/*
|
| 106 |
+
* RELATE V_VAR TO ACT_RU ACROSS R617
|
| 107 |
+
*/
|
| 108 |
+
void
|
| 109 |
+
ooaofooa_ACT_RU_R617_Link_is_one_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 110 |
+
{
|
| 111 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 112 |
+
form->One_Side_Var_ID = part->Var_ID;
|
| 113 |
+
form->V_VAR_R617_one = part;
|
| 114 |
+
Escher_SetInsertElement( &part->ACT_RU_R617_is_one_variable, (Escher_ObjectSet_s *) form );
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/*
|
| 118 |
+
* UNRELATE V_VAR FROM ACT_RU ACROSS R617
|
| 119 |
+
*/
|
| 120 |
+
void
|
| 121 |
+
ooaofooa_ACT_RU_R617_Unlink_is_one_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 122 |
+
{
|
| 123 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 124 |
+
form->One_Side_Var_ID = 0;
|
| 125 |
+
form->V_VAR_R617_one = 0;
|
| 126 |
+
Escher_SetRemoveElement( &part->ACT_RU_R617_is_one_variable, (Escher_ObjectSet_s *) form );
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/*
|
| 130 |
+
* RELATE V_VAR TO ACT_RU ACROSS R618
|
| 131 |
+
*/
|
| 132 |
+
void
|
| 133 |
+
ooaofooa_ACT_RU_R618_Link_is_other_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 134 |
+
{
|
| 135 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 136 |
+
form->Other_Side_Var_ID = part->Var_ID;
|
| 137 |
+
form->V_VAR_R618_other = part;
|
| 138 |
+
Escher_SetInsertElement( &part->ACT_RU_R618_is_other_variable, (Escher_ObjectSet_s *) form );
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/*
|
| 142 |
+
* UNRELATE V_VAR FROM ACT_RU ACROSS R618
|
| 143 |
+
*/
|
| 144 |
+
void
|
| 145 |
+
ooaofooa_ACT_RU_R618_Unlink_is_other_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 146 |
+
{
|
| 147 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 148 |
+
form->Other_Side_Var_ID = 0;
|
| 149 |
+
form->V_VAR_R618_other = 0;
|
| 150 |
+
Escher_SetRemoveElement( &part->ACT_RU_R618_is_other_variable, (Escher_ObjectSet_s *) form );
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/*
|
| 154 |
+
* RELATE V_VAR TO ACT_RU ACROSS R619
|
| 155 |
+
*/
|
| 156 |
+
void
|
| 157 |
+
ooaofooa_ACT_RU_R619_Link_is_using_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 158 |
+
{
|
| 159 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 160 |
+
form->Associative_Var_ID = part->Var_ID;
|
| 161 |
+
form->V_VAR_R619_using = part;
|
| 162 |
+
Escher_SetInsertElement( &part->ACT_RU_R619_is_using_variable, (Escher_ObjectSet_s *) form );
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/*
|
| 166 |
+
* UNRELATE V_VAR FROM ACT_RU ACROSS R619
|
| 167 |
+
*/
|
| 168 |
+
void
|
| 169 |
+
ooaofooa_ACT_RU_R619_Unlink_is_using_variable( ooaofooa_V_VAR * part, ooaofooa_ACT_RU * form )
|
| 170 |
+
{
|
| 171 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 172 |
+
form->Associative_Var_ID = 0;
|
| 173 |
+
form->V_VAR_R619_using = 0;
|
| 174 |
+
Escher_SetRemoveElement( &part->ACT_RU_R619_is_using_variable, (Escher_ObjectSet_s *) form );
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/*
|
| 178 |
+
* RELATE R_REL TO ACT_RU ACROSS R654
|
| 179 |
+
*/
|
| 180 |
+
void
|
| 181 |
+
ooaofooa_ACT_RU_R654_Link( ooaofooa_R_REL * part, ooaofooa_ACT_RU * form )
|
| 182 |
+
{
|
| 183 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 184 |
+
form->Rel_ID = part->Rel_ID;
|
| 185 |
+
form->R_REL_R654_creates = part;
|
| 186 |
+
Escher_SetInsertElement( &part->ACT_RU_R654, (Escher_ObjectSet_s *) form );
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/*
|
| 190 |
+
* UNRELATE R_REL FROM ACT_RU ACROSS R654
|
| 191 |
+
*/
|
| 192 |
+
void
|
| 193 |
+
ooaofooa_ACT_RU_R654_Unlink( ooaofooa_R_REL * part, ooaofooa_ACT_RU * form )
|
| 194 |
+
{
|
| 195 |
+
/* Use TagEmptyHandleDetectionOn() to detect empty handle references. */
|
| 196 |
+
form->Rel_ID = 0;
|
| 197 |
+
form->R_REL_R654_creates = 0;
|
| 198 |
+
Escher_SetRemoveElement( &part->ACT_RU_R654, (Escher_ObjectSet_s *) form );
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/*
|
| 202 |
+
* Dump instances in SQL format.
|
| 203 |
+
*/
|
| 204 |
+
void
|
| 205 |
+
ooaofooa_ACT_RU_instancedumper( Escher_iHandle_t instance )
|
| 206 |
+
{
|
| 207 |
+
ooaofooa_ACT_RU * self = (ooaofooa_ACT_RU *) instance;
|
| 208 |
+
printf( "INSERT INTO ACT_RU VALUES ( %ld,%ld,%ld,%ld,'%s',%ld,%d,%d,%d,%d );\n",
|
| 209 |
+
((long)self->Statement_ID & ESCHER_IDDUMP_MASK),
|
| 210 |
+
((long)self->One_Side_Var_ID & ESCHER_IDDUMP_MASK),
|
| 211 |
+
((long)self->Other_Side_Var_ID & ESCHER_IDDUMP_MASK),
|
| 212 |
+
((long)self->Associative_Var_ID & ESCHER_IDDUMP_MASK),
|
| 213 |
+
( 0 != self->relationship_phrase ) ? self->relationship_phrase : "",
|
| 214 |
+
((long)self->Rel_ID & ESCHER_IDDUMP_MASK),
|
| 215 |
+
self->associationNumberLineNumber,
|
| 216 |
+
self->associationNumberColumn,
|
| 217 |
+
self->associationPhraseLineNumber,
|
| 218 |
+
self->associationPhraseColumn );
|
| 219 |
+
}
|
| 220 |
+
/*
|
| 221 |
+
* Statically allocate space for the instance population for this class.
|
| 222 |
+
* Allocate space for the class instance and its attribute values.
|
| 223 |
+
* Depending upon the collection scheme, allocate containoids (collection
|
| 224 |
+
* nodes) for gathering instances into free and active extents.
|
| 225 |
+
*/
|
| 226 |
+
static Escher_SetElement_s ooaofooa_ACT_RU_container[ ooaofooa_ACT_RU_MAX_EXTENT_SIZE ];
|
| 227 |
+
static ooaofooa_ACT_RU ooaofooa_ACT_RU_instances[ ooaofooa_ACT_RU_MAX_EXTENT_SIZE ];
|
| 228 |
+
Escher_Extent_t pG_ooaofooa_ACT_RU_extent = {
|
| 229 |
+
{0,0}, {0,0}, &ooaofooa_ACT_RU_container[ 0 ],
|
| 230 |
+
(Escher_iHandle_t) &ooaofooa_ACT_RU_instances,
|
| 231 |
+
sizeof( ooaofooa_ACT_RU ), 0, ooaofooa_ACT_RU_MAX_EXTENT_SIZE
|
| 232 |
+
};
|
| 233 |
+
|
| 234 |
+
|
pool/shard006/C/0117050_kern_condvar.c
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-
|
| 2 |
+
* Copyright (c) 2000 Jake Burkholder <jake@freebsd.org>.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* Redistribution and use in source and binary forms, with or without
|
| 6 |
+
* modification, are permitted provided that the following conditions
|
| 7 |
+
* are met:
|
| 8 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 9 |
+
* notice, this list of conditions and the following disclaimer.
|
| 10 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
* documentation and/or other materials provided with the distribution.
|
| 13 |
+
*
|
| 14 |
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
| 15 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 16 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 17 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 18 |
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 19 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 20 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 21 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 22 |
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 23 |
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 24 |
+
* SUCH DAMAGE.
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
#include <sys/cdefs.h>
|
| 28 |
+
__FBSDID("$FreeBSD: src/sys/kern/kern_condvar.c,v 1.50.2.1 2004/09/03 15:14:14 jhb Exp $");
|
| 29 |
+
|
| 30 |
+
#include "opt_ktrace.h"
|
| 31 |
+
|
| 32 |
+
#include <sys/param.h>
|
| 33 |
+
#include <sys/systm.h>
|
| 34 |
+
#include <sys/lock.h>
|
| 35 |
+
#include <sys/mutex.h>
|
| 36 |
+
#include <sys/proc.h>
|
| 37 |
+
#include <sys/kernel.h>
|
| 38 |
+
#include <sys/ktr.h>
|
| 39 |
+
#include <sys/condvar.h>
|
| 40 |
+
#include <sys/sched.h>
|
| 41 |
+
#include <sys/signalvar.h>
|
| 42 |
+
#include <sys/sleepqueue.h>
|
| 43 |
+
#include <sys/resourcevar.h>
|
| 44 |
+
#ifdef KTRACE
|
| 45 |
+
#include <sys/uio.h>
|
| 46 |
+
#include <sys/ktrace.h>
|
| 47 |
+
#endif
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* Common sanity checks for cv_wait* functions.
|
| 51 |
+
*/
|
| 52 |
+
#define CV_ASSERT(cvp, mp, td) do { \
|
| 53 |
+
KASSERT((td) != NULL, ("%s: curthread NULL", __func__)); \
|
| 54 |
+
KASSERT(TD_IS_RUNNING(td), ("%s: not TDS_RUNNING", __func__)); \
|
| 55 |
+
KASSERT((cvp) != NULL, ("%s: cvp NULL", __func__)); \
|
| 56 |
+
KASSERT((mp) != NULL, ("%s: mp NULL", __func__)); \
|
| 57 |
+
mtx_assert((mp), MA_OWNED | MA_NOTRECURSED); \
|
| 58 |
+
} while (0)
|
| 59 |
+
|
| 60 |
+
/*
|
| 61 |
+
* Initialize a condition variable. Must be called before use.
|
| 62 |
+
*/
|
| 63 |
+
void
|
| 64 |
+
cv_init(struct cv *cvp, const char *desc)
|
| 65 |
+
{
|
| 66 |
+
cvp->cv_description = desc;
|
| 67 |
+
cvp->cv_waiters = 0;
|
| 68 |
+
cvp->signals = 0;
|
| 69 |
+
ddekit_lock_init(&cvp->lock);
|
| 70 |
+
cvp->sem = ddekit_sem_init(0);
|
| 71 |
+
cvp->handshake = ddekit_sem_init(0);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/*
|
| 75 |
+
* Destroy a condition variable. The condition variable must be re-initialized
|
| 76 |
+
* in order to be re-used.
|
| 77 |
+
*/
|
| 78 |
+
void
|
| 79 |
+
cv_destroy(struct cv *cvp)
|
| 80 |
+
{
|
| 81 |
+
ddekit_lock_deinit(&cvp->lock);
|
| 82 |
+
ddekit_sem_deinit(cvp->sem);
|
| 83 |
+
ddekit_sem_deinit(cvp->handshake);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/*
|
| 87 |
+
* Wait on a condition variable. The current thread is placed on the condition
|
| 88 |
+
* variable's wait queue and suspended. A cv_signal or cv_broadcast on the same
|
| 89 |
+
* condition variable will resume the thread. The mutex is released before
|
| 90 |
+
* sleeping and will be held on return. It is recommended that the mutex be
|
| 91 |
+
* held when cv_signal or cv_broadcast are called.
|
| 92 |
+
*/
|
| 93 |
+
void
|
| 94 |
+
cv_wait(struct cv *cvp, struct mtx *mp)
|
| 95 |
+
{
|
| 96 |
+
cv_timedwait(cvp, mp, -1);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/*
|
| 100 |
+
* Wait on a condition variable, allowing interruption by signals. Return 0 if
|
| 101 |
+
* the thread was resumed with cv_signal or cv_broadcast, EINTR or ERESTART if
|
| 102 |
+
* a signal was caught. If ERESTART is returned the system call should be
|
| 103 |
+
* restarted if possible.
|
| 104 |
+
*/
|
| 105 |
+
int
|
| 106 |
+
cv_wait_sig(struct cv *cvp, struct mtx *mp)
|
| 107 |
+
{
|
| 108 |
+
return cv_timedwait(cvp, mp, -1);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/*
|
| 112 |
+
* Wait on a condition variable for at most timo/hz seconds. Returns 0 if the
|
| 113 |
+
* process was resumed by cv_signal or cv_broadcast, EWOULDBLOCK if the timeout
|
| 114 |
+
* expires.
|
| 115 |
+
*/
|
| 116 |
+
int
|
| 117 |
+
cv_timedwait(struct cv *cvp, struct mtx *mp, int timo)
|
| 118 |
+
{
|
| 119 |
+
struct thread *td;
|
| 120 |
+
int rval;
|
| 121 |
+
WITNESS_SAVE_DECL(mp);
|
| 122 |
+
|
| 123 |
+
td = curthread;
|
| 124 |
+
rval = 0;
|
| 125 |
+
#ifdef KTRACE
|
| 126 |
+
if (KTRPOINT(td, KTR_CSW))
|
| 127 |
+
ktrcsw(1, 0);
|
| 128 |
+
#endif
|
| 129 |
+
CV_ASSERT(cvp, mp, td);
|
| 130 |
+
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
|
| 131 |
+
"Waiting on \"%s\"", cvp->cv_description);
|
| 132 |
+
WITNESS_SAVE(&mp->mtx_object, mp);
|
| 133 |
+
|
| 134 |
+
if (cold || panicstr) {
|
| 135 |
+
/*
|
| 136 |
+
* After a panic, or during autoconfiguration, just give
|
| 137 |
+
* interrupts a chance, then just return; don't run any other
|
| 138 |
+
* thread or panic below, in case this is the idle process and
|
| 139 |
+
* already asleep.
|
| 140 |
+
*/
|
| 141 |
+
return 0;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
ddekit_lock_lock(&cvp->lock);
|
| 145 |
+
cvp->cv_waiters++;
|
| 146 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 147 |
+
DROP_GIANT();
|
| 148 |
+
mtx_unlock(mp);
|
| 149 |
+
|
| 150 |
+
if (timo == -1) {
|
| 151 |
+
ddekit_sem_down(cvp->sem);
|
| 152 |
+
} else {
|
| 153 |
+
if (ddekit_sem_down_timed(cvp->sem, timo*1000/hz)) {
|
| 154 |
+
rval = EWOULDBLOCK;
|
| 155 |
+
} else {
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
ddekit_lock_lock(&cvp->lock);
|
| 160 |
+
if (cvp->signals > 0) {
|
| 161 |
+
// if we timed out, but there is a signal now, consume it
|
| 162 |
+
if (rval) ddekit_sem_down(cvp->sem);
|
| 163 |
+
|
| 164 |
+
ddekit_sem_up(cvp->handshake);
|
| 165 |
+
cvp->signals--;
|
| 166 |
+
}
|
| 167 |
+
cvp->cv_waiters--;
|
| 168 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 169 |
+
|
| 170 |
+
#ifdef KTRACE
|
| 171 |
+
if (KTRPOINT(td, KTR_CSW))
|
| 172 |
+
ktrcsw(0, 0);
|
| 173 |
+
#endif
|
| 174 |
+
PICKUP_GIANT();
|
| 175 |
+
mtx_lock(mp);
|
| 176 |
+
WITNESS_RESTORE(&mp->mtx_object, mp);
|
| 177 |
+
|
| 178 |
+
return (rval);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/*
|
| 182 |
+
* Wait on a condition variable for at most timo/hz seconds, allowing
|
| 183 |
+
* interruption by signals. Returns 0 if the thread was resumed by cv_signal
|
| 184 |
+
* or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if
|
| 185 |
+
* a signal was caught.
|
| 186 |
+
*/
|
| 187 |
+
int
|
| 188 |
+
cv_timedwait_sig(struct cv *cvp, struct mtx *mp, int timo)
|
| 189 |
+
{
|
| 190 |
+
return cv_timedwait(cvp, mp, timo);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/*
|
| 194 |
+
* Signal a condition variable, wakes up one waiting thread. Will also wakeup
|
| 195 |
+
* the swapper if the process is not in memory, so that it can bring the
|
| 196 |
+
* sleeping process in. Note that this may also result in additional threads
|
| 197 |
+
* being made runnable. Should be called with the same mutex as was passed to
|
| 198 |
+
* cv_wait held.
|
| 199 |
+
*/
|
| 200 |
+
void
|
| 201 |
+
cv_signal(struct cv *cvp)
|
| 202 |
+
{
|
| 203 |
+
ddekit_lock_lock(&cvp->lock);
|
| 204 |
+
|
| 205 |
+
if (cvp->cv_waiters > cvp->signals) {
|
| 206 |
+
cvp->signals++;
|
| 207 |
+
ddekit_sem_up(cvp->sem);
|
| 208 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 209 |
+
ddekit_sem_down(cvp->handshake);
|
| 210 |
+
} else {
|
| 211 |
+
// nobody left to wakeup
|
| 212 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/*
|
| 217 |
+
* Broadcast a signal to a condition variable. Wakes up all waiting threads.
|
| 218 |
+
* Should be called with the same mutex as was passed to cv_wait held.
|
| 219 |
+
*/
|
| 220 |
+
void
|
| 221 |
+
cv_broadcastpri(struct cv *cvp, int pri)
|
| 222 |
+
{
|
| 223 |
+
int waiters;
|
| 224 |
+
|
| 225 |
+
ddekit_lock_lock(&cvp->lock);
|
| 226 |
+
|
| 227 |
+
waiters = cvp->cv_waiters - cvp->signals;
|
| 228 |
+
if (waiters > 0) {
|
| 229 |
+
int i;
|
| 230 |
+
|
| 231 |
+
cvp->signals = cvp->cv_waiters;
|
| 232 |
+
for (i=0; i<waiters; i++) {
|
| 233 |
+
ddekit_sem_up(cvp->sem);
|
| 234 |
+
}
|
| 235 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 236 |
+
for (i=0; i<waiters; i++) {
|
| 237 |
+
ddekit_sem_down(cvp->handshake);
|
| 238 |
+
}
|
| 239 |
+
} else {
|
| 240 |
+
ddekit_lock_unlock(&cvp->lock);
|
| 241 |
+
}
|
| 242 |
+
}
|
pool/shard006/C/0117055_sysschevt.c
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// $Id$
|
| 2 |
+
// $Locker$
|
| 3 |
+
|
| 4 |
+
// Author. Roar Thronæs.
|
| 5 |
+
/**
|
| 6 |
+
\file sysschevt.c
|
| 7 |
+
\brief system scheduling and timer
|
| 8 |
+
\author Roar Thronæs
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include<linux/linkage.h>
|
| 12 |
+
#include<linux/sched.h>
|
| 13 |
+
#include<ssdef.h>
|
| 14 |
+
#include<tqedef.h>
|
| 15 |
+
#include<cpudef.h>
|
| 16 |
+
#include<dyndef.h>
|
| 17 |
+
#include<system_data_cells.h>
|
| 18 |
+
#include <ipl.h>
|
| 19 |
+
#include<internals.h>
|
| 20 |
+
#include <statedef.h>
|
| 21 |
+
#include<linux/vmalloc.h>
|
| 22 |
+
#include<linux/smp.h>
|
| 23 |
+
#include <linux/slab.h>
|
| 24 |
+
#include <exe_routines.h>
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
\brief set timer - see 5.2 11.6.1
|
| 28 |
+
\param efn event flag
|
| 29 |
+
\param daytim time
|
| 30 |
+
\param astadr ast routine
|
| 31 |
+
\param reqidt param for it
|
| 32 |
+
\param flags
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
asmlinkage int exe$setimr (unsigned int efn, signed long long *daytim,
|
| 36 |
+
void (*astadr)(long), unsigned
|
| 37 |
+
long reqidt, unsigned int flags)
|
| 38 |
+
{
|
| 39 |
+
unsigned long long time;
|
| 40 |
+
/** test time location - MISSING */
|
| 41 |
+
/** test astcnt - MISSING */
|
| 42 |
+
/** decrement jib tqcnt, test and maybe MWAIT - MISSING */
|
| 43 |
+
/** allocate tqe */
|
| 44 |
+
struct _tqe * t=kmalloc(sizeof(struct _tqe),GFP_KERNEL);
|
| 45 |
+
struct _cpu * cpu=smp$gl_cpu_data[smp_processor_id()];
|
| 46 |
+
memset(t,0,sizeof(struct _tqe));
|
| 47 |
+
t->tqe$b_type=DYN$C_TQE;
|
| 48 |
+
/** clear event flag */
|
| 49 |
+
exe$clref(efn);
|
| 50 |
+
/** fifth nonzero argument test */
|
| 51 |
+
/** wrong use TODO use chk_cputim field */
|
| 52 |
+
if (flags) t->tqe$b_rqtype=TQE$M_CHK_CPUTIM;
|
| 53 |
+
if (!daytim) return SS$_ACCVIO;
|
| 54 |
+
/** if negative, then relative time */
|
| 55 |
+
/** set absolute bit - MISSING */
|
| 56 |
+
if (*daytim<0)
|
| 57 |
+
{
|
| 58 |
+
time=exe$gq_systime-*daytim;
|
| 59 |
+
}
|
| 60 |
+
else
|
| 61 |
+
{
|
| 62 |
+
time=*daytim;
|
| 63 |
+
}
|
| 64 |
+
//printk("astadr %x\n",astadr);
|
| 65 |
+
/** store access mode in tqe - MISSING */
|
| 66 |
+
/** if no astadr, decrease astcnt and set quota bit - MISSING */
|
| 67 |
+
t->tqe$l_ast=astadr;
|
| 68 |
+
// printk("astadr2 %x\n",t->tqe$l_fpc);
|
| 69 |
+
t->tqe$l_astprm=reqidt;
|
| 70 |
+
t->tqe$q_time=time;
|
| 71 |
+
t->tqe$b_rqtype=TQE$C_TMSNGL;
|
| 72 |
+
t->tqe$l_pid=ctl$gl_pcb->pcb$l_pid;
|
| 73 |
+
t->tqe$b_efn=efn;
|
| 74 |
+
//printast((struct _acb * )t);
|
| 75 |
+
/** insert in timer queue */
|
| 76 |
+
exe$instimq(t);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
\brief schedule wakeup - see 5.2 11.6.3
|
| 81 |
+
\param pidadr address of pid
|
| 82 |
+
\param prcnam process name
|
| 83 |
+
\param daytim time of day
|
| 84 |
+
\param reptim time to repeat
|
| 85 |
+
*/
|
| 86 |
+
|
| 87 |
+
asmlinkage int exe$schdwk(unsigned int *pidadr, void *prcnam, signed long long * daytim, signed long long * reptim)
|
| 88 |
+
{
|
| 89 |
+
struct _pcb * retpcb, *p;
|
| 90 |
+
unsigned long retipid, retepid;
|
| 91 |
+
/** invoke exe$nampid to find pcb */
|
| 92 |
+
int sts=exe$nampid(current,pidadr,prcnam,&retpcb,&retipid,&retepid);
|
| 93 |
+
p=retpcb;
|
| 94 |
+
/** TODO better handling of sts and vmsunlock */
|
| 95 |
+
vmsunlock(&SPIN_SCHED,0);
|
| 96 |
+
/** maybe cwps - MISSING */
|
| 97 |
+
if (!p) return;
|
| 98 |
+
{
|
| 99 |
+
unsigned long long time;
|
| 100 |
+
/** allocate and init tqe */
|
| 101 |
+
struct _tqe * t=kmalloc(sizeof(struct _tqe),GFP_KERNEL);
|
| 102 |
+
struct _cpu * cpu=smp$gl_cpu_data[smp_processor_id()];
|
| 103 |
+
memset(t,0,sizeof(struct _tqe));
|
| 104 |
+
t->tqe$b_type=DYN$C_TQE;
|
| 105 |
+
/** test if one-time or repeating */
|
| 106 |
+
if (*daytim<0)
|
| 107 |
+
{
|
| 108 |
+
/** convert repeat to system time format */
|
| 109 |
+
time=exe$gq_systime-*daytim;
|
| 110 |
+
/** if relative clear tqe absolute bit - MISSING */
|
| 111 |
+
}
|
| 112 |
+
else
|
| 113 |
+
{
|
| 114 |
+
time=*daytim;
|
| 115 |
+
}
|
| 116 |
+
t->tqe$l_pid=p->pcb$l_pid;
|
| 117 |
+
t->tqe$q_time=time;
|
| 118 |
+
if (reptim) t->tqe$q_delta=-(*reptim);
|
| 119 |
+
t->tqe$b_rqtype=TQE$C_WKSNGL;
|
| 120 |
+
if (reptim) t->tqe$b_rqtype|=TQE$M_REPEAT;
|
| 121 |
+
//printast((struct _acb * )t);
|
| 122 |
+
/** decrement astcnt - MISSING */
|
| 123 |
+
/** insert with instimq */
|
| 124 |
+
exe$instimq(t);
|
| 125 |
+
}
|
| 126 |
+
/** return value - MISSING */
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
pool/shard006/C/0117061_find_missing.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
void output(int *array, size_t len)
|
| 8 |
+
{
|
| 9 |
+
int i;
|
| 10 |
+
for(i=0; i<len; i++) {
|
| 11 |
+
printf("%2i,", array[i]);
|
| 12 |
+
}
|
| 13 |
+
puts("");
|
| 14 |
+
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
void swap(int *x, int *y)
|
| 18 |
+
{
|
| 19 |
+
if( x != y) {
|
| 20 |
+
*x = *x ^ *y;
|
| 21 |
+
*y = *x ^ *y;
|
| 22 |
+
*x = *x ^ *y;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* find missing number in 0...N array */
|
| 27 |
+
int find_missing0(int array[], size_t len)
|
| 28 |
+
{
|
| 29 |
+
int i;
|
| 30 |
+
|
| 31 |
+
for(i=0; i<len; i++) {
|
| 32 |
+
while(array[i] != i && array[i] < len) swap(array+i, array+array[i]);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
for(i=array[0]; i<len; i++) {
|
| 36 |
+
if(array[i] != i) return i;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return len;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
/* find missing number in array */
|
| 44 |
+
int find_missing1(int array[], size_t len)
|
| 45 |
+
{
|
| 46 |
+
|
| 47 |
+
return 0;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
int main(int argc, char** argv)
|
| 51 |
+
{
|
| 52 |
+
int retval = 0;
|
| 53 |
+
int array[] = {2, 9, 4, 7, 5, 3, 6, 0, 8};
|
| 54 |
+
size_t len = sizeof(array)/sizeof(array[0]);
|
| 55 |
+
|
| 56 |
+
output(array, len);
|
| 57 |
+
printf("missing: %d\n", find_missing0(array, len));
|
| 58 |
+
output(array, len);
|
| 59 |
+
|
| 60 |
+
return retval;
|
| 61 |
+
}
|
| 62 |
+
|
pool/shard006/C/0117064_filesys.c
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <string.h>
|
| 2 |
+
#include <types.h>
|
| 3 |
+
#include <debug.h>
|
| 4 |
+
#include <memory.h>
|
| 5 |
+
#include <filesys.h>
|
| 6 |
+
#include <floppy.h>
|
| 7 |
+
#include <errno.h>
|
| 8 |
+
|
| 9 |
+
#define TD_TRACK (TD_SECTOR * NSECTORS)
|
| 10 |
+
#define TD_DISK (TD_TRACK * NTRACKS)
|
| 11 |
+
|
| 12 |
+
#define IOF_EOF 0x0002
|
| 13 |
+
#define IOF_ERR 0x8000
|
| 14 |
+
|
| 15 |
+
/* On disk directory entries are always aligned to 2-byte boundary. */
|
| 16 |
+
typedef struct FileEntry {
|
| 17 |
+
u_char reclen; /* total size of this record in bytes */
|
| 18 |
+
u_char type; /* type of file (1: executable, 0: regular) */
|
| 19 |
+
u_short start; /* sector where the file begins (0..1759) */
|
| 20 |
+
u_int size; /* file size in bytes (up to 1MiB) */
|
| 21 |
+
char name[0]; /* name of the file (NUL terminated) */
|
| 22 |
+
} FileEntryT;
|
| 23 |
+
|
| 24 |
+
static FileEntryT *NextFileEntry(FileEntryT *fe) {
|
| 25 |
+
return (void *)fe + fe->reclen;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/* Finished by NUL character (reclen = 0). */
|
| 29 |
+
static FileEntryT *rootDir = NULL;
|
| 30 |
+
|
| 31 |
+
struct File {
|
| 32 |
+
FileOpsT *ops;
|
| 33 |
+
|
| 34 |
+
u_int offset;
|
| 35 |
+
u_int length;
|
| 36 |
+
|
| 37 |
+
u_short flags;
|
| 38 |
+
u_int pos;
|
| 39 |
+
|
| 40 |
+
struct {
|
| 41 |
+
u_int left;
|
| 42 |
+
u_char *pos;
|
| 43 |
+
u_char *track;
|
| 44 |
+
} buf;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
static inline bool ReadTrack(void *data, int offset) {
|
| 48 |
+
int trknum = div16(offset, TD_TRACK);
|
| 49 |
+
Log("[Floppy] Read track %d.\n", trknum);
|
| 50 |
+
FloppyTrackRead(trknum);
|
| 51 |
+
FloppyTrackDecode(data);
|
| 52 |
+
return true;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static bool FillBuffer(FileT *file) {
|
| 56 |
+
u_int abspos = file->offset + file->pos;
|
| 57 |
+
u_int waste = mod16(abspos, TD_TRACK);
|
| 58 |
+
|
| 59 |
+
if (file->pos == file->length) {
|
| 60 |
+
file->flags |= IOF_EOF;
|
| 61 |
+
return false;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
if (!ReadTrack(file->buf.track, abspos - waste)) {
|
| 65 |
+
file->flags |= IOF_ERR;
|
| 66 |
+
return false;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
file->buf.pos = file->buf.track + waste;
|
| 70 |
+
file->buf.left = min(file->length - file->pos, TD_TRACK - waste);
|
| 71 |
+
file->pos += file->buf.left;
|
| 72 |
+
return true;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
static int FsRead(FileT *f, void *buf, u_int nbyte);
|
| 76 |
+
static int FsSeek(FileT *f, int offset, int whence);
|
| 77 |
+
static void FsClose(FileT *f);
|
| 78 |
+
|
| 79 |
+
static FileOpsT FsOps = {
|
| 80 |
+
.read = FsRead,
|
| 81 |
+
.write = NULL,
|
| 82 |
+
.seek = FsSeek,
|
| 83 |
+
.close = FsClose
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
static FileT *NewFile(int length, int offset) {
|
| 87 |
+
FileT *f = MemAlloc(sizeof(FileT), MEMF_PUBLIC|MEMF_CLEAR);
|
| 88 |
+
|
| 89 |
+
f->ops = &FsOps;
|
| 90 |
+
f->length = length;
|
| 91 |
+
f->offset = offset;
|
| 92 |
+
f->buf.track = MemAlloc(TD_TRACK, MEMF_PUBLIC);
|
| 93 |
+
f->buf.pos = f->buf.track;
|
| 94 |
+
|
| 95 |
+
return f;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
static FileEntryT *LookupFile(const char *path) {
|
| 99 |
+
FileEntryT *fe = rootDir;
|
| 100 |
+
|
| 101 |
+
if (fe == NULL)
|
| 102 |
+
return NULL;
|
| 103 |
+
|
| 104 |
+
do {
|
| 105 |
+
if (strcmp(path, fe->name) == 0)
|
| 106 |
+
return fe;
|
| 107 |
+
fe = NextFileEntry(fe);
|
| 108 |
+
} while (fe->reclen);
|
| 109 |
+
|
| 110 |
+
return NULL;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
FileT *OpenFile(const char *path) {
|
| 114 |
+
FileEntryT *entry;
|
| 115 |
+
if ((entry = LookupFile(path)))
|
| 116 |
+
return NewFile(entry->size, entry->start * TD_SECTOR);
|
| 117 |
+
return NULL;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
static void FsClose(FileT *file) {
|
| 121 |
+
MemFree(file->buf.track);
|
| 122 |
+
MemFree(file);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static int FsRead(FileT *file, void *buf, u_int size) {
|
| 126 |
+
u_int left = size;
|
| 127 |
+
|
| 128 |
+
if (!file)
|
| 129 |
+
return EBADF;
|
| 130 |
+
|
| 131 |
+
if (file->flags & IOF_ERR)
|
| 132 |
+
return EIO;
|
| 133 |
+
|
| 134 |
+
if (size == 0)
|
| 135 |
+
return 0;
|
| 136 |
+
|
| 137 |
+
// Log("[FileRead] $%p $%p %d\n", file, buf, size);
|
| 138 |
+
|
| 139 |
+
while (left > 0) {
|
| 140 |
+
if (!file->buf.left && !FillBuffer(file))
|
| 141 |
+
break;
|
| 142 |
+
|
| 143 |
+
{
|
| 144 |
+
/* Read to the end of buffer or less. */
|
| 145 |
+
int length = min(left, file->buf.left);
|
| 146 |
+
|
| 147 |
+
memcpy(buf, file->buf.pos, length);
|
| 148 |
+
|
| 149 |
+
file->buf.pos += length;
|
| 150 |
+
file->buf.left -= length;
|
| 151 |
+
buf += length; left -= length;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return size - left; /* how much did we read? */
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static int FsSeek(FileT *file, int offset, int whence) {
|
| 159 |
+
if (file->flags & IOF_ERR)
|
| 160 |
+
return EIO;
|
| 161 |
+
|
| 162 |
+
// Log("[FileSeek] $%p %d %d\n", file, pos, mode);
|
| 163 |
+
|
| 164 |
+
file->flags &= ~IOF_EOF;
|
| 165 |
+
|
| 166 |
+
if (whence == SEEK_CUR) {
|
| 167 |
+
offset += file->pos - file->buf.left;
|
| 168 |
+
whence = SEEK_SET;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (whence == SEEK_SET) {
|
| 172 |
+
int bufsize = file->buf.pos - file->buf.track + (int)file->buf.left;
|
| 173 |
+
int bufstart = file->pos - bufsize;
|
| 174 |
+
int bufend = file->pos;
|
| 175 |
+
|
| 176 |
+
/* New position is within buffer boundaries. */
|
| 177 |
+
if ((offset >= bufstart) && (offset < bufend)) {
|
| 178 |
+
file->buf.pos = file->buf.track + offset - bufstart;
|
| 179 |
+
file->buf.left = file->pos - offset;
|
| 180 |
+
return offset;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/* New position is not within file. */
|
| 184 |
+
if ((offset < 0) || (offset > (int)file->length))
|
| 185 |
+
return EINVAL;
|
| 186 |
+
|
| 187 |
+
file->pos = offset;
|
| 188 |
+
(void)FillBuffer(file);
|
| 189 |
+
return offset;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
return EINVAL;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
int GetFileSize(const char *path) {
|
| 196 |
+
FileEntryT *entry;
|
| 197 |
+
if ((entry = LookupFile(path)))
|
| 198 |
+
return entry->size;
|
| 199 |
+
return ENOENT;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
int GetCursorPos(FileT *file) {
|
| 203 |
+
if (!file)
|
| 204 |
+
return EBADF;
|
| 205 |
+
if (file->flags & IOF_ERR)
|
| 206 |
+
return EIO;
|
| 207 |
+
return file->pos - file->buf.left;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
#define ONSTACK(x) (&(x)), sizeof((x))
|
| 211 |
+
|
| 212 |
+
void InitFileSys(void) {
|
| 213 |
+
FileT *fh;
|
| 214 |
+
u_short rootDirLen;
|
| 215 |
+
|
| 216 |
+
/* Create a file that represent whole floppy disk without boot sector. */
|
| 217 |
+
fh = NewFile(TD_DISK - TD_SECTOR * 2, TD_SECTOR * 2);
|
| 218 |
+
|
| 219 |
+
/* read directory size */
|
| 220 |
+
FileRead(fh, ONSTACK(rootDirLen));
|
| 221 |
+
|
| 222 |
+
Log("[FileSys] Reading directory of %d bytes.\n", rootDirLen);
|
| 223 |
+
|
| 224 |
+
/* read directory entries */
|
| 225 |
+
rootDir = MemAlloc(rootDirLen + 1, MEMF_PUBLIC|MEMF_CLEAR);
|
| 226 |
+
FileRead(fh, rootDir, rootDirLen);
|
| 227 |
+
FileClose(fh);
|
| 228 |
+
|
| 229 |
+
/* associate names with file entries */
|
| 230 |
+
{
|
| 231 |
+
FileEntryT *fe = rootDir;
|
| 232 |
+
do {
|
| 233 |
+
Log("[FileSys] Sector %d: %s file '%s' of %d bytes.\n",
|
| 234 |
+
fe->start, fe->type ? "executable" : "regular", fe->name, fe->size);
|
| 235 |
+
fe = NextFileEntry(fe);
|
| 236 |
+
} while (fe->reclen);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
void KillFileSys(void) {
|
| 241 |
+
if (rootDir) {
|
| 242 |
+
MemFree(rootDir);
|
| 243 |
+
rootDir = NULL;
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
void *LoadFile(const char *path, u_int memoryFlags) {
|
| 248 |
+
char *data = NULL;
|
| 249 |
+
int size = GetFileSize(path);
|
| 250 |
+
|
| 251 |
+
if (size > 0 && (data = MemAlloc(size + 1, memoryFlags))) {
|
| 252 |
+
FileT *f = OpenFile(path);
|
| 253 |
+
|
| 254 |
+
if (!FileRead(f, data, size)) {
|
| 255 |
+
MemFree(data);
|
| 256 |
+
data = NULL;
|
| 257 |
+
} else {
|
| 258 |
+
/* Add extra byte and mark the end of file by zero. */
|
| 259 |
+
data[size] = 0;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
FileClose(f);
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
return data;
|
| 266 |
+
}
|
pool/shard006/C/0117068_print-mobile.c
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* (c) 1998 The NetBSD Foundation, Inc.
|
| 5 |
+
* All rights reserved.
|
| 6 |
+
*
|
| 7 |
+
* This code is derived from software contributed to The NetBSD Foundation
|
| 8 |
+
* by Heiko W.Rupp <hwr@pilhuhn.de>
|
| 9 |
+
*
|
| 10 |
+
* Redistribution and use in source and binary forms, with or without
|
| 11 |
+
* modification, are permitted provided that the following conditions
|
| 12 |
+
* are met:
|
| 13 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 14 |
+
* notice, this list of conditions and the following disclaimer.
|
| 15 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 16 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 17 |
+
* documentation and/or other materials provided with the distribution.
|
| 18 |
+
* 3. All advertising materials mentioning features or use of this software
|
| 19 |
+
* must display the following acknowledgement:
|
| 20 |
+
* This product includes software developed by the NetBSD
|
| 21 |
+
* Foundation, Inc. and its contributors.
|
| 22 |
+
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
| 23 |
+
* contributors may be used to endorse or promote products derived
|
| 24 |
+
* from this software without specific prior written permission.
|
| 25 |
+
*
|
| 26 |
+
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
| 27 |
+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
| 28 |
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 29 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
| 30 |
+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 31 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 32 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 33 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 34 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 35 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 36 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
#ifdef HAVE_CONFIG_H
|
| 40 |
+
#include "config.h"
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
#ifndef lint
|
| 44 |
+
static const char rcsid[] _U_ =
|
| 45 |
+
"@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.15 2004/03/24 01:58:14 guy Exp $";
|
| 46 |
+
#endif
|
| 47 |
+
|
| 48 |
+
#include "tcpdump-stdinc.h"
|
| 49 |
+
|
| 50 |
+
#include <stdio.h>
|
| 51 |
+
|
| 52 |
+
#include "interface.h"
|
| 53 |
+
#include "addrtoname.h"
|
| 54 |
+
#include "extract.h" /* must come after interface.h */
|
| 55 |
+
|
| 56 |
+
#define MOBILE_SIZE (8)
|
| 57 |
+
|
| 58 |
+
struct mobile_ip {
|
| 59 |
+
u_int16_t proto;
|
| 60 |
+
u_int16_t hcheck;
|
| 61 |
+
u_int32_t odst;
|
| 62 |
+
u_int32_t osrc;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
#define OSRC_PRES 0x0080 /* old source is present */
|
| 66 |
+
|
| 67 |
+
/*
|
| 68 |
+
* Deencapsulate and print a mobile-tunneled IP datagram
|
| 69 |
+
*/
|
| 70 |
+
void
|
| 71 |
+
mobile_print(const u_char *bp, u_int length)
|
| 72 |
+
{
|
| 73 |
+
const u_char *cp = bp +8 ;
|
| 74 |
+
const struct mobile_ip *mob;
|
| 75 |
+
u_short proto,crc;
|
| 76 |
+
u_char osp =0; /* old source address present */
|
| 77 |
+
|
| 78 |
+
mob = (const struct mobile_ip *)bp;
|
| 79 |
+
|
| 80 |
+
if (length < MOBILE_SIZE || !TTEST(*mob)) {
|
| 81 |
+
fputs("[|mobile]", stdout);
|
| 82 |
+
return;
|
| 83 |
+
}
|
| 84 |
+
fputs("mobile: ", stdout);
|
| 85 |
+
|
| 86 |
+
proto = EXTRACT_16BITS(&mob->proto);
|
| 87 |
+
crc = EXTRACT_16BITS(&mob->hcheck);
|
| 88 |
+
if (proto & OSRC_PRES) {
|
| 89 |
+
osp=1;
|
| 90 |
+
cp +=4 ;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if (osp) {
|
| 94 |
+
fputs("[S] ",stdout);
|
| 95 |
+
if (vflag)
|
| 96 |
+
(void)printf("%s ",ipaddr_string(&mob->osrc));
|
| 97 |
+
} else {
|
| 98 |
+
fputs("[] ",stdout);
|
| 99 |
+
}
|
| 100 |
+
if (vflag) {
|
| 101 |
+
(void)printf("> %s ",ipaddr_string(&mob->odst));
|
| 102 |
+
(void)printf("(oproto=%d)",proto>>8);
|
| 103 |
+
}
|
| 104 |
+
if (in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) {
|
| 105 |
+
(void)printf(" (bad checksum %d)",crc);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return;
|
| 109 |
+
}
|
pool/shard006/C/0117072_util.c
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* libid3tag - ID3 tag manipulation library
|
| 3 |
+
* Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
+
*
|
| 19 |
+
* $Id: util.c 1032 2006-05-13 17:42:58Z amadeus_ds $
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
# ifdef HAVE_CONFIG_H
|
| 23 |
+
# include "config.h"
|
| 24 |
+
# endif
|
| 25 |
+
|
| 26 |
+
# include "global.h"
|
| 27 |
+
|
| 28 |
+
# include <stdlib.h>
|
| 29 |
+
# include <zlib.h>
|
| 30 |
+
|
| 31 |
+
# include "id3tag.h"
|
| 32 |
+
# include "util.h"
|
| 33 |
+
|
| 34 |
+
/*
|
| 35 |
+
* NAME: util->unsynchronise()
|
| 36 |
+
* DESCRIPTION: perform (in-place) unsynchronisation
|
| 37 |
+
*/
|
| 38 |
+
id3_length_t id3_util_unsynchronise(id3_byte_t *data, id3_length_t length)
|
| 39 |
+
{
|
| 40 |
+
id3_length_t bytes = 0, count;
|
| 41 |
+
id3_byte_t *end = data + length;
|
| 42 |
+
id3_byte_t const *ptr;
|
| 43 |
+
|
| 44 |
+
if (length == 0)
|
| 45 |
+
return 0;
|
| 46 |
+
|
| 47 |
+
for (ptr = data; ptr < end - 1; ++ptr) {
|
| 48 |
+
if (ptr[0] == 0xff && (ptr[1] == 0x00 || (ptr[1] & 0xe0) == 0xe0))
|
| 49 |
+
++bytes;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (bytes) {
|
| 53 |
+
ptr = end;
|
| 54 |
+
end += bytes;
|
| 55 |
+
|
| 56 |
+
*--end = *--ptr;
|
| 57 |
+
|
| 58 |
+
for (count = bytes; count; *--end = *--ptr) {
|
| 59 |
+
if (ptr[-1] == 0xff && (ptr[0] == 0x00 || (ptr[0] & 0xe0) == 0xe0)) {
|
| 60 |
+
*--end = 0x00;
|
| 61 |
+
--count;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return length + bytes;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/*
|
| 70 |
+
* NAME: util->deunsynchronise()
|
| 71 |
+
* DESCRIPTION: undo unsynchronisation (in-place)
|
| 72 |
+
*/
|
| 73 |
+
id3_length_t id3_util_deunsynchronise(id3_byte_t *data, id3_length_t length)
|
| 74 |
+
{
|
| 75 |
+
id3_byte_t const *old, *end = data + length;
|
| 76 |
+
id3_byte_t *new;
|
| 77 |
+
|
| 78 |
+
if (length == 0)
|
| 79 |
+
return 0;
|
| 80 |
+
|
| 81 |
+
for (old = new = data; old < end - 1; ++old) {
|
| 82 |
+
*new++ = *old;
|
| 83 |
+
if (old[0] == 0xff && old[1] == 0x00)
|
| 84 |
+
++old;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
*new++ = *old;
|
| 88 |
+
|
| 89 |
+
return new - data;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/*
|
| 93 |
+
* NAME: util->compress()
|
| 94 |
+
* DESCRIPTION: perform zlib deflate method compression
|
| 95 |
+
*/
|
| 96 |
+
id3_byte_t *id3_util_compress(id3_byte_t const *data, id3_length_t length,
|
| 97 |
+
id3_length_t *newlength)
|
| 98 |
+
{
|
| 99 |
+
id3_byte_t *compressed;
|
| 100 |
+
|
| 101 |
+
*newlength = length + 12;
|
| 102 |
+
*newlength += *newlength / 1000;
|
| 103 |
+
|
| 104 |
+
compressed = malloc(*newlength);
|
| 105 |
+
if (compressed) {
|
| 106 |
+
if (compress2(compressed, newlength, data, length,
|
| 107 |
+
Z_BEST_COMPRESSION) != Z_OK ||
|
| 108 |
+
*newlength >= length) {
|
| 109 |
+
free(compressed);
|
| 110 |
+
compressed = 0;
|
| 111 |
+
}
|
| 112 |
+
else {
|
| 113 |
+
id3_byte_t *resized;
|
| 114 |
+
|
| 115 |
+
resized = realloc(compressed, *newlength ? *newlength : 1);
|
| 116 |
+
if (resized)
|
| 117 |
+
compressed = resized;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return compressed;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/*
|
| 125 |
+
* NAME: util->decompress()
|
| 126 |
+
* DESCRIPTION: undo zlib deflate method compression
|
| 127 |
+
*/
|
| 128 |
+
id3_byte_t *id3_util_decompress(id3_byte_t const *data, id3_length_t length,
|
| 129 |
+
id3_length_t newlength)
|
| 130 |
+
{
|
| 131 |
+
id3_byte_t *decompressed;
|
| 132 |
+
|
| 133 |
+
decompressed = malloc(newlength ? newlength : 1);
|
| 134 |
+
if (decompressed) {
|
| 135 |
+
id3_length_t size;
|
| 136 |
+
|
| 137 |
+
size = newlength;
|
| 138 |
+
|
| 139 |
+
if (uncompress(decompressed, &size, data, length) != Z_OK ||
|
| 140 |
+
size != newlength) {
|
| 141 |
+
free(decompressed);
|
| 142 |
+
decompressed = 0;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return decompressed;
|
| 147 |
+
}
|
pool/shard006/C/0117080_uws_datatype.c
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "uws_datatype.h"
|
| 2 |
+
#include "uws_memory.h"
|
| 3 |
+
int_queue_t* init_int_queue() {
|
| 4 |
+
int_queue_t* new_queue = (int_queue_t*) uws_malloc(sizeof(int_queue_t));
|
| 5 |
+
new_queue->length = 0;
|
| 6 |
+
new_queue->head = NULL;
|
| 7 |
+
return new_queue;
|
| 8 |
+
}
|
| 9 |
+
void push_int_queue(int_queue_t *queue, int data) {
|
| 10 |
+
int_node_t** next = &queue->head;
|
| 11 |
+
while(*next != NULL) {
|
| 12 |
+
next = &((*next)->next);
|
| 13 |
+
}
|
| 14 |
+
int_node_t* new_node = (int_node_t*) uws_malloc(sizeof(int_node_t));
|
| 15 |
+
new_node->element = data;
|
| 16 |
+
new_node->next = NULL;
|
| 17 |
+
*next = new_node;
|
| 18 |
+
queue->length++;
|
| 19 |
+
}
|
| 20 |
+
int pop_int_queue(int_queue_t *queue) {
|
| 21 |
+
int_node_t* tmp = queue->head;
|
| 22 |
+
int ret_val = queue->head->element;
|
| 23 |
+
queue->head = queue->head->next;
|
| 24 |
+
uws_free(tmp);
|
| 25 |
+
queue->length--;
|
| 26 |
+
return ret_val;
|
| 27 |
+
}
|
pool/shard006/C/0117089_hashHelper.c
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <stdlib.h>
|
| 3 |
+
#include <string.h>
|
| 4 |
+
#include "../Headers/hashHelper.h"
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Assumptions: assuming the charictors red are ascii char only
|
| 8 |
+
* @author: Dalin Williams
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/**/
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
int hashFindIndex(hashM hash, const char *key){
|
| 15 |
+
if(!hash){
|
| 16 |
+
return -1;
|
| 17 |
+
}
|
| 18 |
+
for(int i = 0; i < hash->len; ++i){
|
| 19 |
+
if (!strcmp(hash->item[i].key, key)) {
|
| 20 |
+
//hash->item[i]->key;
|
| 21 |
+
return i;
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
return -1;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
int hashFind(hashM hash, const char* key){
|
| 30 |
+
if(!hash){
|
| 31 |
+
return -1;
|
| 32 |
+
}
|
| 33 |
+
int index = hashFindIndex(hash, key);
|
| 34 |
+
return (index == -1) ? -1 : hash->item[index].value;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void hashAdd(hashM hash, const char *key, int val){
|
| 38 |
+
if(!hash){
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
//We do not take non, positive numbers here
|
| 42 |
+
val = abs(val);
|
| 43 |
+
//Modify the value if it exists
|
| 44 |
+
int index = hashFindIndex(hash, key);
|
| 45 |
+
if(index != -1){
|
| 46 |
+
hash->item[index].value = val;
|
| 47 |
+
return;
|
| 48 |
+
}
|
| 49 |
+
//Double the length if we have expended our Resources
|
| 50 |
+
if(hash->len == hash->cap){
|
| 51 |
+
hash->cap *= 2;
|
| 52 |
+
|
| 53 |
+
hash->item = realloc(hash->item, hash->cap * sizeof(hashV));
|
| 54 |
+
}
|
| 55 |
+
//Add new
|
| 56 |
+
hash->item[hash->len].key = strdup(key);
|
| 57 |
+
hash->item[hash->len].value = val;
|
| 58 |
+
hash->len++;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void incramentAdd(hashM hash, const char *key){
|
| 62 |
+
if(!hash){
|
| 63 |
+
return;
|
| 64 |
+
}
|
| 65 |
+
//Modify the value if it exists
|
| 66 |
+
int index = hashFindIndex(hash, key);
|
| 67 |
+
if(index != -1){
|
| 68 |
+
hash->item[index].value += 1;
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
//Double the length if we have expended our Resources
|
| 72 |
+
if(hash->len == hash->cap){
|
| 73 |
+
hash->cap *= 2;
|
| 74 |
+
|
| 75 |
+
hash->item = realloc(hash->item, hash->cap * sizeof(hashV));
|
| 76 |
+
}
|
| 77 |
+
//Add new
|
| 78 |
+
hash->item[hash->len].key = strdup(key);
|
| 79 |
+
hash->item[hash->len].value = 1;
|
| 80 |
+
hash->len++;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
int hashCompare(const void* a, const void* b){
|
| 84 |
+
hashV *ia = (hashV *)a;
|
| 85 |
+
hashV *ib = (hashV *)b;
|
| 86 |
+
return strcmp(ia->key, ib->key);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void hashPrint(hashM hash){
|
| 90 |
+
//Quick sort to order the items a-z
|
| 91 |
+
int size = hash->len;
|
| 92 |
+
qsort(hash->item, size, sizeof(hashV), hashCompare);
|
| 93 |
+
for(int i = 0; i < hash->len; i++){
|
| 94 |
+
printf("%s %d \n", hash->item[i].key, hash->item[i].value);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
hashM newHash(void){
|
| 99 |
+
hashMap newHash ={0, 10, malloc(10 * sizeof(hashV))};
|
| 100 |
+
hashM hashPointer = malloc(sizeof(hashMap));
|
| 101 |
+
*hashPointer = newHash;
|
| 102 |
+
return hashPointer;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
void freeHash(hashM hashPointer){
|
| 106 |
+
//First free the sub-value parts
|
| 107 |
+
for(int i = 0; i < hashPointer->len; i++){
|
| 108 |
+
free((void *) hashPointer->item[i].key);
|
| 109 |
+
}
|
| 110 |
+
//Remove the rest
|
| 111 |
+
free(hashPointer->item);
|
| 112 |
+
free(hashPointer);
|
| 113 |
+
}
|
pool/shard006/C/0117090_rotlet_direct.c
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "mex.h"
|
| 2 |
+
#include "math.h"
|
| 3 |
+
|
| 4 |
+
#define X prhs[0] // Source locations
|
| 5 |
+
#define F prhs[1] // Source strengths
|
| 6 |
+
|
| 7 |
+
#define U plhs[0] // Output
|
| 8 |
+
|
| 9 |
+
#ifndef VERBOSE
|
| 10 |
+
#define VERBOSE 0
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
#define PI 3.141592653589793
|
| 14 |
+
|
| 15 |
+
inline void cross(double * a,double * b, double *c)
|
| 16 |
+
{
|
| 17 |
+
c[0] = a[1]*b[2] - a[2]*b[1];
|
| 18 |
+
c[1] = a[2]*b[0] - a[0]*b[2];
|
| 19 |
+
c[2] = a[0]*b[1] - a[1]*b[0];
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* no input checking is done */
|
| 23 |
+
void mexFunction(int nlhs, mxArray *plhs[],
|
| 24 |
+
int nrhs, const mxArray *prhs[] )
|
| 25 |
+
{
|
| 26 |
+
// input dims
|
| 27 |
+
const int N = mxGetM(X);
|
| 28 |
+
|
| 29 |
+
const double* restrict x = mxGetPr(X);
|
| 30 |
+
const double* restrict f = mxGetPr(F);
|
| 31 |
+
|
| 32 |
+
U = mxCreateDoubleMatrix(N, 3, mxREAL);
|
| 33 |
+
double* restrict u = mxGetPr(U);
|
| 34 |
+
|
| 35 |
+
if(VERBOSE)
|
| 36 |
+
mexPrintf("[FS Rotlet Direct ] MEX N=%d ",N);
|
| 37 |
+
|
| 38 |
+
// call kernel
|
| 39 |
+
#ifdef _OPENMP
|
| 40 |
+
#pragma omp parallel for
|
| 41 |
+
#endif
|
| 42 |
+
for(int m=0; m<N; m++)
|
| 43 |
+
{
|
| 44 |
+
double p[] = {0,0,0};
|
| 45 |
+
double fxr[3];
|
| 46 |
+
for(int n = 0; n<N; n++){
|
| 47 |
+
double fn[] = {f[n], f[n+N], f[n+2*N]};
|
| 48 |
+
double r[] = {x[m]-x[n], x[m+N]-x[n+N],x[m+2*N]-x[n+2*N]};
|
| 49 |
+
|
| 50 |
+
cross(fn,r,fxr);
|
| 51 |
+
double ri = sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]);
|
| 52 |
+
double ri3 = 1.0/(ri*ri*ri);
|
| 53 |
+
|
| 54 |
+
if(m==n)
|
| 55 |
+
continue;
|
| 56 |
+
|
| 57 |
+
p[0] += ri3*fxr[0];
|
| 58 |
+
p[1] += ri3*fxr[1];
|
| 59 |
+
p[2] += ri3*fxr[2];
|
| 60 |
+
}
|
| 61 |
+
u[m ] = p[0];
|
| 62 |
+
u[m+ N] = p[1];
|
| 63 |
+
u[m+2*N] = p[2];
|
| 64 |
+
}
|
| 65 |
+
}
|
pool/shard006/C/0117104_macronix.c
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: GPL-2.0
|
| 2 |
+
/*
|
| 3 |
+
* Copyright (C) 2005, Intec Automation Inc.
|
| 4 |
+
* Copyright (C) 2014, Freescale Semiconductor, Inc.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
#include <linux/mtd/spi-nor.h>
|
| 8 |
+
|
| 9 |
+
#include "core.h"
|
| 10 |
+
|
| 11 |
+
static int
|
| 12 |
+
mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
|
| 13 |
+
const struct sfdp_parameter_header *bfpt_header,
|
| 14 |
+
const struct sfdp_bfpt *bfpt)
|
| 15 |
+
{
|
| 16 |
+
/*
|
| 17 |
+
* MX25L25635F supports 4B opcodes but MX25L25635E does not.
|
| 18 |
+
* Unfortunately, Macronix has re-used the same JEDEC ID for both
|
| 19 |
+
* variants which prevents us from defining a new entry in the parts
|
| 20 |
+
* table.
|
| 21 |
+
* We need a way to differentiate MX25L25635E and MX25L25635F, and it
|
| 22 |
+
* seems that the F version advertises support for Fast Read 4-4-4 in
|
| 23 |
+
* its BFPT table.
|
| 24 |
+
*/
|
| 25 |
+
if (bfpt->dwords[BFPT_DWORD(5)] & BFPT_DWORD5_FAST_READ_4_4_4)
|
| 26 |
+
nor->flags |= SNOR_F_4B_OPCODES;
|
| 27 |
+
|
| 28 |
+
return 0;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
static struct spi_nor_fixups mx25l25635_fixups = {
|
| 32 |
+
.post_bfpt = mx25l25635_post_bfpt_fixups,
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
static const struct flash_info macronix_parts[] = {
|
| 36 |
+
/* Macronix */
|
| 37 |
+
{ "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) },
|
| 38 |
+
{ "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) },
|
| 39 |
+
{ "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) },
|
| 40 |
+
{ "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) },
|
| 41 |
+
{ "mx25l1606e", INFO(0xc22015, 0, 64 * 1024, 32, SECT_4K) },
|
| 42 |
+
{ "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },
|
| 43 |
+
{ "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) },
|
| 44 |
+
{ "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
|
| 45 |
+
{ "mx25u2033e", INFO(0xc22532, 0, 64 * 1024, 4, SECT_4K) },
|
| 46 |
+
{ "mx25u3235f", INFO(0xc22536, 0, 64 * 1024, 64,
|
| 47 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 48 |
+
SPI_NOR_QUAD_READ) },
|
| 49 |
+
{ "mx25u4035", INFO(0xc22533, 0, 64 * 1024, 8, SECT_4K) },
|
| 50 |
+
{ "mx25u8035", INFO(0xc22534, 0, 64 * 1024, 16, SECT_4K) },
|
| 51 |
+
{ "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
|
| 52 |
+
{ "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, SECT_4K) },
|
| 53 |
+
{ "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
|
| 54 |
+
{ "mx25r1635f", INFO(0xc22815, 0, 64 * 1024, 32,
|
| 55 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 56 |
+
SPI_NOR_QUAD_READ) },
|
| 57 |
+
{ "mx25r3235f", INFO(0xc22816, 0, 64 * 1024, 64,
|
| 58 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 59 |
+
SPI_NOR_QUAD_READ) },
|
| 60 |
+
{ "mx25u12835f", INFO(0xc22538, 0, 64 * 1024, 256,
|
| 61 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 62 |
+
SPI_NOR_QUAD_READ) },
|
| 63 |
+
{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512,
|
| 64 |
+
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
|
| 65 |
+
.fixups = &mx25l25635_fixups },
|
| 66 |
+
{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
|
| 67 |
+
SECT_4K | SPI_NOR_4B_OPCODES) },
|
| 68 |
+
{ "mx25u51245g", INFO(0xc2253a, 0, 64 * 1024, 1024,
|
| 69 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 70 |
+
SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
|
| 71 |
+
{ "mx25v8035f", INFO(0xc22314, 0, 64 * 1024, 16,
|
| 72 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 73 |
+
SPI_NOR_QUAD_READ) },
|
| 74 |
+
{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
|
| 75 |
+
{ "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024,
|
| 76 |
+
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
|
| 77 |
+
SPI_NOR_4B_OPCODES) },
|
| 78 |
+
{ "mx66u51235f", INFO(0xc2253a, 0, 64 * 1024, 1024,
|
| 79 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 80 |
+
SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
|
| 81 |
+
{ "mx66l1g45g", INFO(0xc2201b, 0, 64 * 1024, 2048,
|
| 82 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 83 |
+
SPI_NOR_QUAD_READ) },
|
| 84 |
+
{ "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048,
|
| 85 |
+
SPI_NOR_QUAD_READ) },
|
| 86 |
+
{ "mx66u2g45g", INFO(0xc2253c, 0, 64 * 1024, 4096,
|
| 87 |
+
SECT_4K | SPI_NOR_DUAL_READ |
|
| 88 |
+
SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
static void macronix_default_init(struct spi_nor *nor)
|
| 92 |
+
{
|
| 93 |
+
nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
|
| 94 |
+
nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
static const struct spi_nor_fixups macronix_fixups = {
|
| 98 |
+
.default_init = macronix_default_init,
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
const struct spi_nor_manufacturer spi_nor_macronix = {
|
| 102 |
+
.name = "macronix",
|
| 103 |
+
.parts = macronix_parts,
|
| 104 |
+
.nparts = ARRAY_SIZE(macronix_parts),
|
| 105 |
+
.fixups = ¯onix_fixups,
|
| 106 |
+
};
|
pool/shard006/C/0117111_boo.c
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://c-programming-blog.blogspot.com/2015/05/pcre2-simple-sample-program.html
|
| 2 |
+
|
| 3 |
+
#include <stdio.h>
|
| 4 |
+
#include <pcre2.h>
|
| 5 |
+
|
| 6 |
+
int main(int argc, char *argv[]) {
|
| 7 |
+
if(argc < 3) {
|
| 8 |
+
printf("usage: %s pattern string\n", argv[0]);
|
| 9 |
+
return 0;
|
| 10 |
+
}
|
| 11 |
+
pcre2_code *re;
|
| 12 |
+
pcre2_match_data *match_data;
|
| 13 |
+
// size_t erroffset;
|
| 14 |
+
// size_t *ovector;
|
| 15 |
+
PCRE2_SIZE erroffset, *ovector;
|
| 16 |
+
int errorcode;
|
| 17 |
+
int rc;
|
| 18 |
+
PCRE2_SPTR pattern = argv[1];
|
| 19 |
+
PCRE2_SPTR value = argv[2];
|
| 20 |
+
re = pcre2_compile(pattern, -1, 0, &errorcode, &erroffset, NULL);
|
| 21 |
+
if (re == NULL) {
|
| 22 |
+
PCRE2_UCHAR8 buffer[120];
|
| 23 |
+
(void)pcre2_get_error_message(errorcode, buffer, 120);
|
| 24 |
+
/* Handle error */
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
| 27 |
+
match_data = pcre2_match_data_create(20, NULL);
|
| 28 |
+
rc = pcre2_match(re, value, -1, 0, 0, match_data, NULL);
|
| 29 |
+
if (rc <= 0)
|
| 30 |
+
printf("No matchx\n");
|
| 31 |
+
else {
|
| 32 |
+
ovector = pcre2_get_ovector_pointer(match_data);
|
| 33 |
+
printf( "Match succeeded at offset %zu\n", ovector[0] );
|
| 34 |
+
/* Use ovector to get matched strings */
|
| 35 |
+
PCRE2_SIZE i;
|
| 36 |
+
for(i = 0; i < rc; i++) {
|
| 37 |
+
PCRE2_SPTR start = value + ovector[2*i];
|
| 38 |
+
PCRE2_SIZE slen = ovector[2*i+1] - ovector[2*i];
|
| 39 |
+
printf( "%2d: %.*s\n", i, (int)slen, (char *)start );
|
| 40 |
+
break;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
pcre2_match_data_free(match_data);
|
| 44 |
+
pcre2_code_free(re);
|
| 45 |
+
}
|
pool/shard006/C/0117113_stm32f4xx_rng.c
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
******************************************************************************
|
| 3 |
+
* @file stm32f4xx_rng.c
|
| 4 |
+
* @author MCD Application Team
|
| 5 |
+
* @version V1.0.0
|
| 6 |
+
* @date 30-September-2011
|
| 7 |
+
* @brief This file provides firmware functions to manage the following
|
| 8 |
+
* functionalities of the Random Number Generator (RNG) peripheral:
|
| 9 |
+
* - Initialization and Configuration
|
| 10 |
+
* - Get 32 bit Random number
|
| 11 |
+
* - Interrupts and flags management
|
| 12 |
+
*
|
| 13 |
+
* @verbatim
|
| 14 |
+
*
|
| 15 |
+
* ===================================================================
|
| 16 |
+
* How to use this driver
|
| 17 |
+
* ===================================================================
|
| 18 |
+
* 1. Enable The RNG controller clock using
|
| 19 |
+
* RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE) function.
|
| 20 |
+
*
|
| 21 |
+
* 2. Activate the RNG peripheral using RNG_Cmd() function.
|
| 22 |
+
*
|
| 23 |
+
* 3. Wait until the 32 bit Random number Generator contains a valid
|
| 24 |
+
* random data (using polling/interrupt mode). For more details,
|
| 25 |
+
* refer to "Interrupts and flags management functions" module
|
| 26 |
+
* description.
|
| 27 |
+
*
|
| 28 |
+
* 4. Get the 32 bit Random number using RNG_GetRandomNumber() function
|
| 29 |
+
*
|
| 30 |
+
* 5. To get another 32 bit Random number, go to step 3.
|
| 31 |
+
*
|
| 32 |
+
*
|
| 33 |
+
*
|
| 34 |
+
* @endverbatim
|
| 35 |
+
*
|
| 36 |
+
******************************************************************************
|
| 37 |
+
* @attention
|
| 38 |
+
*
|
| 39 |
+
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
| 40 |
+
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
| 41 |
+
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
| 42 |
+
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
| 43 |
+
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
| 44 |
+
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
| 45 |
+
*
|
| 46 |
+
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
| 47 |
+
******************************************************************************
|
| 48 |
+
*/
|
| 49 |
+
|
| 50 |
+
/* Includes ------------------------------------------------------------------*/
|
| 51 |
+
#include "stm32f4xx_rng.h"
|
| 52 |
+
#include "stm32f4xx_rcc.h"
|
| 53 |
+
|
| 54 |
+
/** @addtogroup STM32F4xx_StdPeriph_Driver
|
| 55 |
+
* @{
|
| 56 |
+
*/
|
| 57 |
+
|
| 58 |
+
/** @defgroup RNG
|
| 59 |
+
* @brief RNG driver modules
|
| 60 |
+
* @{
|
| 61 |
+
*/
|
| 62 |
+
|
| 63 |
+
/* Private typedef -----------------------------------------------------------*/
|
| 64 |
+
/* Private define ------------------------------------------------------------*/
|
| 65 |
+
/* Private macro -------------------------------------------------------------*/
|
| 66 |
+
/* Private variables ---------------------------------------------------------*/
|
| 67 |
+
/* Private function prototypes -----------------------------------------------*/
|
| 68 |
+
/* Private functions ---------------------------------------------------------*/
|
| 69 |
+
|
| 70 |
+
/** @defgroup RNG_Private_Functions
|
| 71 |
+
* @{
|
| 72 |
+
*/
|
| 73 |
+
|
| 74 |
+
/** @defgroup RNG_Group1 Initialization and Configuration functions
|
| 75 |
+
* @brief Initialization and Configuration functions
|
| 76 |
+
*
|
| 77 |
+
@verbatim
|
| 78 |
+
===============================================================================
|
| 79 |
+
Initialization and Configuration functions
|
| 80 |
+
===============================================================================
|
| 81 |
+
This section provides functions allowing to
|
| 82 |
+
- Initialize the RNG peripheral
|
| 83 |
+
- Enable or disable the RNG peripheral
|
| 84 |
+
|
| 85 |
+
@endverbatim
|
| 86 |
+
* @{
|
| 87 |
+
*/
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* @brief Deinitializes the RNG peripheral registers to their default reset values.
|
| 91 |
+
* @param None
|
| 92 |
+
* @retval None
|
| 93 |
+
*/
|
| 94 |
+
void RNG_DeInit(void)
|
| 95 |
+
{
|
| 96 |
+
/* Enable RNG reset state */
|
| 97 |
+
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_RNG, ENABLE);
|
| 98 |
+
|
| 99 |
+
/* Release RNG from reset state */
|
| 100 |
+
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_RNG, DISABLE);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* @brief Enables or disables the RNG peripheral.
|
| 105 |
+
* @param NewState: new state of the RNG peripheral.
|
| 106 |
+
* This parameter can be: ENABLE or DISABLE.
|
| 107 |
+
* @retval None
|
| 108 |
+
*/
|
| 109 |
+
void RNG_Cmd(FunctionalState NewState)
|
| 110 |
+
{
|
| 111 |
+
/* Check the parameters */
|
| 112 |
+
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
| 113 |
+
|
| 114 |
+
if (NewState != DISABLE)
|
| 115 |
+
{
|
| 116 |
+
/* Enable the RNG */
|
| 117 |
+
RNG->CR |= RNG_CR_RNGEN;
|
| 118 |
+
}
|
| 119 |
+
else
|
| 120 |
+
{
|
| 121 |
+
/* Disable the RNG */
|
| 122 |
+
RNG->CR &= ~RNG_CR_RNGEN;
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
/**
|
| 126 |
+
* @}
|
| 127 |
+
*/
|
| 128 |
+
|
| 129 |
+
/** @defgroup RNG_Group2 Get 32 bit Random number function
|
| 130 |
+
* @brief Get 32 bit Random number function
|
| 131 |
+
*
|
| 132 |
+
|
| 133 |
+
@verbatim
|
| 134 |
+
===============================================================================
|
| 135 |
+
Get 32 bit Random number function
|
| 136 |
+
===============================================================================
|
| 137 |
+
This section provides a function allowing to get the 32 bit Random number
|
| 138 |
+
|
| 139 |
+
@note Before to call this function you have to wait till DRDY flag is set,
|
| 140 |
+
using RNG_GetFlagStatus(RNG_FLAG_DRDY) function.
|
| 141 |
+
|
| 142 |
+
@endverbatim
|
| 143 |
+
* @{
|
| 144 |
+
*/
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* @brief Returns a 32-bit random number.
|
| 149 |
+
*
|
| 150 |
+
* @note Before to call this function you have to wait till DRDY (data ready)
|
| 151 |
+
* flag is set, using RNG_GetFlagStatus(RNG_FLAG_DRDY) function.
|
| 152 |
+
* @note Each time the the Random number data is read (using RNG_GetRandomNumber()
|
| 153 |
+
* function), the RNG_FLAG_DRDY flag is automatically cleared.
|
| 154 |
+
* @note In the case of a seed error, the generation of random numbers is
|
| 155 |
+
* interrupted for as long as the SECS bit is '1'. If a number is
|
| 156 |
+
* available in the RNG_DR register, it must not be used because it may
|
| 157 |
+
* not have enough entropy. In this case, it is recommended to clear the
|
| 158 |
+
* SEIS bit(using RNG_ClearFlag(RNG_FLAG_SECS) function), then disable
|
| 159 |
+
* and enable the RNG peripheral (using RNG_Cmd() function) to
|
| 160 |
+
* reinitialize and restart the RNG.
|
| 161 |
+
* @note In the case of a clock error, the RNG is no more able to generate
|
| 162 |
+
* random numbers because the PLL48CLK clock is not correct. User have
|
| 163 |
+
* to check that the clock controller is correctly configured to provide
|
| 164 |
+
* the RNG clock and clear the CEIS bit (using RNG_ClearFlag(RNG_FLAG_CECS)
|
| 165 |
+
* function) . The clock error has no impact on the previously generated
|
| 166 |
+
* random numbers, and the RNG_DR register contents can be used.
|
| 167 |
+
*
|
| 168 |
+
* @param None
|
| 169 |
+
* @retval 32-bit random number.
|
| 170 |
+
*/
|
| 171 |
+
uint32_t RNG_GetRandomNumber(void)
|
| 172 |
+
{
|
| 173 |
+
/* Return the 32 bit random number from the DR register */
|
| 174 |
+
return RNG->DR;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* @}
|
| 180 |
+
*/
|
| 181 |
+
|
| 182 |
+
/** @defgroup RNG_Group3 Interrupts and flags management functions
|
| 183 |
+
* @brief Interrupts and flags management functions
|
| 184 |
+
*
|
| 185 |
+
@verbatim
|
| 186 |
+
===============================================================================
|
| 187 |
+
Interrupts and flags management functions
|
| 188 |
+
===============================================================================
|
| 189 |
+
|
| 190 |
+
This section provides functions allowing to configure the RNG Interrupts and
|
| 191 |
+
to get the status and clear flags and Interrupts pending bits.
|
| 192 |
+
|
| 193 |
+
The RNG provides 3 Interrupts sources and 3 Flags:
|
| 194 |
+
|
| 195 |
+
Flags :
|
| 196 |
+
----------
|
| 197 |
+
1. RNG_FLAG_DRDY : In the case of the RNG_DR register contains valid
|
| 198 |
+
random data. it is cleared by reading the valid data
|
| 199 |
+
(using RNG_GetRandomNumber() function).
|
| 200 |
+
|
| 201 |
+
2. RNG_FLAG_CECS : In the case of a seed error detection.
|
| 202 |
+
|
| 203 |
+
3. RNG_FLAG_SECS : In the case of a clock error detection.
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
Interrupts :
|
| 207 |
+
------------
|
| 208 |
+
if enabled, an RNG interrupt is pending :
|
| 209 |
+
|
| 210 |
+
1. In the case of the RNG_DR register contains valid random data.
|
| 211 |
+
This interrupt source is cleared once the RNG_DR register has been read
|
| 212 |
+
(using RNG_GetRandomNumber() function) until a new valid value is
|
| 213 |
+
computed.
|
| 214 |
+
|
| 215 |
+
or
|
| 216 |
+
2. In the case of a seed error : One of the following faulty sequences has
|
| 217 |
+
been detected:
|
| 218 |
+
- More than 64 consecutive bits at the same value (0 or 1)
|
| 219 |
+
- More than 32 consecutive alternance of 0 and 1 (0101010101...01)
|
| 220 |
+
This interrupt source is cleared using RNG_ClearITPendingBit(RNG_IT_SEI)
|
| 221 |
+
function.
|
| 222 |
+
|
| 223 |
+
or
|
| 224 |
+
3. In the case of a clock error : the PLL48CLK (RNG peripheral clock source)
|
| 225 |
+
was not correctly detected (fPLL48CLK< fHCLK/16).
|
| 226 |
+
This interrupt source is cleared using RNG_ClearITPendingBit(RNG_IT_CEI)
|
| 227 |
+
function.
|
| 228 |
+
@note In this case, User have to check that the clock controller is
|
| 229 |
+
correctly configured to provide the RNG clock.
|
| 230 |
+
|
| 231 |
+
Managing the RNG controller events :
|
| 232 |
+
------------------------------------
|
| 233 |
+
The user should identify which mode will be used in his application to manage
|
| 234 |
+
the RNG controller events: Polling mode or Interrupt mode.
|
| 235 |
+
|
| 236 |
+
1. In the Polling Mode it is advised to use the following functions:
|
| 237 |
+
- RNG_GetFlagStatus() : to check if flags events occur.
|
| 238 |
+
- RNG_ClearFlag() : to clear the flags events.
|
| 239 |
+
|
| 240 |
+
@note RNG_FLAG_DRDY can not be cleared by RNG_ClearFlag(). it is cleared only
|
| 241 |
+
by reading the Random number data.
|
| 242 |
+
|
| 243 |
+
2. In the Interrupt Mode it is advised to use the following functions:
|
| 244 |
+
- RNG_ITConfig() : to enable or disable the interrupt source.
|
| 245 |
+
- RNG_GetITStatus() : to check if Interrupt occurs.
|
| 246 |
+
- RNG_ClearITPendingBit() : to clear the Interrupt pending Bit
|
| 247 |
+
(corresponding Flag).
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
@endverbatim
|
| 251 |
+
* @{
|
| 252 |
+
*/
|
| 253 |
+
|
| 254 |
+
/**
|
| 255 |
+
* @brief Enables or disables the RNG interrupt.
|
| 256 |
+
* @note The RNG provides 3 interrupt sources,
|
| 257 |
+
* - Computed data is ready event (DRDY), and
|
| 258 |
+
* - Seed error Interrupt (SEI) and
|
| 259 |
+
* - Clock error Interrupt (CEI),
|
| 260 |
+
* all these interrupts sources are enabled by setting the IE bit in
|
| 261 |
+
* CR register. However, each interrupt have its specific status bit
|
| 262 |
+
* (see RNG_GetITStatus() function) and clear bit except the DRDY event
|
| 263 |
+
* (see RNG_ClearITPendingBit() function).
|
| 264 |
+
* @param NewState: new state of the RNG interrupt.
|
| 265 |
+
* This parameter can be: ENABLE or DISABLE.
|
| 266 |
+
* @retval None
|
| 267 |
+
*/
|
| 268 |
+
void RNG_ITConfig(FunctionalState NewState)
|
| 269 |
+
{
|
| 270 |
+
/* Check the parameters */
|
| 271 |
+
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
| 272 |
+
|
| 273 |
+
if (NewState != DISABLE)
|
| 274 |
+
{
|
| 275 |
+
/* Enable the RNG interrupt */
|
| 276 |
+
RNG->CR |= RNG_CR_IE;
|
| 277 |
+
}
|
| 278 |
+
else
|
| 279 |
+
{
|
| 280 |
+
/* Disable the RNG interrupt */
|
| 281 |
+
RNG->CR &= ~RNG_CR_IE;
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/**
|
| 286 |
+
* @brief Checks whether the specified RNG flag is set or not.
|
| 287 |
+
* @param RNG_FLAG: specifies the RNG flag to check.
|
| 288 |
+
* This parameter can be one of the following values:
|
| 289 |
+
* @arg RNG_FLAG_DRDY: Data Ready flag.
|
| 290 |
+
* @arg RNG_FLAG_CECS: Clock Error Current flag.
|
| 291 |
+
* @arg RNG_FLAG_SECS: Seed Error Current flag.
|
| 292 |
+
* @retval The new state of RNG_FLAG (SET or RESET).
|
| 293 |
+
*/
|
| 294 |
+
FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG)
|
| 295 |
+
{
|
| 296 |
+
FlagStatus bitstatus = RESET;
|
| 297 |
+
/* Check the parameters */
|
| 298 |
+
assert_param(IS_RNG_GET_FLAG(RNG_FLAG));
|
| 299 |
+
|
| 300 |
+
/* Check the status of the specified RNG flag */
|
| 301 |
+
if ((RNG->SR & RNG_FLAG) != (uint8_t)RESET)
|
| 302 |
+
{
|
| 303 |
+
/* RNG_FLAG is set */
|
| 304 |
+
bitstatus = SET;
|
| 305 |
+
}
|
| 306 |
+
else
|
| 307 |
+
{
|
| 308 |
+
/* RNG_FLAG is reset */
|
| 309 |
+
bitstatus = RESET;
|
| 310 |
+
}
|
| 311 |
+
/* Return the RNG_FLAG status */
|
| 312 |
+
return bitstatus;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* @brief Clears the RNG flags.
|
| 318 |
+
* @param RNG_FLAG: specifies the flag to clear.
|
| 319 |
+
* This parameter can be any combination of the following values:
|
| 320 |
+
* @arg RNG_FLAG_CECS: Clock Error Current flag.
|
| 321 |
+
* @arg RNG_FLAG_SECS: Seed Error Current flag.
|
| 322 |
+
* @note RNG_FLAG_DRDY can not be cleared by RNG_ClearFlag() function.
|
| 323 |
+
* This flag is cleared only by reading the Random number data (using
|
| 324 |
+
* RNG_GetRandomNumber() function).
|
| 325 |
+
* @retval None
|
| 326 |
+
*/
|
| 327 |
+
void RNG_ClearFlag(uint8_t RNG_FLAG)
|
| 328 |
+
{
|
| 329 |
+
/* Check the parameters */
|
| 330 |
+
assert_param(IS_RNG_CLEAR_FLAG(RNG_FLAG));
|
| 331 |
+
/* Clear the selected RNG flags */
|
| 332 |
+
RNG->SR = ~(uint32_t)(((uint32_t)RNG_FLAG) << 4);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
/**
|
| 336 |
+
* @brief Checks whether the specified RNG interrupt has occurred or not.
|
| 337 |
+
* @param RNG_IT: specifies the RNG interrupt source to check.
|
| 338 |
+
* This parameter can be one of the following values:
|
| 339 |
+
* @arg RNG_IT_CEI: Clock Error Interrupt.
|
| 340 |
+
* @arg RNG_IT_SEI: Seed Error Interrupt.
|
| 341 |
+
* @retval The new state of RNG_IT (SET or RESET).
|
| 342 |
+
*/
|
| 343 |
+
ITStatus RNG_GetITStatus(uint8_t RNG_IT)
|
| 344 |
+
{
|
| 345 |
+
ITStatus bitstatus = RESET;
|
| 346 |
+
/* Check the parameters */
|
| 347 |
+
assert_param(IS_RNG_GET_IT(RNG_IT));
|
| 348 |
+
|
| 349 |
+
/* Check the status of the specified RNG interrupt */
|
| 350 |
+
if ((RNG->SR & RNG_IT) != (uint8_t)RESET)
|
| 351 |
+
{
|
| 352 |
+
/* RNG_IT is set */
|
| 353 |
+
bitstatus = SET;
|
| 354 |
+
}
|
| 355 |
+
else
|
| 356 |
+
{
|
| 357 |
+
/* RNG_IT is reset */
|
| 358 |
+
bitstatus = RESET;
|
| 359 |
+
}
|
| 360 |
+
/* Return the RNG_IT status */
|
| 361 |
+
return bitstatus;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
/**
|
| 366 |
+
* @brief Clears the RNG interrupt pending bit(s).
|
| 367 |
+
* @param RNG_IT: specifies the RNG interrupt pending bit(s) to clear.
|
| 368 |
+
* This parameter can be any combination of the following values:
|
| 369 |
+
* @arg RNG_IT_CEI: Clock Error Interrupt.
|
| 370 |
+
* @arg RNG_IT_SEI: Seed Error Interrupt.
|
| 371 |
+
* @retval None
|
| 372 |
+
*/
|
| 373 |
+
void RNG_ClearITPendingBit(uint8_t RNG_IT)
|
| 374 |
+
{
|
| 375 |
+
/* Check the parameters */
|
| 376 |
+
assert_param(IS_RNG_IT(RNG_IT));
|
| 377 |
+
|
| 378 |
+
/* Clear the selected RNG interrupt pending bit */
|
| 379 |
+
RNG->SR = (uint8_t)~RNG_IT;
|
| 380 |
+
}
|
| 381 |
+
/**
|
| 382 |
+
* @}
|
| 383 |
+
*/
|
| 384 |
+
|
| 385 |
+
/**
|
| 386 |
+
* @}
|
| 387 |
+
*/
|
| 388 |
+
|
| 389 |
+
/**
|
| 390 |
+
* @}
|
| 391 |
+
*/
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
/**
|
| 395 |
+
* @}
|
| 396 |
+
*/
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
pool/shard006/C/0117118_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52a.c
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52a.c
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.string.label.xml
|
| 4 |
+
Template File: sources-sink-52a.tmpl.c
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Allocate using malloc() and set data pointer to a small buffer
|
| 10 |
+
* GoodSource: Allocate using malloc() and set data pointer to a large buffer
|
| 11 |
+
* Sink: snprintf
|
| 12 |
+
* BadSink : Copy string to data using snprintf
|
| 13 |
+
* Flow Variant: 52 Data flow: data passed as an argument from one function to another to another in three different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#include <wchar.h>
|
| 20 |
+
|
| 21 |
+
#ifdef _WIN32
|
| 22 |
+
#define SNPRINTF _snwprintf
|
| 23 |
+
#else
|
| 24 |
+
#define SNPRINTF snprintf
|
| 25 |
+
#endif
|
| 26 |
+
|
| 27 |
+
#ifndef OMITBAD
|
| 28 |
+
|
| 29 |
+
/* bad function declaration */
|
| 30 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52b_badSink(wchar_t * data);
|
| 31 |
+
|
| 32 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52_bad()
|
| 33 |
+
{
|
| 34 |
+
wchar_t * data;
|
| 35 |
+
data = NULL;
|
| 36 |
+
/* FLAW: Allocate and point data to a small buffer that is smaller than the large buffer used in the sinks */
|
| 37 |
+
data = (wchar_t *)malloc(50*sizeof(wchar_t));
|
| 38 |
+
if (data == NULL) {exit(-1);}
|
| 39 |
+
data[0] = L'\0'; /* null terminate */
|
| 40 |
+
CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52b_badSink(data);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
#endif /* OMITBAD */
|
| 44 |
+
|
| 45 |
+
#ifndef OMITGOOD
|
| 46 |
+
|
| 47 |
+
/* good function declaration */
|
| 48 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52b_goodG2BSink(wchar_t * data);
|
| 49 |
+
|
| 50 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 51 |
+
static void goodG2B()
|
| 52 |
+
{
|
| 53 |
+
wchar_t * data;
|
| 54 |
+
data = NULL;
|
| 55 |
+
/* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */
|
| 56 |
+
data = (wchar_t *)malloc(100*sizeof(wchar_t));
|
| 57 |
+
if (data == NULL) {exit(-1);}
|
| 58 |
+
data[0] = L'\0'; /* null terminate */
|
| 59 |
+
CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52b_goodG2BSink(data);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52_good()
|
| 63 |
+
{
|
| 64 |
+
goodG2B();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
#endif /* OMITGOOD */
|
| 68 |
+
|
| 69 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 70 |
+
* its own for testing or for building a binary to use in testing binary
|
| 71 |
+
* analysis tools. It is not used when compiling all the testcases as one
|
| 72 |
+
* application, which is how source code analysis tools are tested.
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
#ifdef INCLUDEMAIN
|
| 76 |
+
|
| 77 |
+
int main(int argc, char * argv[])
|
| 78 |
+
{
|
| 79 |
+
/* seed randomness */
|
| 80 |
+
srand( (unsigned)time(NULL) );
|
| 81 |
+
#ifndef OMITGOOD
|
| 82 |
+
printLine("Calling good()...");
|
| 83 |
+
CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52_good();
|
| 84 |
+
printLine("Finished good()");
|
| 85 |
+
#endif /* OMITGOOD */
|
| 86 |
+
#ifndef OMITBAD
|
| 87 |
+
printLine("Calling bad()...");
|
| 88 |
+
CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_snprintf_52_bad();
|
| 89 |
+
printLine("Finished bad()");
|
| 90 |
+
#endif /* OMITBAD */
|
| 91 |
+
return 0;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#endif
|
pool/shard006/C/0117122_dht22.c
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* ----------------------------------------------------------------------------
|
| 3 |
+
* "THE BEER-WARE LICENSE" (Revision 42):
|
| 4 |
+
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you
|
| 5 |
+
* retain
|
| 6 |
+
* this notice you can do whatever you want with this stuff. If we meet some
|
| 7 |
+
* day,
|
| 8 |
+
* and you think this stuff is worth it, you can buy me a beer in return.
|
| 9 |
+
* ----------------------------------------------------------------------------
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include "ets_sys.h"
|
| 13 |
+
#include "osapi.h"
|
| 14 |
+
#include "espmissingincludes.h"
|
| 15 |
+
#include "c_types.h"
|
| 16 |
+
#include "user_interface.h"
|
| 17 |
+
#include "espconn.h"
|
| 18 |
+
#include "mem.h"
|
| 19 |
+
#include "gpio.h"
|
| 20 |
+
#include "dht.h"
|
| 21 |
+
|
| 22 |
+
#define MAXTIMINGS 10000
|
| 23 |
+
#define DHT_MAXCOUNT 32000
|
| 24 |
+
#define BREAKTIME 32
|
| 25 |
+
|
| 26 |
+
#define DHT_PIN 2
|
| 27 |
+
|
| 28 |
+
enum sensor_type SENSOR;
|
| 29 |
+
|
| 30 |
+
static inline float scale_humidity(int *data) {
|
| 31 |
+
if (SENSOR == SENSOR_DHT11) {
|
| 32 |
+
return data[0];
|
| 33 |
+
} else {
|
| 34 |
+
float humidity = data[0] * 256 + data[1];
|
| 35 |
+
return humidity /= 10;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
static inline float scale_temperature(int *data) {
|
| 40 |
+
if (SENSOR == SENSOR_DHT11) {
|
| 41 |
+
return data[2];
|
| 42 |
+
} else {
|
| 43 |
+
float temperature = data[2] & 0x7f;
|
| 44 |
+
temperature *= 256;
|
| 45 |
+
temperature += data[3];
|
| 46 |
+
temperature /= 10;
|
| 47 |
+
if (data[2] & 0x80)
|
| 48 |
+
temperature *= -1;
|
| 49 |
+
return temperature;
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
static inline void delay_ms(int sleep) {
|
| 54 |
+
os_delay_us(1000 * sleep);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static struct sensor_reading reading = {
|
| 58 |
+
.source = "DHT11", .success = 0
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
Originally from: http://harizanov.com/2014/11/esp8266-powered-web-server-led-control-dht22-temperaturehumidity-sensor-reading/
|
| 66 |
+
Adapted from: https://github.com/adafruit/Adafruit_Python_DHT/blob/master/source/Raspberry_Pi/pi_dht_read.c
|
| 67 |
+
LICENSE:
|
| 68 |
+
// Copyright (c) 2014 Adafruit Industries
|
| 69 |
+
// Author: Tony DiCola
|
| 70 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 71 |
+
// of this software and associated documentation files (the "Software"), to deal
|
| 72 |
+
// in the Software without restriction, including without limitation the rights
|
| 73 |
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 74 |
+
// copies of the Software, and to permit persons to whom the Software is
|
| 75 |
+
// furnished to do so, subject to the following conditions:
|
| 76 |
+
// The above copyright notice and this permission notice shall be included in all
|
| 77 |
+
// copies or substantial portions of the Software.
|
| 78 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 79 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 80 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 81 |
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 82 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 83 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 84 |
+
// SOFTWARE.
|
| 85 |
+
*/
|
| 86 |
+
static void ICACHE_FLASH_ATTR pollDHTCb(void * arg){
|
| 87 |
+
int counter = 0;
|
| 88 |
+
int laststate = 1;
|
| 89 |
+
int i = 0;
|
| 90 |
+
int bits_in = 0;
|
| 91 |
+
// int bitidx = 0;
|
| 92 |
+
// int bits[250];
|
| 93 |
+
|
| 94 |
+
int data[100];
|
| 95 |
+
|
| 96 |
+
data[0] = data[1] = data[2] = data[3] = data[4] = 0;
|
| 97 |
+
|
| 98 |
+
//disable interrupts, start of critical section
|
| 99 |
+
os_intr_lock();
|
| 100 |
+
wdt_feed();
|
| 101 |
+
// Wake up device, 250ms of high
|
| 102 |
+
GPIO_OUTPUT_SET(DHT_PIN, 1);
|
| 103 |
+
delay_ms(20);
|
| 104 |
+
|
| 105 |
+
// Hold low for 20ms
|
| 106 |
+
GPIO_OUTPUT_SET(DHT_PIN, 0);
|
| 107 |
+
delay_ms(20);
|
| 108 |
+
|
| 109 |
+
// High for 40ms
|
| 110 |
+
// GPIO_OUTPUT_SET(2, 1);
|
| 111 |
+
|
| 112 |
+
GPIO_DIS_OUTPUT(DHT_PIN);
|
| 113 |
+
os_delay_us(40);
|
| 114 |
+
|
| 115 |
+
// Set pin to input with pullup
|
| 116 |
+
// PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
|
| 117 |
+
|
| 118 |
+
// os_printf("Waiting for gpio2 to drop \n");
|
| 119 |
+
|
| 120 |
+
// wait for pin to drop?
|
| 121 |
+
while (GPIO_INPUT_GET(DHT_PIN) == 1 && i < DHT_MAXCOUNT) {
|
| 122 |
+
if (i >= DHT_MAXCOUNT) {
|
| 123 |
+
goto fail;
|
| 124 |
+
}
|
| 125 |
+
i++;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// os_printf("Reading DHT\n");
|
| 129 |
+
|
| 130 |
+
// read data!
|
| 131 |
+
for (i = 0; i < MAXTIMINGS; i++) {
|
| 132 |
+
// Count high time (in approx us)
|
| 133 |
+
counter = 0;
|
| 134 |
+
while (GPIO_INPUT_GET(DHT_PIN) == laststate) {
|
| 135 |
+
counter++;
|
| 136 |
+
os_delay_us(1);
|
| 137 |
+
if (counter == 1000)
|
| 138 |
+
break;
|
| 139 |
+
}
|
| 140 |
+
laststate = GPIO_INPUT_GET(DHT_PIN);
|
| 141 |
+
|
| 142 |
+
if (counter == 1000)
|
| 143 |
+
break;
|
| 144 |
+
|
| 145 |
+
// store data after 3 reads
|
| 146 |
+
if ((i > 3) && (i % 2 == 0)) {
|
| 147 |
+
// shove each bit into the storage bytes
|
| 148 |
+
data[bits_in / 8] <<= 1;
|
| 149 |
+
if (counter > BREAKTIME) {
|
| 150 |
+
//os_printf("1");
|
| 151 |
+
data[bits_in / 8] |= 1;
|
| 152 |
+
} else {
|
| 153 |
+
//os_printf("0");
|
| 154 |
+
}
|
| 155 |
+
bits_in++;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
//Re-enable interrupts, end of critical section
|
| 160 |
+
os_intr_unlock();
|
| 161 |
+
|
| 162 |
+
if (bits_in < 40) {
|
| 163 |
+
os_printf("Got too few bits: %d should be at least 40", bits_in);
|
| 164 |
+
goto fail;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
int checksum = (data[0] + data[1] + data[2] + data[3]) & 0xFF;
|
| 169 |
+
|
| 170 |
+
os_printf("DHT: %02x %02x %02x %02x [%02x] CS: %02x\n", data[0], data[1],data[2],data[3],data[4],checksum);
|
| 171 |
+
|
| 172 |
+
if (data[4] != checksum) {
|
| 173 |
+
os_printf("Checksum was incorrect after %d bits. Expected %d but got %d",
|
| 174 |
+
bits_in, data[4], checksum);
|
| 175 |
+
goto fail;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
reading.temperature = scale_temperature(data);
|
| 179 |
+
reading.humidity = scale_humidity(data);
|
| 180 |
+
os_printf("Temp = %d *C, Hum = %d %%\n", (int)(reading.temperature),
|
| 181 |
+
(int)(reading.humidity));
|
| 182 |
+
|
| 183 |
+
reading.success = 1;
|
| 184 |
+
return;
|
| 185 |
+
fail:
|
| 186 |
+
|
| 187 |
+
os_printf("Failed to get reading, dying\n");
|
| 188 |
+
reading.success = 0;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
struct sensor_reading *ICACHE_FLASH_ATTR readDHT(int force) {
|
| 192 |
+
if(force){
|
| 193 |
+
pollDHTCb(NULL);
|
| 194 |
+
}
|
| 195 |
+
return &reading;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
void ICACHE_FLASH_ATTR DHTInit(enum sensor_type sensor_type, uint32_t polltime) {
|
| 199 |
+
SENSOR = sensor_type;
|
| 200 |
+
// Set GPIO2 to output mode for DHT22
|
| 201 |
+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
|
| 202 |
+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
|
| 203 |
+
//PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
|
| 204 |
+
|
| 205 |
+
os_printf("DHT Setup for type %d, poll interval of %d\n", sensor_type, (int)polltime);
|
| 206 |
+
|
| 207 |
+
static ETSTimer dhtTimer;
|
| 208 |
+
os_timer_setfn(&dhtTimer, pollDHTCb, NULL);
|
| 209 |
+
os_timer_arm(&dhtTimer, polltime, 1);
|
| 210 |
+
}
|
pool/shard006/C/0117136_pthread_exit.c
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <pthread.h>
|
| 4 |
+
#include <unistd.h>
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
void *func1(void *arg)
|
| 8 |
+
{
|
| 9 |
+
int i = 0;
|
| 10 |
+
static char buf[] = "hello";
|
| 11 |
+
for (i = 0;i < 5;i++)
|
| 12 |
+
{
|
| 13 |
+
printf("in func1\n");
|
| 14 |
+
sleep(1);
|
| 15 |
+
if (i == 3)
|
| 16 |
+
{
|
| 17 |
+
pthread_exit((void *)buf);
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
int main(int argc, char *argv[])
|
| 23 |
+
{
|
| 24 |
+
int *save = NULL;
|
| 25 |
+
pthread_t tid;
|
| 26 |
+
|
| 27 |
+
pthread_create(&tid,NULL,func1,NULL);
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
pthread_join(tid,((void*)&save));
|
| 31 |
+
|
| 32 |
+
printf("%s\n",((char *)save));
|
| 33 |
+
return 0;
|
| 34 |
+
}
|
pool/shard006/C/0117143_pr67790.c
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* { dg-require-effective-target vect_int } */
|
| 2 |
+
|
| 3 |
+
#include "tree-vect.h"
|
| 4 |
+
|
| 5 |
+
struct {
|
| 6 |
+
int x_advance;
|
| 7 |
+
int y_advance;
|
| 8 |
+
} a[256];
|
| 9 |
+
|
| 10 |
+
int b, c;
|
| 11 |
+
|
| 12 |
+
void __attribute__((noinline,noclone)) fn1()
|
| 13 |
+
{
|
| 14 |
+
for (int i = 0; i < 256; i++)
|
| 15 |
+
{
|
| 16 |
+
c -= a[i].x_advance;
|
| 17 |
+
b -= a[i].y_advance;
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
int main()
|
| 22 |
+
{
|
| 23 |
+
check_vect ();
|
| 24 |
+
|
| 25 |
+
for (int i = 0; i < 256; ++i)
|
| 26 |
+
{
|
| 27 |
+
a[i].x_advance = i;
|
| 28 |
+
a[i].y_advance = -i + 3;
|
| 29 |
+
__asm__ volatile ("" : : : "memory");
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
fn1();
|
| 33 |
+
|
| 34 |
+
if (c != -32640 || b != 31872)
|
| 35 |
+
abort ();
|
| 36 |
+
|
| 37 |
+
return 0;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/* { dg-final { scan-tree-dump "vectorizing stmts using SLP" "vect" } } */
|
| 41 |
+
/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 0 "vect" } } */
|
pool/shard006/C/0117153_mkdepend.c
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <stdlib.h>
|
| 3 |
+
#include <string.h>
|
| 4 |
+
#include <errno.h>
|
| 5 |
+
|
| 6 |
+
#define ObjExtension ".o"
|
| 7 |
+
|
| 8 |
+
static char *getobj(const char *pSrc)
|
| 9 |
+
{
|
| 10 |
+
static char buffer[255];
|
| 11 |
+
int l = strlen(pSrc);
|
| 12 |
+
char *pSearch;
|
| 13 |
+
|
| 14 |
+
if (l < sizeof(buffer) - 5)
|
| 15 |
+
l = sizeof(buffer) - 5;
|
| 16 |
+
memcpy(buffer, pSrc, l); buffer[l] = '\0';
|
| 17 |
+
|
| 18 |
+
pSearch = strrchr(buffer, '.');
|
| 19 |
+
if (pSearch)
|
| 20 |
+
strcpy(pSearch, ObjExtension);
|
| 21 |
+
|
| 22 |
+
return buffer;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
int main(int argc, char **argv)
|
| 26 |
+
{
|
| 27 |
+
int z, l;
|
| 28 |
+
FILE *pFile, *pDestFile;
|
| 29 |
+
char line[512], *pCmd, *pName, *pDestFileName = NULL;
|
| 30 |
+
char used[1024];
|
| 31 |
+
|
| 32 |
+
if (argc < 2)
|
| 33 |
+
{
|
| 34 |
+
fprintf(stderr, "usage: %s [args] <file(s)>\n", *argv);
|
| 35 |
+
exit(1);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
memset(used, 0, sizeof(used));
|
| 39 |
+
|
| 40 |
+
for (z = 1; z < argc; z++)
|
| 41 |
+
if ((!used[z]) && (*argv[z] == '-'))
|
| 42 |
+
{
|
| 43 |
+
used[z] = 1;
|
| 44 |
+
if (!strcmp(argv[z] + 1, "o"))
|
| 45 |
+
{
|
| 46 |
+
if (z >= argc - 1)
|
| 47 |
+
pDestFileName = NULL;
|
| 48 |
+
else
|
| 49 |
+
{
|
| 50 |
+
pDestFileName = argv[z + 1];
|
| 51 |
+
used[z + 1] = 1;
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if (pDestFileName)
|
| 57 |
+
{
|
| 58 |
+
pDestFile = fopen(pDestFileName, "w");
|
| 59 |
+
if (!pDestFile)
|
| 60 |
+
{
|
| 61 |
+
perror(pDestFileName);
|
| 62 |
+
exit(errno);
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
else
|
| 66 |
+
pDestFile = stdout;
|
| 67 |
+
|
| 68 |
+
fprintf(pDestFile, "# auto-generated by %s - do not edit\n\n", *argv);
|
| 69 |
+
|
| 70 |
+
for (z = 1; z < argc; z++)
|
| 71 |
+
{
|
| 72 |
+
if (used[z])
|
| 73 |
+
continue;
|
| 74 |
+
|
| 75 |
+
fprintf(pDestFile, "%s:", getobj(argv[z]));
|
| 76 |
+
|
| 77 |
+
pFile = fopen(argv[z], "r");
|
| 78 |
+
if (!pFile)
|
| 79 |
+
{
|
| 80 |
+
perror(argv[z]);
|
| 81 |
+
exit(errno);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
while (!feof(pFile))
|
| 85 |
+
{
|
| 86 |
+
fgets(line, sizeof(line), pFile);
|
| 87 |
+
l = strlen(line);
|
| 88 |
+
if ((l > 0) && (line[l - 1] == '\n'))
|
| 89 |
+
line[l - 1] = '\0';
|
| 90 |
+
|
| 91 |
+
if (*line != '#')
|
| 92 |
+
continue;
|
| 93 |
+
pCmd = strtok(line + 1, " \t");
|
| 94 |
+
if (strcmp(pCmd, "include"))
|
| 95 |
+
continue;
|
| 96 |
+
|
| 97 |
+
pName = strtok(NULL, " \t");
|
| 98 |
+
if (!pName)
|
| 99 |
+
continue;
|
| 100 |
+
l = strlen(pName);
|
| 101 |
+
if ((*pName != '"') || (pName[l - 1] != '"'))
|
| 102 |
+
continue;
|
| 103 |
+
|
| 104 |
+
fprintf(pDestFile, " %*.*s", l - 2, l - 2, pName + 1);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
fclose(pFile);
|
| 108 |
+
|
| 109 |
+
fprintf(pDestFile, "\n\n");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if (pDestFileName)
|
| 113 |
+
{
|
| 114 |
+
fprintf(pDestFile, "%s:", pDestFileName);
|
| 115 |
+
for (z = 1; z < argc; z++)
|
| 116 |
+
if (!used[z])
|
| 117 |
+
fprintf(pDestFile, " %s", argv[z]);
|
| 118 |
+
fprintf(pDestFile, "\n");
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return 0;
|
| 122 |
+
}
|
pool/shard006/C/0117158_gl_hwdec_vdpau.c
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* This file is part of mpv.
|
| 3 |
+
*
|
| 4 |
+
* mpv is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU General Public License as published by
|
| 6 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* mpv is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License along
|
| 15 |
+
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include <stddef.h>
|
| 19 |
+
#include <assert.h>
|
| 20 |
+
|
| 21 |
+
#include <GL/glx.h>
|
| 22 |
+
|
| 23 |
+
#include "gl_hwdec.h"
|
| 24 |
+
#include "gl_utils.h"
|
| 25 |
+
#include "video/vdpau.h"
|
| 26 |
+
#include "video/vdpau_mixer.h"
|
| 27 |
+
|
| 28 |
+
// This is a GL_NV_vdpau_interop specification bug, and headers (unfortunately)
|
| 29 |
+
// follow it. I'm not sure about the original nvidia headers.
|
| 30 |
+
#define BRAINDEATH(x) ((void *)(uintptr_t)(x))
|
| 31 |
+
|
| 32 |
+
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params);
|
| 33 |
+
|
| 34 |
+
struct priv {
|
| 35 |
+
struct mp_log *log;
|
| 36 |
+
struct mp_vdpau_ctx *ctx;
|
| 37 |
+
uint64_t preemption_counter;
|
| 38 |
+
struct mp_image_params image_params;
|
| 39 |
+
GLuint gl_texture;
|
| 40 |
+
GLvdpauSurfaceNV vdpgl_surface;
|
| 41 |
+
VdpOutputSurface vdp_surface;
|
| 42 |
+
struct mp_vdpau_mixer *mixer;
|
| 43 |
+
bool mapped;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
static void mark_vdpau_objects_uninitialized(struct gl_hwdec *hw)
|
| 47 |
+
{
|
| 48 |
+
struct priv *p = hw->priv;
|
| 49 |
+
|
| 50 |
+
p->vdp_surface = VDP_INVALID_HANDLE;
|
| 51 |
+
p->mixer->video_mixer = VDP_INVALID_HANDLE;
|
| 52 |
+
p->mapped = false;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static void destroy_objects(struct gl_hwdec *hw)
|
| 56 |
+
{
|
| 57 |
+
struct priv *p = hw->priv;
|
| 58 |
+
GL *gl = hw->gl;
|
| 59 |
+
struct vdp_functions *vdp = &p->ctx->vdp;
|
| 60 |
+
VdpStatus vdp_st;
|
| 61 |
+
|
| 62 |
+
if (p->mapped)
|
| 63 |
+
gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
|
| 64 |
+
p->mapped = false;
|
| 65 |
+
|
| 66 |
+
if (p->vdpgl_surface)
|
| 67 |
+
gl->VDPAUUnregisterSurfaceNV(p->vdpgl_surface);
|
| 68 |
+
p->vdpgl_surface = 0;
|
| 69 |
+
|
| 70 |
+
glDeleteTextures(1, &p->gl_texture);
|
| 71 |
+
p->gl_texture = 0;
|
| 72 |
+
|
| 73 |
+
if (p->vdp_surface != VDP_INVALID_HANDLE) {
|
| 74 |
+
vdp_st = vdp->output_surface_destroy(p->vdp_surface);
|
| 75 |
+
CHECK_VDP_WARNING(p, "Error when calling vdp_output_surface_destroy");
|
| 76 |
+
}
|
| 77 |
+
p->vdp_surface = VDP_INVALID_HANDLE;
|
| 78 |
+
|
| 79 |
+
glCheckError(gl, hw->log, "Before uninitializing OpenGL interop");
|
| 80 |
+
|
| 81 |
+
gl->VDPAUFiniNV();
|
| 82 |
+
|
| 83 |
+
// If the GL/vdpau state is not initialized, above calls raises an error.
|
| 84 |
+
while (1) {
|
| 85 |
+
if (gl->GetError() == GL_NO_ERROR)
|
| 86 |
+
break;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
static void destroy(struct gl_hwdec *hw)
|
| 91 |
+
{
|
| 92 |
+
struct priv *p = hw->priv;
|
| 93 |
+
|
| 94 |
+
destroy_objects(hw);
|
| 95 |
+
mp_vdpau_mixer_destroy(p->mixer);
|
| 96 |
+
mp_vdpau_destroy(p->ctx);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
static int create(struct gl_hwdec *hw)
|
| 100 |
+
{
|
| 101 |
+
GL *gl = hw->gl;
|
| 102 |
+
if (hw->hwctx)
|
| 103 |
+
return -1;
|
| 104 |
+
Display *x11disp = glXGetCurrentDisplay();
|
| 105 |
+
if (!x11disp)
|
| 106 |
+
return -1;
|
| 107 |
+
if (!(gl->mpgl_caps & MPGL_CAP_VDPAU))
|
| 108 |
+
return -1;
|
| 109 |
+
struct priv *p = talloc_zero(hw, struct priv);
|
| 110 |
+
hw->priv = p;
|
| 111 |
+
p->log = hw->log;
|
| 112 |
+
p->ctx = mp_vdpau_create_device_x11(hw->log, x11disp);
|
| 113 |
+
if (!p->ctx)
|
| 114 |
+
return -1;
|
| 115 |
+
if (mp_vdpau_handle_preemption(p->ctx, &p->preemption_counter) < 1)
|
| 116 |
+
return -1;
|
| 117 |
+
p->vdp_surface = VDP_INVALID_HANDLE;
|
| 118 |
+
p->mixer = mp_vdpau_mixer_create(p->ctx, hw->log);
|
| 119 |
+
if (hw->reject_emulated && mp_vdpau_guess_if_emulated(p->ctx)) {
|
| 120 |
+
destroy(hw);
|
| 121 |
+
return -1;
|
| 122 |
+
}
|
| 123 |
+
hw->hwctx = &p->ctx->hwctx;
|
| 124 |
+
hw->converted_imgfmt = IMGFMT_RGB0;
|
| 125 |
+
return 0;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
|
| 129 |
+
{
|
| 130 |
+
struct priv *p = hw->priv;
|
| 131 |
+
GL *gl = hw->gl;
|
| 132 |
+
struct vdp_functions *vdp = &p->ctx->vdp;
|
| 133 |
+
VdpStatus vdp_st;
|
| 134 |
+
|
| 135 |
+
destroy_objects(hw);
|
| 136 |
+
|
| 137 |
+
params->imgfmt = hw->driver->imgfmt;
|
| 138 |
+
p->image_params = *params;
|
| 139 |
+
|
| 140 |
+
if (mp_vdpau_handle_preemption(p->ctx, &p->preemption_counter) < 1)
|
| 141 |
+
return -1;
|
| 142 |
+
|
| 143 |
+
gl->VDPAUInitNV(BRAINDEATH(p->ctx->vdp_device), p->ctx->get_proc_address);
|
| 144 |
+
|
| 145 |
+
vdp_st = vdp->output_surface_create(p->ctx->vdp_device,
|
| 146 |
+
VDP_RGBA_FORMAT_B8G8R8A8,
|
| 147 |
+
params->w, params->h, &p->vdp_surface);
|
| 148 |
+
CHECK_VDP_ERROR(p, "Error when calling vdp_output_surface_create");
|
| 149 |
+
|
| 150 |
+
gl->GenTextures(1, &p->gl_texture);
|
| 151 |
+
gl->BindTexture(GL_TEXTURE_2D, p->gl_texture);
|
| 152 |
+
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
| 153 |
+
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| 154 |
+
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| 155 |
+
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| 156 |
+
gl->BindTexture(GL_TEXTURE_2D, 0);
|
| 157 |
+
|
| 158 |
+
p->vdpgl_surface = gl->VDPAURegisterOutputSurfaceNV(BRAINDEATH(p->vdp_surface),
|
| 159 |
+
GL_TEXTURE_2D,
|
| 160 |
+
1, &p->gl_texture);
|
| 161 |
+
if (!p->vdpgl_surface)
|
| 162 |
+
return -1;
|
| 163 |
+
|
| 164 |
+
gl->VDPAUSurfaceAccessNV(p->vdpgl_surface, GL_READ_ONLY);
|
| 165 |
+
|
| 166 |
+
glCheckError(gl, hw->log, "After initializing vdpau OpenGL interop");
|
| 167 |
+
|
| 168 |
+
return 0;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
|
| 172 |
+
GLuint *out_textures)
|
| 173 |
+
{
|
| 174 |
+
struct priv *p = hw->priv;
|
| 175 |
+
GL *gl = hw->gl;
|
| 176 |
+
|
| 177 |
+
assert(hw_image && hw_image->imgfmt == IMGFMT_VDPAU);
|
| 178 |
+
|
| 179 |
+
int pe = mp_vdpau_handle_preemption(p->ctx, &p->preemption_counter);
|
| 180 |
+
if (pe < 1) {
|
| 181 |
+
mark_vdpau_objects_uninitialized(hw);
|
| 182 |
+
if (pe < 0)
|
| 183 |
+
return -1;
|
| 184 |
+
if (reinit(hw, &p->image_params) < 0)
|
| 185 |
+
return -1;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (!p->vdpgl_surface)
|
| 189 |
+
return -1;
|
| 190 |
+
|
| 191 |
+
if (p->mapped)
|
| 192 |
+
gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
|
| 193 |
+
|
| 194 |
+
mp_vdpau_mixer_render(p->mixer, NULL, p->vdp_surface, NULL, hw_image, NULL);
|
| 195 |
+
|
| 196 |
+
gl->VDPAUMapSurfacesNV(1, &p->vdpgl_surface);
|
| 197 |
+
p->mapped = true;
|
| 198 |
+
out_textures[0] = p->gl_texture;
|
| 199 |
+
return 0;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
const struct gl_hwdec_driver gl_hwdec_vdpau = {
|
| 203 |
+
.api_name = "vdpau",
|
| 204 |
+
.imgfmt = IMGFMT_VDPAU,
|
| 205 |
+
.create = create,
|
| 206 |
+
.reinit = reinit,
|
| 207 |
+
.map_image = map_image,
|
| 208 |
+
.destroy = destroy,
|
| 209 |
+
};
|
pool/shard006/C/0117160_sendcommit-proc.c
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
| 2 |
+
/*
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU General Public License as published by
|
| 6 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 59 Temple Place, Suite 330,
|
| 17 |
+
* Boston, MA 02111-1307, USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "common.h"
|
| 21 |
+
|
| 22 |
+
#include <unistd.h>
|
| 23 |
+
#include <sys/types.h>
|
| 24 |
+
#include <fcntl.h>
|
| 25 |
+
#include <errno.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
#include <sys/stat.h>
|
| 28 |
+
|
| 29 |
+
#include <ccnet.h>
|
| 30 |
+
#include "net.h"
|
| 31 |
+
#include "utils.h"
|
| 32 |
+
|
| 33 |
+
#include "seafile-session.h"
|
| 34 |
+
#include "commit-mgr.h"
|
| 35 |
+
#include "sendcommit-proc.h"
|
| 36 |
+
#include "processors/objecttx-common.h"
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
seafile-recvcommit
|
| 40 |
+
INIT --------------------->
|
| 41 |
+
200 OK
|
| 42 |
+
INIT <---------------------
|
| 43 |
+
|
| 44 |
+
Object IDs
|
| 45 |
+
SEND_OBJ ---------------------->
|
| 46 |
+
End
|
| 47 |
+
SEND_OBJ ---------------------->
|
| 48 |
+
|
| 49 |
+
Get Object
|
| 50 |
+
SEND_OBJ <-----------------------
|
| 51 |
+
Object
|
| 52 |
+
SEND_OBJ ----------------------->
|
| 53 |
+
|
| 54 |
+
...
|
| 55 |
+
|
| 56 |
+
End
|
| 57 |
+
<-----------------------
|
| 58 |
+
*/
|
| 59 |
+
|
| 60 |
+
enum {
|
| 61 |
+
INIT,
|
| 62 |
+
SEND_OBJECT
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
static int send_commit_start (CcnetProcessor *processor, int argc, char **argv);
|
| 66 |
+
static void handle_response (CcnetProcessor *processor,
|
| 67 |
+
char *code, char *code_msg,
|
| 68 |
+
char *content, int clen);
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
G_DEFINE_TYPE (SeafileSendcommitProc, seafile_sendcommit_proc, CCNET_TYPE_PROCESSOR)
|
| 72 |
+
|
| 73 |
+
static void
|
| 74 |
+
seafile_sendcommit_proc_class_init (SeafileSendcommitProcClass *klass)
|
| 75 |
+
{
|
| 76 |
+
CcnetProcessorClass *proc_class = CCNET_PROCESSOR_CLASS (klass);
|
| 77 |
+
|
| 78 |
+
proc_class->name = "sendcommit-proc";
|
| 79 |
+
proc_class->start = send_commit_start;
|
| 80 |
+
proc_class->handle_response = handle_response;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
static void
|
| 84 |
+
seafile_sendcommit_proc_init (SeafileSendcommitProc *processor)
|
| 85 |
+
{
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
static gboolean
|
| 89 |
+
commit_collector (SeafCommit *commit, void *data, gboolean *stop)
|
| 90 |
+
{
|
| 91 |
+
ObjectList *ol = data;
|
| 92 |
+
|
| 93 |
+
object_list_insert (ol, commit->commit_id);
|
| 94 |
+
|
| 95 |
+
return TRUE;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
static int
|
| 99 |
+
send_commit_start (CcnetProcessor *processor, int argc, char **argv)
|
| 100 |
+
{
|
| 101 |
+
GString *buf;
|
| 102 |
+
int ret;
|
| 103 |
+
TransferTask *task = ((SeafileSendcommitProc *)processor)->tx_task;
|
| 104 |
+
|
| 105 |
+
ObjectList *ol = object_list_new ();
|
| 106 |
+
ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
|
| 107 |
+
task->head,
|
| 108 |
+
commit_collector,
|
| 109 |
+
ol, FALSE);
|
| 110 |
+
if (ret == FALSE) {
|
| 111 |
+
object_list_free (ol);
|
| 112 |
+
g_warning ("[sendcommit] Load commits error\n");
|
| 113 |
+
ccnet_processor_done (processor, FALSE);
|
| 114 |
+
return -1;
|
| 115 |
+
}
|
| 116 |
+
g_assert (object_list_length(ol) != 0);
|
| 117 |
+
task->commits = ol;
|
| 118 |
+
|
| 119 |
+
/* Send to_branch to the relay. */
|
| 120 |
+
buf = g_string_new (NULL);
|
| 121 |
+
g_string_printf (buf, "remote %s seafile-recvcommit %s %s",
|
| 122 |
+
processor->peer_id, task->to_branch, task->session_token);
|
| 123 |
+
ccnet_processor_send_request (processor, buf->str);
|
| 124 |
+
g_string_free (buf, TRUE);
|
| 125 |
+
|
| 126 |
+
processor->state = INIT;
|
| 127 |
+
|
| 128 |
+
return 0;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
static gboolean
|
| 132 |
+
send_commit (CcnetProcessor *processor, char *object_id)
|
| 133 |
+
{
|
| 134 |
+
char *data;
|
| 135 |
+
int len;
|
| 136 |
+
ObjectPack *pack = NULL;
|
| 137 |
+
int pack_size;
|
| 138 |
+
|
| 139 |
+
if (seaf_obj_store_read_obj (seaf->commit_mgr->obj_store,
|
| 140 |
+
object_id, (void**)&data, &len) < 0) {
|
| 141 |
+
g_warning ("Failed to read commit %s.\n", object_id);
|
| 142 |
+
goto fail;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
pack_size = sizeof(ObjectPack) + len;
|
| 146 |
+
pack = malloc (pack_size);
|
| 147 |
+
memcpy (pack->id, object_id, 41);
|
| 148 |
+
memcpy (pack->object, data, len);
|
| 149 |
+
|
| 150 |
+
ccnet_processor_send_update (processor, SC_OBJECT, SS_OBJECT,
|
| 151 |
+
(char *)pack, pack_size);
|
| 152 |
+
|
| 153 |
+
g_free (data);
|
| 154 |
+
free (pack);
|
| 155 |
+
return TRUE;
|
| 156 |
+
|
| 157 |
+
fail:
|
| 158 |
+
ccnet_processor_send_update (processor, SC_NOT_FOUND, SS_NOT_FOUND,
|
| 159 |
+
object_id, 41);
|
| 160 |
+
ccnet_processor_done (processor, FALSE);
|
| 161 |
+
return FALSE;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
static void
|
| 165 |
+
send_commits (CcnetProcessor *processor, char *content, int clen)
|
| 166 |
+
{
|
| 167 |
+
char *object_id;
|
| 168 |
+
int n_objects;
|
| 169 |
+
int i;
|
| 170 |
+
|
| 171 |
+
if (clen % 41 != 1 || content[clen-1] != '\0') {
|
| 172 |
+
g_warning ("Bad fs object list.\n");
|
| 173 |
+
ccnet_processor_send_update (processor, SC_BAD_OL, SS_BAD_OL, NULL, 0);
|
| 174 |
+
ccnet_processor_done (processor, FALSE);
|
| 175 |
+
return;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
n_objects = clen/41;
|
| 179 |
+
|
| 180 |
+
object_id = content;
|
| 181 |
+
for (i = 0; i < n_objects; ++i) {
|
| 182 |
+
object_id[40] = '\0';
|
| 183 |
+
if (send_commit (processor, object_id) == FALSE)
|
| 184 |
+
return;
|
| 185 |
+
object_id += 41;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
static void
|
| 190 |
+
send_commit_ids (CcnetProcessor *processor)
|
| 191 |
+
{
|
| 192 |
+
SeafileSendcommitProc *proc = (SeafileSendcommitProc *)processor;
|
| 193 |
+
char buf[2048];
|
| 194 |
+
char *ptr = buf;
|
| 195 |
+
int i, count = 0;
|
| 196 |
+
ObjectList *ol = proc->tx_task->commits;
|
| 197 |
+
int ollen = object_list_length (ol);
|
| 198 |
+
|
| 199 |
+
for (i = 0; i < ollen; i++) {
|
| 200 |
+
memcpy (ptr, g_ptr_array_index(ol->obj_ids, i), 40);
|
| 201 |
+
ptr += 40;
|
| 202 |
+
*ptr++ = '\n';
|
| 203 |
+
|
| 204 |
+
if (++count == 48) {
|
| 205 |
+
*ptr = '\0';
|
| 206 |
+
ccnet_processor_send_update (processor, SC_COMMIT_IDS,
|
| 207 |
+
SS_COMMIT_IDS, buf, 41 * count + 1);
|
| 208 |
+
ptr = buf;
|
| 209 |
+
count = 0;
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
if (count) {
|
| 214 |
+
*ptr = '\0';
|
| 215 |
+
ccnet_processor_send_update (processor, SC_COMMIT_IDS,
|
| 216 |
+
SS_COMMIT_IDS, buf, 41 * count + 1);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
object_list_free (ol);
|
| 220 |
+
ccnet_processor_send_update (processor, SC_END, SS_END, NULL, 0);
|
| 221 |
+
|
| 222 |
+
processor->state = SEND_OBJECT;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
static void handle_response (CcnetProcessor *processor,
|
| 226 |
+
char *code, char *code_msg,
|
| 227 |
+
char *content, int clen)
|
| 228 |
+
{
|
| 229 |
+
SeafileSendcommitProc *proc = (SeafileSendcommitProc *)processor;
|
| 230 |
+
TransferTask *task = proc->tx_task;
|
| 231 |
+
if (task->state != TASK_STATE_NORMAL) {
|
| 232 |
+
/* TODO: not tested yet */
|
| 233 |
+
ccnet_processor_send_update (processor, SC_SHUTDOWN, SS_SHUTDOWN,
|
| 234 |
+
NULL, 0);
|
| 235 |
+
ccnet_processor_done (processor, TRUE);
|
| 236 |
+
return;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
switch (processor->state) {
|
| 240 |
+
case INIT:
|
| 241 |
+
if (memcmp (code, SC_OK, 3) == 0)
|
| 242 |
+
send_commit_ids (processor);
|
| 243 |
+
else {
|
| 244 |
+
g_warning ("Bad response: %s %s.\n", code, code_msg);
|
| 245 |
+
ccnet_processor_done (processor, FALSE);
|
| 246 |
+
}
|
| 247 |
+
break;
|
| 248 |
+
case SEND_OBJECT:
|
| 249 |
+
if (strncmp(code, SC_GET_OBJECT, 3) == 0) {
|
| 250 |
+
send_commits (processor, content, clen);
|
| 251 |
+
} else if (strncmp(code, SC_END, 3) == 0) {
|
| 252 |
+
ccnet_processor_done (processor, TRUE);
|
| 253 |
+
} else {
|
| 254 |
+
g_warning ("[sendcommit] Bad response in state SEND_OBJECT: %s %s\n",
|
| 255 |
+
code, code_msg);
|
| 256 |
+
ccnet_processor_done (processor, FALSE);
|
| 257 |
+
}
|
| 258 |
+
break;
|
| 259 |
+
default:
|
| 260 |
+
g_assert (0);
|
| 261 |
+
}
|
| 262 |
+
}
|
pool/shard006/C/0117164_ged_base.c
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* (C) Copyright 2010
|
| 3 |
+
* MediaTek <www.MediaTek.com>
|
| 4 |
+
*
|
| 5 |
+
* MTK GPU Extension Device
|
| 6 |
+
*
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#include "ged_base.h"
|
| 10 |
+
#include <asm/page.h>
|
| 11 |
+
#include <linux/version.h>
|
| 12 |
+
#include <linux/vmalloc.h>
|
| 13 |
+
#include <linux/slab.h>
|
| 14 |
+
#include <linux/sched.h>
|
| 15 |
+
#include <linux/interrupt.h>
|
| 16 |
+
|
| 17 |
+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38))
|
| 18 |
+
#ifndef AUTOCONF_INCLUDED
|
| 19 |
+
#include <linux/config.h>
|
| 20 |
+
#endif
|
| 21 |
+
#endif
|
| 22 |
+
|
| 23 |
+
#include <asm/uaccess.h>
|
| 24 |
+
|
| 25 |
+
unsigned long ged_copy_to_user(void __user *pvTo, const void *pvFrom, unsigned long ulBytes)
|
| 26 |
+
{
|
| 27 |
+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
|
| 28 |
+
if (access_ok(VERIFY_WRITE, pvTo, ulBytes))
|
| 29 |
+
{
|
| 30 |
+
return __copy_to_user(pvTo, pvFrom, ulBytes);
|
| 31 |
+
}
|
| 32 |
+
return ulBytes;
|
| 33 |
+
#else
|
| 34 |
+
return copy_to_user(pvTo, pvFrom, ulBytes);
|
| 35 |
+
#endif
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
unsigned long ged_copy_from_user(void *pvTo, const void __user *pvFrom, unsigned long ulBytes)
|
| 39 |
+
{
|
| 40 |
+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
|
| 41 |
+
if (access_ok(VERIFY_READ, pvFrom, ulBytes))
|
| 42 |
+
{
|
| 43 |
+
return __copy_from_user(pvTo, pvFrom, ulBytes);
|
| 44 |
+
}
|
| 45 |
+
return ulBytes;
|
| 46 |
+
#else
|
| 47 |
+
return copy_from_user(pvTo, pvFrom, ulBytes);
|
| 48 |
+
#endif
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void* ged_alloc(int i32Size)
|
| 52 |
+
{
|
| 53 |
+
void *pvBuf;
|
| 54 |
+
|
| 55 |
+
if (i32Size <= PAGE_SIZE)
|
| 56 |
+
{
|
| 57 |
+
pvBuf = kmalloc(i32Size, GFP_KERNEL);
|
| 58 |
+
}
|
| 59 |
+
else
|
| 60 |
+
{
|
| 61 |
+
pvBuf = vmalloc(i32Size);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return pvBuf;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void* ged_alloc_atomic(int i32Size)
|
| 68 |
+
{
|
| 69 |
+
void *pvBuf;
|
| 70 |
+
|
| 71 |
+
if (i32Size <= PAGE_SIZE)
|
| 72 |
+
{
|
| 73 |
+
pvBuf = kmalloc(i32Size, GFP_ATOMIC);
|
| 74 |
+
}
|
| 75 |
+
else
|
| 76 |
+
{
|
| 77 |
+
pvBuf = vmalloc(i32Size);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return pvBuf;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void ged_free(void* pvBuf, int i32Size)
|
| 84 |
+
{
|
| 85 |
+
if (pvBuf)
|
| 86 |
+
{
|
| 87 |
+
if (i32Size <= PAGE_SIZE)
|
| 88 |
+
{
|
| 89 |
+
kfree(pvBuf);
|
| 90 |
+
}
|
| 91 |
+
else
|
| 92 |
+
{
|
| 93 |
+
vfree(pvBuf);
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
long ged_get_pid(void)
|
| 99 |
+
{
|
| 100 |
+
if (in_interrupt())
|
| 101 |
+
{
|
| 102 |
+
return 0xffffffffL;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
|
| 106 |
+
return (long)current->pgrp;
|
| 107 |
+
#else
|
| 108 |
+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
|
| 109 |
+
return (long)task_tgid_nr(current);
|
| 110 |
+
#else
|
| 111 |
+
return (long)current->tgid;
|
| 112 |
+
#endif
|
| 113 |
+
#endif
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
unsigned long long ged_get_time()
|
| 117 |
+
{
|
| 118 |
+
unsigned long long temp;
|
| 119 |
+
|
| 120 |
+
preempt_disable();
|
| 121 |
+
temp = cpu_clock(smp_processor_id());
|
| 122 |
+
preempt_enable();
|
| 123 |
+
|
| 124 |
+
return temp;
|
| 125 |
+
}
|
| 126 |
+
|
pool/shard006/C/0117166_empty-Seed4-RandomFuns-Type_int-ControlStructures_12-BB1-ForBound_boundedInput-Operators_PlusA_MinusA_Lt_Gt_Le_Ge_Eq_Ne.c
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Generated by CIL v. 1.7.0 */
|
| 2 |
+
/* print_CIL_Input is false */
|
| 3 |
+
|
| 4 |
+
struct _IO_FILE;
|
| 5 |
+
struct timeval;
|
| 6 |
+
extern void signal(int sig , void *func ) ;
|
| 7 |
+
extern float strtof(char const *str , char const *endptr ) ;
|
| 8 |
+
typedef struct _IO_FILE FILE;
|
| 9 |
+
extern int atoi(char const *s ) ;
|
| 10 |
+
extern double strtod(char const *str , char const *endptr ) ;
|
| 11 |
+
extern int fclose(void *stream ) ;
|
| 12 |
+
extern void *fopen(char const *filename , char const *mode ) ;
|
| 13 |
+
extern void abort() ;
|
| 14 |
+
extern void exit(int status ) ;
|
| 15 |
+
extern int raise(int sig ) ;
|
| 16 |
+
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
|
| 17 |
+
extern int strcmp(char const *a , char const *b ) ;
|
| 18 |
+
extern int rand() ;
|
| 19 |
+
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
|
| 20 |
+
void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ;
|
| 21 |
+
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
|
| 22 |
+
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
|
| 23 |
+
extern int printf(char const *format , ...) ;
|
| 24 |
+
int main(int argc , char *argv[] ) ;
|
| 25 |
+
void megaInit(void) ;
|
| 26 |
+
extern unsigned long strlen(char const *s ) ;
|
| 27 |
+
extern long strtol(char const *str , char const *endptr , int base ) ;
|
| 28 |
+
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
|
| 29 |
+
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
|
| 30 |
+
struct timeval {
|
| 31 |
+
long tv_sec ;
|
| 32 |
+
long tv_usec ;
|
| 33 |
+
};
|
| 34 |
+
extern void *malloc(unsigned long size ) ;
|
| 35 |
+
extern int scanf(char const *format , ...) ;
|
| 36 |
+
void RandomFunc(unsigned int input[1] , unsigned int output[1] )
|
| 37 |
+
{
|
| 38 |
+
unsigned int state[1] ;
|
| 39 |
+
unsigned int local1 ;
|
| 40 |
+
unsigned short copy11 ;
|
| 41 |
+
|
| 42 |
+
{
|
| 43 |
+
state[0UL] = (input[0UL] + 914778474UL) - 981234615U;
|
| 44 |
+
local1 = 0UL;
|
| 45 |
+
while (local1 < 0U) {
|
| 46 |
+
if (state[0UL] < local1) {
|
| 47 |
+
if (state[0UL] != local1) {
|
| 48 |
+
copy11 = *((unsigned short *)(& state[local1]) + 0);
|
| 49 |
+
*((unsigned short *)(& state[local1]) + 0) = *((unsigned short *)(& state[local1]) + 1);
|
| 50 |
+
*((unsigned short *)(& state[local1]) + 1) = copy11;
|
| 51 |
+
}
|
| 52 |
+
} else {
|
| 53 |
+
state[0UL] = state[local1] + state[local1];
|
| 54 |
+
}
|
| 55 |
+
local1 ++;
|
| 56 |
+
}
|
| 57 |
+
output[0UL] = (state[0UL] + 973391845UL) + 40566171U;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
void megaInit(void)
|
| 61 |
+
{
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
{
|
| 65 |
+
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
int main(int argc , char *argv[] )
|
| 69 |
+
{
|
| 70 |
+
unsigned int input[1] ;
|
| 71 |
+
unsigned int output[1] ;
|
| 72 |
+
int randomFuns_i5 ;
|
| 73 |
+
unsigned int randomFuns_value6 ;
|
| 74 |
+
int randomFuns_main_i7 ;
|
| 75 |
+
|
| 76 |
+
{
|
| 77 |
+
megaInit();
|
| 78 |
+
if (argc != 2) {
|
| 79 |
+
printf("Call this program with %i arguments\n", 1);
|
| 80 |
+
exit(-1);
|
| 81 |
+
} else {
|
| 82 |
+
|
| 83 |
+
}
|
| 84 |
+
randomFuns_i5 = 0;
|
| 85 |
+
while (randomFuns_i5 < 1) {
|
| 86 |
+
randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
|
| 87 |
+
input[randomFuns_i5] = randomFuns_value6;
|
| 88 |
+
randomFuns_i5 ++;
|
| 89 |
+
}
|
| 90 |
+
RandomFunc(input, output);
|
| 91 |
+
if (output[0] == 947514220U) {
|
| 92 |
+
printf("You win!\n");
|
| 93 |
+
} else {
|
| 94 |
+
|
| 95 |
+
}
|
| 96 |
+
randomFuns_main_i7 = 0;
|
| 97 |
+
while (randomFuns_main_i7 < 1) {
|
| 98 |
+
printf("%u\n", output[randomFuns_main_i7]);
|
| 99 |
+
randomFuns_main_i7 ++;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
pool/shard006/C/0117167_lab7.c
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//*****************************************
|
| 2 |
+
//Jason Laske
|
| 3 |
+
//Daniel Rogers
|
| 4 |
+
//CSC 311
|
| 5 |
+
//Due Date: 4/10/2014
|
| 6 |
+
//Submitted: 4/10/2014
|
| 7 |
+
//*****************************************
|
| 8 |
+
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include <stdio.h>
|
| 11 |
+
#include <string.h>
|
| 12 |
+
|
| 13 |
+
int main(){
|
| 14 |
+
|
| 15 |
+
//*****************************************
|
| 16 |
+
//VARIABLE DECLARATION
|
| 17 |
+
//*****************************************
|
| 18 |
+
|
| 19 |
+
char a;
|
| 20 |
+
char b;
|
| 21 |
+
char c;
|
| 22 |
+
char d;
|
| 23 |
+
char e;
|
| 24 |
+
char f;
|
| 25 |
+
|
| 26 |
+
int k = 0;
|
| 27 |
+
|
| 28 |
+
//******************************************
|
| 29 |
+
//1.) PROMPT FOR BASE OF INPUT
|
| 30 |
+
//******************************************
|
| 31 |
+
while(k == 0){
|
| 32 |
+
|
| 33 |
+
int i = 0;
|
| 34 |
+
|
| 35 |
+
char str[32];
|
| 36 |
+
int bin = 0;
|
| 37 |
+
int j = 0;
|
| 38 |
+
|
| 39 |
+
printf("Base of input integer: Enter b for binary, d for decimal, h for hexadecimal and o for octal: \n");
|
| 40 |
+
|
| 41 |
+
//Input
|
| 42 |
+
//*******************
|
| 43 |
+
scanf("%c", &a);
|
| 44 |
+
scanf("%c", &d);
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
//Control structure
|
| 48 |
+
//*******************
|
| 49 |
+
printf("Enter the number: \n");
|
| 50 |
+
|
| 51 |
+
if(a == 'b'){
|
| 52 |
+
scanf("%s", &str);
|
| 53 |
+
scanf("%c", &d);
|
| 54 |
+
while(str[j] != '\0')
|
| 55 |
+
{
|
| 56 |
+
bin = bin * 2 + str[j] - '0';
|
| 57 |
+
j++;
|
| 58 |
+
}
|
| 59 |
+
}else if(a == 'd'){
|
| 60 |
+
scanf("%d", &i);
|
| 61 |
+
scanf("%c", &d);
|
| 62 |
+
}else if(a == 'h'){
|
| 63 |
+
scanf("%x", &i);
|
| 64 |
+
scanf("%c", &d);
|
| 65 |
+
}else if(a == 'o'){
|
| 66 |
+
scanf("%o", &i);
|
| 67 |
+
scanf("%c", &d);
|
| 68 |
+
}else{
|
| 69 |
+
printf("Error1\n");
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
//******************************************
|
| 73 |
+
//2.) PROMPT FOR BASE OF OUTPUT / OUTPUT
|
| 74 |
+
//******************************************
|
| 75 |
+
|
| 76 |
+
printf("Enter the base of the output(d, h or o): ");
|
| 77 |
+
|
| 78 |
+
scanf("%c", &e);
|
| 79 |
+
scanf("%c", &d);
|
| 80 |
+
|
| 81 |
+
if(a == 'b'){
|
| 82 |
+
printf("The integer %s in binary is ", str);
|
| 83 |
+
}else if(a == 'd'){
|
| 84 |
+
printf("The integer %d in decimal is ", i);
|
| 85 |
+
}else if(a == 'h'){
|
| 86 |
+
printf("The integer %x in hexadecimal is ", i);
|
| 87 |
+
}else if(a == 'o'){
|
| 88 |
+
printf("The integer %o in octal is ", i);
|
| 89 |
+
}else{
|
| 90 |
+
printf("Error2\n");
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if(e == 'd'){
|
| 94 |
+
if(a == 'b'){
|
| 95 |
+
printf("%d in decimal.\n", bin);
|
| 96 |
+
}else{
|
| 97 |
+
printf("%d in decimal.\n", i);
|
| 98 |
+
}
|
| 99 |
+
}else if(e == 'h'){
|
| 100 |
+
if(a == 'b'){
|
| 101 |
+
printf("%x in hexadecimal.\n", bin);
|
| 102 |
+
}else{
|
| 103 |
+
printf("%x in hexadecimal.\n", i);
|
| 104 |
+
}
|
| 105 |
+
}else if(e == 'o'){
|
| 106 |
+
if(a == 'b'){
|
| 107 |
+
printf("%o in octal.\n", bin);
|
| 108 |
+
}else{
|
| 109 |
+
printf("%o in octal.\n", i);
|
| 110 |
+
}
|
| 111 |
+
}else{
|
| 112 |
+
printf("Error3\n");
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
//*******************************************
|
| 116 |
+
//3.) CONTINUE?
|
| 117 |
+
//*******************************************
|
| 118 |
+
|
| 119 |
+
printf("Do you wish to do another? (Y or N): ");
|
| 120 |
+
|
| 121 |
+
scanf("%c", &f);
|
| 122 |
+
scanf("%c", &d);
|
| 123 |
+
|
| 124 |
+
if(f != 'Y'){
|
| 125 |
+
k = 1;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
}//end while
|
| 129 |
+
|
| 130 |
+
//*******************************************
|
| 131 |
+
//4.)EXIT
|
| 132 |
+
//*******************************************
|
| 133 |
+
|
| 134 |
+
printf("Thank you, have a nice day.\n\n");
|
| 135 |
+
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
pool/shard006/C/0117169_waitqueue.c
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <linux/module.h>
|
| 2 |
+
#include <linux/init.h>
|
| 3 |
+
#include <linux/sched.h>
|
| 4 |
+
#include <linux/wait.h>
|
| 5 |
+
#include <linux/time.h>
|
| 6 |
+
#include <linux/delay.h>
|
| 7 |
+
#include <linux/workqueue.h>
|
| 8 |
+
#include <linux/slab.h>
|
| 9 |
+
#include <linux/fs.h>
|
| 10 |
+
#include <linux/seq_file.h>
|
| 11 |
+
#include <linux/proc_fs.h>
|
| 12 |
+
#include <linux/errno.h>
|
| 13 |
+
#include <linux/fcntl.h>
|
| 14 |
+
#include <asm/uaccess.h>
|
| 15 |
+
#include <linux/cdev.h>
|
| 16 |
+
#include <linux/semaphore.h>
|
| 17 |
+
|
| 18 |
+
MODULE_LICENSE("GPL");
|
| 19 |
+
MODULE_AUTHOR("Linhu");
|
| 20 |
+
MODULE_DESCRIPTION("A simple BLOCKING IO example");
|
| 21 |
+
|
| 22 |
+
#define CDEV_MAJOR 0 /* dynamic major by default */
|
| 23 |
+
|
| 24 |
+
static int cdev_major = CDEV_MAJOR;
|
| 25 |
+
|
| 26 |
+
static wait_queue_head_t my_wait_queue;
|
| 27 |
+
|
| 28 |
+
//static struct work_struct workq;
|
| 29 |
+
|
| 30 |
+
static char *ptr_buffer = NULL;
|
| 31 |
+
|
| 32 |
+
static struct semaphore sem;
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
static int test_proc_show(struct seq_file *ptr,void * param);
|
| 36 |
+
static int test_proc_open(struct inode *inode, struct file *file);
|
| 37 |
+
static ssize_t test_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos);
|
| 38 |
+
static ssize_t test_proc_write(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos);
|
| 39 |
+
|
| 40 |
+
static int test_open(struct inode *inode, struct file *filp);
|
| 41 |
+
static ssize_t test_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos);
|
| 42 |
+
static ssize_t test_write(struct file *filp, const char __user *buf, size_t nbytes, loff_t *f_pos);
|
| 43 |
+
static int test_release(struct inode *inode, struct file *filp);
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
typedef struct chardev{
|
| 47 |
+
char *pbuf;
|
| 48 |
+
struct semaphore sem;
|
| 49 |
+
wait_queue_head_t waitq;
|
| 50 |
+
struct cdev cdev;
|
| 51 |
+
}chardev_t;
|
| 52 |
+
|
| 53 |
+
static chardev_t *char_devices;
|
| 54 |
+
|
| 55 |
+
static struct file_operations char_ops = {
|
| 56 |
+
.owner = THIS_MODULE,
|
| 57 |
+
.open = test_open,
|
| 58 |
+
.release = test_release,
|
| 59 |
+
.read = test_read,
|
| 60 |
+
.write = test_write
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
static struct file_operations proc_ops = {
|
| 65 |
+
.owner = THIS_MODULE,
|
| 66 |
+
.open = test_proc_open,
|
| 67 |
+
.read = test_proc_read,
|
| 68 |
+
.write = test_proc_write,
|
| 69 |
+
.release = single_release
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
static int test_proc_show(struct seq_file *ptr,void * param)
|
| 74 |
+
{
|
| 75 |
+
printk(KERN_INFO "test_proc opened.\n");
|
| 76 |
+
return 0;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
static int test_proc_open(struct inode *inode, struct file *file)
|
| 80 |
+
{
|
| 81 |
+
return single_open(file, test_proc_show, NULL);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
static ssize_t test_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
| 85 |
+
{
|
| 86 |
+
ssize_t rbytes = 0;
|
| 87 |
+
|
| 88 |
+
if(ptr_buffer == NULL)
|
| 89 |
+
{
|
| 90 |
+
printk(KERN_INFO "Buffer is NULL.\n");
|
| 91 |
+
return EFAULT;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if(strlen(ptr_buffer) == 0)
|
| 95 |
+
{
|
| 96 |
+
printk(KERN_INFO "Buffer is not available, wait until data is available.\n");
|
| 97 |
+
interruptible_sleep_on(&my_wait_queue);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
down_interruptible(&sem);
|
| 101 |
+
|
| 102 |
+
rbytes = copy_to_user(buf, ptr_buffer, strlen(ptr_buffer));
|
| 103 |
+
|
| 104 |
+
up(&sem);
|
| 105 |
+
|
| 106 |
+
if(rbytes == 0)
|
| 107 |
+
{
|
| 108 |
+
printk(KERN_ERR "Failed to copy to user.\n");
|
| 109 |
+
return EFAULT;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
printk(KERN_INFO "read data: %s\n", ptr_buffer);
|
| 113 |
+
|
| 114 |
+
memset(ptr_buffer, 0, strlen(ptr_buffer));
|
| 115 |
+
|
| 116 |
+
return rbytes;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
static ssize_t test_proc_write(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos)
|
| 121 |
+
{
|
| 122 |
+
|
| 123 |
+
down_interruptible(&sem);
|
| 124 |
+
|
| 125 |
+
if(copy_from_user(ptr_buffer, buf, nbytes) < 0)
|
| 126 |
+
{
|
| 127 |
+
printk(KERN_ERR "Failed to copy from user.\n");
|
| 128 |
+
return EFAULT;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
up(&sem);
|
| 132 |
+
|
| 133 |
+
printk(KERN_ERR "Wake up to read the buffer.\n");
|
| 134 |
+
wake_up_interruptible(&my_wait_queue);
|
| 135 |
+
return nbytes;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
static int test_open(struct inode *inode, struct file *filp)
|
| 140 |
+
{
|
| 141 |
+
struct chardev *dev;
|
| 142 |
+
|
| 143 |
+
dev = container_of(inode->i_cdev, struct chardev, cdev);
|
| 144 |
+
|
| 145 |
+
dev->pbuf = kmalloc(1024, GFP_KERNEL);
|
| 146 |
+
|
| 147 |
+
if(dev->pbuf == NULL)
|
| 148 |
+
{
|
| 149 |
+
printk(KERN_ERR "kmalloc failed.\n");
|
| 150 |
+
return ENOMEM;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
filp->private_data = dev;
|
| 154 |
+
|
| 155 |
+
return 0;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static ssize_t test_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
|
| 159 |
+
{
|
| 160 |
+
ssize_t rbytes = 0;
|
| 161 |
+
|
| 162 |
+
struct chardev *dev = filp->private_data;
|
| 163 |
+
|
| 164 |
+
if(dev->pbuf == NULL)
|
| 165 |
+
{
|
| 166 |
+
printk(KERN_INFO "Buffer is NULL.\n");
|
| 167 |
+
return EFAULT;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
if(strlen(dev->pbuf) == 0)
|
| 171 |
+
{
|
| 172 |
+
printk(KERN_INFO "Buffer is not available, wait until data is available.\n");
|
| 173 |
+
interruptible_sleep_on(&dev->waitq);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
down_interruptible(&dev->sem);
|
| 177 |
+
|
| 178 |
+
rbytes = copy_to_user(buf, dev->pbuf, strlen(dev->pbuf));
|
| 179 |
+
|
| 180 |
+
up(&dev->sem);
|
| 181 |
+
|
| 182 |
+
if(rbytes == 0)
|
| 183 |
+
{
|
| 184 |
+
printk(KERN_ERR "Failed to copy to user.\n");
|
| 185 |
+
return EFAULT;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
printk(KERN_INFO "read data: %s\n", dev->pbuf);
|
| 189 |
+
|
| 190 |
+
memset(dev->pbuf, 0, strlen(dev->pbuf));
|
| 191 |
+
|
| 192 |
+
return rbytes;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
static ssize_t test_write(struct file *filp, const char __user *buf, size_t nbytes, loff_t *f_pos)
|
| 196 |
+
{
|
| 197 |
+
struct chardev *dev = filp->private_data;
|
| 198 |
+
|
| 199 |
+
down_interruptible(&dev->sem);
|
| 200 |
+
|
| 201 |
+
if(copy_from_user(dev->pbuf, buf, nbytes) < 0)
|
| 202 |
+
{
|
| 203 |
+
printk(KERN_ERR "Failed to copy from user.\n");
|
| 204 |
+
return EFAULT;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
up(&dev->sem);
|
| 208 |
+
|
| 209 |
+
printk(KERN_ERR "Wake up to read the buffer.\n");
|
| 210 |
+
wake_up_interruptible(&dev->waitq);
|
| 211 |
+
return nbytes;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
static int test_release(struct inode *inode, struct file *filp)
|
| 216 |
+
{
|
| 217 |
+
struct chardev *dev = filp->private_data;
|
| 218 |
+
|
| 219 |
+
kfree(dev->pbuf);
|
| 220 |
+
|
| 221 |
+
return 0;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
static void chardev_init(void)
|
| 225 |
+
{
|
| 226 |
+
int result, err = 0;
|
| 227 |
+
dev_t devno = MKDEV(CDEV_MAJOR, 0);
|
| 228 |
+
|
| 229 |
+
if (cdev_major)
|
| 230 |
+
result = register_chrdev_region(devno, cdev_major, "cdev");
|
| 231 |
+
else {
|
| 232 |
+
result = alloc_chrdev_region(&devno, 0, cdev_major, "cdev");
|
| 233 |
+
cdev_major = MAJOR(devno);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
if(result < 0)
|
| 237 |
+
{
|
| 238 |
+
printk("device allocation failed.\n");
|
| 239 |
+
return;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
char_devices = kmalloc(sizeof(struct chardev), GFP_KERNEL);
|
| 243 |
+
|
| 244 |
+
if(!char_devices)
|
| 245 |
+
{
|
| 246 |
+
result = -ENOMEM;
|
| 247 |
+
unregister_chrdev_region(devno, 1);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
memset(char_devices, 0, sizeof(struct chardev));
|
| 251 |
+
|
| 252 |
+
sema_init(&char_devices->sem, 1);
|
| 253 |
+
init_waitqueue_head(&char_devices->waitq);
|
| 254 |
+
|
| 255 |
+
cdev_init(&char_devices->cdev, &char_ops);
|
| 256 |
+
char_devices->cdev.owner = THIS_MODULE;
|
| 257 |
+
char_devices->cdev.ops = &char_ops;
|
| 258 |
+
|
| 259 |
+
err = cdev_add(&char_devices->cdev, devno, 1);
|
| 260 |
+
|
| 261 |
+
if(err)
|
| 262 |
+
printk(KERN_ERR "Error adding char device %d", devno);
|
| 263 |
+
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/*
|
| 267 |
+
void my_workqueue_handler(struct work_struct *work)
|
| 268 |
+
{
|
| 269 |
+
printk("WORK QUEUE: I'm just a timer to wake up the sleeping module.\n");
|
| 270 |
+
msleep(1000);
|
| 271 |
+
printk("WORK QUEUE: Time up Module wake up.\n");
|
| 272 |
+
wake_up_interruptible(&my_wait_queue);
|
| 273 |
+
}
|
| 274 |
+
*/
|
| 275 |
+
int init_module(void)
|
| 276 |
+
{
|
| 277 |
+
printk("Wait queue create buffer...\n");
|
| 278 |
+
|
| 279 |
+
ptr_buffer = kmalloc(1024*sizeof(char), GFP_KERNEL);
|
| 280 |
+
|
| 281 |
+
// INIT_WORK(&workq, my_workqueue_handler);
|
| 282 |
+
|
| 283 |
+
// schedule_work(&workq);
|
| 284 |
+
|
| 285 |
+
chardev_init();
|
| 286 |
+
|
| 287 |
+
sema_init(&sem, 1);
|
| 288 |
+
|
| 289 |
+
init_waitqueue_head(&my_wait_queue);
|
| 290 |
+
|
| 291 |
+
proc_create("Waitq", 0, NULL, &proc_ops);
|
| 292 |
+
|
| 293 |
+
return 0;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
void cleanup_module(void)
|
| 297 |
+
{
|
| 298 |
+
remove_proc_entry("Waitq", NULL);
|
| 299 |
+
|
| 300 |
+
cdev_del(&char_devices->cdev);
|
| 301 |
+
unregister_chrdev_region(MKDEV(CDEV_MAJOR, 0), 1);
|
| 302 |
+
|
| 303 |
+
kfree(ptr_buffer);
|
| 304 |
+
printk("<1> Start to cleanup \n");
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
|
pool/shard006/C/0117173_sorter.c
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma config(Sensor, in1, lineFollower, sensorLineFollower)
|
| 2 |
+
#pragma config(Sensor, dgtl1, encod, sensorQuadEncoder)
|
| 3 |
+
#pragma config(Sensor, dgtl3, pushB, sensorTouch)
|
| 4 |
+
#pragma config(Sensor, dgtl11, ind0, sensorLEDtoVCC)
|
| 5 |
+
#pragma config(Sensor, dgtl12, ind1, sensorLEDtoVCC)
|
| 6 |
+
#pragma config(Motor, port1, flight, tmotorVexFlashlight, openLoop, reversed)
|
| 7 |
+
#pragma config(Motor, port2, rMotorGateId, tmotorVex393_MC29, openLoop, reversed)
|
| 8 |
+
#pragma config(Motor, port3, rMotorServRId, tmotorServoStandard, openLoop)
|
| 9 |
+
#pragma config(Motor, port4, rMotorServLId, tmotorServoStandard, openLoop)
|
| 10 |
+
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
|
| 11 |
+
|
| 12 |
+
#include "utilities.c"
|
| 13 |
+
#include "indicators.c"
|
| 14 |
+
#include "measure.c"
|
| 15 |
+
#include "gate.c"
|
| 16 |
+
|
| 17 |
+
int material = -1;
|
| 18 |
+
|
| 19 |
+
int sort(bool learn);
|
| 20 |
+
|
| 21 |
+
task main() {
|
| 22 |
+
|
| 23 |
+
doConfig();
|
| 24 |
+
indMode[0] = 1;
|
| 25 |
+
indMode[1] = 3;
|
| 26 |
+
while (!SensorValue[pushB]) doIndicateTick();
|
| 27 |
+
delayInd(100);
|
| 28 |
+
while (SensorValue[pushB]) doIndicateTick();
|
| 29 |
+
indMode[0] = 2;
|
| 30 |
+
indMode[1] = 0;
|
| 31 |
+
|
| 32 |
+
// precalibrate
|
| 33 |
+
|
| 34 |
+
SensorValue[encod] = 0;
|
| 35 |
+
mgate = 0;
|
| 36 |
+
|
| 37 |
+
// learn four materials
|
| 38 |
+
|
| 39 |
+
for (int i = 0; i < 4; ++i) {
|
| 40 |
+
sort(true);
|
| 41 |
+
delayInd(CONFIG.SORT_DELAY);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
while (1) {
|
| 45 |
+
|
| 46 |
+
indMode[0] = 0;
|
| 47 |
+
indMode[1] = 3;
|
| 48 |
+
while (!SensorValue[pushB]) doIndicateTick();
|
| 49 |
+
delayInd(100);
|
| 50 |
+
while (SensorValue[pushB]) doIndicateTick();
|
| 51 |
+
delayInd(100);
|
| 52 |
+
|
| 53 |
+
while (1) {
|
| 54 |
+
indMode[1] = 1;
|
| 55 |
+
indMode[0] = 4;
|
| 56 |
+
if (SensorValue[pushB]) break;
|
| 57 |
+
|
| 58 |
+
delayInd(CONFIG.SORT_DELAY);
|
| 59 |
+
|
| 60 |
+
indMode[1] = 0;
|
| 61 |
+
indMode[0] = 4;
|
| 62 |
+
|
| 63 |
+
sort(false);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
indMode[1] = 1;
|
| 67 |
+
indMode[0] = 3;
|
| 68 |
+
|
| 69 |
+
while (!SensorValue[pushB]) doIndicateTick();
|
| 70 |
+
delayInd(100);
|
| 71 |
+
while (SensorValue[pushB]) doIndicateTick();
|
| 72 |
+
delayInd(100);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
int sort(bool learn) {
|
| 77 |
+
material = getMaterial(learn);
|
| 78 |
+
|
| 79 |
+
switch (material) {
|
| 80 |
+
case 0:
|
| 81 |
+
mgate = -CONFIG.GATE_SPEED;
|
| 82 |
+
msl = CONFIG.SERVO_PATH_LEFT;
|
| 83 |
+
break;
|
| 84 |
+
case 1:
|
| 85 |
+
mgate = -CONFIG.GATE_SPEED;
|
| 86 |
+
msl = CONFIG.SERVO_PATH_RIGHT;
|
| 87 |
+
break;
|
| 88 |
+
case 2:
|
| 89 |
+
mgate = CONFIG.GATE_SPEED;
|
| 90 |
+
msr = CONFIG.SERVO_PATH_LEFT;
|
| 91 |
+
break;
|
| 92 |
+
case 3:
|
| 93 |
+
mgate = CONFIG.GATE_SPEED;
|
| 94 |
+
msr = CONFIG.SERVO_PATH_RIGHT;
|
| 95 |
+
break;
|
| 96 |
+
default:
|
| 97 |
+
return -1;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
delayInd(CONFIG.GATE_LENGTH);
|
| 101 |
+
if (material > 1) {
|
| 102 |
+
// do a quick hop back the other way -
|
| 103 |
+
// this should help get the sensor in a better place each time.
|
| 104 |
+
mgate = -100;
|
| 105 |
+
delayInd(50);
|
| 106 |
+
mgate = 0;
|
| 107 |
+
}
|
| 108 |
+
goToZero();
|
| 109 |
+
|
| 110 |
+
return material;
|
| 111 |
+
}
|
pool/shard006/C/0117174_clock_config.c
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
| 3 |
+
* Copyright 2016-2017 NXP
|
| 4 |
+
*
|
| 5 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
| 6 |
+
* are permitted provided that the following conditions are met:
|
| 7 |
+
*
|
| 8 |
+
* o Redistributions of source code must retain the above copyright notice, this list
|
| 9 |
+
* of conditions and the following disclaimer.
|
| 10 |
+
*
|
| 11 |
+
* o Redistributions in binary form must reproduce the above copyright notice, this
|
| 12 |
+
* list of conditions and the following disclaimer in the documentation and/or
|
| 13 |
+
* other materials provided with the distribution.
|
| 14 |
+
*
|
| 15 |
+
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
| 16 |
+
* contributors may be used to endorse or promote products derived from this
|
| 17 |
+
* software without specific prior written permission.
|
| 18 |
+
*
|
| 19 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 20 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 21 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 22 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 23 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 24 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 25 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 26 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 27 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
* How to setup clock using clock driver functions:
|
| 33 |
+
*
|
| 34 |
+
* 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock
|
| 35 |
+
* and flash clock are in allowed range during clock mode switch.
|
| 36 |
+
*
|
| 37 |
+
* 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode.
|
| 38 |
+
*
|
| 39 |
+
* 3. Set MCG configuration, MCG includes three parts: FLL clock, PLL clock and
|
| 40 |
+
* internal reference clock(MCGIRCLK). Follow the steps to setup:
|
| 41 |
+
*
|
| 42 |
+
* 1). Call CLOCK_BootToXxxMode to set MCG to target mode.
|
| 43 |
+
*
|
| 44 |
+
* 2). If target mode is FBI/BLPI/PBI mode, the MCGIRCLK has been configured
|
| 45 |
+
* correctly. For other modes, need to call CLOCK_SetInternalRefClkConfig
|
| 46 |
+
* explicitly to setup MCGIRCLK.
|
| 47 |
+
*
|
| 48 |
+
* 3). Don't need to configure FLL explicitly, because if target mode is FLL
|
| 49 |
+
* mode, then FLL has been configured by the function CLOCK_BootToXxxMode,
|
| 50 |
+
* if the target mode is not FLL mode, the FLL is disabled.
|
| 51 |
+
*
|
| 52 |
+
* 4). If target mode is PEE/PBE/PEI/PBI mode, then the related PLL has been
|
| 53 |
+
* setup by CLOCK_BootToXxxMode. In FBE/FBI/FEE/FBE mode, the PLL could
|
| 54 |
+
* be enabled independently, call CLOCK_EnablePll0 explicitly in this case.
|
| 55 |
+
*
|
| 56 |
+
* 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM.
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
/* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
|
| 60 |
+
!!ClocksProfile
|
| 61 |
+
product: Clocks v1.0
|
| 62 |
+
processor: MKW41Z512xxx4
|
| 63 |
+
package_id: MKW41Z512VHT4
|
| 64 |
+
mcu_data: ksdk2_0
|
| 65 |
+
processor_version: 0.1.28
|
| 66 |
+
board: FRDM-KW41Z
|
| 67 |
+
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
|
| 68 |
+
|
| 69 |
+
#include "fsl_rtc.h"
|
| 70 |
+
#include "clock_config.h"
|
| 71 |
+
|
| 72 |
+
/*******************************************************************************
|
| 73 |
+
* Definitions
|
| 74 |
+
******************************************************************************/
|
| 75 |
+
#define RTC_OSC_CAP_LOAD_0PF 0x0U /*!< RTC oscillator capacity load: 0pF */
|
| 76 |
+
#define SIM_LPUART_CLK_SEL_OSCERCLK_CLK 2U /*!< LPUART clock select: OSCERCLK clock */
|
| 77 |
+
#define SIM_OSC32KSEL_OSC32KCLK_CLK 0U /*!< OSC32KSEL select: OSC32KCLK clock */
|
| 78 |
+
#define SIM_TPM_CLK_SEL_OSCERCLK_CLK 2U /*!< TPM clock select: OSCERCLK clock */
|
| 79 |
+
|
| 80 |
+
/*******************************************************************************
|
| 81 |
+
* Variables
|
| 82 |
+
******************************************************************************/
|
| 83 |
+
/* System clock frequency. */
|
| 84 |
+
extern uint32_t SystemCoreClock;
|
| 85 |
+
|
| 86 |
+
/*******************************************************************************
|
| 87 |
+
* Code
|
| 88 |
+
******************************************************************************/
|
| 89 |
+
/*FUNCTION**********************************************************************
|
| 90 |
+
*
|
| 91 |
+
* Function Name : CLOCK_CONFIG_FllStableDelay
|
| 92 |
+
* Description : This function is used to delay for FLL stable.
|
| 93 |
+
*
|
| 94 |
+
*END**************************************************************************/
|
| 95 |
+
static void CLOCK_CONFIG_FllStableDelay(void)
|
| 96 |
+
{
|
| 97 |
+
uint32_t i = 30000U;
|
| 98 |
+
|
| 99 |
+
while (i--)
|
| 100 |
+
{
|
| 101 |
+
__NOP();
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/*FUNCTION**********************************************************************
|
| 106 |
+
*
|
| 107 |
+
* Function Name : CLOCK_CONFIG_SetRtcClock
|
| 108 |
+
* Description : This function is used to configuring RTC clock
|
| 109 |
+
*
|
| 110 |
+
*END**************************************************************************/
|
| 111 |
+
static void CLOCK_CONFIG_SetRtcClock()
|
| 112 |
+
{
|
| 113 |
+
/* RTC clock gate enable */
|
| 114 |
+
CLOCK_EnableClock(kCLOCK_Rtc0);
|
| 115 |
+
|
| 116 |
+
/* Set RTC_TSR if there is fault value in RTC */
|
| 117 |
+
if (RTC->SR & RTC_SR_TIF_MASK)
|
| 118 |
+
{
|
| 119 |
+
RTC -> TSR = RTC -> TSR;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/* RTC clock gate disable */
|
| 123 |
+
CLOCK_DisableClock(kCLOCK_Rtc0);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/*FUNCTION**********************************************************************
|
| 127 |
+
*
|
| 128 |
+
* Function Name : CLOCK_CONFIG_EnableRtcOsc
|
| 129 |
+
* Description : This function is used to enabling RTC oscillator
|
| 130 |
+
* Param capLoad : Oscillator capacity load
|
| 131 |
+
*
|
| 132 |
+
*END**************************************************************************/
|
| 133 |
+
static void CLOCK_CONFIG_EnableRtcOsc(uint32_t capLoad)
|
| 134 |
+
{
|
| 135 |
+
/* RTC clock gate enable */
|
| 136 |
+
CLOCK_EnableClock(kCLOCK_Rtc0);
|
| 137 |
+
|
| 138 |
+
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) /* Only if the Rtc oscillator is not already enabled */
|
| 139 |
+
{
|
| 140 |
+
/* Set the specified capacitor configuration for the RTC oscillator */
|
| 141 |
+
RTC_SetOscCapLoad(RTC, capLoad);
|
| 142 |
+
/* Enable the RTC 32KHz oscillator */
|
| 143 |
+
RTC->CR |= RTC_CR_OSCE_MASK;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* RTC clock gate disable */
|
| 147 |
+
CLOCK_DisableClock(kCLOCK_Rtc0);
|
| 148 |
+
CLOCK_SetXtal32Freq(32768);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/*FUNCTION**********************************************************************
|
| 152 |
+
*
|
| 153 |
+
* Function Name : BOARD_RfOscInit
|
| 154 |
+
* Description : This function is used to setup Ref oscillator for KW40_512.
|
| 155 |
+
*
|
| 156 |
+
*END**************************************************************************/
|
| 157 |
+
void BOARD_RfOscInit(void)
|
| 158 |
+
{
|
| 159 |
+
uint32_t tempTrim;
|
| 160 |
+
uint8_t revId;
|
| 161 |
+
|
| 162 |
+
/* Obtain REV ID from SIM */
|
| 163 |
+
revId = (uint8_t)((uint32_t)(SIM->SDID & SIM_SDID_REVID_MASK) >> SIM_SDID_REVID_SHIFT);
|
| 164 |
+
|
| 165 |
+
if (0 == revId)
|
| 166 |
+
{
|
| 167 |
+
tempTrim = RSIM->ANA_TRIM;
|
| 168 |
+
RSIM->ANA_TRIM |= RSIM_ANA_TRIM_BB_LDO_XO_TRIM_MASK; /* Set max trim for BB LDO for XO */
|
| 169 |
+
}/* Workaround for Rev 1.0 XTAL startup and ADC analog diagnostics circuitry */
|
| 170 |
+
|
| 171 |
+
/* Turn on clocks for the XCVR */
|
| 172 |
+
|
| 173 |
+
/* Enable RF OSC in RSIM and wait for ready */
|
| 174 |
+
RSIM->CONTROL = ((RSIM->CONTROL & ~RSIM_CONTROL_RF_OSC_EN_MASK) | RSIM_CONTROL_RF_OSC_EN(1));
|
| 175 |
+
|
| 176 |
+
/* ERR010224 */
|
| 177 |
+
RSIM->RF_OSC_CTRL |=
|
| 178 |
+
RSIM_RF_OSC_CTRL_RADIO_EXT_OSC_OVRD_EN_MASK; /* Prevent XTAL_OUT_EN from generating XTAL_OUT request */
|
| 179 |
+
|
| 180 |
+
while ((RSIM->CONTROL & RSIM_CONTROL_RF_OSC_READY_MASK) == 0); /* Wait for RF_OSC_READY */
|
| 181 |
+
|
| 182 |
+
if (0 == revId)
|
| 183 |
+
{
|
| 184 |
+
SIM->SCGC5 |= SIM_SCGC5_PHYDIG_MASK;
|
| 185 |
+
XCVR_TSM->OVRD0 |= XCVR_TSM_OVRD0_BB_LDO_ADCDAC_EN_OVRD_EN_MASK |
|
| 186 |
+
XCVR_TSM_OVRD0_BB_LDO_ADCDAC_EN_OVRD_MASK; /* Force ADC DAC LDO on to prevent BGAP failure */
|
| 187 |
+
|
| 188 |
+
RSIM->ANA_TRIM = tempTrim; /* Reset LDO trim settings */
|
| 189 |
+
}/* Workaround for Rev 1.0 XTAL startup and ADC analog diagnostics circuitry */
|
| 190 |
+
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/*FUNCTION**********************************************************************
|
| 194 |
+
*
|
| 195 |
+
* Function Name : BOARD_InitOsc0
|
| 196 |
+
* Description : This function is used to setup MCG OSC with Ref oscillator for KW40_512.
|
| 197 |
+
*
|
| 198 |
+
*END**************************************************************************/
|
| 199 |
+
void BOARD_InitOsc0(void)
|
| 200 |
+
{
|
| 201 |
+
const osc_config_t oscConfig =
|
| 202 |
+
{
|
| 203 |
+
.freq = BOARD_XTAL0_CLK_HZ, .workMode = kOSC_ModeExt,
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
/* Initializes OSC0 according to previous configuration to meet Ref OSC needs. */
|
| 207 |
+
CLOCK_InitOsc0(&oscConfig);
|
| 208 |
+
|
| 209 |
+
/* Passing the XTAL0 frequency to clock driver. */
|
| 210 |
+
CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/*******************************************************************************
|
| 214 |
+
********************** Configuration BOARD_BootClockRUN ***********************
|
| 215 |
+
******************************************************************************/
|
| 216 |
+
/* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
|
| 217 |
+
!!Configuration
|
| 218 |
+
name: BOARD_BootClockRUN
|
| 219 |
+
outputs:
|
| 220 |
+
- {id: Bus_clock.outFreq, value: 23.986176 MHz}
|
| 221 |
+
- {id: Core_clock.outFreq, value: 47.972352 MHz}
|
| 222 |
+
- {id: ERCLK32K.outFreq, value: 32.768 kHz}
|
| 223 |
+
- {id: Flash_clock.outFreq, value: 23.986176 MHz}
|
| 224 |
+
- {id: LPO_clock.outFreq, value: 1 kHz}
|
| 225 |
+
- {id: LPUART0CLK.outFreq, value: 32 MHz}
|
| 226 |
+
- {id: MCGFLLCLK.outFreq, value: 47.972352 MHz}
|
| 227 |
+
- {id: MCGIRCLK.outFreq, value: 32.768 kHz}
|
| 228 |
+
- {id: OSCERCLK.outFreq, value: 32 MHz}
|
| 229 |
+
- {id: System_clock.outFreq, value: 47.972352 MHz}
|
| 230 |
+
- {id: TPMCLK.outFreq, value: 32 MHz}
|
| 231 |
+
settings:
|
| 232 |
+
- {id: MCGMode, value: FEE}
|
| 233 |
+
- {id: LPUART0ClkConfig, value: 'yes'}
|
| 234 |
+
- {id: MCG.FCRDIV.scale, value: '1'}
|
| 235 |
+
- {id: MCG.FLL_mul.scale, value: '1464'}
|
| 236 |
+
- {id: MCG.IREFS.sel, value: MCG.FRDIV}
|
| 237 |
+
- {id: MCG.OSCSEL.sel, value: RTC_32K.OSCCLK32K}
|
| 238 |
+
- {id: MCG_C1_IRCLKEN_CFG, value: Enabled}
|
| 239 |
+
- {id: RTC_CR_OSCE_CFG, value: Oscillator_enabled}
|
| 240 |
+
- {id: SIM.LPUART0SRCSEL.sel, value: REFOSC.OSCCLK}
|
| 241 |
+
- {id: SIM.TPMSRCSEL.sel, value: REFOSC.OSCCLK}
|
| 242 |
+
- {id: TPMClkConfig, value: 'yes'}
|
| 243 |
+
sources:
|
| 244 |
+
- {id: REFOSC.OSC.outFreq, value: 32 MHz, enabled: true}
|
| 245 |
+
- {id: RTC_32K.OSC32kHz.outFreq, value: 32.768 kHz, enabled: true}
|
| 246 |
+
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
|
| 247 |
+
|
| 248 |
+
/*******************************************************************************
|
| 249 |
+
* Variables for BOARD_BootClockRUN configuration
|
| 250 |
+
******************************************************************************/
|
| 251 |
+
const mcg_config_t mcgConfig_BOARD_BootClockRUN =
|
| 252 |
+
{
|
| 253 |
+
.mcgMode = kMCG_ModeFEE, /* FEE - FLL Engaged External */
|
| 254 |
+
.irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
|
| 255 |
+
.ircs = kMCG_IrcSlow, /* Slow internal reference clock selected */
|
| 256 |
+
.fcrdiv = 0x0U, /* Fast IRC divider: divided by 1 */
|
| 257 |
+
.frdiv = 0x0U, /* FLL reference clock divider: divided by 1 */
|
| 258 |
+
.drs = kMCG_DrsMid, /* Mid frequency range */
|
| 259 |
+
.dmx32 = kMCG_Dmx32Fine, /* DCO is fine-tuned for maximum frequency with 32.768 kHz reference */
|
| 260 |
+
.oscsel = kMCG_OscselRtc, /* Selects 32 kHz RTC Oscillator */
|
| 261 |
+
};
|
| 262 |
+
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
|
| 263 |
+
{
|
| 264 |
+
.er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK, /* OSC32KSEL select: OSC32KCLK clock */
|
| 265 |
+
.clkdiv1 = 0x10000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
/*******************************************************************************
|
| 269 |
+
* Code for BOARD_BootClockRUN configuration
|
| 270 |
+
******************************************************************************/
|
| 271 |
+
void BOARD_BootClockRUN(void)
|
| 272 |
+
{
|
| 273 |
+
/* Setup the reference oscillator. */
|
| 274 |
+
BOARD_RfOscInit();
|
| 275 |
+
/* Set the system clock dividers in SIM to safe value. */
|
| 276 |
+
CLOCK_SetSimSafeDivs();
|
| 277 |
+
/* Enable RTC oscillator. */
|
| 278 |
+
CLOCK_CONFIG_EnableRtcOsc(RTC_OSC_CAP_LOAD_0PF);
|
| 279 |
+
/* Initializes OSC0 according to Ref OSC needs. */
|
| 280 |
+
BOARD_InitOsc0();
|
| 281 |
+
/* Set MCG to FEE mode. */
|
| 282 |
+
CLOCK_BootToFeeMode(mcgConfig_BOARD_BootClockRUN.oscsel,
|
| 283 |
+
mcgConfig_BOARD_BootClockRUN.frdiv,
|
| 284 |
+
mcgConfig_BOARD_BootClockRUN.dmx32,
|
| 285 |
+
mcgConfig_BOARD_BootClockRUN.drs,
|
| 286 |
+
CLOCK_CONFIG_FllStableDelay);
|
| 287 |
+
/* Configure the Internal Reference clock (MCGIRCLK). */
|
| 288 |
+
CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,
|
| 289 |
+
mcgConfig_BOARD_BootClockRUN.ircs,
|
| 290 |
+
mcgConfig_BOARD_BootClockRUN.fcrdiv);
|
| 291 |
+
/* Set the clock configuration in SIM module. */
|
| 292 |
+
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
|
| 293 |
+
/* Configure RTC clock. */
|
| 294 |
+
CLOCK_CONFIG_SetRtcClock();
|
| 295 |
+
/* Set SystemCoreClock variable. */
|
| 296 |
+
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
|
| 297 |
+
/* Set LPUART0 clock source. */
|
| 298 |
+
CLOCK_SetLpuartClock(SIM_LPUART_CLK_SEL_OSCERCLK_CLK);
|
| 299 |
+
/* Set TPM clock source. */
|
| 300 |
+
CLOCK_SetTpmClock(SIM_TPM_CLK_SEL_OSCERCLK_CLK);
|
| 301 |
+
}
|
| 302 |
+
|
pool/shard006/C/0117193_netdev.c
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
BNEP implementation for Linux Bluetooth stack (BlueZ).
|
| 3 |
+
Copyright (C) 2001-2002 Inventel Systemes
|
| 4 |
+
Written 2001-2002 by
|
| 5 |
+
Clément Moreau <clement.moreau@inventel.fr>
|
| 6 |
+
David Libault <david.libault@inventel.fr>
|
| 7 |
+
|
| 8 |
+
Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
|
| 9 |
+
|
| 10 |
+
This program is free software; you can redistribute it and/or modify
|
| 11 |
+
it under the terms of the GNU General Public License version 2 as
|
| 12 |
+
published by the Free Software Foundation;
|
| 13 |
+
|
| 14 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 15 |
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
| 17 |
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
|
| 18 |
+
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
|
| 19 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 20 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 21 |
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 22 |
+
|
| 23 |
+
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
|
| 24 |
+
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
|
| 25 |
+
SOFTWARE IS DISCLAIMED.
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
#include <linux/module.h>
|
| 29 |
+
#include <linux/interrupt.h>
|
| 30 |
+
#include <linux/slab.h>
|
| 31 |
+
|
| 32 |
+
#include <linux/socket.h>
|
| 33 |
+
#include <linux/netdevice.h>
|
| 34 |
+
#include <linux/etherdevice.h>
|
| 35 |
+
#include <linux/skbuff.h>
|
| 36 |
+
#include <linux/wait.h>
|
| 37 |
+
|
| 38 |
+
#include <asm/unaligned.h>
|
| 39 |
+
|
| 40 |
+
#include <net/bluetooth/bluetooth.h>
|
| 41 |
+
#include <net/bluetooth/hci_core.h>
|
| 42 |
+
#include <net/bluetooth/l2cap.h>
|
| 43 |
+
|
| 44 |
+
#include "bnep.h"
|
| 45 |
+
|
| 46 |
+
#define BNEP_TX_QUEUE_LEN 20
|
| 47 |
+
|
| 48 |
+
static int bnep_net_open(struct net_device *dev)
|
| 49 |
+
{
|
| 50 |
+
netif_start_queue(dev);
|
| 51 |
+
return 0;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
static int bnep_net_close(struct net_device *dev)
|
| 55 |
+
{
|
| 56 |
+
netif_stop_queue(dev);
|
| 57 |
+
return 0;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
static void bnep_net_set_mc_list(struct net_device *dev)
|
| 61 |
+
{
|
| 62 |
+
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
| 63 |
+
struct bnep_session *s = netdev_priv(dev);
|
| 64 |
+
struct sock *sk = s->sock->sk;
|
| 65 |
+
struct bnep_set_filter_req *r;
|
| 66 |
+
struct sk_buff *skb;
|
| 67 |
+
int size;
|
| 68 |
+
|
| 69 |
+
BT_DBG("%s mc_count %d", dev->name, netdev_mc_count(dev));
|
| 70 |
+
|
| 71 |
+
size = sizeof(*r) + (BNEP_MAX_MULTICAST_FILTERS + 1) * ETH_ALEN * 2;
|
| 72 |
+
skb = alloc_skb(size, GFP_ATOMIC);
|
| 73 |
+
if (!skb) {
|
| 74 |
+
BT_ERR("%s Multicast list allocation failed", dev->name);
|
| 75 |
+
return;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
r = (void *) skb->data;
|
| 79 |
+
__skb_put(skb, sizeof(*r));
|
| 80 |
+
|
| 81 |
+
r->type = BNEP_CONTROL;
|
| 82 |
+
r->ctrl = BNEP_FILTER_MULTI_ADDR_SET;
|
| 83 |
+
|
| 84 |
+
if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
|
| 85 |
+
u8 start[ETH_ALEN] = { 0x01 };
|
| 86 |
+
|
| 87 |
+
/* Request all addresses */
|
| 88 |
+
memcpy(__skb_put(skb, ETH_ALEN), start, ETH_ALEN);
|
| 89 |
+
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
| 90 |
+
r->len = htons(ETH_ALEN * 2);
|
| 91 |
+
} else {
|
| 92 |
+
struct netdev_hw_addr *ha;
|
| 93 |
+
int i, len = skb->len;
|
| 94 |
+
|
| 95 |
+
if (dev->flags & IFF_BROADCAST) {
|
| 96 |
+
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
| 97 |
+
memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/* FIXME: We should group addresses here. */
|
| 101 |
+
|
| 102 |
+
i = 0;
|
| 103 |
+
netdev_for_each_mc_addr(ha, dev) {
|
| 104 |
+
if (i == BNEP_MAX_MULTICAST_FILTERS)
|
| 105 |
+
break;
|
| 106 |
+
memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN);
|
| 107 |
+
memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN);
|
| 108 |
+
|
| 109 |
+
i++;
|
| 110 |
+
}
|
| 111 |
+
r->len = htons(skb->len - len);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
skb_queue_tail(&sk->sk_write_queue, skb);
|
| 115 |
+
wake_up_interruptible(sk_sleep(sk));
|
| 116 |
+
#endif
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
static int bnep_net_set_mac_addr(struct net_device *dev, void *arg)
|
| 120 |
+
{
|
| 121 |
+
BT_DBG("%s", dev->name);
|
| 122 |
+
return 0;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static void bnep_net_timeout(struct net_device *dev)
|
| 126 |
+
{
|
| 127 |
+
BT_DBG("net_timeout");
|
| 128 |
+
netif_wake_queue(dev);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
| 132 |
+
static inline int bnep_net_mc_filter(struct sk_buff *skb, struct bnep_session *s)
|
| 133 |
+
{
|
| 134 |
+
struct ethhdr *eh = (void *) skb->data;
|
| 135 |
+
|
| 136 |
+
if ((eh->h_dest[0] & 1) && !test_bit(bnep_mc_hash(eh->h_dest), (ulong *) &s->mc_filter))
|
| 137 |
+
return 1;
|
| 138 |
+
return 0;
|
| 139 |
+
}
|
| 140 |
+
#endif
|
| 141 |
+
|
| 142 |
+
#ifdef CONFIG_BT_BNEP_PROTO_FILTER
|
| 143 |
+
/* Determine ether protocol. Based on eth_type_trans. */
|
| 144 |
+
static inline u16 bnep_net_eth_proto(struct sk_buff *skb)
|
| 145 |
+
{
|
| 146 |
+
struct ethhdr *eh = (void *) skb->data;
|
| 147 |
+
u16 proto = ntohs(eh->h_proto);
|
| 148 |
+
|
| 149 |
+
if (proto >= 1536)
|
| 150 |
+
return proto;
|
| 151 |
+
|
| 152 |
+
if (get_unaligned((__be16 *) skb->data) == htons(0xFFFF))
|
| 153 |
+
return ETH_P_802_3;
|
| 154 |
+
|
| 155 |
+
return ETH_P_802_2;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static inline int bnep_net_proto_filter(struct sk_buff *skb, struct bnep_session *s)
|
| 159 |
+
{
|
| 160 |
+
u16 proto = bnep_net_eth_proto(skb);
|
| 161 |
+
struct bnep_proto_filter *f = s->proto_filter;
|
| 162 |
+
int i;
|
| 163 |
+
|
| 164 |
+
for (i = 0; i < BNEP_MAX_PROTO_FILTERS && f[i].end; i++) {
|
| 165 |
+
if (proto >= f[i].start && proto <= f[i].end)
|
| 166 |
+
return 0;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
BT_DBG("BNEP: filtered skb %p, proto 0x%.4x", skb, proto);
|
| 170 |
+
return 1;
|
| 171 |
+
}
|
| 172 |
+
#endif
|
| 173 |
+
|
| 174 |
+
static netdev_tx_t bnep_net_xmit(struct sk_buff *skb,
|
| 175 |
+
struct net_device *dev)
|
| 176 |
+
{
|
| 177 |
+
struct bnep_session *s = netdev_priv(dev);
|
| 178 |
+
struct sock *sk = s->sock->sk;
|
| 179 |
+
|
| 180 |
+
BT_DBG("skb %p, dev %p", skb, dev);
|
| 181 |
+
|
| 182 |
+
#ifdef CONFIG_BT_BNEP_MC_FILTER
|
| 183 |
+
if (bnep_net_mc_filter(skb, s)) {
|
| 184 |
+
kfree_skb(skb);
|
| 185 |
+
return NETDEV_TX_OK;
|
| 186 |
+
}
|
| 187 |
+
#endif
|
| 188 |
+
|
| 189 |
+
#ifdef CONFIG_BT_BNEP_PROTO_FILTER
|
| 190 |
+
if (bnep_net_proto_filter(skb, s)) {
|
| 191 |
+
kfree_skb(skb);
|
| 192 |
+
return NETDEV_TX_OK;
|
| 193 |
+
}
|
| 194 |
+
#endif
|
| 195 |
+
|
| 196 |
+
/*
|
| 197 |
+
* We cannot send L2CAP packets from here as we are potentially in a bh.
|
| 198 |
+
* So we have to queue them and wake up session thread which is sleeping
|
| 199 |
+
* on the sk_sleep(sk).
|
| 200 |
+
*/
|
| 201 |
+
dev->trans_start = jiffies;
|
| 202 |
+
skb_queue_tail(&sk->sk_write_queue, skb);
|
| 203 |
+
wake_up_interruptible(sk_sleep(sk));
|
| 204 |
+
|
| 205 |
+
if (skb_queue_len(&sk->sk_write_queue) >= BNEP_TX_QUEUE_LEN) {
|
| 206 |
+
BT_DBG("tx queue is full");
|
| 207 |
+
|
| 208 |
+
/* Stop queuing.
|
| 209 |
+
* Session thread will do netif_wake_queue() */
|
| 210 |
+
netif_stop_queue(dev);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
return NETDEV_TX_OK;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
static const struct net_device_ops bnep_netdev_ops = {
|
| 217 |
+
.ndo_open = bnep_net_open,
|
| 218 |
+
.ndo_stop = bnep_net_close,
|
| 219 |
+
.ndo_start_xmit = bnep_net_xmit,
|
| 220 |
+
.ndo_validate_addr = eth_validate_addr,
|
| 221 |
+
.ndo_set_rx_mode = bnep_net_set_mc_list,
|
| 222 |
+
.ndo_set_mac_address = bnep_net_set_mac_addr,
|
| 223 |
+
.ndo_tx_timeout = bnep_net_timeout,
|
| 224 |
+
.ndo_change_mtu = eth_change_mtu,
|
| 225 |
+
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
void bnep_net_setup(struct net_device *dev)
|
| 229 |
+
{
|
| 230 |
+
|
| 231 |
+
memset(dev->broadcast, 0xff, ETH_ALEN);
|
| 232 |
+
dev->addr_len = ETH_ALEN;
|
| 233 |
+
|
| 234 |
+
ether_setup(dev);
|
| 235 |
+
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
|
| 236 |
+
dev->netdev_ops = &bnep_netdev_ops;
|
| 237 |
+
|
| 238 |
+
dev->watchdog_timeo = HZ * 2;
|
| 239 |
+
}
|
pool/shard006/C/0117201_iwl-rx.c
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* Portions of this file are derived from the ipw3945 project, as well
|
| 6 |
+
* as portions of the ieee80211 subsystem header files.
|
| 7 |
+
*
|
| 8 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 9 |
+
* under the terms of version 2 of the GNU General Public License as
|
| 10 |
+
* published by the Free Software Foundation.
|
| 11 |
+
*
|
| 12 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 13 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 14 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 15 |
+
* more details.
|
| 16 |
+
*
|
| 17 |
+
* You should have received a copy of the GNU General Public License along with
|
| 18 |
+
* this program; if not, write to the Free Software Foundation, Inc.,
|
| 19 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
| 20 |
+
*
|
| 21 |
+
* The full GNU General Public License is included in this distribution in the
|
| 22 |
+
* file called LICENSE.
|
| 23 |
+
*
|
| 24 |
+
* Contact Information:
|
| 25 |
+
* Intel Linux Wireless <ilw@linux.intel.com>
|
| 26 |
+
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
| 27 |
+
*
|
| 28 |
+
*****************************************************************************/
|
| 29 |
+
|
| 30 |
+
#include <linux/etherdevice.h>
|
| 31 |
+
#include <linux/slab.h>
|
| 32 |
+
#include <net/mac80211.h>
|
| 33 |
+
#include <asm/unaligned.h>
|
| 34 |
+
#include "iwl-eeprom.h"
|
| 35 |
+
#include "iwl-dev.h"
|
| 36 |
+
#include "iwl-core.h"
|
| 37 |
+
#include "iwl-sta.h"
|
| 38 |
+
#include "iwl-io.h"
|
| 39 |
+
#include "iwl-helpers.h"
|
| 40 |
+
/************************** RX-FUNCTIONS ****************************/
|
| 41 |
+
/*
|
| 42 |
+
* Rx theory of operation
|
| 43 |
+
*
|
| 44 |
+
* Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
|
| 45 |
+
* each of which point to Receive Buffers to be filled by the NIC. These get
|
| 46 |
+
* used not only for Rx frames, but for any command response or notification
|
| 47 |
+
* from the NIC. The driver and NIC manage the Rx buffers by means
|
| 48 |
+
* of indexes into the circular buffer.
|
| 49 |
+
*
|
| 50 |
+
* Rx Queue Indexes
|
| 51 |
+
* The host/firmware share two index registers for managing the Rx buffers.
|
| 52 |
+
*
|
| 53 |
+
* The READ index maps to the first position that the firmware may be writing
|
| 54 |
+
* to -- the driver can read up to (but not including) this position and get
|
| 55 |
+
* good data.
|
| 56 |
+
* The READ index is managed by the firmware once the card is enabled.
|
| 57 |
+
*
|
| 58 |
+
* The WRITE index maps to the last position the driver has read from -- the
|
| 59 |
+
* position preceding WRITE is the last slot the firmware can place a packet.
|
| 60 |
+
*
|
| 61 |
+
* The queue is empty (no good data) if WRITE = READ - 1, and is full if
|
| 62 |
+
* WRITE = READ.
|
| 63 |
+
*
|
| 64 |
+
* During initialization, the host sets up the READ queue position to the first
|
| 65 |
+
* INDEX position, and WRITE to the last (READ - 1 wrapped)
|
| 66 |
+
*
|
| 67 |
+
* When the firmware places a packet in a buffer, it will advance the READ index
|
| 68 |
+
* and fire the RX interrupt. The driver can then query the READ index and
|
| 69 |
+
* process as many packets as possible, moving the WRITE index forward as it
|
| 70 |
+
* resets the Rx queue buffers with new memory.
|
| 71 |
+
*
|
| 72 |
+
* The management in the driver is as follows:
|
| 73 |
+
* + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
|
| 74 |
+
* iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
|
| 75 |
+
* to replenish the iwl->rxq->rx_free.
|
| 76 |
+
* + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
|
| 77 |
+
* iwl->rxq is replenished and the READ INDEX is updated (updating the
|
| 78 |
+
* 'processed' and 'read' driver indexes as well)
|
| 79 |
+
* + A received packet is processed and handed to the kernel network stack,
|
| 80 |
+
* detached from the iwl->rxq. The driver 'processed' index is updated.
|
| 81 |
+
* + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
|
| 82 |
+
* list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
|
| 83 |
+
* INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
|
| 84 |
+
* were enough free buffers and RX_STALLED is set it is cleared.
|
| 85 |
+
*
|
| 86 |
+
*
|
| 87 |
+
* Driver sequence:
|
| 88 |
+
*
|
| 89 |
+
* iwl_legacy_rx_queue_alloc() Allocates rx_free
|
| 90 |
+
* iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
|
| 91 |
+
* iwl_rx_queue_restock
|
| 92 |
+
* iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
|
| 93 |
+
* queue, updates firmware pointers, and updates
|
| 94 |
+
* the WRITE index. If insufficient rx_free buffers
|
| 95 |
+
* are available, schedules iwl_rx_replenish
|
| 96 |
+
*
|
| 97 |
+
* -- enable interrupts --
|
| 98 |
+
* ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
|
| 99 |
+
* READ INDEX, detaching the SKB from the pool.
|
| 100 |
+
* Moves the packet buffer from queue to rx_used.
|
| 101 |
+
* Calls iwl_rx_queue_restock to refill any empty
|
| 102 |
+
* slots.
|
| 103 |
+
* ...
|
| 104 |
+
*
|
| 105 |
+
*/
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* iwl_legacy_rx_queue_space - Return number of free slots available in queue.
|
| 109 |
+
*/
|
| 110 |
+
int iwl_legacy_rx_queue_space(const struct iwl_rx_queue *q)
|
| 111 |
+
{
|
| 112 |
+
int s = q->read - q->write;
|
| 113 |
+
if (s <= 0)
|
| 114 |
+
s += RX_QUEUE_SIZE;
|
| 115 |
+
/* keep some buffer to not confuse full and empty queue */
|
| 116 |
+
s -= 2;
|
| 117 |
+
if (s < 0)
|
| 118 |
+
s = 0;
|
| 119 |
+
return s;
|
| 120 |
+
}
|
| 121 |
+
EXPORT_SYMBOL(iwl_legacy_rx_queue_space);
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* iwl_legacy_rx_queue_update_write_ptr - Update the write pointer for the RX queue
|
| 125 |
+
*/
|
| 126 |
+
void
|
| 127 |
+
iwl_legacy_rx_queue_update_write_ptr(struct iwl_priv *priv,
|
| 128 |
+
struct iwl_rx_queue *q)
|
| 129 |
+
{
|
| 130 |
+
unsigned long flags;
|
| 131 |
+
u32 rx_wrt_ptr_reg = priv->hw_params.rx_wrt_ptr_reg;
|
| 132 |
+
u32 reg;
|
| 133 |
+
|
| 134 |
+
spin_lock_irqsave(&q->lock, flags);
|
| 135 |
+
|
| 136 |
+
if (q->need_update == 0)
|
| 137 |
+
goto exit_unlock;
|
| 138 |
+
|
| 139 |
+
/* If power-saving is in use, make sure device is awake */
|
| 140 |
+
if (test_bit(STATUS_POWER_PMI, &priv->status)) {
|
| 141 |
+
reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
|
| 142 |
+
|
| 143 |
+
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
|
| 144 |
+
IWL_DEBUG_INFO(priv,
|
| 145 |
+
"Rx queue requesting wakeup,"
|
| 146 |
+
" GP1 = 0x%x\n", reg);
|
| 147 |
+
iwl_legacy_set_bit(priv, CSR_GP_CNTRL,
|
| 148 |
+
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
|
| 149 |
+
goto exit_unlock;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
q->write_actual = (q->write & ~0x7);
|
| 153 |
+
iwl_legacy_write_direct32(priv, rx_wrt_ptr_reg,
|
| 154 |
+
q->write_actual);
|
| 155 |
+
|
| 156 |
+
/* Else device is assumed to be awake */
|
| 157 |
+
} else {
|
| 158 |
+
/* Device expects a multiple of 8 */
|
| 159 |
+
q->write_actual = (q->write & ~0x7);
|
| 160 |
+
iwl_legacy_write_direct32(priv, rx_wrt_ptr_reg,
|
| 161 |
+
q->write_actual);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
q->need_update = 0;
|
| 165 |
+
|
| 166 |
+
exit_unlock:
|
| 167 |
+
spin_unlock_irqrestore(&q->lock, flags);
|
| 168 |
+
}
|
| 169 |
+
EXPORT_SYMBOL(iwl_legacy_rx_queue_update_write_ptr);
|
| 170 |
+
|
| 171 |
+
int iwl_legacy_rx_queue_alloc(struct iwl_priv *priv)
|
| 172 |
+
{
|
| 173 |
+
struct iwl_rx_queue *rxq = &priv->rxq;
|
| 174 |
+
struct device *dev = &priv->pci_dev->dev;
|
| 175 |
+
int i;
|
| 176 |
+
|
| 177 |
+
spin_lock_init(&rxq->lock);
|
| 178 |
+
INIT_LIST_HEAD(&rxq->rx_free);
|
| 179 |
+
INIT_LIST_HEAD(&rxq->rx_used);
|
| 180 |
+
|
| 181 |
+
/* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
|
| 182 |
+
rxq->bd = dma_alloc_coherent(dev, 4 * RX_QUEUE_SIZE, &rxq->bd_dma,
|
| 183 |
+
GFP_KERNEL);
|
| 184 |
+
if (!rxq->bd)
|
| 185 |
+
goto err_bd;
|
| 186 |
+
|
| 187 |
+
rxq->rb_stts = dma_alloc_coherent(dev, sizeof(struct iwl_rb_status),
|
| 188 |
+
&rxq->rb_stts_dma, GFP_KERNEL);
|
| 189 |
+
if (!rxq->rb_stts)
|
| 190 |
+
goto err_rb;
|
| 191 |
+
|
| 192 |
+
/* Fill the rx_used queue with _all_ of the Rx buffers */
|
| 193 |
+
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
|
| 194 |
+
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
|
| 195 |
+
|
| 196 |
+
/* Set us so that we have processed and used all buffers, but have
|
| 197 |
+
* not restocked the Rx queue with fresh buffers */
|
| 198 |
+
rxq->read = rxq->write = 0;
|
| 199 |
+
rxq->write_actual = 0;
|
| 200 |
+
rxq->free_count = 0;
|
| 201 |
+
rxq->need_update = 0;
|
| 202 |
+
return 0;
|
| 203 |
+
|
| 204 |
+
err_rb:
|
| 205 |
+
dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
|
| 206 |
+
rxq->bd_dma);
|
| 207 |
+
err_bd:
|
| 208 |
+
return -ENOMEM;
|
| 209 |
+
}
|
| 210 |
+
EXPORT_SYMBOL(iwl_legacy_rx_queue_alloc);
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
void iwl_legacy_rx_spectrum_measure_notif(struct iwl_priv *priv,
|
| 214 |
+
struct iwl_rx_mem_buffer *rxb)
|
| 215 |
+
{
|
| 216 |
+
struct iwl_rx_packet *pkt = rxb_addr(rxb);
|
| 217 |
+
struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
|
| 218 |
+
|
| 219 |
+
if (!report->state) {
|
| 220 |
+
IWL_DEBUG_11H(priv,
|
| 221 |
+
"Spectrum Measure Notification: Start\n");
|
| 222 |
+
return;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
memcpy(&priv->measure_report, report, sizeof(*report));
|
| 226 |
+
priv->measurement_status |= MEASUREMENT_READY;
|
| 227 |
+
}
|
| 228 |
+
EXPORT_SYMBOL(iwl_legacy_rx_spectrum_measure_notif);
|
| 229 |
+
|
| 230 |
+
/*
|
| 231 |
+
* returns non-zero if packet should be dropped
|
| 232 |
+
*/
|
| 233 |
+
int iwl_legacy_set_decrypted_flag(struct iwl_priv *priv,
|
| 234 |
+
struct ieee80211_hdr *hdr,
|
| 235 |
+
u32 decrypt_res,
|
| 236 |
+
struct ieee80211_rx_status *stats)
|
| 237 |
+
{
|
| 238 |
+
u16 fc = le16_to_cpu(hdr->frame_control);
|
| 239 |
+
|
| 240 |
+
/*
|
| 241 |
+
* All contexts have the same setting here due to it being
|
| 242 |
+
* a module parameter, so OK to check any context.
|
| 243 |
+
*/
|
| 244 |
+
if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
|
| 245 |
+
RXON_FILTER_DIS_DECRYPT_MSK)
|
| 246 |
+
return 0;
|
| 247 |
+
|
| 248 |
+
if (!(fc & IEEE80211_FCTL_PROTECTED))
|
| 249 |
+
return 0;
|
| 250 |
+
|
| 251 |
+
IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
|
| 252 |
+
switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
|
| 253 |
+
case RX_RES_STATUS_SEC_TYPE_TKIP:
|
| 254 |
+
/* The uCode has got a bad phase 1 Key, pushes the packet.
|
| 255 |
+
* Decryption will be done in SW. */
|
| 256 |
+
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
|
| 257 |
+
RX_RES_STATUS_BAD_KEY_TTAK)
|
| 258 |
+
break;
|
| 259 |
+
|
| 260 |
+
case RX_RES_STATUS_SEC_TYPE_WEP:
|
| 261 |
+
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
|
| 262 |
+
RX_RES_STATUS_BAD_ICV_MIC) {
|
| 263 |
+
/* bad ICV, the packet is destroyed since the
|
| 264 |
+
* decryption is inplace, drop it */
|
| 265 |
+
IWL_DEBUG_RX(priv, "Packet destroyed\n");
|
| 266 |
+
return -1;
|
| 267 |
+
}
|
| 268 |
+
case RX_RES_STATUS_SEC_TYPE_CCMP:
|
| 269 |
+
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
|
| 270 |
+
RX_RES_STATUS_DECRYPT_OK) {
|
| 271 |
+
IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
|
| 272 |
+
stats->flag |= RX_FLAG_DECRYPTED;
|
| 273 |
+
}
|
| 274 |
+
break;
|
| 275 |
+
|
| 276 |
+
default:
|
| 277 |
+
break;
|
| 278 |
+
}
|
| 279 |
+
return 0;
|
| 280 |
+
}
|
| 281 |
+
EXPORT_SYMBOL(iwl_legacy_set_decrypted_flag);
|
pool/shard006/C/0117203_yaffs_ramdisk.c
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* YAFFS: Yet another FFS. A NAND-flash specific file system.
|
| 3 |
+
* yaffs_ramdisk.c: yaffs ram disk component
|
| 4 |
+
*
|
| 5 |
+
* Copyright (C) 2002 Aleph One Ltd.
|
| 6 |
+
*
|
| 7 |
+
* Created by Charles Manning <charles@aleph1.co.uk>
|
| 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 |
+
*/
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
const char *yaffs_ramdisk_c_version = "$Id: yaffs_ramdisk.c,v 1.2 2004/11/22 03:22:25 charles Exp $";
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
#include "yportenv.h"
|
| 20 |
+
|
| 21 |
+
#include "yaffs_ramdisk.h"
|
| 22 |
+
#include "yaffs_guts.h"
|
| 23 |
+
#include "devextras.h"
|
| 24 |
+
#include "yaffs_packedtags1.h"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
#define SIZE_IN_MB 2
|
| 29 |
+
|
| 30 |
+
#define BLOCK_SIZE (32 * 528)
|
| 31 |
+
#define BLOCKS_PER_MEG ((1024*1024)/(32 * 512))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
typedef struct
|
| 38 |
+
{
|
| 39 |
+
__u8 data[528];
|
| 40 |
+
} yramdisk_Page;
|
| 41 |
+
|
| 42 |
+
typedef struct
|
| 43 |
+
{
|
| 44 |
+
yramdisk_Page page[32];
|
| 45 |
+
|
| 46 |
+
} yramdisk_Block;
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
typedef struct
|
| 51 |
+
{
|
| 52 |
+
yramdisk_Block **block;
|
| 53 |
+
int nBlocks;
|
| 54 |
+
} yramdisk_Device;
|
| 55 |
+
|
| 56 |
+
static yramdisk_Device ramdisk;
|
| 57 |
+
|
| 58 |
+
static int CheckInit(yaffs_Device *dev)
|
| 59 |
+
{
|
| 60 |
+
static int initialised = 0;
|
| 61 |
+
|
| 62 |
+
int i;
|
| 63 |
+
int fail = 0;
|
| 64 |
+
|
| 65 |
+
int nAllocated = 0;
|
| 66 |
+
|
| 67 |
+
if(initialised)
|
| 68 |
+
{
|
| 69 |
+
return YAFFS_OK;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
initialised = 1;
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024);
|
| 76 |
+
|
| 77 |
+
ramdisk.block = YMALLOC(sizeof(yramdisk_Block *) * ramdisk.nBlocks);
|
| 78 |
+
|
| 79 |
+
if(!ramdisk.block) return 0;
|
| 80 |
+
|
| 81 |
+
for(i=0; i <ramdisk.nBlocks; i++)
|
| 82 |
+
{
|
| 83 |
+
ramdisk.block[i] = NULL;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
for(i=0; i <ramdisk.nBlocks && !fail; i++)
|
| 87 |
+
{
|
| 88 |
+
if((ramdisk.block[i] = YMALLOC(sizeof(yramdisk_Block))) == 0)
|
| 89 |
+
{
|
| 90 |
+
fail = 1;
|
| 91 |
+
}
|
| 92 |
+
else
|
| 93 |
+
{
|
| 94 |
+
yramdisk_EraseBlockInNAND(dev,i);
|
| 95 |
+
nAllocated++;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if(fail)
|
| 100 |
+
{
|
| 101 |
+
for(i = 0; i < nAllocated; i++)
|
| 102 |
+
{
|
| 103 |
+
YFREE(ramdisk.block[i]);
|
| 104 |
+
}
|
| 105 |
+
YFREE(ramdisk.block);
|
| 106 |
+
|
| 107 |
+
T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n",
|
| 108 |
+
nAllocated/64,ramdisk.nBlocks * 528));
|
| 109 |
+
return 0;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
return 1;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
int yramdisk_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_ExtendedTags *tags)
|
| 117 |
+
{
|
| 118 |
+
int blk;
|
| 119 |
+
int pg;
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
CheckInit(dev);
|
| 123 |
+
|
| 124 |
+
blk = chunkInNAND/32;
|
| 125 |
+
pg = chunkInNAND%32;
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if(data)
|
| 129 |
+
{
|
| 130 |
+
memcpy(ramdisk.block[blk]->page[pg].data,data,512);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if(tags)
|
| 135 |
+
{
|
| 136 |
+
yaffs_PackedTags1 pt;
|
| 137 |
+
|
| 138 |
+
yaffs_PackTags1(&pt,tags);
|
| 139 |
+
memcpy(&ramdisk.block[blk]->page[pg].data[512],&pt,sizeof(pt));
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
return YAFFS_OK;
|
| 143 |
+
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
int yramdisk_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
|
| 148 |
+
{
|
| 149 |
+
int blk;
|
| 150 |
+
int pg;
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
CheckInit(dev);
|
| 154 |
+
|
| 155 |
+
blk = chunkInNAND/32;
|
| 156 |
+
pg = chunkInNAND%32;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
if(data)
|
| 160 |
+
{
|
| 161 |
+
memcpy(data,ramdisk.block[blk]->page[pg].data,512);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if(tags)
|
| 166 |
+
{
|
| 167 |
+
yaffs_PackedTags1 pt;
|
| 168 |
+
|
| 169 |
+
memcpy(&pt,&ramdisk.block[blk]->page[pg].data[512],sizeof(pt));
|
| 170 |
+
yaffs_UnpackTags1(tags,&pt);
|
| 171 |
+
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
return YAFFS_OK;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
int yramdisk_CheckChunkErased(yaffs_Device *dev,int chunkInNAND)
|
| 179 |
+
{
|
| 180 |
+
int blk;
|
| 181 |
+
int pg;
|
| 182 |
+
int i;
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
CheckInit(dev);
|
| 186 |
+
|
| 187 |
+
blk = chunkInNAND/32;
|
| 188 |
+
pg = chunkInNAND%32;
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
for(i = 0; i < 528; i++)
|
| 192 |
+
{
|
| 193 |
+
if(ramdisk.block[blk]->page[pg].data[i] != 0xFF)
|
| 194 |
+
{
|
| 195 |
+
return YAFFS_FAIL;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
return YAFFS_OK;
|
| 200 |
+
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
int yramdisk_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
|
| 204 |
+
{
|
| 205 |
+
|
| 206 |
+
CheckInit(dev);
|
| 207 |
+
|
| 208 |
+
if(blockNumber < 0 || blockNumber >= ramdisk.nBlocks)
|
| 209 |
+
{
|
| 210 |
+
T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
|
| 211 |
+
return YAFFS_FAIL;
|
| 212 |
+
}
|
| 213 |
+
else
|
| 214 |
+
{
|
| 215 |
+
memset(ramdisk.block[blockNumber],0xFF,sizeof(yramdisk_Block));
|
| 216 |
+
return YAFFS_OK;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
int yramdisk_InitialiseNAND(yaffs_Device *dev)
|
| 222 |
+
{
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
return YAFFS_OK;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
|
pool/shard006/C/0117206_dpll44xx.c
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* OMAP4-specific DPLL control functions
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2011 Texas Instruments, Inc.
|
| 5 |
+
* Rajendra Nayak
|
| 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/kernel.h>
|
| 13 |
+
#include <linux/errno.h>
|
| 14 |
+
#include <linux/clk.h>
|
| 15 |
+
#include <linux/io.h>
|
| 16 |
+
#include <linux/bitops.h>
|
| 17 |
+
|
| 18 |
+
#include <plat/cpu.h>
|
| 19 |
+
#include <plat/clock.h>
|
| 20 |
+
|
| 21 |
+
#include "clock.h"
|
| 22 |
+
#include "clock44xx.h"
|
| 23 |
+
#include "cm-regbits-44xx.h"
|
| 24 |
+
|
| 25 |
+
/* Supported only on OMAP4 */
|
| 26 |
+
int omap4_dpllmx_gatectrl_read(struct clk *clk)
|
| 27 |
+
{
|
| 28 |
+
u32 v;
|
| 29 |
+
u32 mask;
|
| 30 |
+
|
| 31 |
+
if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
|
| 32 |
+
return -EINVAL;
|
| 33 |
+
|
| 34 |
+
mask = clk->flags & CLOCK_CLKOUTX2 ?
|
| 35 |
+
OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
|
| 36 |
+
OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
|
| 37 |
+
|
| 38 |
+
v = __raw_readl(clk->clksel_reg);
|
| 39 |
+
v &= mask;
|
| 40 |
+
v >>= __ffs(mask);
|
| 41 |
+
|
| 42 |
+
return v;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void omap4_dpllmx_allow_gatectrl(struct clk *clk)
|
| 46 |
+
{
|
| 47 |
+
u32 v;
|
| 48 |
+
u32 mask;
|
| 49 |
+
|
| 50 |
+
if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
|
| 51 |
+
return;
|
| 52 |
+
|
| 53 |
+
mask = clk->flags & CLOCK_CLKOUTX2 ?
|
| 54 |
+
OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
|
| 55 |
+
OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
|
| 56 |
+
|
| 57 |
+
v = __raw_readl(clk->clksel_reg);
|
| 58 |
+
/* Clear the bit to allow gatectrl */
|
| 59 |
+
v &= ~mask;
|
| 60 |
+
__raw_writel(v, clk->clksel_reg);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
void omap4_dpllmx_deny_gatectrl(struct clk *clk)
|
| 64 |
+
{
|
| 65 |
+
u32 v;
|
| 66 |
+
u32 mask;
|
| 67 |
+
|
| 68 |
+
if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
|
| 69 |
+
return;
|
| 70 |
+
|
| 71 |
+
mask = clk->flags & CLOCK_CLKOUTX2 ?
|
| 72 |
+
OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
|
| 73 |
+
OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
|
| 74 |
+
|
| 75 |
+
v = __raw_readl(clk->clksel_reg);
|
| 76 |
+
/* Set the bit to deny gatectrl */
|
| 77 |
+
v |= mask;
|
| 78 |
+
__raw_writel(v, clk->clksel_reg);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
const struct clkops clkops_omap4_dpllmx_ops = {
|
| 82 |
+
.allow_idle = omap4_dpllmx_allow_gatectrl,
|
| 83 |
+
.deny_idle = omap4_dpllmx_deny_gatectrl,
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
|
| 88 |
+
* @clk: struct clk * of the DPLL to compute the rate for
|
| 89 |
+
*
|
| 90 |
+
* Compute the output rate for the OMAP4 DPLL represented by @clk.
|
| 91 |
+
* Takes the REGM4XEN bit into consideration, which is needed for the
|
| 92 |
+
* OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
|
| 93 |
+
* upon success, or 0 upon error.
|
| 94 |
+
*/
|
| 95 |
+
unsigned long omap4_dpll_regm4xen_recalc(struct clk *clk)
|
| 96 |
+
{
|
| 97 |
+
u32 v;
|
| 98 |
+
unsigned long rate;
|
| 99 |
+
struct dpll_data *dd;
|
| 100 |
+
|
| 101 |
+
if (!clk || !clk->dpll_data)
|
| 102 |
+
return 0;
|
| 103 |
+
|
| 104 |
+
dd = clk->dpll_data;
|
| 105 |
+
|
| 106 |
+
rate = omap2_get_dpll_rate(clk);
|
| 107 |
+
|
| 108 |
+
/* regm4xen adds a multiplier of 4 to DPLL calculations */
|
| 109 |
+
v = __raw_readl(dd->control_reg);
|
| 110 |
+
if (v & OMAP4430_DPLL_REGM4XEN_MASK)
|
| 111 |
+
rate *= OMAP4430_REGM4XEN_MULT;
|
| 112 |
+
|
| 113 |
+
return rate;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
|
| 118 |
+
* @clk: struct clk * of the DPLL to round a rate for
|
| 119 |
+
* @target_rate: the desired rate of the DPLL
|
| 120 |
+
*
|
| 121 |
+
* Compute the rate that would be programmed into the DPLL hardware
|
| 122 |
+
* for @clk if set_rate() were to be provided with the rate
|
| 123 |
+
* @target_rate. Takes the REGM4XEN bit into consideration, which is
|
| 124 |
+
* needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
|
| 125 |
+
* M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
|
| 126 |
+
* ~0 if an error occurred in omap2_dpll_round_rate().
|
| 127 |
+
*/
|
| 128 |
+
long omap4_dpll_regm4xen_round_rate(struct clk *clk, unsigned long target_rate)
|
| 129 |
+
{
|
| 130 |
+
u32 v;
|
| 131 |
+
struct dpll_data *dd;
|
| 132 |
+
long r;
|
| 133 |
+
|
| 134 |
+
if (!clk || !clk->dpll_data)
|
| 135 |
+
return -EINVAL;
|
| 136 |
+
|
| 137 |
+
dd = clk->dpll_data;
|
| 138 |
+
|
| 139 |
+
/* regm4xen adds a multiplier of 4 to DPLL calculations */
|
| 140 |
+
v = __raw_readl(dd->control_reg) & OMAP4430_DPLL_REGM4XEN_MASK;
|
| 141 |
+
|
| 142 |
+
if (v)
|
| 143 |
+
target_rate = target_rate / OMAP4430_REGM4XEN_MULT;
|
| 144 |
+
|
| 145 |
+
r = omap2_dpll_round_rate(clk, target_rate);
|
| 146 |
+
if (r == ~0)
|
| 147 |
+
return r;
|
| 148 |
+
|
| 149 |
+
if (v)
|
| 150 |
+
clk->dpll_data->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
|
| 151 |
+
|
| 152 |
+
return clk->dpll_data->last_rounded_rate;
|
| 153 |
+
}
|
pool/shard006/C/0117220_gsl_sf_exp.c
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "stdlib.h"
|
| 2 |
+
#include "stdio.h"
|
| 3 |
+
#include "/home/lillian/work/install_fpdebug/valgrind-3.7.0/fpdebug/fpdebug.h"
|
| 4 |
+
#include <gsl/gsl_sf.h>
|
| 5 |
+
int main(int argc, const char * argv[]) {
|
| 6 |
+
unsigned long int hexdouble;
|
| 7 |
+
double a;
|
| 8 |
+
sscanf(argv[1], "%lX", &hexdouble);
|
| 9 |
+
a = *(double*)(&hexdouble);
|
| 10 |
+
double result = gsl_sf_exp(a);
|
| 11 |
+
//printf("%.15f\n", result);
|
| 12 |
+
VALGRIND_PRINT_ERROR("result", &result);
|
| 13 |
+
return 0;
|
| 14 |
+
}
|
pool/shard006/C/0117227_edges.c
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "edges.h"
|
| 2 |
+
|
| 3 |
+
edge_p edges_add(struct store *edges, edge_p e_old, node_p start, node_p end)
|
| 4 |
+
{
|
| 5 |
+
edge_p e_new, size;
|
| 6 |
+
|
| 7 |
+
if(e_old == 0) {
|
| 8 |
+
size = 8;
|
| 9 |
+
e_new = store_alloc(edges, size + 8);
|
| 10 |
+
} else {
|
| 11 |
+
size = store_read_ui64(edges, e_old);
|
| 12 |
+
e_new = store_alloc(edges, size + 8);
|
| 13 |
+
store_copy(edges, e_new, e_old, size);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
store_write_ui64(edges, e_new + size, end);
|
| 17 |
+
store_write_ui64(edges, e_new, size + 8);
|
| 18 |
+
store_free(edges, e_old);
|
| 19 |
+
return e_new;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
edge_p edges_remove(struct store *edges, edge_p e_old, node_p start, node_p end)
|
| 23 |
+
{
|
| 24 |
+
if(e_old == 0) return 0;
|
| 25 |
+
|
| 26 |
+
edge_p hdr_sz = 8;
|
| 27 |
+
edge_p item_sz = 8;
|
| 28 |
+
|
| 29 |
+
edge_p size = store_read_ui64(edges, e_old);
|
| 30 |
+
edge_p i;
|
| 31 |
+
for(i = hdr_sz; i < size; i += item_sz) {
|
| 32 |
+
if( store_read_ui64(edges, e_old + i) == end ) break;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
if(i >= size) return e_old;
|
| 36 |
+
|
| 37 |
+
int64_t size_new = size - item_sz;
|
| 38 |
+
if(size_new < 0) return e_old;
|
| 39 |
+
|
| 40 |
+
edge_p e_new = store_alloc(edges, size_new);
|
| 41 |
+
store_copy(edges, e_new, e_old, i);
|
| 42 |
+
store_copy(edges, e_new + i, e_old + i + item_sz, size - i - item_sz);
|
| 43 |
+
|
| 44 |
+
store_write_ui64(edges, e_new, size - item_sz);
|
| 45 |
+
store_free(edges, e_old);
|
| 46 |
+
return e_new;
|
| 47 |
+
}
|
pool/shard006/C/0117253_gb-terminal-application-addin.c
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* gb-terminal-application-addin.c
|
| 2 |
+
*
|
| 3 |
+
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
|
| 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 3 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, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "gb-terminal-application-addin.h"
|
| 20 |
+
|
| 21 |
+
struct _GbTerminalApplicationAddin
|
| 22 |
+
{
|
| 23 |
+
GObject parent_instance;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
static void application_addin_iface_init (GbApplicationAddinInterface *iface);
|
| 27 |
+
|
| 28 |
+
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GbTerminalApplicationAddin,
|
| 29 |
+
gb_terminal_application_addin,
|
| 30 |
+
G_TYPE_OBJECT,
|
| 31 |
+
0,
|
| 32 |
+
G_IMPLEMENT_INTERFACE (GB_TYPE_APPLICATION_ADDIN,
|
| 33 |
+
application_addin_iface_init))
|
| 34 |
+
|
| 35 |
+
static void
|
| 36 |
+
gb_terminal_application_addin_load (GbApplicationAddin *addin,
|
| 37 |
+
GbApplication *application)
|
| 38 |
+
{
|
| 39 |
+
const gchar *new_terminal_accels[] = { "<ctrl><shift>t", NULL };
|
| 40 |
+
|
| 41 |
+
g_assert (GB_IS_TERMINAL_APPLICATION_ADDIN (addin));
|
| 42 |
+
g_assert (GB_IS_APPLICATION (application));
|
| 43 |
+
|
| 44 |
+
gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.new-terminal",
|
| 45 |
+
new_terminal_accels);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
static void
|
| 49 |
+
gb_terminal_application_addin_unload (GbApplicationAddin *addin,
|
| 50 |
+
GbApplication *application)
|
| 51 |
+
{
|
| 52 |
+
g_assert (GB_IS_TERMINAL_APPLICATION_ADDIN (addin));
|
| 53 |
+
g_assert (GB_IS_APPLICATION (application));
|
| 54 |
+
|
| 55 |
+
gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.new-terminal", NULL);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
static void
|
| 59 |
+
gb_terminal_application_addin_class_init (GbTerminalApplicationAddinClass *klass)
|
| 60 |
+
{
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
static void
|
| 64 |
+
gb_terminal_application_addin_class_finalize (GbTerminalApplicationAddinClass *klass)
|
| 65 |
+
{
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
static void
|
| 69 |
+
gb_terminal_application_addin_init (GbTerminalApplicationAddin *self)
|
| 70 |
+
{
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
static void
|
| 74 |
+
application_addin_iface_init (GbApplicationAddinInterface *iface)
|
| 75 |
+
{
|
| 76 |
+
iface->load = gb_terminal_application_addin_load;
|
| 77 |
+
iface->unload = gb_terminal_application_addin_unload;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void
|
| 81 |
+
_gb_terminal_application_addin_register_type (GTypeModule *module)
|
| 82 |
+
{
|
| 83 |
+
gb_terminal_application_addin_register_type (module);
|
| 84 |
+
}
|
pool/shard006/C/0117260_list_test.c
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* list_test.c - some tests for list.c/list.h
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2017-2019, Alexander Kuleshov <kuleshovmail at gmail dot com>
|
| 5 |
+
*
|
| 6 |
+
* This file is released under the BSD license, see the COPYING file
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#include <tmail/list.h>
|
| 10 |
+
|
| 11 |
+
int main(int argc, char *argv[])
|
| 12 |
+
{
|
| 13 |
+
list_t *entry = NULL;
|
| 14 |
+
list_t *list = list_new();
|
| 15 |
+
|
| 16 |
+
printf("list append test: ");
|
| 17 |
+
list_append(list, (list_item *)1);
|
| 18 |
+
list_append(list, (list_item *)2);
|
| 19 |
+
list_append(list, (list_item *)3);
|
| 20 |
+
list_append(list, (list_item *)4);
|
| 21 |
+
list_append(list, (list_item *)5);
|
| 22 |
+
|
| 23 |
+
for_each_list_item(list, entry)
|
| 24 |
+
{
|
| 25 |
+
printf("%lu ", (unsigned long)entry->item);
|
| 26 |
+
}
|
| 27 |
+
printf("\n");
|
| 28 |
+
|
| 29 |
+
printf("list prepend test: ");
|
| 30 |
+
list = list_prepend(list, (list_item *)5);
|
| 31 |
+
for_each_list_item(list, entry)
|
| 32 |
+
{
|
| 33 |
+
printf("%lu ", (unsigned long)entry->item);
|
| 34 |
+
}
|
| 35 |
+
printf("\n");
|
| 36 |
+
|
| 37 |
+
printf("list lookup test: ");
|
| 38 |
+
int *res = (int *)list_lookup(list, (list_item *)5);
|
| 39 |
+
printf("%lu ", (unsigned long)res);
|
| 40 |
+
|
| 41 |
+
res = (int *)list_lookup(list, (list_item *)6);
|
| 42 |
+
printf("%lu ", (unsigned long)res);
|
| 43 |
+
printf("\n");
|
| 44 |
+
|
| 45 |
+
printf("list nth test: ");
|
| 46 |
+
res = (int *)list_nth(list, 0);
|
| 47 |
+
printf("%lu ", (unsigned long)res);
|
| 48 |
+
|
| 49 |
+
res = (int *)list_nth(list, 3);
|
| 50 |
+
printf("%lu", (unsigned long)res);
|
| 51 |
+
printf("\n");
|
| 52 |
+
|
| 53 |
+
printf("list length test: ");
|
| 54 |
+
int l = list_length(list);
|
| 55 |
+
printf("%d", l);
|
| 56 |
+
printf("\n");
|
| 57 |
+
|
| 58 |
+
printf("list remove test: ");
|
| 59 |
+
list = list_remove(list, (list_item *)5);
|
| 60 |
+
for_each_list_item(list, entry)
|
| 61 |
+
{
|
| 62 |
+
printf("%lu ", (unsigned long)entry->item);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
list = list_remove(list, (list_item *)2);
|
| 66 |
+
for_each_list_item(list, entry)
|
| 67 |
+
{
|
| 68 |
+
printf("%lu ", (unsigned long)entry->item);
|
| 69 |
+
}
|
| 70 |
+
printf("\n");
|
| 71 |
+
|
| 72 |
+
printf("list length after remove test: ");
|
| 73 |
+
l = list_length(list);
|
| 74 |
+
printf("%d\n", l);
|
| 75 |
+
|
| 76 |
+
list_free(list);
|
| 77 |
+
|
| 78 |
+
return 0;
|
| 79 |
+
}
|
pool/shard006/C/0117271_max77803_haptic.c
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* haptic motor driver for max77803 - max77673_haptic.c
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2011 ByungChang Cha <bc.cha@samsung.com>
|
| 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 as
|
| 8 |
+
* published by the Free Software Foundation.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <linux/module.h>
|
| 12 |
+
#include <linux/kernel.h>
|
| 13 |
+
#include <linux/hrtimer.h>
|
| 14 |
+
#include <linux/pwm.h>
|
| 15 |
+
#include <linux/platform_device.h>
|
| 16 |
+
#include <linux/err.h>
|
| 17 |
+
#include <linux/slab.h>
|
| 18 |
+
#include <linux/clk.h>
|
| 19 |
+
#include <linux/i2c.h>
|
| 20 |
+
#include <linux/regulator/consumer.h>
|
| 21 |
+
#include <linux/mfd/max77803.h>
|
| 22 |
+
#include <linux/mfd/max77803-private.h>
|
| 23 |
+
|
| 24 |
+
struct max77803_haptic_data {
|
| 25 |
+
struct max77803_dev *max77803;
|
| 26 |
+
struct i2c_client *i2c;
|
| 27 |
+
struct i2c_client *pmic_i2c;
|
| 28 |
+
struct max77803_haptic_platform_data *pdata;
|
| 29 |
+
|
| 30 |
+
spinlock_t lock;
|
| 31 |
+
bool running;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
struct max77803_haptic_data *g_hap_data;
|
| 35 |
+
|
| 36 |
+
static void max77803_haptic_i2c(struct max77803_haptic_data *hap_data, bool en)
|
| 37 |
+
{
|
| 38 |
+
int ret;
|
| 39 |
+
u8 value = hap_data->pdata->reg2;
|
| 40 |
+
u8 lscnfg_val = 0x00;
|
| 41 |
+
|
| 42 |
+
pr_debug("[VIB] %s %d\n", __func__, en);
|
| 43 |
+
|
| 44 |
+
if (en) {
|
| 45 |
+
value |= MOTOR_EN;
|
| 46 |
+
lscnfg_val = 0x80;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
ret = max77803_update_reg(hap_data->pmic_i2c, MAX77803_PMIC_REG_LSCNFG,
|
| 50 |
+
lscnfg_val, 0x80);
|
| 51 |
+
if (ret)
|
| 52 |
+
pr_err("[VIB] i2c update error %d\n", ret);
|
| 53 |
+
|
| 54 |
+
ret = max77803_write_reg(hap_data->i2c,
|
| 55 |
+
MAX77803_HAPTIC_REG_CONFIG2, value);
|
| 56 |
+
if (ret)
|
| 57 |
+
pr_err("[VIB] i2c write error %d\n", ret);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
#ifdef CONFIG_SS_VIBRATOR
|
| 61 |
+
void max77803_vibtonz_en(bool en)
|
| 62 |
+
{
|
| 63 |
+
if (g_hap_data == NULL) {
|
| 64 |
+
printk(KERN_ERR "[VIB] the motor is not ready!!!");
|
| 65 |
+
return ;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if (en) {
|
| 69 |
+
if (g_hap_data->running)
|
| 70 |
+
return;
|
| 71 |
+
|
| 72 |
+
max77803_haptic_i2c(g_hap_data, true);
|
| 73 |
+
|
| 74 |
+
g_hap_data->running = true;
|
| 75 |
+
} else {
|
| 76 |
+
if (!g_hap_data->running)
|
| 77 |
+
return;
|
| 78 |
+
|
| 79 |
+
max77803_haptic_i2c(g_hap_data, false);
|
| 80 |
+
|
| 81 |
+
g_hap_data->running = false;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
EXPORT_SYMBOL(max77803_vibtonz_en);
|
| 85 |
+
#endif
|
| 86 |
+
|
| 87 |
+
static int max77803_haptic_probe(struct platform_device *pdev)
|
| 88 |
+
{
|
| 89 |
+
int error = 0;
|
| 90 |
+
struct max77803_dev *max77803 = dev_get_drvdata(pdev->dev.parent);
|
| 91 |
+
struct max77803_platform_data *max77803_pdata
|
| 92 |
+
= dev_get_platdata(max77803->dev);
|
| 93 |
+
#ifdef CONFIG_SS_VIBRATOR
|
| 94 |
+
struct max77803_haptic_platform_data *pdata
|
| 95 |
+
= max77803_pdata->haptic_data;
|
| 96 |
+
#endif
|
| 97 |
+
struct max77803_haptic_data *hap_data;
|
| 98 |
+
|
| 99 |
+
pr_debug("[VIB] ++ %s\n", __func__);
|
| 100 |
+
if (pdata == NULL) {
|
| 101 |
+
pr_err("%s: no pdata\n", __func__);
|
| 102 |
+
return -ENODEV;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
hap_data = kzalloc(sizeof(struct max77803_haptic_data), GFP_KERNEL);
|
| 106 |
+
if (!hap_data)
|
| 107 |
+
return -ENOMEM;
|
| 108 |
+
|
| 109 |
+
platform_set_drvdata(pdev, hap_data);
|
| 110 |
+
g_hap_data = hap_data;
|
| 111 |
+
hap_data->max77803 = max77803;
|
| 112 |
+
hap_data->i2c = max77803->haptic;
|
| 113 |
+
hap_data->pmic_i2c = max77803->i2c;
|
| 114 |
+
pdata->reg2 = MOTOR_LRA | EXT_PWM | DIVIDER_128;
|
| 115 |
+
hap_data->pdata = pdata;
|
| 116 |
+
|
| 117 |
+
spin_lock_init(&(hap_data->lock));
|
| 118 |
+
|
| 119 |
+
pr_debug("[VIB] -- %s\n", __func__);
|
| 120 |
+
|
| 121 |
+
return error;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
static int __devexit max77803_haptic_remove(struct platform_device *pdev)
|
| 125 |
+
{
|
| 126 |
+
struct max77803_haptic_data *data = platform_get_drvdata(pdev);
|
| 127 |
+
kfree(data);
|
| 128 |
+
g_hap_data = NULL;
|
| 129 |
+
|
| 130 |
+
return 0;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
static int max77803_haptic_suspend(struct platform_device *pdev,
|
| 134 |
+
pm_message_t state)
|
| 135 |
+
{
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
static int max77803_haptic_resume(struct platform_device *pdev)
|
| 139 |
+
{
|
| 140 |
+
return 0;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
static struct platform_driver max77803_haptic_driver = {
|
| 144 |
+
.probe = max77803_haptic_probe,
|
| 145 |
+
.remove = max77803_haptic_remove,
|
| 146 |
+
.suspend = max77803_haptic_suspend,
|
| 147 |
+
.resume = max77803_haptic_resume,
|
| 148 |
+
.driver = {
|
| 149 |
+
.name = "max77803-haptic",
|
| 150 |
+
.owner = THIS_MODULE,
|
| 151 |
+
},
|
| 152 |
+
};
|
| 153 |
+
|
| 154 |
+
static int __init max77803_haptic_init(void)
|
| 155 |
+
{
|
| 156 |
+
pr_debug("[VIB] %s\n", __func__);
|
| 157 |
+
return platform_driver_register(&max77803_haptic_driver);
|
| 158 |
+
}
|
| 159 |
+
module_init(max77803_haptic_init);
|
| 160 |
+
|
| 161 |
+
static void __exit max77803_haptic_exit(void)
|
| 162 |
+
{
|
| 163 |
+
platform_driver_unregister(&max77803_haptic_driver);
|
| 164 |
+
}
|
| 165 |
+
module_exit(max77803_haptic_exit);
|
| 166 |
+
|
| 167 |
+
MODULE_AUTHOR("ByungChang Cha <bc.cha@samsung.com>");
|
| 168 |
+
MODULE_LICENSE("GPL");
|
| 169 |
+
MODULE_DESCRIPTION("MAX77803 haptic driver");
|
pool/shard006/C/0117275_Ex1.c
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
/*Dado dois número inteiro positivo n, calcular e imprimir a sua soma*/
|
| 3 |
+
int main(void){
|
| 4 |
+
int n1 = 0, n2 = 0, result = 0;
|
| 5 |
+
printf("\nDigite o primeiro numero: ");
|
| 6 |
+
scanf("%d", &n1);
|
| 7 |
+
printf("\nDigite o segundo numero: ");
|
| 8 |
+
scanf("%d", &n2);
|
| 9 |
+
result = n1 + n2;
|
| 10 |
+
printf("%d + %d = %d", n1, n2, result);
|
| 11 |
+
|
| 12 |
+
}
|
pool/shard006/C/0117280_CWE401_Memory_Leak__twoIntsStruct_calloc_44.c
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE401_Memory_Leak__twoIntsStruct_calloc_44.c
|
| 3 |
+
Label Definition File: CWE401_Memory_Leak.c.label.xml
|
| 4 |
+
Template File: sources-sinks-44.tmpl.c
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 401 Memory Leak
|
| 9 |
+
* BadSource: calloc Allocate data using calloc()
|
| 10 |
+
* GoodSource: Allocate data on the stack
|
| 11 |
+
* Sinks:
|
| 12 |
+
* GoodSink: call free() on data
|
| 13 |
+
* BadSink : no deallocation of data
|
| 14 |
+
* Flow Variant: 44 Data/control flow: data passed as an argument from one function to a function in the same source file called via a function pointer
|
| 15 |
+
*
|
| 16 |
+
* */
|
| 17 |
+
|
| 18 |
+
#include "std_testcase.h"
|
| 19 |
+
|
| 20 |
+
#include <wchar.h>
|
| 21 |
+
|
| 22 |
+
#ifndef OMITBAD
|
| 23 |
+
|
| 24 |
+
static void badSink(twoIntsStruct * data)
|
| 25 |
+
{
|
| 26 |
+
/* POTENTIAL FLAW: No deallocation */
|
| 27 |
+
; /* empty statement needed for some flow variants */
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void CWE401_Memory_Leak__twoIntsStruct_calloc_44_bad()
|
| 31 |
+
{
|
| 32 |
+
twoIntsStruct * data;
|
| 33 |
+
/* define a function pointer */
|
| 34 |
+
void (*funcPtr) (twoIntsStruct *) = badSink;
|
| 35 |
+
data = NULL;
|
| 36 |
+
/* POTENTIAL FLAW: Allocate memory on the heap */
|
| 37 |
+
data = (twoIntsStruct *)calloc(100, sizeof(twoIntsStruct));
|
| 38 |
+
/* Initialize and make use of data */
|
| 39 |
+
data[0].intOne = 0;
|
| 40 |
+
data[0].intTwo = 0;
|
| 41 |
+
printStructLine(&data[0]);
|
| 42 |
+
/* use the function pointer */
|
| 43 |
+
funcPtr(data);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
#endif /* OMITBAD */
|
| 47 |
+
|
| 48 |
+
#ifndef OMITGOOD
|
| 49 |
+
|
| 50 |
+
/* goodG2B() uses the GoodSource with the BadSink */
|
| 51 |
+
static void goodG2BSink(twoIntsStruct * data)
|
| 52 |
+
{
|
| 53 |
+
/* POTENTIAL FLAW: No deallocation */
|
| 54 |
+
; /* empty statement needed for some flow variants */
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static void goodG2B()
|
| 58 |
+
{
|
| 59 |
+
twoIntsStruct * data;
|
| 60 |
+
void (*funcPtr) (twoIntsStruct *) = goodG2BSink;
|
| 61 |
+
data = NULL;
|
| 62 |
+
/* FIX: Use memory allocated on the stack with ALLOCA */
|
| 63 |
+
data = (twoIntsStruct *)ALLOCA(100*sizeof(twoIntsStruct));
|
| 64 |
+
/* Initialize and make use of data */
|
| 65 |
+
data[0].intOne = 0;
|
| 66 |
+
data[0].intTwo = 0;
|
| 67 |
+
printStructLine(&data[0]);
|
| 68 |
+
funcPtr(data);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* goodB2G() uses the BadSource with the GoodSink */
|
| 72 |
+
static void goodB2GSink(twoIntsStruct * data)
|
| 73 |
+
{
|
| 74 |
+
/* FIX: Deallocate memory */
|
| 75 |
+
free(data);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
static void goodB2G()
|
| 79 |
+
{
|
| 80 |
+
twoIntsStruct * data;
|
| 81 |
+
void (*funcPtr) (twoIntsStruct *) = goodB2GSink;
|
| 82 |
+
data = NULL;
|
| 83 |
+
/* POTENTIAL FLAW: Allocate memory on the heap */
|
| 84 |
+
data = (twoIntsStruct *)calloc(100, sizeof(twoIntsStruct));
|
| 85 |
+
/* Initialize and make use of data */
|
| 86 |
+
data[0].intOne = 0;
|
| 87 |
+
data[0].intTwo = 0;
|
| 88 |
+
printStructLine(&data[0]);
|
| 89 |
+
funcPtr(data);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void CWE401_Memory_Leak__twoIntsStruct_calloc_44_good()
|
| 93 |
+
{
|
| 94 |
+
goodG2B();
|
| 95 |
+
goodB2G();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
#endif /* OMITGOOD */
|
| 99 |
+
|
| 100 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 101 |
+
its own for testing or for building a binary to use in testing binary
|
| 102 |
+
analysis tools. It is not used when compiling all the testcases as one
|
| 103 |
+
application, which is how source code analysis tools are tested. */
|
| 104 |
+
#ifdef INCLUDEMAIN
|
| 105 |
+
|
| 106 |
+
int main(int argc, char * argv[])
|
| 107 |
+
{
|
| 108 |
+
/* seed randomness */
|
| 109 |
+
srand( (unsigned)time(NULL) );
|
| 110 |
+
#ifndef OMITGOOD
|
| 111 |
+
printLine("Calling good()...");
|
| 112 |
+
CWE401_Memory_Leak__twoIntsStruct_calloc_44_good();
|
| 113 |
+
printLine("Finished good()");
|
| 114 |
+
#endif /* OMITGOOD */
|
| 115 |
+
#ifndef OMITBAD
|
| 116 |
+
printLine("Calling bad()...");
|
| 117 |
+
CWE401_Memory_Leak__twoIntsStruct_calloc_44_bad();
|
| 118 |
+
printLine("Finished bad()");
|
| 119 |
+
#endif /* OMITBAD */
|
| 120 |
+
return 0;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
#endif
|
pool/shard006/C/0117283_reaper.c
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: LGPL-2.1-or-later
|
| 2 |
+
/*
|
| 3 |
+
* Copyright (C) 2020-2021 Paul Cercueil <paul@crapouillou.net>
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include "blockcache.h"
|
| 7 |
+
#include "debug.h"
|
| 8 |
+
#include "lightrec-private.h"
|
| 9 |
+
#include "memmanager.h"
|
| 10 |
+
#include "slist.h"
|
| 11 |
+
#include "reaper.h"
|
| 12 |
+
|
| 13 |
+
#include <errno.h>
|
| 14 |
+
#include <pthread.h>
|
| 15 |
+
#include <stdatomic.h>
|
| 16 |
+
#include <stdbool.h>
|
| 17 |
+
|
| 18 |
+
struct reaper_elm {
|
| 19 |
+
reap_func_t func;
|
| 20 |
+
void *data;
|
| 21 |
+
struct slist_elm slist;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
struct reaper {
|
| 25 |
+
struct lightrec_state *state;
|
| 26 |
+
pthread_mutex_t mutex;
|
| 27 |
+
struct slist_elm reap_list;
|
| 28 |
+
|
| 29 |
+
atomic_uint sem;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
struct reaper *lightrec_reaper_init(struct lightrec_state *state)
|
| 33 |
+
{
|
| 34 |
+
struct reaper *reaper;
|
| 35 |
+
int ret;
|
| 36 |
+
|
| 37 |
+
reaper = lightrec_malloc(state, MEM_FOR_LIGHTREC, sizeof(*reaper));
|
| 38 |
+
if (!reaper) {
|
| 39 |
+
pr_err("Cannot create reaper: Out of memory\n");
|
| 40 |
+
return NULL;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
reaper->state = state;
|
| 44 |
+
reaper->sem = 0;
|
| 45 |
+
slist_init(&reaper->reap_list);
|
| 46 |
+
|
| 47 |
+
ret = pthread_mutex_init(&reaper->mutex, NULL);
|
| 48 |
+
if (ret) {
|
| 49 |
+
pr_err("Cannot init mutex variable: %d\n", ret);
|
| 50 |
+
lightrec_free(reaper->state, MEM_FOR_LIGHTREC,
|
| 51 |
+
sizeof(*reaper), reaper);
|
| 52 |
+
return NULL;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return reaper;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void lightrec_reaper_destroy(struct reaper *reaper)
|
| 59 |
+
{
|
| 60 |
+
pthread_mutex_destroy(&reaper->mutex);
|
| 61 |
+
lightrec_free(reaper->state, MEM_FOR_LIGHTREC, sizeof(*reaper), reaper);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
int lightrec_reaper_add(struct reaper *reaper, reap_func_t f, void *data)
|
| 65 |
+
{
|
| 66 |
+
struct reaper_elm *reaper_elm;
|
| 67 |
+
struct slist_elm *elm;
|
| 68 |
+
int ret = 0;
|
| 69 |
+
|
| 70 |
+
pthread_mutex_lock(&reaper->mutex);
|
| 71 |
+
|
| 72 |
+
for (elm = reaper->reap_list.next; elm; elm = elm->next) {
|
| 73 |
+
reaper_elm = container_of(elm, struct reaper_elm, slist);
|
| 74 |
+
|
| 75 |
+
if (reaper_elm->data == data)
|
| 76 |
+
goto out_unlock;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
reaper_elm = lightrec_malloc(reaper->state, MEM_FOR_LIGHTREC,
|
| 80 |
+
sizeof(*reaper_elm));
|
| 81 |
+
if (!reaper_elm) {
|
| 82 |
+
pr_err("Cannot add reaper entry: Out of memory\n");
|
| 83 |
+
ret = -ENOMEM;
|
| 84 |
+
goto out_unlock;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
reaper_elm->func = f;
|
| 88 |
+
reaper_elm->data = data;
|
| 89 |
+
slist_append(&reaper->reap_list, &reaper_elm->slist);
|
| 90 |
+
|
| 91 |
+
out_unlock:
|
| 92 |
+
pthread_mutex_unlock(&reaper->mutex);
|
| 93 |
+
return ret;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
static bool lightrec_reaper_can_reap(struct reaper *reaper)
|
| 97 |
+
{
|
| 98 |
+
return !atomic_load_explicit(&reaper->sem, memory_order_relaxed);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
void lightrec_reaper_reap(struct reaper *reaper)
|
| 102 |
+
{
|
| 103 |
+
struct reaper_elm *reaper_elm;
|
| 104 |
+
struct slist_elm *elm;
|
| 105 |
+
|
| 106 |
+
pthread_mutex_lock(&reaper->mutex);
|
| 107 |
+
|
| 108 |
+
while (lightrec_reaper_can_reap(reaper) &&
|
| 109 |
+
!!(elm = slist_first(&reaper->reap_list))) {
|
| 110 |
+
slist_remove(&reaper->reap_list, elm);
|
| 111 |
+
pthread_mutex_unlock(&reaper->mutex);
|
| 112 |
+
|
| 113 |
+
reaper_elm = container_of(elm, struct reaper_elm, slist);
|
| 114 |
+
|
| 115 |
+
(*reaper_elm->func)(reaper->state, reaper_elm->data);
|
| 116 |
+
|
| 117 |
+
lightrec_free(reaper->state, MEM_FOR_LIGHTREC,
|
| 118 |
+
sizeof(*reaper_elm), reaper_elm);
|
| 119 |
+
|
| 120 |
+
pthread_mutex_lock(&reaper->mutex);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
pthread_mutex_unlock(&reaper->mutex);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
void lightrec_reaper_pause(struct reaper *reaper)
|
| 127 |
+
{
|
| 128 |
+
atomic_fetch_add_explicit(&reaper->sem, 1, memory_order_relaxed);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
void lightrec_reaper_continue(struct reaper *reaper)
|
| 132 |
+
{
|
| 133 |
+
atomic_fetch_sub_explicit(&reaper->sem, 1, memory_order_relaxed);
|
| 134 |
+
}
|
pool/shard006/C/0117287_strfunc.c
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include<stdio.h>
|
| 2 |
+
#include<string.h>
|
| 3 |
+
void main()
|
| 4 |
+
{
|
| 5 |
+
char str1[31],str2[31];
|
| 6 |
+
strcpy(str1, "Apple is sweet");
|
| 7 |
+
strcpy(str2,str1);
|
| 8 |
+
puts(str2);
|
| 9 |
+
|
| 10 |
+
char a[18]="Microsoft ",b[]=" word";
|
| 11 |
+
strcat(a,b); puts(a);
|
| 12 |
+
strcat(a,"97"); puts(a);
|
| 13 |
+
|
| 14 |
+
char pass_str[80];
|
| 15 |
+
int i = 0;
|
| 16 |
+
while (1)
|
| 17 |
+
{
|
| 18 |
+
printf("请输入密码:\n");
|
| 19 |
+
gets(pass_str);
|
| 20 |
+
if (strcmp(pass_str, "mypass") != 0)
|
| 21 |
+
printf("口令错误,");
|
| 22 |
+
else
|
| 23 |
+
{
|
| 24 |
+
printf("口令正确!");
|
| 25 |
+
break; /*输入正确的密码,中止循环*/
|
| 26 |
+
}
|
| 27 |
+
i++;
|
| 28 |
+
if (i == 3)
|
| 29 |
+
exit(0); //stdlib.h
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
getchar();
|
| 33 |
+
}
|
pool/shard006/C/0117293_hdmi_tx_hdcp.c
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <linux/version.h>
|
| 2 |
+
#include <linux/module.h>
|
| 3 |
+
#include <linux/types.h>
|
| 4 |
+
#include <linux/kernel.h>
|
| 5 |
+
#include <linux/interrupt.h>
|
| 6 |
+
#include <linux/fs.h>
|
| 7 |
+
#include <linux/init.h>
|
| 8 |
+
#include <linux/device.h>
|
| 9 |
+
#include <linux/mm.h>
|
| 10 |
+
#include <linux/major.h>
|
| 11 |
+
#include <linux/platform_device.h>
|
| 12 |
+
#include <linux/mutex.h>
|
| 13 |
+
#include <linux/cdev.h>
|
| 14 |
+
//#include <linux/amports/canvas.h>
|
| 15 |
+
#include <asm/uaccess.h>
|
| 16 |
+
#include <mach/am_regs.h>
|
| 17 |
+
|
| 18 |
+
#include "hdmi_info_global.h"
|
| 19 |
+
#include "hdmi_tx_module.h"
|
| 20 |
+
#include "m1/hdmi_tx_reg.h"
|
| 21 |
+
#include "hdmi_tx_hdcp.h"
|
| 22 |
+
/*
|
| 23 |
+
hdmi_tx_hdcp.c
|
| 24 |
+
version 1.0
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
// Notic: the HDCP key setting has been moved to uboot
|
| 28 |
+
// On MBX project, it is too late for HDCP get from
|
| 29 |
+
// other devices
|
| 30 |
+
|
| 31 |
+
// buf: store buffer
|
| 32 |
+
// endian: 0: little endian 1: big endian
|
| 33 |
+
void hdmi_hdcp_get_aksv(char* buf, int endian)
|
| 34 |
+
{
|
| 35 |
+
int i;
|
| 36 |
+
if(endian ==1) {
|
| 37 |
+
for(i = 0;i < 5; i++) {
|
| 38 |
+
buf[i] = hdmi_rd_reg(TX_HDCP_SHW_AKSV_0 + i);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
else {
|
| 42 |
+
for(i = 0;i < 5; i++) {
|
| 43 |
+
buf[i] = hdmi_rd_reg(TX_HDCP_SHW_AKSV_0 + 4 - i);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void hdmi_hdcp_get_bksv(char* buf, int endian)
|
| 49 |
+
{
|
| 50 |
+
int i;
|
| 51 |
+
if(endian ==1){
|
| 52 |
+
for(i = 0;i < 5; i++) {
|
| 53 |
+
buf[i] = hdmi_rd_reg(TX_HDCP_SHW_BKSV_0 + i);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
else {
|
| 57 |
+
for(i = 0;i < 5; i++) {
|
| 58 |
+
buf[i] = hdmi_rd_reg(TX_HDCP_SHW_BKSV_0 + 4 - i);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* verify ksv, 20 ones and 20 zeroes*/
|
| 64 |
+
int hdcp_ksv_valid(unsigned char * dat)
|
| 65 |
+
{
|
| 66 |
+
int i, j, one_num = 0;
|
| 67 |
+
for(i = 0; i < 5; i++){
|
| 68 |
+
for(j=0;j<8;j++) {
|
| 69 |
+
if((dat[i]>>j)&0x1) {
|
| 70 |
+
one_num++;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
return (one_num == 20);
|
| 75 |
+
}
|
| 76 |
+
|
pool/shard006/C/0117296_dqawst.c
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <float.h>
|
| 3 |
+
#include <math.h>
|
| 4 |
+
#include "cquadpack.h"
|
| 5 |
+
|
| 6 |
+
double f(double x, void* user_data)
|
| 7 |
+
{
|
| 8 |
+
double result;
|
| 9 |
+
result = 0.0;
|
| 10 |
+
if (x > 0.0) result = (1.0/pow(1.0+log(x)*log(x),2.0));
|
| 11 |
+
return result;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
int main()
|
| 15 |
+
{
|
| 16 |
+
double a,b,alfa,beta,epsabs,epsrel,abserr,result;
|
| 17 |
+
int wgtfunc,neval,ier;
|
| 18 |
+
|
| 19 |
+
/* a and b are the integration limits */
|
| 20 |
+
a = 0.0;
|
| 21 |
+
b = 1.0;
|
| 22 |
+
|
| 23 |
+
/* alfa, beta and wgtfunc determine the weight function */
|
| 24 |
+
alfa = 0.0;
|
| 25 |
+
beta = 0.0;
|
| 26 |
+
wgtfunc = 2;
|
| 27 |
+
|
| 28 |
+
/* epsabs and epsrel determine the accuracy requirement */
|
| 29 |
+
epsabs = 0.0;
|
| 30 |
+
epsrel = 1.0e-5;
|
| 31 |
+
|
| 32 |
+
result = dqaws(f,a,b,alfa,beta,wgtfunc,epsabs,epsrel,&abserr,
|
| 33 |
+
&neval,&ier,0);
|
| 34 |
+
|
| 35 |
+
printf("Integral approximation = %.12lf\n",result);
|
| 36 |
+
printf("Estimate of absolute error = %.12lf\n",abserr);
|
| 37 |
+
printf("Number of function evaluations = %d\n",neval);
|
| 38 |
+
printf("Error code = %d\n",ier);
|
| 39 |
+
return 0;
|
| 40 |
+
}
|
pool/shard006/C/0117298_idmap.c
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <linux/kernel.h>
|
| 2 |
+
|
| 3 |
+
#include <asm/cputype.h>
|
| 4 |
+
#include <asm/idmap.h>
|
| 5 |
+
#include <asm/pgalloc.h>
|
| 6 |
+
#include <asm/pgtable.h>
|
| 7 |
+
#include <asm/sections.h>
|
| 8 |
+
#include <asm/system_info.h>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
/** 20150620
|
| 12 |
+
* 커널 이미지의 밖을 접근한다.
|
| 13 |
+
* Note: accesses outside of the kernel image and the identity map area
|
| 14 |
+
* are not supported on any CPU using the idmap tables as its current
|
| 15 |
+
* page tables.
|
| 16 |
+
**/
|
| 17 |
+
pgd_t *idmap_pgd;
|
| 18 |
+
|
| 19 |
+
#ifdef CONFIG_ARM_LPAE
|
| 20 |
+
static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
|
| 21 |
+
unsigned long prot)
|
| 22 |
+
{
|
| 23 |
+
pmd_t *pmd;
|
| 24 |
+
unsigned long next;
|
| 25 |
+
|
| 26 |
+
if (pud_none_or_clear_bad(pud) || (pud_val(*pud) & L_PGD_SWAPPER)) {
|
| 27 |
+
pmd = pmd_alloc_one(&init_mm, addr);
|
| 28 |
+
if (!pmd) {
|
| 29 |
+
pr_warning("Failed to allocate identity pmd.\n");
|
| 30 |
+
return;
|
| 31 |
+
}
|
| 32 |
+
pud_populate(&init_mm, pud, pmd);
|
| 33 |
+
pmd += pmd_index(addr);
|
| 34 |
+
} else
|
| 35 |
+
pmd = pmd_offset(pud, addr);
|
| 36 |
+
|
| 37 |
+
do {
|
| 38 |
+
next = pmd_addr_end(addr, end);
|
| 39 |
+
*pmd = __pmd((addr & PMD_MASK) | prot);
|
| 40 |
+
flush_pmd_entry(pmd);
|
| 41 |
+
} while (pmd++, addr = next, addr != end);
|
| 42 |
+
}
|
| 43 |
+
#else /* !CONFIG_ARM_LPAE */
|
| 44 |
+
static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
|
| 45 |
+
unsigned long prot)
|
| 46 |
+
{
|
| 47 |
+
pmd_t *pmd = pmd_offset(pud, addr);
|
| 48 |
+
|
| 49 |
+
addr = (addr & PMD_MASK) | prot;
|
| 50 |
+
pmd[0] = __pmd(addr);
|
| 51 |
+
addr += SECTION_SIZE;
|
| 52 |
+
pmd[1] = __pmd(addr);
|
| 53 |
+
flush_pmd_entry(pmd);
|
| 54 |
+
}
|
| 55 |
+
#endif /* CONFIG_ARM_LPAE */
|
| 56 |
+
|
| 57 |
+
static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
|
| 58 |
+
unsigned long prot)
|
| 59 |
+
{
|
| 60 |
+
pud_t *pud = pud_offset(pgd, addr);
|
| 61 |
+
unsigned long next;
|
| 62 |
+
|
| 63 |
+
do {
|
| 64 |
+
next = pud_addr_end(addr, end);
|
| 65 |
+
idmap_add_pmd(pud, addr, next, prot);
|
| 66 |
+
} while (pud++, addr = next, addr != end);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/** 20150620
|
| 70 |
+
* addr ~ end 영역을 pgd 에 매핑시킨다.
|
| 71 |
+
**/
|
| 72 |
+
static void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
|
| 73 |
+
{
|
| 74 |
+
unsigned long prot, next;
|
| 75 |
+
|
| 76 |
+
/** 20150620
|
| 77 |
+
* SECTION, Read/Write Access 속성을 지정한다.
|
| 78 |
+
**/
|
| 79 |
+
prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_AF;
|
| 80 |
+
/** 20150620
|
| 81 |
+
* cpu_architecture는 ARMv7이다.
|
| 82 |
+
**/
|
| 83 |
+
if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
|
| 84 |
+
prot |= PMD_BIT4;
|
| 85 |
+
|
| 86 |
+
/** 20150620
|
| 87 |
+
* addr부터 end까지 영역을 mapping 시킨다.
|
| 88 |
+
*
|
| 89 |
+
* pgd_index에 해당하는 address는 보통 가상메모리를 주고, 그에 해당하는
|
| 90 |
+
* entry의 위치를 찾아오기 위함인데, 여기서 넘어온 address는 physical이다.
|
| 91 |
+
* 물리주소를 가상주소와 동일하게 매핑하기 위한 것이다.
|
| 92 |
+
**/
|
| 93 |
+
pgd += pgd_index(addr);
|
| 94 |
+
do {
|
| 95 |
+
next = pgd_addr_end(addr, end);
|
| 96 |
+
idmap_add_pud(pgd, addr, next, prot);
|
| 97 |
+
} while (pgd++, addr = next, addr != end);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/** 20150620
|
| 101 |
+
* section의 시작과 끝.
|
| 102 |
+
*
|
| 103 |
+
* __idmap으로 section을 지정하면 이 영역에 위치시킬 수 있다.
|
| 104 |
+
* 또는 assembly에서 .pushsection .idmap.text로 직접 지정한다.
|
| 105 |
+
**/
|
| 106 |
+
extern char __idmap_text_start[], __idmap_text_end[];
|
| 107 |
+
|
| 108 |
+
/** 20150613
|
| 109 |
+
* idmap page table을 위한 초기화를 한다.
|
| 110 |
+
*
|
| 111 |
+
* page table을 새로 할당 받고, 기존의 page table에서 커널 영역에 해당하는 부분을 복사한다.
|
| 112 |
+
* idmap_start ~ idmap_end 사이의 영역에 대해 page table에 mapping 시킨다.
|
| 113 |
+
**/
|
| 114 |
+
static int __init init_static_idmap(void)
|
| 115 |
+
{
|
| 116 |
+
phys_addr_t idmap_start, idmap_end;
|
| 117 |
+
|
| 118 |
+
/** 20150620
|
| 119 |
+
* idmap을 위한 L1 page table을 할당받는다.
|
| 120 |
+
**/
|
| 121 |
+
idmap_pgd = pgd_alloc(&init_mm);
|
| 122 |
+
if (!idmap_pgd)
|
| 123 |
+
return -ENOMEM;
|
| 124 |
+
|
| 125 |
+
/* Add an identity mapping for the physical address of the section. */
|
| 126 |
+
/** 20150620
|
| 127 |
+
* idmap 영역을 identity mapping으로 추가하기 위해 물리 주소를 받아온다.
|
| 128 |
+
**/
|
| 129 |
+
idmap_start = virt_to_phys((void *)__idmap_text_start);
|
| 130 |
+
idmap_end = virt_to_phys((void *)__idmap_text_end);
|
| 131 |
+
|
| 132 |
+
pr_info("Setting up static identity map for 0x%llx - 0x%llx\n",
|
| 133 |
+
(long long)idmap_start, (long long)idmap_end);
|
| 134 |
+
/** 20150620
|
| 135 |
+
* idmap_pgd에 idmap_start ~ idmap_end 영역에 대한 mapping을 추가한다.
|
| 136 |
+
* 물리주소와 가상주소를 동일하게 매핑시킨다.
|
| 137 |
+
*
|
| 138 |
+
* kernel 빌드 후 System.map을 확인하면 __idmap_text_start ~ __idmap_text_end
|
| 139 |
+
* 사이의 심볼을 확인할 수 있다.
|
| 140 |
+
**/
|
| 141 |
+
identity_mapping_add(idmap_pgd, idmap_start, idmap_end);
|
| 142 |
+
|
| 143 |
+
return 0;
|
| 144 |
+
}
|
| 145 |
+
early_initcall(init_static_idmap);
|
| 146 |
+
|
| 147 |
+
/*
|
| 148 |
+
* In order to soft-boot, we need to switch to a 1:1 mapping for the
|
| 149 |
+
* cpu_reset functions. This will then ensure that we have predictable
|
| 150 |
+
* results when turning off the mmu.
|
| 151 |
+
*/
|
| 152 |
+
void setup_mm_for_reboot(void)
|
| 153 |
+
{
|
| 154 |
+
/* Clean and invalidate L1. */
|
| 155 |
+
flush_cache_all();
|
| 156 |
+
|
| 157 |
+
/* Switch to the identity mapping. */
|
| 158 |
+
cpu_switch_mm(idmap_pgd, &init_mm);
|
| 159 |
+
|
| 160 |
+
/* Flush the TLB. */
|
| 161 |
+
local_flush_tlb_all();
|
| 162 |
+
}
|
pool/shard006/C/0117299_spy.c
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdlib.h>
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <stdint.h>
|
| 4 |
+
#include <stdbool.h>
|
| 5 |
+
#include <fcntl.h>
|
| 6 |
+
#include <sys/stat.h>
|
| 7 |
+
#include <sys/mman.h>
|
| 8 |
+
#include <unistd.h>
|
| 9 |
+
#include "parson.h"
|
| 10 |
+
|
| 11 |
+
char *spy_memory();
|
| 12 |
+
void spy_on_memory();
|
| 13 |
+
void spy_on_waiting();
|
| 14 |
+
|
| 15 |
+
int main(int argc, const char *argv[])
|
| 16 |
+
{
|
| 17 |
+
bool op_exit = false;
|
| 18 |
+
int code;
|
| 19 |
+
char *serialized_string = NULL;
|
| 20 |
+
do
|
| 21 |
+
{
|
| 22 |
+
puts("Algoritmos:");
|
| 23 |
+
puts("[1] - Estado de la memoria.");
|
| 24 |
+
puts("[2] - Estado de procesos.");
|
| 25 |
+
puts("[0] - Salir");
|
| 26 |
+
printf("Ingrese su eleccion (0-2): ");
|
| 27 |
+
scanf("%d", &code);
|
| 28 |
+
switch (code)
|
| 29 |
+
{
|
| 30 |
+
case 0:
|
| 31 |
+
op_exit = true;
|
| 32 |
+
break;
|
| 33 |
+
case 1:
|
| 34 |
+
serialized_string = spy_memory();
|
| 35 |
+
puts(serialized_string);
|
| 36 |
+
break;
|
| 37 |
+
case 2:
|
| 38 |
+
printf("Procesos en espera:\n");
|
| 39 |
+
spy_on_waiting();
|
| 40 |
+
printf("Procesos en memoria:\n");
|
| 41 |
+
spy_on_memory();
|
| 42 |
+
break;
|
| 43 |
+
default:
|
| 44 |
+
puts("Opcion incorrecta.");
|
| 45 |
+
break;
|
| 46 |
+
}
|
| 47 |
+
} while (op_exit == false);
|
| 48 |
+
return 0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
char *spy_memory()
|
| 52 |
+
{
|
| 53 |
+
|
| 54 |
+
const char *filepath = "/tmp/mmapped.bin";
|
| 55 |
+
|
| 56 |
+
int fd = open(filepath, O_RDONLY, (mode_t)0600);
|
| 57 |
+
|
| 58 |
+
if (fd == -1)
|
| 59 |
+
{
|
| 60 |
+
perror("Error opening file for writing");
|
| 61 |
+
exit(EXIT_FAILURE);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
struct stat fileInfo = {0};
|
| 65 |
+
|
| 66 |
+
if (fstat(fd, &fileInfo) == -1)
|
| 67 |
+
{
|
| 68 |
+
perror("Error getting the file size");
|
| 69 |
+
exit(EXIT_FAILURE);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (fileInfo.st_size == 0)
|
| 73 |
+
{
|
| 74 |
+
fprintf(stderr, "Error: File is empty, nothing to do\n");
|
| 75 |
+
exit(EXIT_FAILURE);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
printf("File size is %ji\n", (intmax_t)fileInfo.st_size);
|
| 79 |
+
|
| 80 |
+
char *map = mmap(0, fileInfo.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
| 81 |
+
if (map == MAP_FAILED)
|
| 82 |
+
{
|
| 83 |
+
close(fd);
|
| 84 |
+
perror("Error mmapping the file");
|
| 85 |
+
exit(EXIT_FAILURE);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
JSON_Value *output_value = NULL;
|
| 89 |
+
output_value = json_parse_string(map);
|
| 90 |
+
char *serialized_string = NULL;
|
| 91 |
+
serialized_string = json_serialize_to_string_pretty(output_value);
|
| 92 |
+
|
| 93 |
+
//puts(serialized_string);
|
| 94 |
+
|
| 95 |
+
// Don't forget to free the mmapped memory
|
| 96 |
+
if (munmap(map, fileInfo.st_size) == -1)
|
| 97 |
+
{
|
| 98 |
+
close(fd);
|
| 99 |
+
perror("Error un-mmapping the file");
|
| 100 |
+
exit(EXIT_FAILURE);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Un-mmaping doesn't close the file, so we still need to do that.
|
| 104 |
+
close(fd);
|
| 105 |
+
return serialized_string;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void spy_on_memory()
|
| 109 |
+
{
|
| 110 |
+
char *serialized_string = NULL;
|
| 111 |
+
serialized_string = spy_memory();
|
| 112 |
+
//puts(serialized_string);
|
| 113 |
+
JSON_Value *mem_value = json_parse_string(serialized_string);
|
| 114 |
+
JSON_Array *mem_arr = json_value_get_array(mem_value);
|
| 115 |
+
int n = json_array_get_count(mem_arr);
|
| 116 |
+
JSON_Value *to_print_value;
|
| 117 |
+
for (int i = 0; i < n; i++)
|
| 118 |
+
{
|
| 119 |
+
JSON_Object *root_object = json_array_get_object(mem_arr, i);
|
| 120 |
+
JSON_Object *processes = json_object_get_object(root_object, "processes");
|
| 121 |
+
|
| 122 |
+
to_print_value = json_object_get_wrapping_value(processes);
|
| 123 |
+
if (!json_value_equals(to_print_value, json_value_init_object()))
|
| 124 |
+
{
|
| 125 |
+
serialized_string = NULL;
|
| 126 |
+
serialized_string = json_serialize_to_string_pretty(to_print_value);
|
| 127 |
+
puts(serialized_string);
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
void spy_on_waiting()
|
| 133 |
+
{
|
| 134 |
+
|
| 135 |
+
const char *filepath = "/tmp/mmapped_pro_on_waiting.bin";
|
| 136 |
+
|
| 137 |
+
int fd = open(filepath, O_RDONLY, (mode_t)0600);
|
| 138 |
+
|
| 139 |
+
if (fd == -1)
|
| 140 |
+
{
|
| 141 |
+
perror("Error opening file for writing");
|
| 142 |
+
exit(EXIT_FAILURE);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
struct stat fileInfo = {0};
|
| 146 |
+
|
| 147 |
+
if (fstat(fd, &fileInfo) == -1)
|
| 148 |
+
{
|
| 149 |
+
perror("Error getting the file size");
|
| 150 |
+
exit(EXIT_FAILURE);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (fileInfo.st_size == 0)
|
| 154 |
+
{
|
| 155 |
+
fprintf(stderr, "Error: File is empty, nothing to do\n");
|
| 156 |
+
exit(EXIT_FAILURE);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
printf("File size is %ji\n", (intmax_t)fileInfo.st_size);
|
| 160 |
+
|
| 161 |
+
char *map = mmap(0, fileInfo.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
| 162 |
+
if (map == MAP_FAILED)
|
| 163 |
+
{
|
| 164 |
+
close(fd);
|
| 165 |
+
perror("Error mmapping the file");
|
| 166 |
+
exit(EXIT_FAILURE);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
JSON_Value *output_value = NULL;
|
| 170 |
+
output_value = json_parse_string(map);
|
| 171 |
+
char *serialized_string = NULL;
|
| 172 |
+
serialized_string = json_serialize_to_string_pretty(output_value);
|
| 173 |
+
|
| 174 |
+
puts(serialized_string);
|
| 175 |
+
|
| 176 |
+
// Don't forget to free the mmapped memory
|
| 177 |
+
if (munmap(map, fileInfo.st_size) == -1)
|
| 178 |
+
{
|
| 179 |
+
close(fd);
|
| 180 |
+
perror("Error un-mmapping the file");
|
| 181 |
+
exit(EXIT_FAILURE);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
// Un-mmaping doesn't close the file, so we still need to do that.
|
| 185 |
+
close(fd);
|
| 186 |
+
}
|
pool/shard006/C/0117302_xmalloc.c
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* transsip - the telephony network
|
| 3 |
+
* By Daniel Borkmann <daniel@transsip.org>
|
| 4 |
+
* Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
|
| 5 |
+
* Swiss federal institute of technology (ETH Zurich)
|
| 6 |
+
* Subject to the GPL, version 2.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
#include <stdarg.h>
|
| 10 |
+
#include <stdio.h>
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
#include <string.h>
|
| 13 |
+
#include <unistd.h>
|
| 14 |
+
#include <malloc.h>
|
| 15 |
+
|
| 16 |
+
#ifndef SIZE_T_MAX
|
| 17 |
+
# define SIZE_T_MAX ((size_t) ~0)
|
| 18 |
+
#endif
|
| 19 |
+
|
| 20 |
+
#include "compiler.h"
|
| 21 |
+
#include "xmalloc.h"
|
| 22 |
+
#include "strlcpy.h"
|
| 23 |
+
#include "die.h"
|
| 24 |
+
|
| 25 |
+
__hidden void *xmalloc(size_t size)
|
| 26 |
+
{
|
| 27 |
+
void *ptr;
|
| 28 |
+
if (size == 0)
|
| 29 |
+
panic("xmalloc: zero size\n");
|
| 30 |
+
ptr = malloc(size);
|
| 31 |
+
if (ptr == NULL)
|
| 32 |
+
panic("xmalloc: out of memory (allocating %zu bytes)\n", size);
|
| 33 |
+
return ptr;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
__hidden void *xvalloc(size_t size)
|
| 37 |
+
{
|
| 38 |
+
void *ptr;
|
| 39 |
+
if (size == 0)
|
| 40 |
+
panic("xmalloc: zero size\n");
|
| 41 |
+
ptr = valloc(size);
|
| 42 |
+
if (ptr == NULL)
|
| 43 |
+
panic("xvalloc: out of memory (allocating %zu bytes)\n", size);
|
| 44 |
+
return ptr;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
__hidden void *xzmalloc(size_t size)
|
| 48 |
+
{
|
| 49 |
+
void *ptr;
|
| 50 |
+
if (size == 0)
|
| 51 |
+
panic("xzmalloc: zero size\n");
|
| 52 |
+
ptr = malloc(size);
|
| 53 |
+
if (ptr == NULL)
|
| 54 |
+
panic("xzmalloc: out of memory (allocating %zu bytes)\n", size);
|
| 55 |
+
memset(ptr, 0, size);
|
| 56 |
+
return ptr;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
__hidden void *xmalloc_aligned(size_t size, size_t alignment)
|
| 60 |
+
{
|
| 61 |
+
int ret;
|
| 62 |
+
void *ptr;
|
| 63 |
+
if (size == 0)
|
| 64 |
+
panic("xmalloc_aligned: zero size\n");
|
| 65 |
+
ret = posix_memalign(&ptr, alignment, size);
|
| 66 |
+
if (ret != 0)
|
| 67 |
+
panic("xmalloc_aligned: out of memory (allocating %zu bytes)\n",
|
| 68 |
+
size);
|
| 69 |
+
return ptr;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
__hidden void *xmallocz(size_t size)
|
| 73 |
+
{
|
| 74 |
+
void *ptr;
|
| 75 |
+
if (size + 1 < size)
|
| 76 |
+
panic("xmallocz: data too large to fit "
|
| 77 |
+
"into virtual memory space\n");
|
| 78 |
+
ptr = xmalloc(size + 1);
|
| 79 |
+
((char *) ptr)[size] = 0;
|
| 80 |
+
return ptr;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
__hidden void *xmemdupz(const void *data, size_t len)
|
| 84 |
+
{
|
| 85 |
+
return memcpy(xmallocz(len), data, len);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
__hidden void *xrealloc(void *ptr, size_t nmemb, size_t size)
|
| 89 |
+
{
|
| 90 |
+
void *new_ptr;
|
| 91 |
+
size_t new_size = nmemb * size;
|
| 92 |
+
if (new_size == 0)
|
| 93 |
+
panic("xrealloc: zero size\n");
|
| 94 |
+
if (SIZE_T_MAX / nmemb < size)
|
| 95 |
+
panic("xrealloc: nmemb * size > SIZE_T_MAX\n");
|
| 96 |
+
if (ptr == NULL)
|
| 97 |
+
new_ptr = malloc(new_size);
|
| 98 |
+
else
|
| 99 |
+
new_ptr = realloc(ptr, new_size);
|
| 100 |
+
if (new_ptr == NULL)
|
| 101 |
+
panic("xrealloc: out of memory (size %zu bytes)\n", new_size);
|
| 102 |
+
return new_ptr;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
__hidden void xfree(void *ptr)
|
| 106 |
+
{
|
| 107 |
+
if (ptr == NULL)
|
| 108 |
+
panic("xfree: NULL pointer given as argument\n");
|
| 109 |
+
free(ptr);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
__hidden char *xstrdup(const char *str)
|
| 113 |
+
{
|
| 114 |
+
size_t len;
|
| 115 |
+
char *cp;
|
| 116 |
+
len = strlen(str) + 1;
|
| 117 |
+
cp = xmalloc(len);
|
| 118 |
+
strlcpy(cp, str, len);
|
| 119 |
+
return cp;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
__hidden char *xstrndup(const char *str, size_t size)
|
| 123 |
+
{
|
| 124 |
+
size_t len;
|
| 125 |
+
char *cp;
|
| 126 |
+
len = strlen(str) + 1;
|
| 127 |
+
if (size < len)
|
| 128 |
+
len = size;
|
| 129 |
+
cp = xmalloc(len);
|
| 130 |
+
strlcpy(cp, str, len);
|
| 131 |
+
return cp;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
__hidden int xdup(int fd)
|
| 135 |
+
{
|
| 136 |
+
int ret = dup(fd);
|
| 137 |
+
if (ret < 0)
|
| 138 |
+
panic("xdup: dup failed\n");
|
| 139 |
+
return ret;
|
| 140 |
+
}
|
| 141 |
+
|
pool/shard006/C/0117305_pool.c
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include <utillib.h>
|
| 3 |
+
#include <test.h>
|
| 4 |
+
|
| 5 |
+
#define ITEM_COUNT 10
|
| 6 |
+
|
| 7 |
+
typedef struct {
|
| 8 |
+
int data1;
|
| 9 |
+
int data2;
|
| 10 |
+
} my_data_t;
|
| 11 |
+
|
| 12 |
+
void test_do(test_context_t *test)
|
| 13 |
+
{
|
| 14 |
+
pool_ctxt_t pool;
|
| 15 |
+
my_data_t *tmp;
|
| 16 |
+
int i;
|
| 17 |
+
void *buffer[ITEM_COUNT];
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
test_mark(test, "pool functions");
|
| 22 |
+
|
| 23 |
+
test_group_start(test, "Setup and sanity check");
|
| 24 |
+
{
|
| 25 |
+
int ret = pool_init( &pool, sizeof(my_data_t), ITEM_COUNT);
|
| 26 |
+
test_not_equal(test, "could init pool", ret, 0);
|
| 27 |
+
|
| 28 |
+
}
|
| 29 |
+
test_group_end(test);
|
| 30 |
+
|
| 31 |
+
test_group_start(test, "get pool items");
|
| 32 |
+
{
|
| 33 |
+
for(i = 0; i < ITEM_COUNT; i++) {
|
| 34 |
+
buffer[i] = pool_alloc(&pool);
|
| 35 |
+
test_not_null( test, "getting items from pool", buffer[i] );
|
| 36 |
+
if(buffer[i]) {
|
| 37 |
+
tmp = (my_data_t *) buffer[i];
|
| 38 |
+
tmp->data1 = i;
|
| 39 |
+
tmp->data2 = i;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
tmp = pool_alloc(& pool);
|
| 43 |
+
test_null( test, "Pool must be empty", tmp);
|
| 44 |
+
}
|
| 45 |
+
test_group_end(test);
|
| 46 |
+
|
| 47 |
+
test_group_start(test, "return pool items");
|
| 48 |
+
{
|
| 49 |
+
my_data_t *tmp1, *tmp2, *tmp3, *tmp4;
|
| 50 |
+
|
| 51 |
+
/* return two items to pool */
|
| 52 |
+
tmp1 = buffer[0];
|
| 53 |
+
tmp2 = buffer[1];
|
| 54 |
+
|
| 55 |
+
pool_free( &pool, tmp1);
|
| 56 |
+
pool_free( &pool, tmp2);
|
| 57 |
+
|
| 58 |
+
/* now when we allocate we must get the same two back */
|
| 59 |
+
tmp3 = pool_alloc(& pool);
|
| 60 |
+
tmp4 = pool_alloc(& pool);
|
| 61 |
+
|
| 62 |
+
if( (tmp1 == tmp3 && tmp2 == tmp4) || (tmp1 == tmp4 && tmp2 == tmp3) ) {
|
| 63 |
+
/* got them ! */
|
| 64 |
+
} else {
|
| 65 |
+
test_fail(test, "Did not get the freed items back");
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
tmp = pool_alloc(& pool);
|
| 69 |
+
test_null( test, "Pool must be empty (again)", tmp);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
test_group_end(test);
|
| 73 |
+
}
|
| 74 |
+
|
pool/shard006/C/0117309_main.c
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
******************************************************************************
|
| 3 |
+
* @file TIM/TIM_OCActive/main.c
|
| 4 |
+
* @author MCD Application Team
|
| 5 |
+
* @version V1.1.0
|
| 6 |
+
* @date 18-January-2013
|
| 7 |
+
* @brief Main program body
|
| 8 |
+
******************************************************************************
|
| 9 |
+
* @attention
|
| 10 |
+
*
|
| 11 |
+
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
| 12 |
+
*
|
| 13 |
+
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
| 14 |
+
* You may not use this file except in compliance with the License.
|
| 15 |
+
* You may obtain a copy of the License at:
|
| 16 |
+
*
|
| 17 |
+
* http://www.st.com/software_license_agreement_liberty_v2
|
| 18 |
+
*
|
| 19 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 20 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 21 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 22 |
+
* See the License for the specific language governing permissions and
|
| 23 |
+
* limitations under the License.
|
| 24 |
+
*
|
| 25 |
+
******************************************************************************
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
/* Includes ------------------------------------------------------------------*/
|
| 29 |
+
#include "main.h"
|
| 30 |
+
|
| 31 |
+
/** @addtogroup STM32F4xx_StdPeriph_Examples
|
| 32 |
+
* @{
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
/** @addtogroup TIM_OCActive
|
| 36 |
+
* @{
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
/* Private typedef -----------------------------------------------------------*/
|
| 40 |
+
/* Private define ------------------------------------------------------------*/
|
| 41 |
+
/* Private macro -------------------------------------------------------------*/
|
| 42 |
+
/* Private variables ---------------------------------------------------------*/
|
| 43 |
+
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
| 44 |
+
TIM_OCInitTypeDef TIM_OCInitStructure;
|
| 45 |
+
|
| 46 |
+
uint16_t uhCCR1_Val = 1000;
|
| 47 |
+
uint16_t uhCCR2_Val = 500;
|
| 48 |
+
uint16_t uhCCR3_Val = 250;
|
| 49 |
+
uint16_t uhCCR4_Val = 125;
|
| 50 |
+
uint16_t uhPrescalerValue = 0;
|
| 51 |
+
|
| 52 |
+
/* Private function prototypes -----------------------------------------------*/
|
| 53 |
+
static void TIM_Config(void);
|
| 54 |
+
|
| 55 |
+
/* Private functions ---------------------------------------------------------*/
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* @brief Main program
|
| 59 |
+
* @param None
|
| 60 |
+
* @retval None
|
| 61 |
+
*/
|
| 62 |
+
int main(void)
|
| 63 |
+
{
|
| 64 |
+
/*!< At this stage the microcontroller clock setting is already configured,
|
| 65 |
+
this is done through SystemInit() function which is called from startup
|
| 66 |
+
files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to
|
| 67 |
+
application main.
|
| 68 |
+
To reconfigure the default setting of SystemInit() function, refer to
|
| 69 |
+
system_stm32f4xx.c file
|
| 70 |
+
*/
|
| 71 |
+
|
| 72 |
+
/* TIM Configuration */
|
| 73 |
+
TIM_Config();
|
| 74 |
+
|
| 75 |
+
/* Time base default values configuration */
|
| 76 |
+
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
| 77 |
+
|
| 78 |
+
/* Output compare default values configuration */
|
| 79 |
+
TIM_OCStructInit(&TIM_OCInitStructure);
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
/* ---------------------------------------------------------------------------
|
| 83 |
+
TIM3 Configuration: Output Compare Active Mode:
|
| 84 |
+
In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1),
|
| 85 |
+
since APB1 prescaler is different from 1.
|
| 86 |
+
TIM3CLK = 2 * PCLK1
|
| 87 |
+
PCLK1 = HCLK / 4
|
| 88 |
+
=> TIM3CLK = HCLK / 2 = SystemCoreClock /2
|
| 89 |
+
|
| 90 |
+
To get TIM3 counter clock at 2 KHz, the prescaler is computed as follows:
|
| 91 |
+
Prescaler = (TIM3CLK / TIM3 counter clock) - 1
|
| 92 |
+
Prescaler = ((SystemCoreClock /2) /1 KHz) - 1
|
| 93 |
+
|
| 94 |
+
Generate 4 signals with 4 different delays:
|
| 95 |
+
TIM3_CH1 delay = uhCCR1_Val/TIM3 counter clock = 500 ms
|
| 96 |
+
TIM3_CH2 delay = uhCCR2_Val/TIM3 counter clock = 250 ms
|
| 97 |
+
TIM3_CH3 delay = uhCCR3_Val/TIM3 counter clock = 125 ms
|
| 98 |
+
TIM3_CH4 delay = uhCCR4_Val/TIM3 counter clock = 62.5 ms
|
| 99 |
+
|
| 100 |
+
Note:
|
| 101 |
+
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
|
| 102 |
+
Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
|
| 103 |
+
function to update SystemCoreClock variable value. Otherwise, any configuration
|
| 104 |
+
based on this variable will be incorrect.
|
| 105 |
+
|
| 106 |
+
--------------------------------------------------------------------------- */
|
| 107 |
+
|
| 108 |
+
/* Compute the prescaler value */
|
| 109 |
+
uhPrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 2000) - 1;
|
| 110 |
+
|
| 111 |
+
/* Time base configuration */
|
| 112 |
+
TIM_TimeBaseStructure.TIM_Period = 65535;
|
| 113 |
+
TIM_TimeBaseStructure.TIM_Prescaler = uhPrescalerValue;
|
| 114 |
+
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
| 115 |
+
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
| 116 |
+
|
| 117 |
+
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
|
| 118 |
+
|
| 119 |
+
/* Output Compare Active Mode configuration: Channel1 */
|
| 120 |
+
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active;
|
| 121 |
+
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
| 122 |
+
TIM_OCInitStructure.TIM_Pulse = uhCCR1_Val;
|
| 123 |
+
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
|
| 124 |
+
|
| 125 |
+
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
|
| 126 |
+
TIM_ARRPreloadConfig(TIM3, DISABLE);
|
| 127 |
+
/* Output Compare Active Mode configuration: Channel2 */
|
| 128 |
+
TIM_OCInitStructure.TIM_Pulse = uhCCR2_Val;
|
| 129 |
+
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
|
| 130 |
+
|
| 131 |
+
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Disable);
|
| 132 |
+
|
| 133 |
+
/* Output Compare Active Mode configuration: Channel3 */
|
| 134 |
+
TIM_OCInitStructure.TIM_Pulse = uhCCR3_Val;
|
| 135 |
+
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
|
| 136 |
+
|
| 137 |
+
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);
|
| 138 |
+
|
| 139 |
+
/* Output Compare Active Mode configuration: Channel4 */
|
| 140 |
+
TIM_OCInitStructure.TIM_Pulse = uhCCR4_Val;
|
| 141 |
+
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
|
| 142 |
+
|
| 143 |
+
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Disable);
|
| 144 |
+
|
| 145 |
+
/* TIM3 enable counter */
|
| 146 |
+
TIM_Cmd(TIM3, ENABLE);
|
| 147 |
+
|
| 148 |
+
TIM_GenerateEvent(TIM3, TIM_EventSource_Update);
|
| 149 |
+
|
| 150 |
+
/* Turn on LED1 */
|
| 151 |
+
STM_EVAL_LEDOn(LED1);
|
| 152 |
+
|
| 153 |
+
while (1)
|
| 154 |
+
{
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* @brief Configure the TIM3 pins.
|
| 160 |
+
* @param None
|
| 161 |
+
* @retval None
|
| 162 |
+
*/
|
| 163 |
+
static void TIM_Config(void)
|
| 164 |
+
{
|
| 165 |
+
GPIO_InitTypeDef GPIO_InitStructure;
|
| 166 |
+
|
| 167 |
+
/* TIM3 clock enable */
|
| 168 |
+
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
| 169 |
+
|
| 170 |
+
/* GPIOC clock enable */
|
| 171 |
+
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
| 172 |
+
|
| 173 |
+
/* GPIOC Configuration: TIM3 CH1 (PC6), TIM3 CH2 (PC7), TIM3 CH2 (PC8) and TIM3 CH4 (PC9) */
|
| 174 |
+
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
|
| 175 |
+
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
| 176 |
+
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
| 177 |
+
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
| 178 |
+
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
| 179 |
+
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
| 180 |
+
|
| 181 |
+
/* Connect TIM Channels to AF2 */
|
| 182 |
+
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3);
|
| 183 |
+
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM3);
|
| 184 |
+
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
|
| 185 |
+
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3);
|
| 186 |
+
|
| 187 |
+
/* Initialize Leds mounted on STM324xG-EVAL/STM324x7I-EVAL boards */
|
| 188 |
+
STM_EVAL_LEDInit(LED1);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
#ifdef USE_FULL_ASSERT
|
| 192 |
+
|
| 193 |
+
/**
|
| 194 |
+
* @brief Reports the name of the source file and the source line number
|
| 195 |
+
* where the assert_param error has occurred.
|
| 196 |
+
* @param file: pointer to the source file name
|
| 197 |
+
* @param line: assert_param error line source number
|
| 198 |
+
* @retval None
|
| 199 |
+
*/
|
| 200 |
+
void assert_failed(uint8_t* file, uint32_t line)
|
| 201 |
+
{
|
| 202 |
+
/* User can add his own implementation to report the file name and line number,
|
| 203 |
+
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
| 204 |
+
|
| 205 |
+
while (1)
|
| 206 |
+
{}
|
| 207 |
+
}
|
| 208 |
+
#endif
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* @}
|
| 212 |
+
*/
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* @}
|
| 216 |
+
*/
|
| 217 |
+
|
| 218 |
+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
pool/shard006/C/0117311_utent.c
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <unistd.h>
|
| 2 |
+
#include <fcntl.h>
|
| 3 |
+
#include <string.h>
|
| 4 |
+
#include <utmp.h>
|
| 5 |
+
|
| 6 |
+
static const char *utmp_file_name = _PATH_UTMP;
|
| 7 |
+
static int fd = -1;
|
| 8 |
+
static off_t utmp_current = 0;
|
| 9 |
+
|
| 10 |
+
static int lock_record(int type) {
|
| 11 |
+
struct flock fl;
|
| 12 |
+
fl.l_whence = SEEK_CUR;
|
| 13 |
+
fl.l_start = 0;
|
| 14 |
+
fl.l_len = sizeof(struct utmp);
|
| 15 |
+
fl.l_pid = 0;
|
| 16 |
+
fl.l_type = type;
|
| 17 |
+
return fcntl(fd, F_SETLKW, &fl);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
static int unlock_record() {
|
| 21 |
+
struct flock fl;
|
| 22 |
+
fl.l_whence = SEEK_CUR;
|
| 23 |
+
fl.l_start = -sizeof(struct utmp);
|
| 24 |
+
fl.l_len = sizeof(struct utmp);
|
| 25 |
+
fl.l_pid = 0;
|
| 26 |
+
fl.l_type = F_UNLCK;
|
| 27 |
+
return fcntl(fd, F_SETLK, &fl);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void utmpname(const char *file) {
|
| 31 |
+
if (file)
|
| 32 |
+
utmp_file_name = file;
|
| 33 |
+
else
|
| 34 |
+
utmp_file_name = _PATH_UTMP;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void setutent() {
|
| 38 |
+
if (fd<0) fd = open(utmp_file_name,O_RDWR);
|
| 39 |
+
if (fd<0) fd = open(utmp_file_name,O_RDONLY);
|
| 40 |
+
fcntl (fd, F_SETFD, FD_CLOEXEC);
|
| 41 |
+
utmp_current = lseek(fd,0,SEEK_SET);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void endutent() {
|
| 45 |
+
if (fd<0) return;
|
| 46 |
+
close(fd); fd=-1;
|
| 47 |
+
utmp_current = 0;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
struct utmp *getutent(void) {
|
| 51 |
+
static struct utmp getutent_tmp;
|
| 52 |
+
ssize_t ret;
|
| 53 |
+
|
| 54 |
+
if (fd<0) {
|
| 55 |
+
setutent();
|
| 56 |
+
if (fd<0) return 0;
|
| 57 |
+
}
|
| 58 |
+
utmp_current = lseek (fd, 0, SEEK_CUR);
|
| 59 |
+
if (lock_record(F_RDLCK)) return 0;
|
| 60 |
+
ret=read(fd, &getutent_tmp, sizeof(struct utmp));
|
| 61 |
+
unlock_record();
|
| 62 |
+
if (ret<1) return 0;
|
| 63 |
+
return &getutent_tmp;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
struct utmp *getutid(struct utmp *ut) {
|
| 67 |
+
struct utmp *tmp;
|
| 68 |
+
|
| 69 |
+
while ((tmp = getutent())) {
|
| 70 |
+
if (ut->ut_type && (ut->ut_type <= OLD_TIME)) {
|
| 71 |
+
if (ut->ut_type == tmp->ut_type) break;
|
| 72 |
+
}
|
| 73 |
+
if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) {
|
| 74 |
+
if (!strncmp(ut->ut_id,tmp->ut_id,4)) break;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
return tmp;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
struct utmp *getutline(struct utmp *ut) {
|
| 81 |
+
struct utmp *tmp;
|
| 82 |
+
|
| 83 |
+
while ((tmp = getutent())) {
|
| 84 |
+
if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) {
|
| 85 |
+
if (!strncmp(ut->ut_line,tmp->ut_line,UT_LINESIZE)) break;
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
return tmp;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
void pututline(struct utmp *ut) {
|
| 92 |
+
struct utmp *tmp;
|
| 93 |
+
|
| 94 |
+
/* Seek to the current record before searching. */
|
| 95 |
+
lseek (fd, utmp_current, SEEK_SET);
|
| 96 |
+
if ((tmp = getutid(ut))) {
|
| 97 |
+
lseek(fd, - (off_t)sizeof(struct utmp), SEEK_CUR);
|
| 98 |
+
if (lock_record(F_WRLCK)) return;
|
| 99 |
+
write(fd, ut, sizeof(struct utmp));
|
| 100 |
+
utmp_current += sizeof(struct utmp);
|
| 101 |
+
}
|
| 102 |
+
else {
|
| 103 |
+
utmp_current = lseek(fd, 0, SEEK_END);
|
| 104 |
+
if (lock_record(F_WRLCK)) return;
|
| 105 |
+
write(fd, ut, sizeof(struct utmp));
|
| 106 |
+
}
|
| 107 |
+
unlock_record();
|
| 108 |
+
}
|
| 109 |
+
|
pool/shard006/C/0117315_tclLoadDld.c
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* tclLoadDld.c --
|
| 3 |
+
*
|
| 4 |
+
* This procedure provides a version of the TclLoadFile that
|
| 5 |
+
* works with the "dld_link" and "dld_get_func" library procedures
|
| 6 |
+
* for dynamic loading. It has been tested on Linux 1.1.95 and
|
| 7 |
+
* dld-3.2.7. This file probably isn't needed anymore, since it
|
| 8 |
+
* makes more sense to use "dl_open" etc.
|
| 9 |
+
*
|
| 10 |
+
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
|
| 11 |
+
*
|
| 12 |
+
* See the file "license.terms" for information on usage and redistribution
|
| 13 |
+
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
| 14 |
+
*
|
| 15 |
+
* RCS: @(#) $Id$
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "tclInt.h"
|
| 19 |
+
#include "dld.h"
|
| 20 |
+
|
| 21 |
+
/*
|
| 22 |
+
* In some systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined
|
| 23 |
+
* and this argument to dlopen must always be 1.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#ifndef RTLD_NOW
|
| 27 |
+
# define RTLD_NOW 1
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
/*
|
| 31 |
+
*----------------------------------------------------------------------
|
| 32 |
+
*
|
| 33 |
+
* TclpLoadFile --
|
| 34 |
+
*
|
| 35 |
+
* Dynamically loads a binary code file into memory and returns
|
| 36 |
+
* the addresses of two procedures within that file, if they
|
| 37 |
+
* are defined.
|
| 38 |
+
*
|
| 39 |
+
* Results:
|
| 40 |
+
* A standard Tcl completion code. If an error occurs, an error
|
| 41 |
+
* message is left in the interp's result. *proc1Ptr and *proc2Ptr
|
| 42 |
+
* are filled in with the addresses of the symbols given by
|
| 43 |
+
* *sym1 and *sym2, or NULL if those symbols can't be found.
|
| 44 |
+
*
|
| 45 |
+
* Side effects:
|
| 46 |
+
* New code suddenly appears in memory.
|
| 47 |
+
*
|
| 48 |
+
*----------------------------------------------------------------------
|
| 49 |
+
*/
|
| 50 |
+
|
| 51 |
+
int
|
| 52 |
+
TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr)
|
| 53 |
+
Tcl_Interp *interp; /* Used for error reporting. */
|
| 54 |
+
char *fileName; /* Name of the file containing the desired
|
| 55 |
+
* code. */
|
| 56 |
+
char *sym1, *sym2; /* Names of two procedures to look up in
|
| 57 |
+
* the file's symbol table. */
|
| 58 |
+
Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
|
| 59 |
+
/* Where to return the addresses corresponding
|
| 60 |
+
* to sym1 and sym2. */
|
| 61 |
+
ClientData *clientDataPtr; /* Filled with token for dynamically loaded
|
| 62 |
+
* file which will be passed back to
|
| 63 |
+
* TclpUnloadFile() to unload the file. */
|
| 64 |
+
{
|
| 65 |
+
static int firstTime = 1;
|
| 66 |
+
int returnCode;
|
| 67 |
+
|
| 68 |
+
/*
|
| 69 |
+
* The dld package needs to know the pathname to the tcl binary.
|
| 70 |
+
* If that's not know, return an error.
|
| 71 |
+
*/
|
| 72 |
+
|
| 73 |
+
if (firstTime) {
|
| 74 |
+
if (tclExecutableName == NULL) {
|
| 75 |
+
Tcl_SetResult(interp,
|
| 76 |
+
"don't know name of application binary file, so can't initialize dynamic loader",
|
| 77 |
+
TCL_STATIC);
|
| 78 |
+
return TCL_ERROR;
|
| 79 |
+
}
|
| 80 |
+
returnCode = dld_init(tclExecutableName);
|
| 81 |
+
if (returnCode != 0) {
|
| 82 |
+
Tcl_AppendResult(interp,
|
| 83 |
+
"initialization failed for dynamic loader: ",
|
| 84 |
+
dld_strerror(returnCode), (char *) NULL);
|
| 85 |
+
return TCL_ERROR;
|
| 86 |
+
}
|
| 87 |
+
firstTime = 0;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
if ((returnCode = dld_link(fileName)) != 0) {
|
| 91 |
+
Tcl_AppendResult(interp, "couldn't load file \"", fileName,
|
| 92 |
+
"\": ", dld_strerror(returnCode), (char *) NULL);
|
| 93 |
+
return TCL_ERROR;
|
| 94 |
+
}
|
| 95 |
+
*proc1Ptr = (Tcl_PackageInitProc *) dld_get_func(sym1);
|
| 96 |
+
*proc2Ptr = (Tcl_PackageInitProc *) dld_get_func(sym2);
|
| 97 |
+
*clientDataPtr = strcpy(
|
| 98 |
+
(char *) ckalloc((unsigned) (strlen(fileName) + 1)), fileName);
|
| 99 |
+
return TCL_OK;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/*
|
| 103 |
+
*----------------------------------------------------------------------
|
| 104 |
+
*
|
| 105 |
+
* TclpUnloadFile --
|
| 106 |
+
*
|
| 107 |
+
* Unloads a dynamically loaded binary code file from memory.
|
| 108 |
+
* Code pointers in the formerly loaded file are no longer valid
|
| 109 |
+
* after calling this function.
|
| 110 |
+
*
|
| 111 |
+
* Results:
|
| 112 |
+
* None.
|
| 113 |
+
*
|
| 114 |
+
* Side effects:
|
| 115 |
+
* Code removed from memory.
|
| 116 |
+
*
|
| 117 |
+
*----------------------------------------------------------------------
|
| 118 |
+
*/
|
| 119 |
+
|
| 120 |
+
void
|
| 121 |
+
TclpUnloadFile(clientData)
|
| 122 |
+
ClientData clientData; /* ClientData returned by a previous call
|
| 123 |
+
* to TclpLoadFile(). The clientData is
|
| 124 |
+
* a token that represents the loaded
|
| 125 |
+
* file. */
|
| 126 |
+
{
|
| 127 |
+
char *fileName;
|
| 128 |
+
|
| 129 |
+
handle = (char *) clientData;
|
| 130 |
+
dld_unlink_by_file(handle, 0);
|
| 131 |
+
ckfree(handle);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/*
|
| 135 |
+
*----------------------------------------------------------------------
|
| 136 |
+
*
|
| 137 |
+
* TclGuessPackageName --
|
| 138 |
+
*
|
| 139 |
+
* If the "load" command is invoked without providing a package
|
| 140 |
+
* name, this procedure is invoked to try to figure it out.
|
| 141 |
+
*
|
| 142 |
+
* Results:
|
| 143 |
+
* Always returns 0 to indicate that we couldn't figure out a
|
| 144 |
+
* package name; generic code will then try to guess the package
|
| 145 |
+
* from the file name. A return value of 1 would have meant that
|
| 146 |
+
* we figured out the package name and put it in bufPtr.
|
| 147 |
+
*
|
| 148 |
+
* Side effects:
|
| 149 |
+
* None.
|
| 150 |
+
*
|
| 151 |
+
*----------------------------------------------------------------------
|
| 152 |
+
*/
|
| 153 |
+
|
| 154 |
+
int
|
| 155 |
+
TclGuessPackageName(fileName, bufPtr)
|
| 156 |
+
char *fileName; /* Name of file containing package (already
|
| 157 |
+
* translated to local form if needed). */
|
| 158 |
+
Tcl_DString *bufPtr; /* Initialized empty dstring. Append
|
| 159 |
+
* package name to this if possible. */
|
| 160 |
+
{
|
| 161 |
+
return 0;
|
| 162 |
+
}
|
| 163 |
+
|
pool/shard006/C/0117317_div.c
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* libx/div.c
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include <div.h>
|
| 6 |
+
|
| 7 |
+
static const unsigned char byte_reverse_table[] = {
|
| 8 |
+
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
| 9 |
+
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
| 10 |
+
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
| 11 |
+
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
| 12 |
+
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
| 13 |
+
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
| 14 |
+
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
| 15 |
+
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
| 16 |
+
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
| 17 |
+
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
| 18 |
+
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
| 19 |
+
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
| 20 |
+
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
| 21 |
+
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
| 22 |
+
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
| 23 |
+
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
static inline u32_t do_fls64(u64_t value)
|
| 27 |
+
{
|
| 28 |
+
u32_t num_bits = 0;
|
| 29 |
+
if(value & 0xFFFF000000000000ULL)
|
| 30 |
+
{
|
| 31 |
+
num_bits += 16;
|
| 32 |
+
value = value >> 16;
|
| 33 |
+
}
|
| 34 |
+
if(value & 0x0000FFFF00000000ULL)
|
| 35 |
+
{
|
| 36 |
+
num_bits += 16;
|
| 37 |
+
value = value >> 16;
|
| 38 |
+
}
|
| 39 |
+
if(value & 0x00000000FFFF0000ULL)
|
| 40 |
+
{
|
| 41 |
+
num_bits += 16;
|
| 42 |
+
value = value >> 16;
|
| 43 |
+
}
|
| 44 |
+
if(value & 0x000000000000FF00ULL)
|
| 45 |
+
{
|
| 46 |
+
num_bits += 8;
|
| 47 |
+
value = value >> 8;
|
| 48 |
+
}
|
| 49 |
+
if(value & 0x00000000000000F0ULL)
|
| 50 |
+
{
|
| 51 |
+
num_bits += 4;
|
| 52 |
+
value = value >> 4;
|
| 53 |
+
}
|
| 54 |
+
if(value & 0x000000000000000CULL)
|
| 55 |
+
{
|
| 56 |
+
num_bits += 2;
|
| 57 |
+
value = value >> 2;
|
| 58 |
+
}
|
| 59 |
+
if(value & 0x0000000000000003ULL)
|
| 60 |
+
{
|
| 61 |
+
num_bits += 2;
|
| 62 |
+
value = value >> 2;
|
| 63 |
+
}
|
| 64 |
+
return num_bits;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
u64_t do_udiv64(u64_t dividend, u64_t divisor, u64_t * remainder)
|
| 68 |
+
{
|
| 69 |
+
u64_t quotient, remaind;
|
| 70 |
+
u32_t num_bits;
|
| 71 |
+
register u8_t * p, * q;
|
| 72 |
+
|
| 73 |
+
if(divisor == 0)
|
| 74 |
+
{
|
| 75 |
+
while(1);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if(dividend <= divisor)
|
| 79 |
+
{
|
| 80 |
+
remaind = divisor - dividend;
|
| 81 |
+
if(remainder)
|
| 82 |
+
{
|
| 83 |
+
*remainder = (remaind) ? dividend : 0;
|
| 84 |
+
}
|
| 85 |
+
return (remaind) ? 0 : 1;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
remaind = 0;
|
| 89 |
+
num_bits = do_fls64(dividend);
|
| 90 |
+
dividend = dividend << (64 - num_bits);
|
| 91 |
+
p = (u8_t *) ÷nd;
|
| 92 |
+
q = (u8_t *) "ient;
|
| 93 |
+
q[7] = byte_reverse_table[p[0]];
|
| 94 |
+
q[6] = byte_reverse_table[p[1]];
|
| 95 |
+
q[5] = byte_reverse_table[p[2]];
|
| 96 |
+
q[4] = byte_reverse_table[p[3]];
|
| 97 |
+
q[3] = byte_reverse_table[p[4]];
|
| 98 |
+
q[2] = byte_reverse_table[p[5]];
|
| 99 |
+
q[1] = byte_reverse_table[p[6]];
|
| 100 |
+
q[0] = byte_reverse_table[p[7]];
|
| 101 |
+
dividend = quotient;
|
| 102 |
+
quotient = 0;
|
| 103 |
+
|
| 104 |
+
while(num_bits)
|
| 105 |
+
{
|
| 106 |
+
remaind = (remaind << 1) | (dividend & 0x1);
|
| 107 |
+
dividend = dividend >> 1;
|
| 108 |
+
if(remaind < divisor)
|
| 109 |
+
{
|
| 110 |
+
quotient = ((quotient) << 1) | 0;
|
| 111 |
+
}
|
| 112 |
+
else
|
| 113 |
+
{
|
| 114 |
+
quotient = ((quotient) << 1) | 1;
|
| 115 |
+
remaind = remaind - divisor;
|
| 116 |
+
}
|
| 117 |
+
num_bits--;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if(remainder)
|
| 121 |
+
{
|
| 122 |
+
*remainder = remaind;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return quotient;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
static inline u32_t do_fls32(u32_t value)
|
| 129 |
+
{
|
| 130 |
+
u32_t num_bits = 0;
|
| 131 |
+
if(value & 0xFFFF0000)
|
| 132 |
+
{
|
| 133 |
+
num_bits += 16;
|
| 134 |
+
value = value >> 16;
|
| 135 |
+
}
|
| 136 |
+
if(value & 0x0000FF00)
|
| 137 |
+
{
|
| 138 |
+
num_bits += 8;
|
| 139 |
+
value = value >> 8;
|
| 140 |
+
}
|
| 141 |
+
if(value & 0x000000F0)
|
| 142 |
+
{
|
| 143 |
+
num_bits += 4;
|
| 144 |
+
value = value >> 4;
|
| 145 |
+
}
|
| 146 |
+
if(value & 0x0000000C)
|
| 147 |
+
{
|
| 148 |
+
num_bits += 2;
|
| 149 |
+
value = value >> 2;
|
| 150 |
+
}
|
| 151 |
+
if(value & 0x00000003)
|
| 152 |
+
{
|
| 153 |
+
num_bits += 2;
|
| 154 |
+
value = value >> 2;
|
| 155 |
+
}
|
| 156 |
+
return num_bits;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
u32_t do_udiv32(u32_t dividend, u32_t divisor, u32_t * remainder)
|
| 160 |
+
{
|
| 161 |
+
register u8_t *p, *q;
|
| 162 |
+
u32_t num_bits, quotient, remaind;
|
| 163 |
+
|
| 164 |
+
if(divisor == 0)
|
| 165 |
+
{
|
| 166 |
+
while(1)
|
| 167 |
+
;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
if(dividend <= divisor)
|
| 171 |
+
{
|
| 172 |
+
remaind = divisor - dividend;
|
| 173 |
+
if(remainder)
|
| 174 |
+
{
|
| 175 |
+
*remainder = (remaind) ? dividend : 0;
|
| 176 |
+
}
|
| 177 |
+
return (remaind) ? 0 : 1;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
remaind = 0;
|
| 181 |
+
num_bits = do_fls32(dividend);
|
| 182 |
+
dividend = dividend << (32 - num_bits);
|
| 183 |
+
p = (u8_t *) ÷nd;
|
| 184 |
+
q = (u8_t *) "ient;
|
| 185 |
+
q[3] = byte_reverse_table[p[0]];
|
| 186 |
+
q[2] = byte_reverse_table[p[1]];
|
| 187 |
+
q[1] = byte_reverse_table[p[2]];
|
| 188 |
+
q[0] = byte_reverse_table[p[3]];
|
| 189 |
+
dividend = quotient;
|
| 190 |
+
quotient = 0;
|
| 191 |
+
|
| 192 |
+
while(num_bits)
|
| 193 |
+
{
|
| 194 |
+
remaind = (remaind << 1) | (dividend & 0x1);
|
| 195 |
+
dividend = dividend >> 1;
|
| 196 |
+
if(remaind < divisor)
|
| 197 |
+
{
|
| 198 |
+
quotient = ((quotient) << 1) | 0;
|
| 199 |
+
}
|
| 200 |
+
else
|
| 201 |
+
{
|
| 202 |
+
quotient = ((quotient) << 1) | 1;
|
| 203 |
+
remaind = remaind - divisor;
|
| 204 |
+
}
|
| 205 |
+
num_bits--;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
if(remainder)
|
| 209 |
+
{
|
| 210 |
+
*remainder = remaind;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
return quotient;
|
| 214 |
+
}
|